From e9c293bdb77f4e8237c0895a809fcbd4f708d5eb Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Thu, 20 Jan 2022 21:53:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E9=81=97=E7=95=99=E5=90=88?= =?UTF-8?q?=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 1630106..37f7766 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"); }