diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index e243ab45a5b83a680f69f0b642c6c887b919f15c..919cab56c5af3d9e46492d25c2a44239911d1005 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 5d49ef5357452064317f294f19455bbfb4a6f28a..2b9820bb1a0c28b2b505dab59d0f428f565f954e 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 bd33f4f9afd99b6676a3520df9b5e59fb347d5cf..ac490031efc6a683634ea07cef4d6e43137a060b 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 656828495b3c49ee1c517307b092ef2f5e13c86b..0c2d5effa22f14116fcead9fe6f6ef5fcb33f2ff 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 d6004798005bd348013f08067ea9841cf779185e..acc3674e1671e7c0d17ac6e70b017c060c5b7138 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();