From b5d63eac82c72acb020f33b401ca96cea21b0a8b Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Thu, 20 Jan 2022 20:15:35 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E6=B3=95=E4=B8=BAservice=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhouyongfei --- .../src/input_method_controller.cpp | 6 +- .../include/input_method_system_ability.h | 2 +- services/include/peruser_session.h | 2 +- services/src/input_method_system_ability.cpp | 66 +++++++------------ 4 files changed, 29 insertions(+), 47 deletions(-) diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index a8fa03e52..d934a2807 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -355,9 +355,9 @@ using namespace MessageID; } MessageParcel data; if (!(data.WriteInterfaceToken(mImms->GetDescriptor()) - &&data.WriteRemoteObject(mClient->AsObject().GetRefPtr()) - &&data.WriteInt32(keyEvent->GetKeyCode()) - &&data.WriteInt32(keyEvent->GetKeyAction()))) { + && data.WriteRemoteObject(mClient->AsObject().GetRefPtr()) + && data.WriteInt32(keyEvent->GetKeyCode()) + && data.WriteInt32(keyEvent->GetKeyAction()))) { return false; } mImms->DispatchKey(data); diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index c0f4b3df6..94b81e729 100644 --- a/services/include/input_method_system_ability.h +++ b/services/include/input_method_system_ability.h @@ -70,11 +70,11 @@ namespace MiscServices { void WorkThread(); PerUserSetting *GetUserSetting(int32_t userId); PerUserSession *GetUserSession(int32_t userId); + void StartInputService(); int32_t OnUserStarted(const Message *msg); int32_t OnUserStopped(const Message *msg); int32_t OnUserUnlocked(const Message *msg); int32_t OnUserLocked(const Message *msg); - int32_t OnPrepareInput(Message *msg); int32_t OnHandleMessage(Message *msg); int32_t OnRemotePeerDied(const Message *msg); int32_t OnSettingChanged(const Message *msg); diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index ac2ecac85..cbcb16379 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -114,7 +114,7 @@ namespace MiscServices { void CreateWorkThread(MessageHandler& handler); void JoinWorkThread(); void SetInputMethodAbility(sptr &inputMethodAbility); - static void BindInputAbility(); + static bool StartInputService(); private: int userId_; // the id of the user to whom the object is linking int userState; // the state of the user to whom the object is linking diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index a9a9bf7f9..ec0e13aac 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -96,7 +96,7 @@ namespace MiscServices { void InputMethodSystemAbility::OnStart() { - IMSA_HILOGI("Enter OnStart."); + IMSA_HILOGI("InputMethodSystemAbility::OnStart."); if (state_ == ServiceRunningState::STATE_RUNNING) { IMSA_HILOGI("ImsaService is already running."); return; @@ -123,6 +123,7 @@ namespace MiscServices { } IMSA_HILOGI("Publish ErrorCode::NO_ERROR."); state_ = ServiceRunningState::STATE_RUNNING; + StartInputService(); return ErrorCode::NO_ERROR; } @@ -169,6 +170,27 @@ namespace MiscServices { setting->Initialize(); } + void InputMethodSystemAbility::StartInputService() { + PerUserSession *session = GetUserSession(0); + + std::map::const_iterator it = msgHandlers.find(0); + if (it == msgHandlers.end()) { + IMSA_HILOGE("InputMethodSystemAbility::StartInputService() need start handler"); + MessageHandler *handler = new MessageHandler(); + if (session == nullptr) { + IMSA_HILOGE("InputMethodSystemAbility::OnPrepareInput session is nullptr"); + } + session->CreateWorkThread(*handler); + msgHandlers.insert(std::pair(0, handler)); + } + + if (!session->StartInputService()) { + IMSA_HILOGE("StartInputService failed. Try again 10s later"); + auto callback = [=]() { StartInputService(); }; + serviceHandler_->PostTask(callback, INIT_INTERVAL); + } + } + /*! Get the state of user \n This API is added for unit test. \param userID the id of given user @@ -406,10 +428,7 @@ namespace MiscServices { OnSettingChanged(msg); break; } - case MSG_ID_PREPARE_INPUT: { - OnPrepareInput(msg); - break; - } + case MSG_ID_PREPARE_INPUT: case MSG_ID_RELEASE_INPUT: case MSG_ID_START_INPUT: case MSG_ID_STOP_INPUT: @@ -600,43 +619,6 @@ namespace MiscServices { return ErrorCode::NO_ERROR; } - /*! Prepare input. Called by an input client. - \n Run in work thread of input method management service - \param msg the parameters from remote client are saved in msg->msgContent_ - \return ErrorCode::NO_ERROR - \return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked - */ - int32_t InputMethodSystemAbility::OnPrepareInput(Message *msg) - { - IMSA_HILOGI("InputMethodSystemAbility::OnPrepareInput"); - MessageParcel *data = msg->msgContent_; - int32_t userId = data->ReadInt32(); - - PerUserSetting *setting = GetUserSetting(userId); - if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { - IMSA_HILOGE("InputMethodSystemAbility::OnPrepareInput errorCode = ErrorCode::ERROR_USER_NOT_UNLOCKED"); - return ErrorCode::ERROR_USER_NOT_UNLOCKED; - } - - std::map::const_iterator it = msgHandlers.find(userId); - if (it == msgHandlers.end()) { - PerUserSession *session = GetUserSession(userId); - MessageHandler *handler = new MessageHandler(); - if (session == nullptr) { - IMSA_HILOGE("InputMethodSystemAbility::OnPrepareInput session is nullptr"); - } - session->CreateWorkThread(*handler); - msgHandlers.insert(std::pair(userId, handler)); - it = msgHandlers.find(userId); - } - - if (it != msgHandlers.end()) { - MessageHandler *handler = it->second; - handler->SendMessage(msg); - } - return 0; - } - /*! Handle message \param msgId the id of message to run \msg the parameters are saved in msg->msgContent_ -- Gitee From 0129d2ba4e47db1aa0779f443105666b8ad74c62 Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Thu, 20 Jan 2022 21:53:56 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=A1=A5=E5=85=85=E9=81=97=E7=95=99?= =?UTF-8?q?=E5=90=88=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhouyongfei --- services/src/peruser_session.cpp | 42 ++++++++++++++------------------ 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 16301064c..37f77669b 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -494,7 +494,10 @@ namespace MiscServices { lastImeIndex = index; bool supportPhysicalKbd = Platform::Instance()->CheckPhysicalKeyboard(); - localControlChannel[index]->ResetFlag(); + if (imsCore[index] == nullptr) { + IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! imsCore[%{public}d] is nullptr", index); + return ErrorCode::ERROR_NULL_POINTER; + } bool ret = imsCore[index]->startInput(clientInfo->channel, clientInfo->attribute, supportPhysicalKbd); if (!ret || localControlChannel[index]->GetAgentAndChannel(&imsAgent, &imsChannel) == false) { @@ -578,7 +581,6 @@ namespace MiscServices { } currentClient = nullptr; imsAgent = nullptr; - imsCore[index] = nullptr; if (imsChannel != nullptr) { delete imsChannel; imsChannel = nullptr; @@ -999,7 +1001,7 @@ namespace MiscServices { time_t now = time(0); double diffSeconds = difftime(now, past[imeIndex]); - //time difference is more than 5 minutes, reset time and error num; + // time difference is more than 5 minutes, reset time and error num; if (diffSeconds > COMMON_COUNT_THREE_HUNDRED) { past[imeIndex] = now; errorNum[imeIndex] = 1; @@ -1178,18 +1180,21 @@ namespace MiscServices { return (ClientInfo*) it->second; } - void PerUserSession::BindInputAbility() + bool PerUserSession::StartInputService() { - IMSA_HILOGE("PerUserSession::BindInputAbility"); + IMSA_HILOGE("PerUserSession::StartInputService"); + sptr ams = GetAbilityManagerService(); + if (ams == nullptr) { + return false; + } AAFwk::Want want; want.SetAction("action.system.inputmethod"); - want.SetElementName("com.example.kikakeyboard", "com.example.kikakeyboard.MainAbility"); - sptr stub(new (std::nothrow) InputMethodAbilityConnectionStub(0)); - sptr connCallback = new (std::nothrow) AAFwk::AbilityConnectionProxy(stub); - std::shared_ptr setting = AAFwk::AbilityStartSetting::GetEmptySetting(); - setting->AddProperty(AAFwk::AbilityStartSetting::WINDOW_MODE_KEY, - std::to_string(AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_FLOATING)); - GetAbilityManagerService()->StartAbility(want, *setting, nullptr, -1); + want.SetElementName("com.example.kikakeyboard", "com.example.kikakeyboard.ServiceExtAbility"); + int32_t result = ams->StartAbility(want); + if (result != 0) { + IMSA_HILOGE("PerUserSession::StartInputService fail. result = %{public}d", result); + } + return true; } sptr PerUserSession::GetAbilityManagerService() @@ -1241,9 +1246,7 @@ namespace MiscServices { int index = GetImeIndex(client); IMSA_HILOGI("PerUserSession::OnPrepareInput index = %{public}d", index); currentIndex = index; - IMSA_HILOGI("PerUserSession::OnPrepareInput BindInputAbility start"); - BindInputAbility(); - IMSA_HILOGI("PerUserSession::OnPrepareInput BindInputAbility end"); + ShowKeyboard(client); currentClient = client; } @@ -1311,15 +1314,6 @@ namespace MiscServices { } else { IMSA_HILOGI("PerUserSession::onSetInputMethodCore End...[%{public}d]\n", userId_); } - if (currentClient != nullptr) { - usleep(SLEEP_TIME); - ret = ShowKeyboard(currentClient); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("PerUserSession::OnStartInput Aborted! %{public}s", ErrorCode::ToString(ret)); - } else { - IMSA_HILOGI("PerUserSession::OnStartInput End...[%{public}d]\n", userId_); - } - } IMSA_HILOGI("PerUserSession::OnStartInput End. currentClient is nullptr"); } -- Gitee From 7b689538bf3baae0d3b43e6b0aad8593aba6b143 Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Sat, 22 Jan 2022 22:05:03 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhouyongfei --- frameworks/inputmethod_ability/include/i_input_method_core.h | 1 - services/src/peruser_session.cpp | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/inputmethod_ability/include/i_input_method_core.h b/frameworks/inputmethod_ability/include/i_input_method_core.h index c5efbeea0..eb73f9cc4 100644 --- a/frameworks/inputmethod_ability/include/i_input_method_core.h +++ b/frameworks/inputmethod_ability/include/i_input_method_core.h @@ -36,7 +36,6 @@ namespace MiscServices { INITIALIZE_INPUT = FIRST_CALL_TRANSACTION, START_INPUT, STOP_INPUT, - DISPATCH_KEY, SHOW_KEYBOARD, HIDE_KEYBOARD, SET_KEYBOARD_TYPE, diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 37f77669b..6f752bf29 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -1193,6 +1193,7 @@ namespace MiscServices { int32_t result = ams->StartAbility(want); if (result != 0) { IMSA_HILOGE("PerUserSession::StartInputService fail. result = %{public}d", result); + return false; } return true; } -- Gitee