diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index f0a5d479081f4dee293790b9fe6f2279a4a9d1b9..8051f4685ae44aaed42eebda9812b714fd9e9dd6 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -193,6 +193,7 @@ using namespace MessageID; void InputMethodController::Attach(sptr &listener) { textListener = listener; + PrepareInput(0, mClient, mInputDataChannel, mAttribute); StartInput(mClient); } diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index 5793dfa8b0db70ccff82a3f25837074064478cb5..01beb52adca98a1b7fbd1210aea382170205acbc 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 c68f2567d58fb50279cd870c28e6500052be7903..177e6fb7cb351fd9f3cf7b0441fe05a4860e9ba9 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)