From 5d5941a8bdfa78e96eb39a473050c34f37002c5e Mon Sep 17 00:00:00 2001 From: l30054665 Date: Sat, 16 Dec 2023 18:32:28 +0800 Subject: [PATCH] resolve DTS2023121217154 Signed-off-by: l30054665 --- common/include/input_hub.cpp | 8 ++++- common/include/input_hub.h | 1 + .../include/distributed_input_collector.h | 5 +-- .../src/distributed_input_collector.cpp | 13 +++++-- .../distributed_input_collector_test.cpp | 6 ++-- .../include/distributed_input_sink_manager.h | 8 +++++ .../src/distributed_input_sink_manager.cpp | 34 ++++++++++++++++--- 7 files changed, 63 insertions(+), 12 deletions(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index e243ab4..910f214 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; } @@ -1562,6 +1561,13 @@ void InputHub::ClearDeviceStates() DInputState::GetInstance().ClearDeviceStates(); } +void InputHub::ClearSkipDevicePaths() +{ + DHLOGI("Clear Skip device path"); + std::lock_guard lock(skipDevicePathsMutex_); + skipDevicePaths_.clear(); +} + InputHub::Device::Device(int fd, const std::string &path) : next(nullptr), fd(fd), path(path), identifier({}), classes(0), enabled(false), isShare(false), isVirtual(fd < 0) { diff --git a/common/include/input_hub.h b/common/include/input_hub.h index a2be41f..f7f56f8 100644 --- a/common/include/input_hub.h +++ b/common/include/input_hub.h @@ -101,6 +101,7 @@ public: void CheckTargetKeyState(const InputHub::Device *dev, const unsigned long *keyState, const unsigned long len); void SavePressedKeyState(const Device *dev, int32_t keyCode); void ClearDeviceStates(); + void ClearSkipDevicePaths(); private: int32_t Initialize(); int32_t Release(); diff --git a/services/sink/inputcollector/include/distributed_input_collector.h b/services/sink/inputcollector/include/distributed_input_collector.h index 5d49ef5..351326a 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); @@ -54,6 +54,7 @@ public: void ReportDhIdSharingState(const AffectDhIds &dhIds); void GetDeviceInfoByType(const uint32_t inputTypes, std::map &deviceInfo); void ResetSpecEventStatus(); + void ClearSkipDevicePaths(); private: DistributedInputCollector(); diff --git a/services/sink/inputcollector/src/distributed_input_collector.cpp b/services/sink/inputcollector/src/distributed_input_collector.cpp index bd33f4f..e5b0fc6 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(); } @@ -257,6 +257,15 @@ void DistributedInputCollector::GetDeviceInfoByType(const uint32_t inputTypes, s } inputHub_->GetDevicesInfoByType(inputTypes, deviceInfo); } + +void DistributedInputCollector::ClearSkipDevicePaths() +{ + if (inputHub_ == nullptr) { + DHLOGE("inputHub is nullptr!"); + return; + } + inputHub_->ClearSkipDevicePaths(); +} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS 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/include/distributed_input_sink_manager.h b/services/sink/sinkmanager/include/distributed_input_sink_manager.h index f915705..67a21ea 100644 --- a/services/sink/sinkmanager/include/distributed_input_sink_manager.h +++ b/services/sink/sinkmanager/include/distributed_input_sink_manager.h @@ -111,6 +111,13 @@ public: DistributedInputSinkManager *sinkManagerObj_; }; + class PluginStartListener : public PublisherListenerStub { + public: + explicit PluginStartListener() = default; + ~PluginStartListener() override; + void OnMessage(const DHTopic topic, const std::string &message) override; + }; + class DScreenSinkSvrRecipient : public IRemoteObject::DeathRecipient { public: DScreenSinkSvrRecipient(const std::string &srcDevId, const uint64_t srcWinId); @@ -179,6 +186,7 @@ private: bool InitAuto(); DInputDeviceType inputTypes_; sptr projectWindowListener_ = nullptr; + sptr pluginStartListener_ = nullptr; std::set sharingDhIds_; std::map> sharingDhIdsMap_; void StoreStartDhids(int32_t sessionId, const std::vector &dhIds); diff --git a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp index d600479..50173bb 100644 --- a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp +++ b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp @@ -58,6 +58,7 @@ DistributedInputSinkManager::~DistributedInputSinkManager() { DHLOGI("DistributedInputSinkManager dtor!"); projectWindowListener_ = nullptr; + pluginStartListener_ = nullptr; } DistributedInputSinkManager::DInputSinkMgrListener::DInputSinkMgrListener(DistributedInputSinkManager *manager) @@ -132,7 +133,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 +173,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."); @@ -631,7 +632,8 @@ int32_t DistributedInputSinkManager::Init() } projectWindowListener_ = new ProjectWindowListener(this); dhFwkKit->RegisterPublisherListener(DHTopic::TOPIC_SINK_PROJECT_WINDOW_INFO, projectWindowListener_); - + pluginStartListener_ = new PluginStartListener(); + dhFwkKit->RegisterPublisherListener(DHTopic::TOPIC_PHY_DEV_PLUGIN, pluginStartListener_); DistributedInputCollector::GetInstance().PreInit(); return DH_SUCCESS; @@ -652,7 +654,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(); @@ -660,6 +662,10 @@ int32_t DistributedInputSinkManager::Release() DHLOGI("UnPublish ProjectWindowListener"); dhFwkKit->UnregisterPublisherListener(DHTopic::TOPIC_SINK_PROJECT_WINDOW_INFO, projectWindowListener_); } + if (dhFwkKit != nullptr && pluginStartListener_ != nullptr) { + DHLOGI("UnPublish PluginStartListener"); + dhFwkKit->UnregisterPublisherListener(DHTopic::TOPIC_PHY_DEV_PLUGIN, pluginStartListener_); + } if (dhFwkKit != nullptr) { DHLOGD("Disable low Latency!"); dhFwkKit->PublishMessage(DHTopic::TOPIC_LOW_LATENCY, DISABLE_LOW_LATENCY.dump()); @@ -860,6 +866,26 @@ uint32_t DistributedInputSinkManager::ProjectWindowListener::GetScreenHeight() return screen_->GetHeight(); } +DistributedInputSinkManager::PluginStartListener::~PluginStartListener() +{ + DHLOGI("PluginStartListener dtor!"); +} + +void DistributedInputSinkManager::PluginStartListener::OnMessage(const DHTopic topic, + const std::string &message) +{ + DHLOGI("PluginStartListener OnMessage!"); + if (topic != DHTopic::TOPIC_PHY_DEV_PLUGIN) { + DHLOGE("this topic is wrong, %d", static_cast(topic)); + return; + } + if (message.empty()) { + DHLOGE("this message is empty"); + return; + } + DistributedInputCollector::GetInstance().ClearSkipDevicePaths(); +} + DistributedInputSinkManager::DScreenSinkSvrRecipient::DScreenSinkSvrRecipient(const std::string &srcDevId, const uint64_t srcWinId) { -- Gitee