From f303321616ba8274ffa0d18f33d2a78c6ac56d00 Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Wed, 2 Mar 2022 09:56:22 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=9D=E8=AF=81=E5=A4=9A=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=9B=91=E5=90=AC=E8=AE=A2=E9=98=85=E6=88=90=E5=8A=9F?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhouyongfei --- services/include/input_method_system_ability.h | 1 + services/src/input_method_system_ability.cpp | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index 5793dfa..01beb52 100644 --- a/services/include/input_method_system_ability.h +++ b/services/include/input_method_system_ability.h @@ -87,6 +87,7 @@ namespace MiscServices { void OnDisplayOptionalInputMethod(int32_t userId); static sptr GetAbilityManagerService(); OHOS::sptr GetBundleMgr(); + void StartUserIdListener(); ServiceRunningState state_; void InitServiceHandler(); diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index c68f256..13f4f66 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -183,10 +183,20 @@ namespace MiscServices { userId_ = MAIN_USER_ID; setting->Initialize(); + StartUserIdListener(); + } + + void InputMethodSystemAbility::StartUserIdListener() { sptr imCommonEventManager = ImCommonEventManager::GetInstance(); - if (imCommonEventManager->SubscribeEvent(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED)) { + bool isSuccess = imCommonEventManager->SubscribeEvent(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + if (isSuccess) { IMSA_HILOGI("InputMethodSystemAbility::Initialize subscribe service event success"); + return; } + + IMSA_HILOGE("StartUserIdListener failed. Try again 10s later"); + auto callback = [this]() { StartUserIdListener(); }; + serviceHandler_->PostTask(callback, INIT_INTERVAL); } void InputMethodSystemAbility::StartInputService(std::string imeId) From c32d88f4cee424fddd73ee1205152a62efa92ecc Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Wed, 2 Mar 2022 14:10:25 +0800 Subject: [PATCH 2/2] fix Signed-off-by: zhouyongfei --- services/src/input_method_system_ability.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 13f4f66..177e6fb 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -186,7 +186,8 @@ namespace MiscServices { StartUserIdListener(); } - void InputMethodSystemAbility::StartUserIdListener() { + void InputMethodSystemAbility::StartUserIdListener() + { sptr imCommonEventManager = ImCommonEventManager::GetInstance(); bool isSuccess = imCommonEventManager->SubscribeEvent(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED); if (isSuccess) {