From f8a4cbea48f186c31b31dfcfc40c0034fa7cdcb0 Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Thu, 3 Mar 2022 18:59:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BF=AE=E6=94=B9=E5=88=B0we?= =?UTF-8?q?ekly=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhouyongfei --- .../src/input_method_controller.cpp | 1 + services/include/input_method_system_ability.h | 1 + services/src/input_method_system_ability.cpp | 13 ++++++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index f0a5d4790..8051f4685 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 5793dfa8b..01beb52ad 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 c68f2567d..177e6fb7c 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) -- Gitee