From 08fbd5698d7a9d26924a9f0b9be3d28ed1b06cc1 Mon Sep 17 00:00:00 2001 From: l30054665 Date: Thu, 25 Jan 2024 20:18:31 +0800 Subject: [PATCH 01/12] SA crash pull up sdk Signed-off-by: l30054665 --- .../ipc/include/distributed_input_client.h | 5 +++ interfaces/ipc/src/dinput_sa_manager.cpp | 17 +++++-- .../ipc/src/distributed_input_client.cpp | 44 +++++++++++++++++++ 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/interfaces/ipc/include/distributed_input_client.h b/interfaces/ipc/include/distributed_input_client.h index 4ab2627..880fe43 100644 --- a/interfaces/ipc/include/distributed_input_client.h +++ b/interfaces/ipc/include/distributed_input_client.h @@ -115,6 +115,7 @@ public: void CheckSinkRegisterCallback(); void CheckSharingDhIdsCallback(); void CheckSinkScreenInfoCallback(); + int32_t RestoreRegisterListenerAndCallback(); public: class RegisterDInputCb : public OHOS::DistributedHardware::DistributedInput::RegisterDInputCallbackStub { @@ -190,6 +191,8 @@ private: sptr unregSimulationEventListener_ = nullptr; std::set> sharingDhIdListeners_; std::set> getSinkScreenInfosCallbacks_; + std::set> addSaListeners_; + sptr addSaCallback_ = nullptr; std::shared_ptr eventHandler_; @@ -220,6 +223,8 @@ private: std::mutex sharingDhIdsMtx_; // sharing local dhids std::set sharingDhIds_; + std::mutex addSaListenersMtx_; + std::mutex addSaCallbackMtx_; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/interfaces/ipc/src/dinput_sa_manager.cpp b/interfaces/ipc/src/dinput_sa_manager.cpp index 4f3969b..c7116d8 100644 --- a/interfaces/ipc/src/dinput_sa_manager.cpp +++ b/interfaces/ipc/src/dinput_sa_manager.cpp @@ -21,6 +21,7 @@ #include "constants_dinput.h" #include "dinput_errcode.h" #include "dinput_log.h" +#include "distributed_input_client.h" namespace OHOS { namespace DistributedHardware { @@ -76,8 +77,12 @@ void DInputSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAb DHLOGI("SendEvent DINPUT_CLIENT_CHECK_SOURCE_CALLBACK_REGISTER_MSG"); AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(DINPUT_CLIENT_CHECK_SOURCE_CALLBACK_REGISTER_MSG, systemAbilityId); - DInputSAManager::GetInstance().eventHandler_->SendEvent(msgEvent, DINPUT_CLIENT_HANDLER_MSG_DELAY_TIME, - AppExecFwk::EventQueue::Priority::IMMEDIATE); + DInputSAManager::GetInstance().eventHandler_->SendEvent(msgEvent, + DINPUT_CLIENT_HANDLER_MSG_DELAY_TIME, AppExecFwk::EventQueue::Priority::IMMEDIATE); + } + int32_t result = DistributedInputClient::GetInstance().RestoreRegisterListenerAndCallback(); + if (result != DH_SUCCESS) { + DHLOGE("source sa execute RestoreRegisterListenerAndCallback fail, result = %d", result); } } @@ -88,8 +93,12 @@ void DInputSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAb DHLOGI("SendEvent DINPUT_CLIENT_CHECK_SINK_CALLBACK_REGISTER_MSG"); AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(DINPUT_CLIENT_CHECK_SINK_CALLBACK_REGISTER_MSG, systemAbilityId); - DInputSAManager::GetInstance().eventHandler_->SendEvent(msgEvent, DINPUT_CLIENT_HANDLER_MSG_DELAY_TIME, - AppExecFwk::EventQueue::Priority::IMMEDIATE); + DInputSAManager::GetInstance().eventHandler_->SendEvent(msgEvent, + DINPUT_CLIENT_HANDLER_MSG_DELAY_TIME, AppExecFwk::EventQueue::Priority::IMMEDIATE); + } + int32_t result = DistributedInputClient::GetInstance().RestoreRegisterListenerAndCallback(); + if (result != DH_SUCCESS) { + DHLOGE("sink sa execute RestoreRegisterListenerAndCallback fail, result = %d", result); } } DHLOGI("sa %d is added.", systemAbilityId); diff --git a/interfaces/ipc/src/distributed_input_client.cpp b/interfaces/ipc/src/distributed_input_client.cpp index 1cd468f..7102ff4 100644 --- a/interfaces/ipc/src/distributed_input_client.cpp +++ b/interfaces/ipc/src/distributed_input_client.cpp @@ -581,8 +581,10 @@ int32_t DistributedInputClient::RegisterSimulationEventListener(sptrRegisterSimulationEventListener(listener); + std::lock_guard lock(addSaListenersMtx_); if (ret == DH_SUCCESS) { isSimulationEventCbReg = true; + addSaListeners_.insert(listener); } else { isSimulationEventCbReg = false; regSimulationEventListener_ = listener; @@ -607,6 +609,9 @@ int32_t DistributedInputClient::UnregisterSimulationEventListener(sptr lock(addSaListenersMtx_); + addSaListeners_.erase(listener); return ret; } @@ -749,6 +754,8 @@ int32_t DistributedInputClient::RegisterSessionStateCb(sptr lock(addSaCallbackMtx_); + addSaCallback_ = (callback); return DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSessionStateCb(callback); } @@ -758,8 +765,45 @@ int32_t DistributedInputClient::UnregisterSessionStateCb() DHLOGE("DinputStart client fail."); return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; } + std::lock_guard lock(addSaCallbackMtx_); + addSaCallback_ = nullptr; return DInputSAManager::GetInstance().dInputSourceProxy_->UnregisterSessionStateCb(); } + +int32_t DistributedInputClient::RestoreRegisterListenerAndCallback() +{ + DHLOGI("Restore RegisterPublisherListener"); + if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { + DHLOGE("RestoreRegisterSimulationEventListener proxy error, client fail"); + return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; + } + + int32_t result = DH_SUCCESS; + std::lock_guard lock(addSaListenersMtx_); + for (const auto& listener : addSaListeners_) { + int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSimulationEventListener(listener); + if (ret != DH_SUCCESS) { + result = ret; + DHLOGE("SA execute RegisterSimulationEventListener fail, ret = %d", ret); + } + } + + DHLOGI("Restore RegisterSessionStateCb"); + if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { + DHLOGE("Restore RegisterSessionStateCb client fail."); + return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; + } + + { + std::lock_guard lock(addSaCallbackMtx_); + int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSessionStateCb(addSaCallback_); + if (ret != DH_SUCCESS) { + result = ret; + DHLOGE("SA execute RegisterSessionStateCb fail, ret = %d", ret); + } + return result; + } +} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS From f1526d1c37608242c051f00a628b5ecef72c984c Mon Sep 17 00:00:00 2001 From: l30054665 Date: Fri, 2 Feb 2024 11:20:47 +0800 Subject: [PATCH 02/12] change jianshiyijian Signed-off-by: l30054665 --- interfaces/ipc/include/dinput_sa_manager.h | 12 ++++ .../ipc/include/distributed_input_client.h | 5 -- interfaces/ipc/src/dinput_sa_manager.cpp | 68 ++++++++++++++++--- .../ipc/src/distributed_input_client.cpp | 53 +++------------ 4 files changed, 80 insertions(+), 58 deletions(-) diff --git a/interfaces/ipc/include/dinput_sa_manager.h b/interfaces/ipc/include/dinput_sa_manager.h index 8178d6e..f2bbda6 100644 --- a/interfaces/ipc/include/dinput_sa_manager.h +++ b/interfaces/ipc/include/dinput_sa_manager.h @@ -18,6 +18,7 @@ #include #include +#include #include "i_distributed_source_input.h" #include "i_distributed_sink_input.h" @@ -46,6 +47,11 @@ public: bool HasDInputSinkProxy(); bool SetDInputSinkProxy(const sptr &remoteObject); void RegisterEventHandler(std::shared_ptr handler); + int32_t RestoreRegisterListenerAndCallback(); + void AddSimEventListenerToCache(sptr listener); + void RemoveSimEventListenerFromCache(sptr listener); + void AddSessionStateCbToCache(const sptr callback); + void RemoveSessionStateCbFromCache(); public: class SystemAbilityListener : public SystemAbilityStatusChangeStub { @@ -54,6 +60,12 @@ public: void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; }; +private: + std::mutex simEventListenerCacheMtx_; + std::set> simEventListenerCache_; + std::mutex sessionStateCbCacheMtx_; + sptr sessionStateCbCache_ = nullptr; + private: DInputSAManager() = default; ~DInputSAManager() = default; diff --git a/interfaces/ipc/include/distributed_input_client.h b/interfaces/ipc/include/distributed_input_client.h index 880fe43..4ab2627 100644 --- a/interfaces/ipc/include/distributed_input_client.h +++ b/interfaces/ipc/include/distributed_input_client.h @@ -115,7 +115,6 @@ public: void CheckSinkRegisterCallback(); void CheckSharingDhIdsCallback(); void CheckSinkScreenInfoCallback(); - int32_t RestoreRegisterListenerAndCallback(); public: class RegisterDInputCb : public OHOS::DistributedHardware::DistributedInput::RegisterDInputCallbackStub { @@ -191,8 +190,6 @@ private: sptr unregSimulationEventListener_ = nullptr; std::set> sharingDhIdListeners_; std::set> getSinkScreenInfosCallbacks_; - std::set> addSaListeners_; - sptr addSaCallback_ = nullptr; std::shared_ptr eventHandler_; @@ -223,8 +220,6 @@ private: std::mutex sharingDhIdsMtx_; // sharing local dhids std::set sharingDhIds_; - std::mutex addSaListenersMtx_; - std::mutex addSaCallbackMtx_; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/interfaces/ipc/src/dinput_sa_manager.cpp b/interfaces/ipc/src/dinput_sa_manager.cpp index c7116d8..425b3eb 100644 --- a/interfaces/ipc/src/dinput_sa_manager.cpp +++ b/interfaces/ipc/src/dinput_sa_manager.cpp @@ -21,7 +21,6 @@ #include "constants_dinput.h" #include "dinput_errcode.h" #include "dinput_log.h" -#include "distributed_input_client.h" namespace OHOS { namespace DistributedHardware { @@ -80,10 +79,6 @@ void DInputSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAb DInputSAManager::GetInstance().eventHandler_->SendEvent(msgEvent, DINPUT_CLIENT_HANDLER_MSG_DELAY_TIME, AppExecFwk::EventQueue::Priority::IMMEDIATE); } - int32_t result = DistributedInputClient::GetInstance().RestoreRegisterListenerAndCallback(); - if (result != DH_SUCCESS) { - DHLOGE("source sa execute RestoreRegisterListenerAndCallback fail, result = %d", result); - } } if (systemAbilityId == DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID) { @@ -96,10 +91,6 @@ void DInputSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAb DInputSAManager::GetInstance().eventHandler_->SendEvent(msgEvent, DINPUT_CLIENT_HANDLER_MSG_DELAY_TIME, AppExecFwk::EventQueue::Priority::IMMEDIATE); } - int32_t result = DistributedInputClient::GetInstance().RestoreRegisterListenerAndCallback(); - if (result != DH_SUCCESS) { - DHLOGE("sink sa execute RestoreRegisterListenerAndCallback fail, result = %d", result); - } } DHLOGI("sa %d is added.", systemAbilityId); } @@ -284,6 +275,65 @@ bool DInputSAManager::SetDInputSinkProxy(const sptr &remoteObject } return true; } + +int32_t DInputSAManager::RestoreRegisterListenerAndCallback() +{ + DHLOGI("Restore RegisterPublisherListener"); + if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { + DHLOGE("RestoreRegisterSimulationEventListener proxy error, client fail"); + return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; + } + + int32_t result = DH_SUCCESS; + std::lock_guard lock(simEventListenerCacheMtx_); + for (const auto& listener : simEventListenerCache_) { + int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSimulationEventListener(listener); + if (ret != DH_SUCCESS) { + result = ret; + DHLOGE("SA execute RegisterSimulationEventListener fail, ret = %d", ret); + } + } + + DHLOGI("Restore RegisterSessionStateCb"); + if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { + DHLOGE("Restore RegisterSessionStateCb client fail."); + return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; + } + + { + std::lock_guard lock(sessionStateCbCacheMtx_); + int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSessionStateCb(sessionStateCbCache_); + if (ret != DH_SUCCESS) { + result = ret; + DHLOGE("SA execute RegisterSessionStateCb fail, ret = %d", ret); + } + return result; + } +} + +void DHFWKSAManager::AddSimEventListenerToCache(sptr listener) +{ + std::lock_guard simEventListenerLock(simEventListenerCacheMtx_); + simEventListenerCache_.insert(listener); +} + +void DHFWKSAManager::RemoveSimEventListenerFromCache(sptr listener) +{ + std::lock_guard simEventListenerLock(simEventListenerCacheMtx_); + simEventListenerCache_.erase(listener); +} + +void DHFWKSAManager::AddSessionStateCbToCache(const sptr callback) +{ + std::lock_guard sessionStateCbLock(sessionStateCbCacheMtx_); + sessionStateCbCache_ = callback; +} + +void DHFWKSAManager::() +{ + std::lock_guard sessionStateCbLock(sessionStateCbCacheMtx_); + sessionStateCbCache_ = nullptr; +} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/interfaces/ipc/src/distributed_input_client.cpp b/interfaces/ipc/src/distributed_input_client.cpp index 7102ff4..ec0c1af 100644 --- a/interfaces/ipc/src/distributed_input_client.cpp +++ b/interfaces/ipc/src/distributed_input_client.cpp @@ -28,6 +28,7 @@ #include "input_check_param.h" #include "softbus_bus_center.h" #include "white_list_util.h" +#include "dinput_sa_manager.h" namespace OHOS { namespace DistributedHardware { @@ -128,6 +129,10 @@ void DistributedInputClient::DInputClientEventHandler::ProcessEvent(const AppExe DHLOGI("DInputClientEventHandler ProcessEvent start eventId:%d.", eventId); if (eventId == DINPUT_CLIENT_CHECK_SOURCE_CALLBACK_REGISTER_MSG) { DistributedInputClient::GetInstance().CheckSourceRegisterCallback(); + int32_t result = DInputSAManager::GetInstance().RestoreRegisterListenerAndCallback(); + if (result != DH_SUCCESS) { + DHLOGE("source sa execute RestoreRegisterListenerAndCallback fail, result = %d", result); + } return; } @@ -581,10 +586,9 @@ int32_t DistributedInputClient::RegisterSimulationEventListener(sptrRegisterSimulationEventListener(listener); - std::lock_guard lock(addSaListenersMtx_); if (ret == DH_SUCCESS) { isSimulationEventCbReg = true; - addSaListeners_.insert(listener); + DInputSAManager::GetInstance().AddSimEventListenerToCache(listener); } else { isSimulationEventCbReg = false; regSimulationEventListener_ = listener; @@ -609,9 +613,7 @@ int32_t DistributedInputClient::UnregisterSimulationEventListener(sptr lock(addSaListenersMtx_); - addSaListeners_.erase(listener); + DInputSAManager::GetInstance().RemoveSimEventListenerFromCache(listener); return ret; } @@ -754,8 +756,7 @@ int32_t DistributedInputClient::RegisterSessionStateCb(sptr lock(addSaCallbackMtx_); - addSaCallback_ = (callback); + DInputSAManager::GetInstance().AddSessionStateCbToCache(listener); return DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSessionStateCb(callback); } @@ -765,45 +766,9 @@ int32_t DistributedInputClient::UnregisterSessionStateCb() DHLOGE("DinputStart client fail."); return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; } - std::lock_guard lock(addSaCallbackMtx_); - addSaCallback_ = nullptr; + DInputSAManager::GetInstance().RemoveSessionStateCbFromCache(listener); return DInputSAManager::GetInstance().dInputSourceProxy_->UnregisterSessionStateCb(); } - -int32_t DistributedInputClient::RestoreRegisterListenerAndCallback() -{ - DHLOGI("Restore RegisterPublisherListener"); - if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { - DHLOGE("RestoreRegisterSimulationEventListener proxy error, client fail"); - return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; - } - - int32_t result = DH_SUCCESS; - std::lock_guard lock(addSaListenersMtx_); - for (const auto& listener : addSaListeners_) { - int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSimulationEventListener(listener); - if (ret != DH_SUCCESS) { - result = ret; - DHLOGE("SA execute RegisterSimulationEventListener fail, ret = %d", ret); - } - } - - DHLOGI("Restore RegisterSessionStateCb"); - if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { - DHLOGE("Restore RegisterSessionStateCb client fail."); - return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; - } - - { - std::lock_guard lock(addSaCallbackMtx_); - int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSessionStateCb(addSaCallback_); - if (ret != DH_SUCCESS) { - result = ret; - DHLOGE("SA execute RegisterSessionStateCb fail, ret = %d", ret); - } - return result; - } -} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS From c450f17c2aa281adbaac5eefb0c8c04199db2d5c Mon Sep 17 00:00:00 2001 From: l30054665 Date: Sun, 4 Feb 2024 09:34:04 +0800 Subject: [PATCH 03/12] change sa Signed-off-by: l30054665 --- interfaces/ipc/src/dinput_sa_manager.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/interfaces/ipc/src/dinput_sa_manager.cpp b/interfaces/ipc/src/dinput_sa_manager.cpp index 425b3eb..4f8b49f 100644 --- a/interfaces/ipc/src/dinput_sa_manager.cpp +++ b/interfaces/ipc/src/dinput_sa_manager.cpp @@ -311,25 +311,25 @@ int32_t DInputSAManager::RestoreRegisterListenerAndCallback() } } -void DHFWKSAManager::AddSimEventListenerToCache(sptr listener) +void DInputSAManager::AddSimEventListenerToCache(sptr listener) { std::lock_guard simEventListenerLock(simEventListenerCacheMtx_); simEventListenerCache_.insert(listener); } -void DHFWKSAManager::RemoveSimEventListenerFromCache(sptr listener) +void DInputSAManager::RemoveSimEventListenerFromCache(sptr listener) { std::lock_guard simEventListenerLock(simEventListenerCacheMtx_); simEventListenerCache_.erase(listener); } -void DHFWKSAManager::AddSessionStateCbToCache(const sptr callback) +void DInputSAManager::AddSessionStateCbToCache(const sptr callback) { std::lock_guard sessionStateCbLock(sessionStateCbCacheMtx_); sessionStateCbCache_ = callback; } -void DHFWKSAManager::() +void DInputSAManager::RemoveSessionStateCbFromCache() { std::lock_guard sessionStateCbLock(sessionStateCbCacheMtx_); sessionStateCbCache_ = nullptr; From 40a222a4715b8347edba79a925b2e4c2b4cc9871 Mon Sep 17 00:00:00 2001 From: l30054665 Date: Sun, 4 Feb 2024 09:38:17 +0800 Subject: [PATCH 04/12] change sa Signed-off-by: l30054665 --- interfaces/ipc/src/distributed_input_client.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/ipc/src/distributed_input_client.cpp b/interfaces/ipc/src/distributed_input_client.cpp index ec0c1af..22346f0 100644 --- a/interfaces/ipc/src/distributed_input_client.cpp +++ b/interfaces/ipc/src/distributed_input_client.cpp @@ -756,7 +756,7 @@ int32_t DistributedInputClient::RegisterSessionStateCb(sptrRegisterSessionStateCb(callback); } @@ -766,7 +766,7 @@ int32_t DistributedInputClient::UnregisterSessionStateCb() DHLOGE("DinputStart client fail."); return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; } - DInputSAManager::GetInstance().RemoveSessionStateCbFromCache(listener); + DInputSAManager::GetInstance().RemoveSessionStateCbFromCache(callback); return DInputSAManager::GetInstance().dInputSourceProxy_->UnregisterSessionStateCb(); } } // namespace DistributedInput From 44d9354c93292183acf2d1d84712bede3468c5bc Mon Sep 17 00:00:00 2001 From: l30054665 Date: Sun, 4 Feb 2024 09:41:47 +0800 Subject: [PATCH 05/12] change sa Signed-off-by: l30054665 --- interfaces/ipc/src/distributed_input_client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/ipc/src/distributed_input_client.cpp b/interfaces/ipc/src/distributed_input_client.cpp index 22346f0..7f83766 100644 --- a/interfaces/ipc/src/distributed_input_client.cpp +++ b/interfaces/ipc/src/distributed_input_client.cpp @@ -766,7 +766,7 @@ int32_t DistributedInputClient::UnregisterSessionStateCb() DHLOGE("DinputStart client fail."); return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; } - DInputSAManager::GetInstance().RemoveSessionStateCbFromCache(callback); + DInputSAManager::GetInstance().RemoveSessionStateCbFromCache(); return DInputSAManager::GetInstance().dInputSourceProxy_->UnregisterSessionStateCb(); } } // namespace DistributedInput From 120dd75f9a3b9795d41a2ed694c6a98ee947ac5d Mon Sep 17 00:00:00 2001 From: l30054665 Date: Sun, 4 Feb 2024 18:01:54 +0800 Subject: [PATCH 06/12] change sa Signed-off-by: l30054665 --- interfaces/ipc/include/dinput_sa_manager.h | 6 +-- interfaces/ipc/src/dinput_sa_manager.cpp | 44 ++++++++++++---------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/interfaces/ipc/include/dinput_sa_manager.h b/interfaces/ipc/include/dinput_sa_manager.h index f2bbda6..6792393 100644 --- a/interfaces/ipc/include/dinput_sa_manager.h +++ b/interfaces/ipc/include/dinput_sa_manager.h @@ -50,7 +50,7 @@ public: int32_t RestoreRegisterListenerAndCallback(); void AddSimEventListenerToCache(sptr listener); void RemoveSimEventListenerFromCache(sptr listener); - void AddSessionStateCbToCache(const sptr callback); + void AddSessionStateCbToCache(sptr callback); void RemoveSessionStateCbFromCache(); public: @@ -64,8 +64,8 @@ private: std::mutex simEventListenerCacheMtx_; std::set> simEventListenerCache_; std::mutex sessionStateCbCacheMtx_; - sptr sessionStateCbCache_ = nullptr; - + std::set> sessionStateCbCache_; + private: DInputSAManager() = default; ~DInputSAManager() = default; diff --git a/interfaces/ipc/src/dinput_sa_manager.cpp b/interfaces/ipc/src/dinput_sa_manager.cpp index 4f8b49f..d2e7f12 100644 --- a/interfaces/ipc/src/dinput_sa_manager.cpp +++ b/interfaces/ipc/src/dinput_sa_manager.cpp @@ -285,30 +285,36 @@ int32_t DInputSAManager::RestoreRegisterListenerAndCallback() } int32_t result = DH_SUCCESS; - std::lock_guard lock(simEventListenerCacheMtx_); + { + std::lock_guard lock(simEventListenerCacheMtx_); for (const auto& listener : simEventListenerCache_) { + if (listener == nullptr) { + DHLOGE("simEventListenerCache_ is nullptr"); + return ERR_DH_INPUT_CLIENT_REGISTER_FAIL; + } int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSimulationEventListener(listener); if (ret != DH_SUCCESS) { result = ret; DHLOGE("SA execute RegisterSimulationEventListener fail, ret = %d", ret); } - } - - DHLOGI("Restore RegisterSessionStateCb"); - if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) { - DHLOGE("Restore RegisterSessionStateCb client fail."); - return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL; - } - - { - std::lock_guard lock(sessionStateCbCacheMtx_); - int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSessionStateCb(sessionStateCbCache_); - if (ret != DH_SUCCESS) { - result = ret; - DHLOGE("SA execute RegisterSessionStateCb fail, ret = %d", ret); } - return result; } + { + DHLOGI("Restore RegisterSessionStateCb"); + std::lock_guard lock(sessionStateCbCacheMtx_); + for (const auto& callback : sessionStateCbCache_) { + if (callback == nullptr) { + DHLOGE("sessionStateCbCache_ is nullptr"); + return ERR_DH_INPUT_CLIENT_REGISTER_FAIL; + } + int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSessionStateCb(callback); + if (ret != DH_SUCCESS) { + result = ret; + DHLOGE("SA execute RegisterSessionStateCb fail, ret = %d", ret); + } + } + } + return result; } void DInputSAManager::AddSimEventListenerToCache(sptr listener) @@ -323,16 +329,16 @@ void DInputSAManager::RemoveSimEventListenerFromCache(sptr callback) +void DInputSAManager::AddSessionStateCbToCache(sptr callback) { std::lock_guard sessionStateCbLock(sessionStateCbCacheMtx_); - sessionStateCbCache_ = callback; + sessionStateCbCache_.insert(callback); } void DInputSAManager::RemoveSessionStateCbFromCache() { std::lock_guard sessionStateCbLock(sessionStateCbCacheMtx_); - sessionStateCbCache_ = nullptr; + sessionStateCbCache_.clear(); } } // namespace DistributedInput } // namespace DistributedHardware From 320f757c4169bd7a7be8d7123b34de5a7ada4079 Mon Sep 17 00:00:00 2001 From: l30054665 Date: Mon, 5 Feb 2024 16:52:47 +0800 Subject: [PATCH 07/12] huanhang Signed-off-by: l30054665 --- interfaces/ipc/src/dinput_sa_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/ipc/src/dinput_sa_manager.cpp b/interfaces/ipc/src/dinput_sa_manager.cpp index d2e7f12..3ec5435 100644 --- a/interfaces/ipc/src/dinput_sa_manager.cpp +++ b/interfaces/ipc/src/dinput_sa_manager.cpp @@ -290,7 +290,7 @@ int32_t DInputSAManager::RestoreRegisterListenerAndCallback() for (const auto& listener : simEventListenerCache_) { if (listener == nullptr) { DHLOGE("simEventListenerCache_ is nullptr"); - return ERR_DH_INPUT_CLIENT_REGISTER_FAIL; + return ERR_DH_INPUT_CLIENT_REGISTER_FAIL; } int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSimulationEventListener(listener); if (ret != DH_SUCCESS) { @@ -305,7 +305,7 @@ int32_t DInputSAManager::RestoreRegisterListenerAndCallback() for (const auto& callback : sessionStateCbCache_) { if (callback == nullptr) { DHLOGE("sessionStateCbCache_ is nullptr"); - return ERR_DH_INPUT_CLIENT_REGISTER_FAIL; + return ERR_DH_INPUT_CLIENT_REGISTER_FAIL; } int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSessionStateCb(callback); if (ret != DH_SUCCESS) { From 58e9c9e01e83e1ac2f85bef7a360d8ee9283b79c Mon Sep 17 00:00:00 2001 From: l30054665 Date: Mon, 5 Feb 2024 17:09:26 +0800 Subject: [PATCH 08/12] add gn Signed-off-by: l30054665 --- interfaces/ipc/test/clientunittest/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/interfaces/ipc/test/clientunittest/BUILD.gn b/interfaces/ipc/test/clientunittest/BUILD.gn index 301d546..034aa52 100644 --- a/interfaces/ipc/test/clientunittest/BUILD.gn +++ b/interfaces/ipc/test/clientunittest/BUILD.gn @@ -59,6 +59,7 @@ ohos_unittest("distributed_input_client_test") { "${ipc_path}/src/add_white_list_infos_call_back_stub.cpp", "${ipc_path}/src/del_white_list_infos_call_back_proxy.cpp", "${ipc_path}/src/del_white_list_infos_call_back_stub.cpp", + "${ipc_path}/src/dinput_sa_manager.cpp", "${ipc_path}/src/distributed_input_client.cpp", "${ipc_path}/src/distributed_input_sink_proxy.cpp", "${ipc_path}/src/distributed_input_sink_stub.cpp", From 5bb003ad1f6b7c706ce9c46fe5ee1c362cc28510 Mon Sep 17 00:00:00 2001 From: l30054665 Date: Mon, 5 Feb 2024 20:27:17 +0800 Subject: [PATCH 09/12] add mock Signed-off-by: l30054665 --- interfaces/ipc/test/clientunittest/BUILD.gn | 1 - .../ipc/test/clientunittest/mock_samanager.cpp | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/interfaces/ipc/test/clientunittest/BUILD.gn b/interfaces/ipc/test/clientunittest/BUILD.gn index 034aa52..301d546 100644 --- a/interfaces/ipc/test/clientunittest/BUILD.gn +++ b/interfaces/ipc/test/clientunittest/BUILD.gn @@ -59,7 +59,6 @@ ohos_unittest("distributed_input_client_test") { "${ipc_path}/src/add_white_list_infos_call_back_stub.cpp", "${ipc_path}/src/del_white_list_infos_call_back_proxy.cpp", "${ipc_path}/src/del_white_list_infos_call_back_stub.cpp", - "${ipc_path}/src/dinput_sa_manager.cpp", "${ipc_path}/src/distributed_input_client.cpp", "${ipc_path}/src/distributed_input_sink_proxy.cpp", "${ipc_path}/src/distributed_input_sink_stub.cpp", diff --git a/interfaces/ipc/test/clientunittest/mock_samanager.cpp b/interfaces/ipc/test/clientunittest/mock_samanager.cpp index 7da39f4..25e1be5 100644 --- a/interfaces/ipc/test/clientunittest/mock_samanager.cpp +++ b/interfaces/ipc/test/clientunittest/mock_samanager.cpp @@ -97,6 +97,23 @@ bool DInputSAManager::SetDInputSinkProxy(const sptr &remoteObject } return true; } + +int32_t DInputSAManager::RestoreRegisterListenerAndCallback() +{ + return DH_SUCCESS; +} + +void DInputSAManager::AddSimEventListenerToCache(sptr listener) +{} + +void DInputSAManager::RemoveSimEventListenerFromCache(sptr listener) +{} + +void DInputSAManager::AddSessionStateCbToCache(const sptr callback) +{} + +void DInputSAManager::RemoveSessionStateCbFromCache() +{} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file From 18c1ed1af5e71e88fc675c3dcaea427a950b3e68 Mon Sep 17 00:00:00 2001 From: l30054665 Date: Tue, 6 Feb 2024 14:51:06 +0800 Subject: [PATCH 10/12] change Signed-off-by: l30054665 --- interfaces/ipc/src/dinput_sa_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/ipc/src/dinput_sa_manager.cpp b/interfaces/ipc/src/dinput_sa_manager.cpp index 3ec5435..fd2c5fa 100644 --- a/interfaces/ipc/src/dinput_sa_manager.cpp +++ b/interfaces/ipc/src/dinput_sa_manager.cpp @@ -290,7 +290,7 @@ int32_t DInputSAManager::RestoreRegisterListenerAndCallback() for (const auto& listener : simEventListenerCache_) { if (listener == nullptr) { DHLOGE("simEventListenerCache_ is nullptr"); - return ERR_DH_INPUT_CLIENT_REGISTER_FAIL; + continue; } int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSimulationEventListener(listener); if (ret != DH_SUCCESS) { @@ -305,7 +305,7 @@ int32_t DInputSAManager::RestoreRegisterListenerAndCallback() for (const auto& callback : sessionStateCbCache_) { if (callback == nullptr) { DHLOGE("sessionStateCbCache_ is nullptr"); - return ERR_DH_INPUT_CLIENT_REGISTER_FAIL; + continue; } int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSessionStateCb(callback); if (ret != DH_SUCCESS) { From ceff1a3a852b15a7e73829d26e8c3b263cc5305b Mon Sep 17 00:00:00 2001 From: l30054665 Date: Tue, 6 Feb 2024 15:05:15 +0800 Subject: [PATCH 11/12] change Signed-off-by: l30054665 --- interfaces/ipc/src/dinput_sa_manager.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/interfaces/ipc/src/dinput_sa_manager.cpp b/interfaces/ipc/src/dinput_sa_manager.cpp index fd2c5fa..0962957 100644 --- a/interfaces/ipc/src/dinput_sa_manager.cpp +++ b/interfaces/ipc/src/dinput_sa_manager.cpp @@ -320,19 +320,25 @@ int32_t DInputSAManager::RestoreRegisterListenerAndCallback() void DInputSAManager::AddSimEventListenerToCache(sptr listener) { std::lock_guard simEventListenerLock(simEventListenerCacheMtx_); + if (listener != nullptr) { simEventListenerCache_.insert(listener); + } } void DInputSAManager::RemoveSimEventListenerFromCache(sptr listener) { std::lock_guard simEventListenerLock(simEventListenerCacheMtx_); + if (listener != nullptr) { simEventListenerCache_.erase(listener); + } } void DInputSAManager::AddSessionStateCbToCache(sptr callback) { std::lock_guard sessionStateCbLock(sessionStateCbCacheMtx_); + if (callback != nullptr) { sessionStateCbCache_.insert(callback); + } } void DInputSAManager::RemoveSessionStateCbFromCache() From 9117209b0c3ca4d2cc3383786d9ed5d90ff095ed Mon Sep 17 00:00:00 2001 From: l30054665 Date: Tue, 6 Feb 2024 16:39:08 +0800 Subject: [PATCH 12/12] change Signed-off-by: l30054665 --- interfaces/ipc/src/dinput_sa_manager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/ipc/src/dinput_sa_manager.cpp b/interfaces/ipc/src/dinput_sa_manager.cpp index 0962957..243ec7e 100644 --- a/interfaces/ipc/src/dinput_sa_manager.cpp +++ b/interfaces/ipc/src/dinput_sa_manager.cpp @@ -321,7 +321,7 @@ void DInputSAManager::AddSimEventListenerToCache(sptr { std::lock_guard simEventListenerLock(simEventListenerCacheMtx_); if (listener != nullptr) { - simEventListenerCache_.insert(listener); + simEventListenerCache_.insert(listener); } } @@ -329,7 +329,7 @@ void DInputSAManager::RemoveSimEventListenerFromCache(sptr simEventListenerLock(simEventListenerCacheMtx_); if (listener != nullptr) { - simEventListenerCache_.erase(listener); + simEventListenerCache_.erase(listener); } } @@ -337,7 +337,7 @@ void DInputSAManager::AddSessionStateCbToCache(sptr callb { std::lock_guard sessionStateCbLock(sessionStateCbCacheMtx_); if (callback != nullptr) { - sessionStateCbCache_.insert(callback); + sessionStateCbCache_.insert(callback); } }