From fd51a1723ff2d389e3c1e9fb1f0a26477720e356 Mon Sep 17 00:00:00 2001 From: l30054665 Date: Fri, 15 Dec 2023 09:25:22 +0800 Subject: [PATCH] resolve DTS2023121217154 Signed-off-by: l30054665 --- common/include/input_hub.cpp | 12 +++++++++++- .../include/distributed_input_collector.h | 4 ++-- .../src/distributed_input_collector.cpp | 4 ++-- .../distributed_input_collector_test.cpp | 6 +++--- .../src/distributed_input_sink_manager.cpp | 6 +++--- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index e243ab4..919cab5 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -532,7 +532,6 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string &devicePath) int fd = OpenInputDeviceFdByPath(devicePath); if (fd == UN_INIT_FD_VALUE) { DHLOGE("The fd open failed, devicePath %s.", devicePath.c_str()); - RecordSkipDevicePath(devicePath); return ERR_DH_INPUT_HUB_OPEN_DEVICEPATH_FAIL; } @@ -1560,6 +1559,17 @@ void InputHub::ClearDeviceStates() { DHLOGI("Clear Device state"); DInputState::GetInstance().ClearDeviceStates(); + CloseAllDevicesLocked(); + { + std::lock_guard deviceLock(devicesMutex_); + openingDevices_.clear(); + closingDevices_.clear(); + sharedDHIds_.clear(); + } + { + std::lock_guard lock(skipDevicePathsMutex_); + skipDevicePaths_.clear(); + } } InputHub::Device::Device(int fd, const std::string &path) diff --git a/services/sink/inputcollector/include/distributed_input_collector.h b/services/sink/inputcollector/include/distributed_input_collector.h index 5d49ef5..2b9820b 100644 --- a/services/sink/inputcollector/include/distributed_input_collector.h +++ b/services/sink/inputcollector/include/distributed_input_collector.h @@ -41,8 +41,8 @@ public: // PreInit for get the local input devices basic info. // Collect all the local input basic info cost too much time(200+ ms). void PreInit(); - int32_t Init(std::shared_ptr sinkHandler); - void Release(); + int32_t StartCollectionThread(std::shared_ptr sinkHandler); + void StopCollectionThread(); AffectDhIds SetSharingTypes(bool enabled, const uint32_t &inputType); AffectDhIds SetSharingDhIds(bool enabled, std::vector dhIds); void GetMouseNodePath(const std::vector &dhIds, std::string &mouseNodePath, std::string &dhid); diff --git a/services/sink/inputcollector/src/distributed_input_collector.cpp b/services/sink/inputcollector/src/distributed_input_collector.cpp index bd33f4f..ac49003 100644 --- a/services/sink/inputcollector/src/distributed_input_collector.cpp +++ b/services/sink/inputcollector/src/distributed_input_collector.cpp @@ -59,7 +59,7 @@ void DistributedInputCollector::PreInit() inputHub_->RecordDeviceStates(); } -int32_t DistributedInputCollector::Init(std::shared_ptr sinkHandler) +int32_t DistributedInputCollector::StartCollectionThread(std::shared_ptr sinkHandler) { sinkHandler_ = sinkHandler; if (sinkHandler_ == nullptr || inputHub_ == nullptr) { @@ -201,7 +201,7 @@ void DistributedInputCollector::ReportDhIdSharingState(const AffectDhIds &dhIds) } } -void DistributedInputCollector::Release() +void DistributedInputCollector::StopCollectionThread() { StopCollectEventsThread(); } diff --git a/services/sink/inputcollector/test/sinkcollectorunittest/distributed_input_collector_test.cpp b/services/sink/inputcollector/test/sinkcollectorunittest/distributed_input_collector_test.cpp index 6568284..0c2d5ef 100644 --- a/services/sink/inputcollector/test/sinkcollectorunittest/distributed_input_collector_test.cpp +++ b/services/sink/inputcollector/test/sinkcollectorunittest/distributed_input_collector_test.cpp @@ -29,7 +29,7 @@ void DistributedInputCollectorTest::SetUp() void DistributedInputCollectorTest::TearDown() { - DistributedInputCollector::GetInstance().Release(); + DistributedInputCollector::GetInstance().StopCollectionThread(); } void DistributedInputCollectorTest::SetUpTestCase() @@ -54,7 +54,7 @@ void DistributedInputCollectorTest::DInputSinkCollectorEventHandler::ProcessEven HWTEST_F(DistributedInputCollectorTest, Init01, testing::ext::TestSize.Level1) { std::shared_ptr eventHandler_ = nullptr; - int32_t ret = DistributedInputCollector::GetInstance().Init(eventHandler_); + int32_t ret = DistributedInputCollector::GetInstance().StartCollectionThread(eventHandler_); EXPECT_EQ(ERR_DH_INPUT_SERVER_SINK_COLLECTOR_INIT_FAIL, ret); } @@ -64,7 +64,7 @@ HWTEST_F(DistributedInputCollectorTest, Init02, testing::ext::TestSize.Level1) std::shared_ptr eventHandler_ = std::make_shared(runner); - int32_t ret = DistributedInputCollector::GetInstance().Init(eventHandler_); + int32_t ret = DistributedInputCollector::GetInstance().StartCollectionThread(eventHandler_); EXPECT_EQ(DH_SUCCESS, ret); } diff --git a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp index d600479..acc3674 100644 --- a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp +++ b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp @@ -132,7 +132,7 @@ void DistributedInputSinkManager::DInputSinkListener::OnPrepareRemoteInput( nlohmann::json jsonStr; jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONPREPARE; std::string smsg = ""; - int32_t ret = DistributedInputCollector::GetInstance().Init( + int32_t ret = DistributedInputCollector::GetInstance().StartCollectionThread( DistributedInputSinkTransport::GetInstance().GetEventHandler()); if (ret != DH_SUCCESS) { DHLOGE("DInputSinkListener init InputCollector error."); @@ -172,7 +172,7 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayPrepareRemoteInput( jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ON_RELAY_PREPARE; jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = toSrcSessionId; std::string smsg = ""; - int ret = DistributedInputCollector::GetInstance().Init( + int ret = DistributedInputCollector::GetInstance().StartCollectionThread( DistributedInputSinkTransport::GetInstance().GetEventHandler()); if (ret != DH_SUCCESS) { DHLOGE("DInputSinkListener init InputCollector error."); @@ -652,7 +652,7 @@ int32_t DistributedInputSinkManager::Release() // notify callback servertype SetStartTransFlag(DInputServerType::NULL_SERVER_TYPE); // Release input collect resource - DistributedInputCollector::GetInstance().Release(); + DistributedInputCollector::GetInstance().StopCollectionThread(); serviceRunningState_ = ServiceSinkRunningState::STATE_NOT_START; std::shared_ptr dhFwkKit = DInputContext::GetInstance().GetDHFwkKit(); -- Gitee