From ef5141f870a58706bf5555f0843538009478af47 Mon Sep 17 00:00:00 2001 From: cy7717 Date: Tue, 5 Aug 2025 21:09:17 +0800 Subject: [PATCH] Mod Signed-off-by: cy7717 --- .../include/input_client_info.h | 2 + .../include/input_method_types.h | 2 +- services/include/client_group.h | 2 +- .../include/input_method_system_ability.h | 1 + services/include/peruser_session.h | 10 +- services/src/client_group.cpp | 9 +- services/src/input_method_system_ability.cpp | 18 +- services/src/peruser_session.cpp | 225 +++++++++--------- 8 files changed, 138 insertions(+), 131 deletions(-) diff --git a/frameworks/native/inputmethod_controller/include/input_client_info.h b/frameworks/native/inputmethod_controller/include/input_client_info.h index b35768952..902ee578e 100644 --- a/frameworks/native/inputmethod_controller/include/input_client_info.h +++ b/frameworks/native/inputmethod_controller/include/input_client_info.h @@ -31,6 +31,7 @@ enum class UpdateFlag : uint32_t { TEXT_CONFIG, UIEXTENSION_TOKENID, CLIENT_TYPE, + BIND_IME_PID, }; enum class ImeType : int32_t { IME = 0, @@ -62,6 +63,7 @@ struct InputClientInfo { uint64_t displayId { DEFAULT_DISPLAY_ID }; bool isShowKeyboard { false }; // soft keyboard status ImeType bindImeType { ImeType::NONE }; // type of the ime client bind + pid_t bindImePid{ -1 }; TextTotalConfig config = {}; // text config uint32_t eventFlag { NO_EVENT_ON }; // the flag of the all listen event InputAttribute attribute; // the input client attribute diff --git a/interfaces/inner_api/inputmethod_ability/include/input_method_types.h b/interfaces/inner_api/inputmethod_ability/include/input_method_types.h index a0860972e..b06e64629 100644 --- a/interfaces/inner_api/inputmethod_ability/include/input_method_types.h +++ b/interfaces/inner_api/inputmethod_ability/include/input_method_types.h @@ -20,7 +20,7 @@ #include "key_event.h" namespace OHOS { namespace MiscServices { -enum class UnRegisteredType : int32_t { REMOVE_PROXY_IME, SWITCH_PROXY_IME_TO_IME, NONE }; +enum class UnRegisteredType : int32_t { REMOVE_PROXY_IME, NONE }; } // namespace MiscServices } // namespace OHOS #endif // INPUTMETHOD_IMF_PROXY_IME_UNREGISTERED_TYPE_H diff --git a/services/include/client_group.h b/services/include/client_group.h index ad3918935..804e9c9a0 100644 --- a/services/include/client_group.h +++ b/services/include/client_group.h @@ -43,7 +43,7 @@ public: void RemoveClientInfo(const sptr &client, bool isClientDied = false); void UpdateClientInfo(const sptr &client, const std::unordered_map> &updateInfos); + std::variant> &updateInfos); std::shared_ptr GetClientInfo(sptr inputClient); std::shared_ptr GetClientInfo(pid_t pid); diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index 0109ceaa0..96177dfb0 100644 --- a/services/include/input_method_system_ability.h +++ b/services/include/input_method_system_ability.h @@ -208,6 +208,7 @@ private: int32_t RestoreInputmethod(std::string &bundleName); void IncreaseAttachCount(); void DecreaseAttachCount(); + int32_t ChooseBindImeType(int32_t userId, uint64_t displayId, ImeType &bindImeType); class AttachStateGuard { public: diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index cb36cbadc..9d2639407 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -170,6 +170,7 @@ public: void IncreaseScbStartCount(); int32_t TryStartIme(); int32_t TryDisconnectIme(); + ImeType ChooseBindImeType(uint64_t displayId); private: struct ResetManager { @@ -213,15 +214,14 @@ private: int32_t UpdateImeData(sptr core, sptr agent, pid_t pid); int32_t AddImeData(ImeType type, sptr core, sptr agent, pid_t pid); void RemoveImeData(ImeType type, bool isImeDied); - int32_t RemoveIme(const sptr &core, ImeType type); std::shared_ptr GetValidIme(ImeType type); - int32_t BindClientWithIme(const std::shared_ptr &clientInfo, ImeType type, - bool isBindFromClient = false, uint64_t displayId = DEFAULT_DISPLAY_ID); + int32_t BindClientWithIme(const std::shared_ptr &clientInfo, bool isBindFromClient = false, + uint64_t displayId = DEFAULT_DISPLAY_ID); void UnBindClientWithIme(const std::shared_ptr ¤tClientInfo, const DetachOptions &options); void StopClientInput( const std::shared_ptr &clientInfo, bool isStopInactiveClient = false, bool isAsync = false); - void StopImeInput(ImeType currentType, const sptr ¤tChannel, uint32_t sessionId); + void StopImeInput(const std::shared_ptr &clientInfo, uint32_t sessionId); int32_t HideKeyboard(const sptr ¤tClient, const std::shared_ptr &clientGroup); int32_t ShowKeyboard(const sptr ¤tClient, const std::shared_ptr &clientGroup, @@ -253,7 +253,7 @@ private: int32_t HandleFirstStart(const std::shared_ptr &ime, bool isStopCurrentIme); int32_t HandleStartImeTimeout(const std::shared_ptr &ime); bool GetInputTypeToStart(std::shared_ptr &imeToStart); - void HandleImeBindTypeChanged(InputClientInfo &newClientInfo, const std::shared_ptr &clientGroup); + void HandleBindImeChanged(InputClientInfo &newClientInfo, const std::shared_ptr &clientGroup); int32_t NotifyCallingDisplayChanged(uint64_t displayId); bool GetCallingWindowInfo(const InputClientInfo &clientInfo, Rosen::CallingWindowInfo &callingWindowInfo); int32_t SendPrivateData(const std::unordered_map &privateCommand); diff --git a/services/src/client_group.cpp b/services/src/client_group.cpp index 3c8852eee..4622e8520 100644 --- a/services/src/client_group.cpp +++ b/services/src/client_group.cpp @@ -98,8 +98,9 @@ void ClientGroup::RemoveClientInfo(const sptr &client, bool isCli IMSA_HILOGI("client[%{public}d] is removed.", clientInfo->pid); } -void ClientGroup::UpdateClientInfo(const sptr &client, const std::unordered_map> &updateInfos) +void ClientGroup::UpdateClientInfo(const sptr &client, + const std::unordered_map> &updateInfos) { if (client == nullptr) { IMSA_HILOGE("client is nullptr!"); @@ -125,6 +126,10 @@ void ClientGroup::UpdateClientInfo(const sptr &client, const std: VariantUtil::GetValue(updateInfo.second, it->second->bindImeType); break; } + case UpdateFlag::BIND_IME_PID: { + VariantUtil::GetValue(updateInfo.second, it->second->bindImePid); + break; + } case UpdateFlag::STATE: { VariantUtil::GetValue(updateInfo.second, it->second->state); break; diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index caac6c8c6..a5b01f51d 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -578,6 +578,7 @@ int32_t InputMethodSystemAbility::GenerateClientInfo(int32_t userId, InputClient if (identityChecker_->IsFocusedUIExtension(tokenId)) { clientInfo.uiExtensionTokenId = tokenId; } + clientInfo.config.inputAttribute.bundleName = identityChecker_->GetBundleNameByToken(tokenId); auto callingDisplayId = identityChecker_->GetDisplayIdByWindowId(clientInfo.config.windowId); clientInfo.config.privateCommand.insert_or_assign("displayId", PrivateDataValue(static_cast(callingDisplayId))); @@ -685,23 +686,34 @@ int32_t InputMethodSystemAbility::StartInputInner( inputClientInfo.needHide = true; inputClientInfo.isNotifyInputStart = true; } - if (session->IsDefaultDisplayGroup(displayId) && !session->IsProxyImeEnable()) { + inputClientInfo.bindImeType = ChooseBindImeType(userId, displayId); + if (inputClientInfo.bindImeType == ImeType::IME) { auto ret = CheckInputTypeOption(userId, inputClientInfo); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("%{public}d failed to CheckInputTypeOption!", userId); return ret; } + session->SetInputType(); } - inputClientInfo.config.inputAttribute.bundleName = identityChecker_->GetBundleNameByToken(tokenId); int32_t ret = PrepareInput(userId, inputClientInfo); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("failed to PrepareInput!"); return ret; } - session->SetInputType(); return session->OnStartInput(inputClientInfo, agent, imeInfo); } +int32_t InputMethodSystemAbility::ChooseBindImeType(int32_t userId, uint64_t displayId, ImeType &bindImeType) +{ + auto session = UserSessionManager::GetInstance().GetUserSession(userId); + if (session == nullptr) { + IMSA_HILOGE("%{public}d session is nullptr!", userId); + return ErrorCode::ERROR_IMSA_USER_SESSION_NOT_FOUND; + } + bindImeType = session->ChooseBindImeType(displayId); + return ErrorCode::NO_ERROR; +} + int32_t InputMethodSystemAbility::CheckInputTypeOption(int32_t userId, InputClientInfo &inputClientInfo) { IMSA_HILOGI("SecurityImeFlag: %{public}d, IsSameTextInput: %{public}d, IsStarted: %{public}d.", diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 51cc5f8c7..3359c77c7 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -119,7 +119,7 @@ int32_t PerUserSession::HideKeyboard( IMSA_HILOGE("client info is nullptr!"); return ErrorCode::ERROR_CLIENT_NOT_FOUND; } - auto data = GetReadyImeData(clientInfo->bindImeType); + auto data = GetReadyImeData(clientInfo->bindImeType, clientInfo->bindImePid); if (data == nullptr) { IMSA_HILOGE("ime: %{public}d is not exist!", clientInfo->bindImeType); return ErrorCode::ERROR_IME_NOT_STARTED; @@ -147,7 +147,7 @@ int32_t PerUserSession::ShowKeyboard(const sptr ¤tClient, IMSA_HILOGE("client info is nullptr!"); return ErrorCode::ERROR_CLIENT_NOT_FOUND; } - auto data = GetReadyImeData(clientInfo->bindImeType); + auto data = GetReadyImeData(clientInfo->bindImeType, clientInfo->bindImePid); if (data == nullptr) { IMSA_HILOGE("ime: %{public}d is not exist!", clientInfo->bindImeType); return ErrorCode::ERROR_IME_NOT_STARTED; @@ -185,14 +185,14 @@ void PerUserSession::OnClientDied(sptr remote) IMSA_HILOGI("userId: %{public}d.", userId_); if (IsSameClient(remote, clientGroup->GetCurrentClient())) { if (clientInfo != nullptr) { - StopImeInput(clientInfo->bindImeType, clientInfo->channel, 0); + StopImeInput(clientInfo, 0); } clientGroup->SetCurrentClient(nullptr); RestoreCurrentImeSubType(clientGroup->GetDisplayGroupId()); } if (IsSameClient(remote, clientGroup->GetInactiveClient())) { if (clientInfo != nullptr) { - StopImeInput(clientInfo->bindImeType, clientInfo->channel, 0); + StopImeInput(clientInfo, 0); } clientGroup->SetInactiveClient(nullptr); RestoreCurrentImeSubType(clientGroup->GetDisplayGroupId()); @@ -210,15 +210,15 @@ void PerUserSession::OnImeDied(const sptr &remote, ImeType typ return; } IMSA_HILOGI("type: %{public}d.", type); - auto imeData = GetImeData(type); + auto imeData = GetImeData(type); //todo pid if (imeData != nullptr && imeData->imeStatus == ImeStatus::EXITING) { - RemoveImeData(type, true); + RemoveImeData(type, true); //pid InputTypeManager::GetInstance().Set(false); NotifyImeStopFinished(); IMSA_HILOGI("%{public}d not current imeData.", type); return; } - RemoveImeData(type, true); + RemoveImeData(type, true); //todo pid if (!OsAccountAdapter::IsOsAccountForeground(userId_)) { IMSA_HILOGW("userId:%{public}d in background, no need to restart ime.", userId_); return; @@ -252,25 +252,6 @@ void PerUserSession::OnImeDied(const sptr &remote, ImeType typ } } -int32_t PerUserSession::RemoveIme(const sptr &core, ImeType type) -{ - if (core == nullptr) { - return ErrorCode::ERROR_NULL_POINTER; - } - auto data = GetReadyImeData(type); - if (data == nullptr || data->core->AsObject() != core->AsObject()) { - return ErrorCode::ERROR_IME_NOT_STARTED; - } - - auto clientGroup = GetClientGroup(type); - auto clientInfo = clientGroup != nullptr ? clientGroup->GetCurrentClientInfo() : nullptr; - if (clientInfo != nullptr && clientInfo->bindImeType == type) { - UnBindClientWithIme(clientInfo, { .sessionId = 0 }); - } - RemoveImeData(type, true); - return ErrorCode::NO_ERROR; -} - int32_t PerUserSession::OnHideCurrentInput(uint64_t displayId) { auto clientGroup = GetClientGroup(displayId); @@ -366,7 +347,7 @@ int32_t PerUserSession::OnRequestShowInput(uint64_t displayId) return ErrorCode::ERROR_IME_NOT_STARTED; } ImeType type = GetImeType(displayId); - auto data = GetReadyImeData(type); + auto data = GetReadyImeData(type); //// todo 传pid if (data == nullptr) { IMSA_HILOGE("ime: %{public}d doesn't exist!", type); return ErrorCode::ERROR_IME_NOT_STARTED; @@ -503,7 +484,7 @@ void PerUserSession::DeactivateClient(const sptr &client) } clientGroup->SetInactiveClient(client); client->DeactivateClient(); - auto data = GetReadyImeData(clientInfo->bindImeType); + auto data = GetReadyImeData(clientInfo->bindImeType); // todo 传pid if (data == nullptr) { IMSA_HILOGE("ime %{public}d doesn't exist!", clientInfo->bindImeType); return; @@ -519,7 +500,7 @@ void PerUserSession::DeactivateClient(const sptr &client) bool PerUserSession::IsProxyImeEnable() { - auto data = GetReadyImeData(ImeType::PROXY_IME); + auto data = GetReadyImeData(ImeType::PROXY_IME); // todo 不传pid bool ret = false; if (data == nullptr || data->core == nullptr) { return false; @@ -531,50 +512,31 @@ bool PerUserSession::IsProxyImeEnable() int32_t PerUserSession::OnStartInput( const InputClientInfo &inputClientInfo, sptr &agent, std::pair &imeInfo) { - const sptr &client = inputClientInfo.client; - if (client == nullptr) { - IMSA_HILOGE("client is nullptr!"); - return ErrorCode::ERROR_CLIENT_NULL_POINTER; + auto data = GetReadyImeData(inputClientInfo.bindImeType); // todo 不传pid + if (data == nullptr || data->agent == nullptr) { + IMSA_HILOGE("data or agent is nullptr!"); + return ErrorCode::ERROR_IME_NOT_STARTED; } auto clientGroup = GetClientGroup(inputClientInfo.displayId); if (clientGroup == nullptr) { IMSA_HILOGE("client group not found"); return ErrorCode::ERROR_CLIENT_NOT_FOUND; } - auto clientInfo = clientGroup->GetClientInfo(client->AsObject()); - if (clientInfo == nullptr) { - return ErrorCode::ERROR_CLIENT_NOT_FOUND; - } - IMSA_HILOGD("start input with keyboard[%{public}d].", inputClientInfo.isShowKeyboard); - InputClientInfo infoTemp = *clientInfo; - infoTemp.isNotifyInputStart = inputClientInfo.isNotifyInputStart; - ImeType imeType = GetImeType(inputClientInfo.displayId); - if (GetDisplayGroupId(inputClientInfo.displayId) == DEFAULT_DISPLAY_ID) { - HandleImeBindTypeChanged(infoTemp, clientGroup); - imeType = IsProxyImeEnable() ? ImeType::PROXY_IME : ImeType::IME; - } - infoTemp.isShowKeyboard = inputClientInfo.isShowKeyboard; - infoTemp.needHide = inputClientInfo.needHide; - infoTemp.requestKeyboardReason = inputClientInfo.requestKeyboardReason; - infoTemp.config.requestKeyboardReason = inputClientInfo.requestKeyboardReason; - int32_t ret = - BindClientWithIme(std::make_shared(infoTemp), imeType, true, inputClientInfo.displayId); + InputClientInfo clientInfoTmp = inputClientInfo; + clientInfoTmp.bindImePid = data->pid; + HandleBindImeChanged(clientInfoTmp, clientGroup); + int32_t ret = BindClientWithIme(std::make_shared(clientInfoTmp), true, inputClientInfo.displayId); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("bind failed, ret: %{public}d!", ret); return ret; } - auto data = GetReadyImeData(imeType); - if (data == nullptr || data->agent == nullptr) { - IMSA_HILOGE("data or agent is nullptr!"); - return ErrorCode::ERROR_IME_NOT_STARTED; - } agent = data->agent; imeInfo = { data->pid, data->ime.first }; return ErrorCode::NO_ERROR; } int32_t PerUserSession::BindClientWithIme( - const std::shared_ptr &clientInfo, ImeType type, bool isBindFromClient, uint64_t displayId) + const std::shared_ptr &clientInfo, bool isBindFromClient, uint64_t displayId) { if (clientInfo == nullptr) { IMSA_HILOGE("clientInfo is nullptr!"); @@ -585,10 +547,11 @@ int32_t PerUserSession::BindClientWithIme( IMSA_HILOGE("not found group"); return ErrorCode::ERROR_IMSA_NULLPTR; } - IMSA_HILOGD("imeType: %{public}d, isShowKeyboard: %{public}d, isBindFromClient: %{public}d.", type, + auto bindImeType = clientInfo->bindImeType; + IMSA_HILOGD("imeType: %{public}d, isShowKeyboard: %{public}d, isBindFromClient: %{public}d.", bindImeType, clientInfo->isShowKeyboard, isBindFromClient); - auto data = GetValidIme(type); - if (data == nullptr) { + auto data = GetReadyImeData(bindImeType, clientInfo->bindImePid); //TODO + if (data == nullptr || data->core == nullptr) { return ErrorCode::ERROR_IME_NOT_STARTED; } if (!data->imeExtendInfo.privateCommand.empty()) { @@ -608,7 +571,7 @@ int32_t PerUserSession::BindClientWithIme( IMSA_HILOGE("start input failed, ret: %{public}d!", ret); return ErrorCode::ERROR_IME_START_INPUT_FAILED; } - if (type == ImeType::IME) { + if (bindImeType == ImeType::IME) { InputMethodSysEvent::GetInstance().ReportImeState(ImeState::BIND, data->pid, ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_)->bundleName); Memory::MemMgrClient::GetInstance().SetCritical(getpid(), true, INPUT_METHOD_SYSTEM_ABILITY_ID); @@ -620,8 +583,9 @@ int32_t PerUserSession::BindClientWithIme( return ErrorCode::ERROR_IMSA_CLIENT_INPUT_READY_FAILED; } } - clientGroup->UpdateClientInfo(clientInfo->client->AsObject(), { { UpdateFlag::BINDIMETYPE, type }, - { UpdateFlag::ISSHOWKEYBOARD, clientInfo->isShowKeyboard }, { UpdateFlag::STATE, ClientState::ACTIVE } }); + clientGroup->UpdateClientInfo(clientInfo->client->AsObject(), + { { UpdateFlag::BINDIMETYPE, bindImeType }, { UpdateFlag::ISSHOWKEYBOARD, clientInfo->isShowKeyboard }, + { UpdateFlag::STATE, ClientState::ACTIVE }, { UpdateFlag::BIND_IME_PID, clientInfo->bindImePid } }); ReplaceCurrentClient(clientInfo->client, clientGroup); if (clientInfo->isShowKeyboard) { clientGroup->NotifyInputStartToClients( @@ -640,7 +604,7 @@ void PerUserSession::UnBindClientWithIme( IMSA_HILOGD("unbind from service."); StopClientInput(currentClientInfo, options.isNotifyClientAsync); } - StopImeInput(currentClientInfo->bindImeType, currentClientInfo->channel, options.sessionId); + StopImeInput(currentClientInfo, options.sessionId); } void PerUserSession::StopClientInput( @@ -669,12 +633,18 @@ void PerUserSession::StopClientInput( clientInfo->pid, ret); } -void PerUserSession::StopImeInput(ImeType currentType, const sptr ¤tChannel, uint32_t sessionId) +void PerUserSession::StopImeInput(const std::shared_ptr &clientInfo, uint32_t sessionId) { - auto data = GetReadyImeData(currentType); - if (data == nullptr) { + if (clientInfo == nullptr) { + return; + } + auto currentType = clientInfo->bindImeType; + auto currentChannel = clientInfo->channel; + auto data = GetReadyImeData(currentType, clientInfo->bindImePid);//TODO + if (data == nullptr || data->core == nullptr) { return; } + auto ret = RequestIme(data, RequestType::STOP_INPUT, [&data, ¤tChannel, sessionId]() { return data->core->StopInput(currentChannel, sessionId); }); @@ -691,7 +661,7 @@ void PerUserSession::StopImeInput(ImeType currentType, const sptr void PerUserSession::OnSecurityChange(int32_t security) { - auto data = GetReadyImeData(ImeType::IME); + auto data = GetReadyImeData(ImeType::IME);// todo 不传pid if (data == nullptr) { IMSA_HILOGE("ime: %{public}d is not exist!", ImeType::IME); return; @@ -704,7 +674,8 @@ void PerUserSession::OnSecurityChange(int32_t security) int32_t PerUserSession::OnSetCoreAndAgent(const sptr &core, const sptr &agent) { IMSA_HILOGI("start."); - auto ret = UpdateImeData(core, agent, IPCSkeleton::GetCallingPid()); + auto pid = IPCSkeleton::GetCallingPid(); + auto ret = UpdateImeData(core, agent, pid); if (ret != ErrorCode::NO_ERROR) { return ret; } @@ -721,7 +692,8 @@ int32_t PerUserSession::OnSetCoreAndAgent(const sptr &core, co auto clientInfo = GetCurrentClientInfo(); if (clientInfo != nullptr && IsImeStartInBind(clientInfo->bindImeType, imeType)) { ClearRequestKeyboardReason(clientInfo); - BindClientWithIme(clientInfo, imeType); + clientInfo->bindImePid = pid; + BindClientWithIme(clientInfo); SetInputType(); } bool isStarted = true; @@ -733,18 +705,22 @@ int32_t PerUserSession::OnRegisterProxyIme(const sptr &core, c { IMSA_HILOGD("start."); auto imeType = ImeType::PROXY_IME; - auto ret = AddImeData(imeType, core, agent, IPCSkeleton::GetCallingPid()); + auto pid = IPCSkeleton::GetCallingPid(); + auto ret = AddImeData(imeType, core, agent, pid); if (ret != ErrorCode::NO_ERROR) { return ret; } auto clientInfo = GetCurrentClientInfo(); if (clientInfo != nullptr) { if (IsProxyImeStartInBind(clientInfo->bindImeType, imeType)) { - BindClientWithIme(clientInfo, imeType); + clientInfo->bindImePid = pid; + BindClientWithIme(clientInfo); } if (IsProxyImeStartInImeBind(clientInfo->bindImeType, imeType)) { UnBindClientWithIme(clientInfo, { .sessionId = 0 }); - BindClientWithIme(clientInfo, imeType); + clientInfo->bindImePid = pid; + clientInfo->bindImeType = imeType; + BindClientWithIme(clientInfo); } } return ErrorCode::NO_ERROR; @@ -778,7 +754,8 @@ int32_t PerUserSession::OnRegisterProxyIme( { IMSA_HILOGI("start. displayId: %{public}" PRIu64 "", displayId); auto imeType = ImeType::PROXY_AGENT_IME; - auto ret = AddImeData(imeType, core, agent, IPCSkeleton::GetCallingPid()); + auto pid = IPCSkeleton::GetCallingPid(); + auto ret = AddImeData(imeType, core, agent, pid); if (ret != ErrorCode::NO_ERROR) { return ret; } @@ -789,7 +766,9 @@ int32_t PerUserSession::OnRegisterProxyIme( agentDisplayId_.store(displayId); auto clientInfo = GetCurrentClientInfo(displayId); if (clientInfo != nullptr) { - BindClientWithIme(clientInfo, imeType); + clientInfo->bindImeType = imeType; + clientInfo->bindImePid = pid; + BindClientWithIme(clientInfo); } return ErrorCode::NO_ERROR; } @@ -800,7 +779,7 @@ int32_t PerUserSession::OnUnregisterProxyIme(uint64_t displayId) if (displayId != agentDisplayId_.load()) { return false; } - RemoveImeData(ImeType::PROXY_AGENT_IME, false); + RemoveImeData(ImeType::PROXY_AGENT_IME, false); // todo pid { std::lock_guard lock(virtualDisplayLock_); virtualScreenDisplayId_.erase(displayId); @@ -817,27 +796,25 @@ int32_t PerUserSession::OnUnregisterProxyIme(uint64_t displayId) int32_t PerUserSession::OnUnRegisteredProxyIme(UnRegisteredType type, const sptr &core) { IMSA_HILOGD("proxy unregister type: %{public}d.", type); - // 0: stop proxy 1: switch to ima - if (type == UnRegisteredType::REMOVE_PROXY_IME) { - RemoveIme(core, ImeType::PROXY_IME); - return ErrorCode::NO_ERROR; + if (type != UnRegisteredType::REMOVE_PROXY_IME) { + return ErrorCode::ERROR_BAD_PARAMETERS; } - if (type == UnRegisteredType::SWITCH_PROXY_IME_TO_IME) { - auto clientInfo = GetCurrentClientInfo(); - if (clientInfo == nullptr) { - IMSA_HILOGE("not found current client!"); - return ErrorCode::ERROR_CLIENT_NOT_BOUND; - } - if (clientInfo->bindImeType == ImeType::PROXY_IME) { - UnBindClientWithIme(clientInfo, { .sessionId = 0 }); - } - InputClientInfo infoTemp; - infoTemp.isShowKeyboard = true; - infoTemp.client = clientInfo->client; - infoTemp.channel = clientInfo->channel; - return BindClientWithIme(std::make_shared(infoTemp), ImeType::IME); + if (core == nullptr) { + return ErrorCode::ERROR_NULL_POINTER; + } + auto imeType = ImeType::PROXY_IME; + auto imePid = IPCSkeleton::GetCallingPid() + auto data = GetReadyImeData(imeType, imePid); + if (data == nullptr) { + return ErrorCode::ERROR_IME_NOT_STARTED; + } + auto clientGroup = GetClientGroup(imeType); + auto clientInfo = clientGroup != nullptr ? clientGroup->GetCurrentClientInfo() : nullptr; + if (clientInfo != nullptr && clientInfo->bindImeType == imeType && clientInfo->bindImePid == imePid) { + UnBindClientWithIme(clientInfo, { .sessionId = 0 }); } - return ErrorCode::ERROR_BAD_PARAMETERS; + RemoveImeData(imeType, imePid, true); //todo + return ErrorCode::NO_ERROR; } int32_t PerUserSession::InitInputControlChannel() @@ -848,7 +825,7 @@ int32_t PerUserSession::InitInputControlChannel() IMSA_HILOGE("new inputControlChannel failed!"); return ErrorCode::ERROR_NULL_POINTER; } - auto data = GetReadyImeData(ImeType::IME); + auto data = GetReadyImeData(ImeType::IME);// todo 不传pid if (data == nullptr) { IMSA_HILOGE("ime: %{public}d is not exist!", ImeType::IME); return ErrorCode::ERROR_IME_NOT_STARTED; @@ -1069,7 +1046,7 @@ void PerUserSession::OnUnfocused(uint64_t displayId, int32_t pid, int32_t uid) void PerUserSession::OnScreenUnlock() { ImeCfgManager::GetInstance().ModifyTempScreenLockImeCfg(userId_, ""); - auto imeData = GetImeData(ImeType::IME); + auto imeData = GetImeData(ImeType::IME); // todo 不传pid if (imeData != nullptr && imeData->ime == GetImeUsedBeforeScreenLocked()) { IMSA_HILOGD("no need to switch"); return; @@ -1084,7 +1061,7 @@ void PerUserSession::OnScreenUnlock() void PerUserSession::OnScreenLock() { - auto imeData = GetImeData(ImeType::IME); + auto imeData = GetImeData(ImeType::IME); // todo 不传pid if (imeData == nullptr) { IMSA_HILOGD("imeData is nullptr"); std::pair ime{ "", "" }; @@ -1217,7 +1194,7 @@ int32_t PerUserSession::StartCurrentIme(bool isStopCurrentIme) InputMethodSysEvent::GetInstance().InputmethodFaultReporter(ret, imeToStart->imeId, "start ime failed!"); return ret; } - auto readyIme = GetReadyImeData(ImeType::IME); + auto readyIme = GetReadyImeData(ImeType::IME);// todo 不传pid if (readyIme == nullptr) { IMSA_HILOGE("ime abnormal."); return ErrorCode::ERROR_IME_NOT_STARTED; @@ -1483,7 +1460,7 @@ int32_t PerUserSession::SwitchSubtype(const SubProperty &subProperty) int32_t PerUserSession::SwitchSubtypeWithoutStartIme(const SubProperty &subProperty) { - auto data = GetReadyImeData(ImeType::IME); + auto data = GetReadyImeData(ImeType::IME);// todo 不传pid if (data == nullptr || data->core == nullptr) { IMSA_HILOGE("ime: %{public}d is not exist, or core is nullptr.", ImeType::IME); return ErrorCode::ERROR_IME_NOT_STARTED; @@ -1530,7 +1507,7 @@ int32_t PerUserSession::RestoreCurrentImeSubType(uint64_t callingDisplayId) } auto typeIme = InputTypeManager::GetInstance().GetCurrentIme(); InputTypeManager::GetInstance().Set(false); - auto imeData = GetReadyImeData(ImeType::IME); + auto imeData = GetReadyImeData(ImeType::IME);// todo 不传pid if (imeData == nullptr) { IMSA_HILOGD("has no ready ime, not deal."); return ErrorCode::NO_ERROR; @@ -1552,7 +1529,7 @@ int32_t PerUserSession::RestoreCurrentImeSubType(uint64_t callingDisplayId) bool PerUserSession::IsCurrentImeByPid(int32_t pid) { - auto imeData = GetImeData(ImeType::IME); + auto imeData = GetImeData(ImeType::IME);// todo 不传pid if (imeData == nullptr) { IMSA_HILOGE("ime not started!"); return false; @@ -1569,7 +1546,7 @@ int32_t PerUserSession::IsPanelShown(const PanelInfo &panelInfo, bool &isShown) isShown = false; return ErrorCode::NO_ERROR; } - auto ime = GetReadyImeData(ImeType::IME); + auto ime = GetReadyImeData(ImeType::IME);// todo 不传pid if (ime == nullptr) { IMSA_HILOGE("ime not started!"); return ErrorCode::ERROR_IME_NOT_STARTED; @@ -1609,7 +1586,7 @@ int32_t PerUserSession::RequestIme(const std::shared_ptr &data, Request int32_t PerUserSession::OnConnectSystemCmd(const sptr &channel, sptr &agent) { - auto data = GetReadyImeData(ImeType::IME); + auto data = GetReadyImeData(ImeType::IME);// todo 不传pid if (data == nullptr) { IMSA_HILOGE("ime: %{public}d is not exist!", ImeType::IME); return ErrorCode::ERROR_IME_NOT_STARTED; @@ -1863,7 +1840,7 @@ int32_t PerUserSession::StartIme(const std::shared_ptr &ime, bool if (ime == nullptr) { return ErrorCode::ERROR_IMSA_IME_TO_START_NULLPTR; } - auto imeData = GetImeData(ImeType::IME); + auto imeData = GetImeData(ImeType::IME);// todo 不传pid if (imeData == nullptr) { return HandleFirstStart(ime, isStopCurrentIme); } @@ -1895,7 +1872,7 @@ ImeAction PerUserSession::GetImeAction(ImeEvent action) int32_t PerUserSession::StartCurrentIme(const std::shared_ptr &ime) { - auto imeData = GetImeData(ImeType::IME); + auto imeData = GetImeData(ImeType::IME);// todo 不传pid if (imeData == nullptr) { return StartInputService(ime); } @@ -1979,7 +1956,7 @@ int32_t PerUserSession::StopReadyCurrentIme() if (clientInfo != nullptr && clientInfo->bindImeType == ImeType::IME) { StopClientInput(clientInfo); } - auto imeData = GetImeData(ImeType::IME); + auto imeData = GetImeData(ImeType::IME);// todo 不传pid if (imeData == nullptr) { return ErrorCode::NO_ERROR; } @@ -2004,13 +1981,13 @@ int32_t PerUserSession::StopReadyCurrentIme() int32_t PerUserSession::ForceStopCurrentIme(bool isNeedWait) { - auto imeData = GetImeData(ImeType::IME); + auto imeData = GetImeData(ImeType::IME);// todo 不传pid if (imeData == nullptr) { return ErrorCode::NO_ERROR; } if (!ImeInfoInquirer::GetInstance().IsRunningIme(userId_, imeData->ime.first)) { IMSA_HILOGW("[%{public}s, %{public}s] already stop.", imeData->ime.first.c_str(), imeData->ime.second.c_str()); - RemoveImeData(ImeType::IME, true); + RemoveImeData(ImeType::IME, true); // todo 此处坚决不能传pid return ErrorCode::NO_ERROR; } auto clientInfo = GetCurrentClientInfo(); @@ -2067,7 +2044,7 @@ int32_t PerUserSession::StartUserSpecifiedIme(uint64_t callingDisplayId) } InputTypeManager::GetInstance().Set(false); auto cfgIme = ImeInfoInquirer::GetInstance().GetImeToStart(userId_); - auto imeData = GetReadyImeData(ImeType::IME); + auto imeData = GetReadyImeData(ImeType::IME);// todo 不传pid if (imeData != nullptr && cfgIme != nullptr && imeData->ime.first == cfgIme->bundleName && imeData->ime.second == cfgIme->extName) { return ErrorCode::NO_ERROR; @@ -2138,7 +2115,7 @@ bool PerUserSession::GetInputTypeToStart(std::shared_ptr &imeToSta return true; } -void PerUserSession::HandleImeBindTypeChanged( +void PerUserSession::HandleBindImeChanged( InputClientInfo &newClientInfo, const std::shared_ptr &clientGroup) { /* isClientInactive: true: represent the oldClientInfo is inactiveClient's @@ -2162,8 +2139,9 @@ void PerUserSession::HandleImeBindTypeChanged( if (oldClientInfo == nullptr) { return; } - if (!IsImeBindTypeChanged(oldClientInfo->bindImeType)) { - return; + if (IsSameClient(newClientInfo.client, oldClientInfo->client) + && oldClientInfo->bindImePid != newClientInfo.bindImePid) { + newClientInfo.isNotifyInputStart = true; } // has current client, but new client is not current client if (!isClientInactive && !IsSameClient(newClientInfo.client, oldClientInfo->client)) { @@ -2178,7 +2156,7 @@ void PerUserSession::HandleImeBindTypeChanged( newClientInfo.isNotifyInputStart = true; } if (isClientInactive) { - StopImeInput(oldClientInfo->bindImeType, oldClientInfo->channel, 0); + StopImeInput(oldClientInfo, 0); return; } UnBindClientWithIme(oldClientInfo, { .sessionId = 0 }); @@ -2186,7 +2164,7 @@ void PerUserSession::HandleImeBindTypeChanged( void PerUserSession::TryUnloadSystemAbility() { - auto data = GetReadyImeData(ImeType::IME); + auto data = GetReadyImeData(ImeType::IME);// todo 不传pid if (data != nullptr && data->imeStateManager != nullptr) { if (data->imeStateManager->IsImeInUse()) { return; @@ -2409,7 +2387,7 @@ int32_t PerUserSession::SpecialSendPrivateData(const std::unordered_map &privateCommand) { - auto data = GetReadyImeData(ImeType::IME); + auto data = GetReadyImeData(ImeType::IME);// todo 不传pid if (data == nullptr) { IMSA_HILOGE("data is nullptr"); return ErrorCode::ERROR_IME_NOT_STARTED; @@ -2500,7 +2478,7 @@ std::pair PerUserSession::StartPreconfiguredD } InputTypeManager::GetInstance().Set(false); auto preDefaultIme = ImeInfoInquirer::GetInstance().GetDefaultIme(); - auto ime = GetReadyImeData(ImeType::IME); + auto ime = GetReadyImeData(ImeType::IME);// todo 不传pid if (ime != nullptr && (ime->ime.first == preDefaultIme.bundleName && ime->ime.second == preDefaultIme.extName)) { return std::make_pair(ErrorCode::NO_ERROR, StartPreDefaultImeStatus::HAS_STARTED); } @@ -2558,7 +2536,7 @@ int32_t PerUserSession::TryStartIme() return ErrorCode::ERROR_OPERATION_NOT_ALLOWED; } isBlockStartedByLowMem_.store(false); - auto imeData = GetImeData(ImeType::IME); + auto imeData = GetImeData(ImeType::IME);// todo 不传pid if (imeData != nullptr) { IMSA_HILOGI("has running ime:%{public}s, no need to deal.", imeData->ime.first.c_str()); return ErrorCode::ERROR_IME_HAS_STARTED; @@ -2578,7 +2556,7 @@ int32_t PerUserSession::TryStartIme() int32_t PerUserSession::TryDisconnectIme() { - auto imeData = GetImeData(ImeType::IME); + auto imeData = GetImeData(ImeType::IME);// todo 不传pid if (imeData == nullptr) { return ErrorCode::ERROR_IME_NOT_STARTED; } @@ -2630,5 +2608,14 @@ void PerUserSession::ClearImeConnection(const sptr &c IMSA_HILOGI("clear imeConnection."); connection_ = nullptr; } + +ImeType PerUserSession::ChooseBindImeType(uint64_t displayId) +{ + auto bindImeType = GetImeType(displayId); + if (GetDisplayGroupId(displayId) == DEFAULT_DISPLAY_ID) { + bindImeType = IsProxyImeEnable() ? ImeType::PROXY_IME : ImeType::IME; + } + return bindImeType; +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file -- Gitee