From 299c10061762f30c8280605f2fa3b9703c9c4bdf Mon Sep 17 00:00:00 2001 From: hwzhangchuang Date: Wed, 7 Feb 2024 00:23:34 +0800 Subject: [PATCH] modify unprepare bug Signed-off-by: hwzhangchuang --- common/include/input_hub.cpp | 13 +++++++++++++ common/include/input_hub.h | 1 + .../include/distributed_input_collector.h | 1 + .../src/distributed_input_collector.cpp | 5 +++++ .../src/distributed_input_sink_manager.cpp | 10 ++++++++-- .../distributed_input_source_transport.h | 2 -- .../src/distributed_input_source_transport.cpp | 18 ------------------ .../distributed_input_sourcetrans_test.cpp | 7 ------- utils/include/dinput_utils_tool.h | 2 ++ utils/src/dinput_utils_tool.cpp | 18 ++++++++++++++++++ 10 files changed, 48 insertions(+), 29 deletions(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index 5a75651..2f80ca2 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -1210,6 +1210,19 @@ AffectDhIds InputHub::SetSharingDevices(bool enabled, std::vector d return affDhIds; } +std::vector InputHub::GetSharingDevices() +{ + std::vector sharingDevices; + std::lock_guard deviceLock(devicesMutex_); + for (const auto &[id, device] : devices_) { + if (device->isShare) { + DHLOGI("Find sharing dhid: %s", GetAnonyString(device->identifier.descriptor).c_str()); + sharingDevices.push_back(device->identifier.descriptor); + } + } + return sharingDevices; +} + void InputHub::GetSharedMousePathByDhId(const std::vector &dhIds, std::string &sharedMousePath, std::string &sharedMouseDhId) { diff --git a/common/include/input_hub.h b/common/include/input_hub.h index 4d31827..6e7f67d 100644 --- a/common/include/input_hub.h +++ b/common/include/input_hub.h @@ -87,6 +87,7 @@ public: AffectDhIds SetSupportInputType(bool enabled, const uint32_t &inputTypes); // return efftive dhids AffectDhIds SetSharingDevices(bool enabled, std::vector dhIds); + std::vector GetSharingDevices(); void GetDevicesInfoByType(const uint32_t inputTypes, std::map &datas); void GetDevicesInfoByDhId(std::vector dhidsVec, std::map &datas); void GetSharedMousePathByDhId(const std::vector &dhIds, std::string &sharedMousePath, diff --git a/services/sink/inputcollector/include/distributed_input_collector.h b/services/sink/inputcollector/include/distributed_input_collector.h index 351326a..c49b722 100644 --- a/services/sink/inputcollector/include/distributed_input_collector.h +++ b/services/sink/inputcollector/include/distributed_input_collector.h @@ -45,6 +45,7 @@ public: void StopCollectionThread(); AffectDhIds SetSharingTypes(bool enabled, const uint32_t &inputType); AffectDhIds SetSharingDhIds(bool enabled, std::vector dhIds); + std::vector GetSharingDhIds(); void GetMouseNodePath(const std::vector &dhIds, std::string &mouseNodePath, std::string &dhid); void GetSharedKeyboardPathsByDhIds(const std::vector &dhIds, std::vector &sharedKeyboardPaths, std::vector &sharedKeyboardDhIds); diff --git a/services/sink/inputcollector/src/distributed_input_collector.cpp b/services/sink/inputcollector/src/distributed_input_collector.cpp index 48e05d9..02895ff 100644 --- a/services/sink/inputcollector/src/distributed_input_collector.cpp +++ b/services/sink/inputcollector/src/distributed_input_collector.cpp @@ -211,6 +211,11 @@ AffectDhIds DistributedInputCollector::SetSharingDhIds(bool enabled, std::vector return inputHub_->SetSharingDevices(enabled, dhIds); } +std::vector DistributedInputCollector::GetSharingDhIds() +{ + return inputHub_->GetSharingDevices(); +} + void DistributedInputCollector::GetMouseNodePath(const std::vector &dhIds, std::string &mouseNodePath, std::string &dhId) { diff --git a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp index c5126bd..21aa808 100644 --- a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp +++ b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp @@ -144,7 +144,10 @@ void DistributedInputSinkManager::DInputSinkListener::OnPrepareRemoteInput( void DistributedInputSinkManager::DInputSinkListener::OnUnprepareRemoteInput(const int32_t &sessionId) { DHLOGI("OnUnprepareRemoteInput called, sessionId: %d", sessionId); - OnStopRemoteInput(sessionId, static_cast(DInputDeviceType::ALL)); + std::vector sharingDhIds = DistributedInputCollector::GetInstance().GetSharingDhIds(); + if (!sharingDhIds.empty()) { + OnStopRemoteInputDhid(sessionId, JointDhIds(sharingDhIds)); + } DistributedInputSinkSwitch::GetInstance().RemoveSession(sessionId); nlohmann::json jsonStr; @@ -176,7 +179,10 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayUnprepareRemoteInpu { DHLOGI("OnRelayUnprepareRemoteInput called, toSinkSessionId: %d, devId: %s", toSinkSessionId, GetAnonyString(deviceId).c_str()); - OnStopRemoteInput(toSinkSessionId, static_cast(DInputDeviceType::ALL)); + std::vector sharingDhIds = DistributedInputCollector::GetInstance().GetSharingDhIds(); + if (!sharingDhIds.empty()) { + OnStopRemoteInputDhid(toSinkSessionId, JointDhIds(sharingDhIds)); + } DistributedInputSinkSwitch::GetInstance().RemoveSession(toSinkSessionId); nlohmann::json jsonStr; diff --git a/services/source/transport/include/distributed_input_source_transport.h b/services/source/transport/include/distributed_input_source_transport.h index 88bcba6..86b790c 100644 --- a/services/source/transport/include/distributed_input_source_transport.h +++ b/services/source/transport/include/distributed_input_source_transport.h @@ -135,8 +135,6 @@ private: void ReceiveRelayStopTypeResult(int32_t sessionId, const nlohmann::json &recMsg); void CalculateLatency(int32_t sessionId, const nlohmann::json &recMsg); - std::string JointDhIds(const std::vector &dhids); - std::vector SplitDhIdString(const std::string &dhIdsString); void RegRespFunMap(); void ResetKeyboardKeyState(const std::string &deviceId, const std::vector &dhids); diff --git a/services/source/transport/src/distributed_input_source_transport.cpp b/services/source/transport/src/distributed_input_source_transport.cpp index ceea71e..b86e999 100644 --- a/services/source/transport/src/distributed_input_source_transport.cpp +++ b/services/source/transport/src/distributed_input_source_transport.cpp @@ -15,7 +15,6 @@ #include "distributed_input_source_transport.h" -#include #include #include @@ -40,7 +39,6 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { namespace { - const char DHID_SPLIT = '.'; const uint64_t MSG_LATENCY_ALARM_US = 20 * 1000; } DistributedInputSourceTransport::~DistributedInputSourceTransport() @@ -893,22 +891,6 @@ int32_t DistributedInputSourceTransport::SendRelayStopTypeRequest(const std::str return DH_SUCCESS; } -std::string DistributedInputSourceTransport::JointDhIds(const std::vector &dhids) -{ - if (dhids.size() <= 0) { - return ""; - } - auto dotFold = [](std::string a, std::string b) {return std::move(a) + DHID_SPLIT + std::move(b);}; - return std::accumulate(std::next(dhids.begin()), dhids.end(), dhids[0], dotFold); -} - -std::vector DistributedInputSourceTransport::SplitDhIdString(const std::string &dhIdsString) -{ - std::vector dhIdsVec; - SplitStringToVector(dhIdsString, DHID_SPLIT, dhIdsVec); - return dhIdsVec; -} - int32_t DistributedInputSourceTransport::SendMessage(int32_t sessionId, std::string &message) { return DistributedInputTransportBase::GetInstance().SendMsg(sessionId, message); diff --git a/services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.cpp b/services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.cpp index dd7b41d..8490740 100644 --- a/services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.cpp +++ b/services/source/transport/test/sourcetransunittest/distributed_input_sourcetrans_test.cpp @@ -483,13 +483,6 @@ HWTEST_F(DistributedInputSourceTransTest, SendRelayStopTypeRequest_02, testing:: EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL, ret); } -HWTEST_F(DistributedInputSourceTransTest, JointDhIds01, testing::ext::TestSize.Level0) -{ - std::vector dhids; - std::string ret = DistributedInputSourceTransport::GetInstance().JointDhIds(dhids); - EXPECT_EQ("", ret); -} - HWTEST_F(DistributedInputSourceTransTest, NotifyResponsePrepareRemoteInput01, testing::ext::TestSize.Level0) { int32_t sessionId = 0; diff --git a/utils/include/dinput_utils_tool.h b/utils/include/dinput_utils_tool.h index 15ab0ad..8944eba 100644 --- a/utils/include/dinput_utils_tool.h +++ b/utils/include/dinput_utils_tool.h @@ -66,6 +66,8 @@ void ResetVirtualDevicePressedKeys(const std::vector &nodePaths); std::string GetString(const std::vector &vec); int32_t GetRandomInt32(); +std::string JointDhIds(const std::vector &dhids); +std::vector SplitDhIdString(const std::string &dhIdsString); } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/src/dinput_utils_tool.cpp b/utils/src/dinput_utils_tool.cpp index a457c4f..6bf0655 100644 --- a/utils/src/dinput_utils_tool.cpp +++ b/utils/src/dinput_utils_tool.cpp @@ -15,6 +15,7 @@ #include "dinput_utils_tool.h" +#include #include #include #include @@ -52,6 +53,7 @@ namespace { constexpr uint32_t ERROR_MSG_MAX_LEN = 256; constexpr int32_t MAX_RETRY_COUNT = 3; constexpr uint32_t SLEEP_TIME_US = 10 * 1000; + constexpr char DHID_SPLIT = '.'; } DevInfo GetLocalDeviceInfo() { @@ -445,6 +447,22 @@ int32_t GetRandomInt32() std::uniform_int_distribution distribution(0, INT32_MAX); return distribution(engine); } + +std::string JointDhIds(const std::vector &dhids) +{ + if (dhids.size() <= 0) { + return ""; + } + auto dotFold = [](std::string a, std::string b) {return std::move(a) + DHID_SPLIT + std::move(b);}; + return std::accumulate(std::next(dhids.begin()), dhids.end(), dhids[0], dotFold); +} + +std::vector SplitDhIdString(const std::string &dhIdsString) +{ + std::vector dhIdsVec; + SplitStringToVector(dhIdsString, DHID_SPLIT, dhIdsVec); + return dhIdsVec; +} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file -- Gitee