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..177e6fb 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -183,10 +183,21 @@ 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)