From c2e49a72fd171deae9d8ba025c519a43e65da52b Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Tue, 16 Jan 2024 22:27:48 +0800 Subject: [PATCH 01/13] modify code Signed-off-by: zhaolinglan --- services/BUILD.gn | 1 + services/include/ime_aging_manager.h | 64 +++++++ services/include/peruser_session.h | 7 +- services/src/ime_aging_manager.cpp | 173 +++++++++++++++++++ services/src/input_method_system_ability.cpp | 13 +- services/src/peruser_session.cpp | 26 ++- 6 files changed, 268 insertions(+), 16 deletions(-) create mode 100644 services/include/ime_aging_manager.h create mode 100644 services/src/ime_aging_manager.cpp diff --git a/services/BUILD.gn b/services/BUILD.gn index 5e3fbc565..360acb54d 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -50,6 +50,7 @@ ohos_shared_library("inputmethod_service") { "${inputmethod_path}/services/identity_checker/src/identity_checker_impl.cpp", "src/global.cpp", "src/im_common_event_manager.cpp", + "src/ime_aging_manager.cpp", "src/ime_cfg_manager.cpp", "src/ime_info_inquirer.cpp", "src/input_control_channel_proxy.cpp", diff --git a/services/include/ime_aging_manager.h b/services/include/ime_aging_manager.h new file mode 100644 index 000000000..798f88d7b --- /dev/null +++ b/services/include/ime_aging_manager.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SERVICES_INCLUDE_IME_AGING_MANAGER_H +#define SERVICES_INCLUDE_IME_AGING_MANAGER_H + +#include +#include +#include + +#include "global.h" +#include "i_input_method_agent.h" +#include "i_input_method_core.h" +#include "input_death_recipient.h" +#include "peruser_session.h" +#include "timer.h" + +namespace OHOS { +namespace MiscServices { +struct ImeCache { + ImeData data; + std::chrono::system_clock::time_point timestamp{}; + ImeCache(ImeData data, std::chrono::system_clock::time_point timestamp) + : data(std::move(data)), timestamp(timestamp) + { + } +}; + +class ImeAgingManager { +public: + static ImeAgingManager &GetInstance(); + bool Push(const std::string &imeName, const std::shared_ptr &imeCache); + std::shared_ptr Pop(const std::string &imeName); + +private: + ImeAgingManager(); + void ClearOldest(); + void AgingCache(); + void StartAging(); + void StopAging(); + void StopIme(const std::shared_ptr &ime); + + std::mutex timerMutex_; + Utils::Timer timer_; + uint32_t timerId_; + std::recursive_mutex cacheMutex_; + std::map> imeCaches_; +}; +} // namespace MiscServices +} // namespace OHOS + +#endif // SERVICES_INCLUDE_IME_AGING_MANAGER_H diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index 946f4999f..f8b745697 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -80,7 +80,7 @@ public: int32_t OnRequestHideInput(); void OnSecurityChange(int32_t &security); void OnHideSoftKeyBoardSelf(); - void StopInputService(); + void StopInputService(const std::string &imeName); void NotifyImeChangeToClients(const Property &property, const SubProperty &subProperty); int32_t SwitchSubtype(const SubProperty &subProperty); void UpdateCurrentUserId(int32_t userId); @@ -89,7 +89,7 @@ public: int64_t GetCurrentClientPid(); int32_t OnPanelStatusChange(const InputWindowStatus &status, const InputWindowInfo &windowInfo); int32_t OnUpdateListenEventFlag(const InputClientInfo &clientInfo); - bool StartInputService(const std::string &imeName, bool isRetry); + bool StartIme(const std::string &imeName, bool isRetry); int32_t OnRegisterProxyIme(const sptr &core, const sptr &agent); int32_t OnUnRegisteredProxyIme(UnRegisteredType type, const sptr &core); bool IsProxyImeEnable(); @@ -137,10 +137,11 @@ private: &updateInfos); int32_t AddImeData(ImeType type, sptr core, sptr agent); - void RemoveImeData(ImeType type); + void RemoveImeData(ImeType type, bool isImeDied = true); int32_t RemoveIme(const sptr &core, ImeType type); std::shared_ptr GetImeData(ImeType type); std::shared_ptr GetValidIme(ImeType type); + bool StartInputService(const std::string &imeName, bool isRetry); int32_t BindClientWithIme( const std::shared_ptr &clientInfo, ImeType type, bool isBindFromClient = false); diff --git a/services/src/ime_aging_manager.cpp b/services/src/ime_aging_manager.cpp new file mode 100644 index 000000000..117ccfd16 --- /dev/null +++ b/services/src/ime_aging_manager.cpp @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ime_aging_manager.h" + +#include "common_timer_errors.h" +#include "peruser_session.h" + +namespace OHOS { +namespace MiscServices { +constexpr uint32_t MAX_CACHES_SIZE = 5; +constexpr uint32_t AGING_TIME = 60; +constexpr uint32_t TIMER_TASK_INTERNAL = 60000; +ImeAgingManager::ImeAgingManager() : timer_("imeCacheTimer"), timerId_(0) +{ +} + +ImeAgingManager &ImeAgingManager::GetInstance() +{ + static ImeAgingManager ImeAgingManager; + return ImeAgingManager; +} + +bool ImeAgingManager::Push(const std::string &imeName, const std::shared_ptr &imeCache) +{ + if (imeName.empty() || imeCache == nullptr) { + IMSA_HILOGE("ime name invalid or imeCache is nullptr"); + return false; + } + imeCache->timestamp = std::chrono::system_clock::now(); + + std::lock_guard lock(cacheMutex_); + auto it = imeCaches_.find(imeName); + if (it != imeCaches_.end()) { + it->second = imeCache; + return true; + } + if (imeCaches_.empty()) { + StartAging(); + } + if (imeCaches_.size() == MAX_CACHES_SIZE) { + ClearOldest(); + } + imeCaches_.insert({ imeName, imeCache }); + return true; +} + +bool ImeAgingManager::Push(const std::string &imeName, const std::shared_ptr &imeData) +{ + if (imeName.empty() || imeCache == nullptr) { + IMSA_HILOGE("ime name invalid or imeCache is nullptr"); + return false; + } + auto imeCache = std::make_shared(*imeData, std::chrono::system_clock::now()); + imeCache->data.deathRecipient->SetDeathRecipient([this, imeName](const wptr &) { Pop(imeName); }); + + std::lock_guard lock(cacheMutex_); + auto it = imeCaches_.find(imeName); + if (it != imeCaches_.end()) { + it->second = imeCache; + return true; + } + if (imeCaches_.empty()) { + StartAging(); + } + if (imeCaches_.size() == MAX_CACHES_SIZE) { + ClearOldest(); + } + imeCaches_.insert({ imeName, imeCache }); + return true; +} + +std::shared_ptr ImeAgingManager::Pop(const std::string &imeName) +{ + std::lock_guard lock(cacheMutex_); + auto it = imeCaches_.find(imeName); + if (it == imeCaches_.end()) { + return nullptr; + } + auto ime = it->second->data; + if (ime.core->AsObject() != nullptr && ime.deathRecipient != nullptr) { + ime.core->AsObject()->RemoveDeathRecipient(ime.deathRecipient); + ime.deathRecipient = nullptr; + } + imeCaches_.erase(imeName); + if (imeCaches_.empty()) { + StopAging(); + } + return std::make_shared(ime); +} + +void ImeAgingManager::ClearOldest() +{ + std::lock_guard lock(cacheMutex_); + auto oldestIme = imeCaches_.begin(); + for (auto it = imeCaches_.begin(); it != imeCaches_.end(); it++) { + if (it->second->timestamp < oldestIme->second->timestamp) { + oldestIme = it; + } + } + auto core = oldestIme->second->data.core; + if (core != nullptr) { + IMSA_HILOGI("stop ime: %{public}s", oldestIme->first.c_str()); + StopIme(oldestIme->second); + } + imeCaches_.erase(oldestIme); +} + +void ImeAgingManager::AgingCache() +{ + std::lock_guard lock(cacheMutex_); + for (auto it = imeCaches_.begin(); it != imeCaches_.end();) { + // each IME can be kept for 60 seconds, and then be stopped. + auto now = std::chrono::system_clock::now(); + if (std::chrono::duration_cast(now - it->second->timestamp).count() < AGING_TIME) { + it++; + continue; + } + auto core = it->second->data.core; + if (core != nullptr) { + IMSA_HILOGI("stop ime: %{public}s", it->first.c_str()); + StopIme(it->second); + } + it = imeCaches_.erase(it); + } + if (imeCaches_.empty()) { + StopAging(); + } +} + +void ImeAgingManager::StopIme(const std::shared_ptr &ime) +{ + auto imeData = ime->data; + if (imeData.core == nullptr) { + return; + } + if (imeData.core->AsObject() != nullptr && imeData.deathRecipient != nullptr) { + imeData.core->AsObject()->RemoveDeathRecipient(imeData.deathRecipient); + } + imeData.core->StopInputService(); +} + +void ImeAgingManager::StartAging() +{ + std::lock_guard lock(timerMutex_); + uint32_t ret = timer_.Setup(); + if (ret != Utils::TIMER_ERR_OK) { + IMSA_HILOGE("failed to create timer"); + return; + } + timerId_ = timer_.Register([this]() { AgingCache(); }, TIMER_TASK_INTERNAL, false); +} + +void ImeAgingManager::StopAging() +{ + std::lock_guard lock(timerMutex_); + timer_.Unregister(timerId_); + timer_.Shutdown(false); +} +} // namespace MiscServices +} // namespace OHOS diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 4cdc35c2a..4199ae269 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -210,7 +210,7 @@ void InputMethodSystemAbility::StartUserIdListener() bool InputMethodSystemAbility::StartInputService(const std::string &imeId) { - return userSession_->StartInputService(imeId, true); + return userSession_->StartIme(imeId, true); } int32_t InputMethodSystemAbility::PrepareInput(InputClientInfo &clientInfo) @@ -596,7 +596,8 @@ int32_t InputMethodSystemAbility::Switch(const std::string &bundleName, const st // Switch the current InputMethodExtension to the new InputMethodExtension int32_t InputMethodSystemAbility::SwitchExtension(const std::shared_ptr &info) { - userSession_->StopInputService(); + auto currentIme = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_)->imeId; + userSession_->StopInputService(currentIme); std::string targetIme = info->prop.name + "/" + info->prop.id; ImeCfgManager::GetInstance().ModifyImeCfg({ userId_, targetIme, info->subProp.id }); ImeInfoInquirer::GetInstance().SetCurrentImeInfo(info); @@ -625,10 +626,10 @@ int32_t InputMethodSystemAbility::SwitchSubType(const std::shared_ptr & int32_t InputMethodSystemAbility::SwitchInputType(const SwitchInfo &switchInfo) { - auto currentImeBundleName = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_)->bundleName; + auto currentIme = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_); bool checkSameIme = InputTypeManager::GetInstance().IsStarted() ? switchInfo.bundleName == InputTypeManager::GetInstance().GetCurrentIme().bundleName - : switchInfo.bundleName == currentImeBundleName; + : switchInfo.bundleName == currentIme->bundleName; if (checkSameIme) { IMSA_HILOGD("only need to switch subtype: %{public}s", switchInfo.subName.c_str()); auto ret = userSession_->SwitchSubtype({ .name = switchInfo.bundleName, .id = switchInfo.subName }); @@ -643,7 +644,7 @@ int32_t InputMethodSystemAbility::SwitchInputType(const SwitchInfo &switchInfo) return ErrorCode::ERROR_NULL_POINTER; } - userSession_->StopInputService(); + userSession_->StopInputService(currentIme->imeId); std::string targetIme = switchInfo.bundleName + '/' + targetImeProperty->id; InputTypeManager::GetInstance().Set(true, { switchInfo.bundleName, switchInfo.subName }); if (!StartInputService(targetIme)) { @@ -780,7 +781,7 @@ int32_t InputMethodSystemAbility::OnUserStarted(const Message *msg) SecurityModeParser::GetInstance()->GetFullModeList(userId_); } auto currentIme = ImeCfgManager::GetInstance().GetCurrentImeCfg(oldUserId)->imeId; - userSession_->StopInputService(); + userSession_->StopInputService(currentIme); // user switch, reset currentImeInfo_ = nullptr ImeInfoInquirer::GetInstance().SetCurrentImeInfo(nullptr); auto newIme = ImeInfoInquirer::GetInstance().GetImeToBeStarted(userId_); diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 60156cc84..74d151c40 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -19,6 +19,7 @@ #include "ability_manager_client.h" #include "element_name.h" +#include "ime_aging_manager.h" #include "ime_cfg_manager.h" #include "ime_info_inquirer.h" #include "input_client_proxy.h" @@ -646,21 +647,21 @@ int32_t PerUserSession::InitInputControlChannel() return data->core->InitInputControlChannel(inputControlChannel); } -void PerUserSession::StopInputService() +void PerUserSession::StopInputService(const std::string &imeName) { auto data = GetImeData(ImeType::IME); if (data == nullptr) { IMSA_HILOGE("ime: %{public}d is not exist", ImeType::IME); return; } - IMSA_HILOGI("PerUserSession"); - RemoveImeData(ImeType::IME); + IMSA_HILOGI("imeName: %{public}s", imeName.c_str()); + ImeAgingManager::GetInstance().Push(imeName, data); + RemoveImeData(ImeType::IME, false); auto client = GetCurrentClient(); auto clientInfo = client != nullptr ? GetClientInfo(client->AsObject()) : nullptr; if (clientInfo != nullptr && clientInfo->bindImeType == ImeType::IME) { StopClientInput(client); } - data->core->StopInputService(); } bool PerUserSession::IsRestartIme() @@ -809,7 +810,7 @@ std::shared_ptr PerUserSession::GetValidIme(ImeType type) return data; } -void PerUserSession::RemoveImeData(ImeType type) +void PerUserSession::RemoveImeData(ImeType type, bool isImeDied) { std::lock_guard lock(imeDataLock_); auto it = imeData_.find(type); @@ -818,7 +819,7 @@ void PerUserSession::RemoveImeData(ImeType type) return; } auto data = it->second; - if (data->core != nullptr && data->core->AsObject() != nullptr) { + if (isImeDied && data->core != nullptr && data->core->AsObject() != nullptr) { data->core->AsObject()->RemoveDeathRecipient(data->deathRecipient); } data->deathRecipient = nullptr; @@ -883,6 +884,16 @@ bool PerUserSession::IsSameClient(sptr source, sptr return source != nullptr && dest != nullptr && source->AsObject() == dest->AsObject(); } +bool PerUserSession::StartIme(const std::string &imeName, bool isRetry) +{ + auto ime = ImeAgingManager::GetInstance().Pop(imeName); + if (ime != nullptr) { + IMSA_HILOGI("hit the ime cache"); + return OnSetCoreAndAgent(ime->core, ime->agent); + } + return StartInputService(imeName, isRetry); +} + bool PerUserSession::StartInputService(const std::string &imeName, bool isRetry) { std::string::size_type pos = imeName.find('/'); @@ -1058,7 +1069,8 @@ int32_t PerUserSession::ExitCurrentInputType() return ret; } IMSA_HILOGI("need switch ime to: %{public}s/%{public}s", cfgIme->bundleName.c_str(), cfgIme->subName.c_str()); - StopInputService(); + std::string typeImeName = typeIme.bundleName + '/' + typeIme.subName; + StopInputService(typeImeName); InputTypeManager::GetInstance().Set(false); if (!StartInputService(cfgIme->imeId, true)) { IMSA_HILOGE("failed to start ime"); -- Gitee From 8982cad34f613fa0364cc2db46b8f02e1a3e03da Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Tue, 16 Jan 2024 22:40:56 +0800 Subject: [PATCH 02/13] modify code Signed-off-by: zhaolinglan --- services/include/ime_aging_manager.h | 12 ++++++------ services/src/ime_aging_manager.cpp | 19 +++++++++---------- services/src/peruser_session.cpp | 2 ++ 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/services/include/ime_aging_manager.h b/services/include/ime_aging_manager.h index 798f88d7b..576e91d58 100644 --- a/services/include/ime_aging_manager.h +++ b/services/include/ime_aging_manager.h @@ -29,10 +29,10 @@ namespace OHOS { namespace MiscServices { -struct ImeCache { +struct AgingIme { ImeData data; std::chrono::system_clock::time_point timestamp{}; - ImeCache(ImeData data, std::chrono::system_clock::time_point timestamp) + AgingIme(ImeData data, std::chrono::system_clock::time_point timestamp) : data(std::move(data)), timestamp(timestamp) { } @@ -46,17 +46,17 @@ public: private: ImeAgingManager(); - void ClearOldest(); - void AgingCache(); void StartAging(); void StopAging(); - void StopIme(const std::shared_ptr &ime); + void AgingCache(); + void ClearOldest(); + void ClearIme(const std::shared_ptr &ime); std::mutex timerMutex_; Utils::Timer timer_; uint32_t timerId_; std::recursive_mutex cacheMutex_; - std::map> imeCaches_; + std::map> imeCaches_; }; } // namespace MiscServices } // namespace OHOS diff --git a/services/src/ime_aging_manager.cpp b/services/src/ime_aging_manager.cpp index 117ccfd16..9ee5e1a1d 100644 --- a/services/src/ime_aging_manager.cpp +++ b/services/src/ime_aging_manager.cpp @@ -33,7 +33,7 @@ ImeAgingManager &ImeAgingManager::GetInstance() return ImeAgingManager; } -bool ImeAgingManager::Push(const std::string &imeName, const std::shared_ptr &imeCache) +bool ImeAgingManager::Push(const std::string &imeName, const std::shared_ptr &imeCache) { if (imeName.empty() || imeCache == nullptr) { IMSA_HILOGE("ime name invalid or imeCache is nullptr"); @@ -59,12 +59,11 @@ bool ImeAgingManager::Push(const std::string &imeName, const std::shared_ptr &imeData) { - if (imeName.empty() || imeCache == nullptr) { - IMSA_HILOGE("ime name invalid or imeCache is nullptr"); + if (imeName.empty() || imeData == nullptr) { + IMSA_HILOGE("ime name invalid or imeData is nullptr"); return false; } - auto imeCache = std::make_shared(*imeData, std::chrono::system_clock::now()); - imeCache->data.deathRecipient->SetDeathRecipient([this, imeName](const wptr &) { Pop(imeName); }); + auto imeCache = std::make_shared(*imeData, std::chrono::system_clock::now()); std::lock_guard lock(cacheMutex_); auto it = imeCaches_.find(imeName); @@ -112,8 +111,8 @@ void ImeAgingManager::ClearOldest() } auto core = oldestIme->second->data.core; if (core != nullptr) { - IMSA_HILOGI("stop ime: %{public}s", oldestIme->first.c_str()); - StopIme(oldestIme->second); + IMSA_HILOGI("clear ime: %{public}s", oldestIme->first.c_str()); + ClearIme(oldestIme->second); } imeCaches_.erase(oldestIme); } @@ -130,8 +129,8 @@ void ImeAgingManager::AgingCache() } auto core = it->second->data.core; if (core != nullptr) { - IMSA_HILOGI("stop ime: %{public}s", it->first.c_str()); - StopIme(it->second); + IMSA_HILOGI("clear ime: %{public}s", it->first.c_str()); + ClearIme(it->second); } it = imeCaches_.erase(it); } @@ -140,7 +139,7 @@ void ImeAgingManager::AgingCache() } } -void ImeAgingManager::StopIme(const std::shared_ptr &ime) +void ImeAgingManager::ClearIme(const std::shared_ptr &ime) { auto imeData = ime->data; if (imeData.core == nullptr) { diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 74d151c40..5d599bc7e 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -655,6 +655,8 @@ void PerUserSession::StopInputService(const std::string &imeName) return; } IMSA_HILOGI("imeName: %{public}s", imeName.c_str()); + data->deathRecipient->SetDeathRecipient( + [this, imeName](const wptr &) { ImeAgingManager::GetInstance().Pop(imeName); }); ImeAgingManager::GetInstance().Push(imeName, data); RemoveImeData(ImeType::IME, false); auto client = GetCurrentClient(); -- Gitee From bd4e4a110def531b9abfa1c688e4718a00f76fe7 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Wed, 17 Jan 2024 10:06:16 +0800 Subject: [PATCH 03/13] modify code Signed-off-by: zhaolinglan --- services/include/ime_aging_manager.h | 2 +- services/src/ime_aging_manager.cpp | 24 ------------------------ 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/services/include/ime_aging_manager.h b/services/include/ime_aging_manager.h index 576e91d58..a16703f42 100644 --- a/services/include/ime_aging_manager.h +++ b/services/include/ime_aging_manager.h @@ -41,7 +41,7 @@ struct AgingIme { class ImeAgingManager { public: static ImeAgingManager &GetInstance(); - bool Push(const std::string &imeName, const std::shared_ptr &imeCache); + bool Push(const std::string &imeName, const std::shared_ptr &imeData); std::shared_ptr Pop(const std::string &imeName); private: diff --git a/services/src/ime_aging_manager.cpp b/services/src/ime_aging_manager.cpp index 9ee5e1a1d..27a7e51c6 100644 --- a/services/src/ime_aging_manager.cpp +++ b/services/src/ime_aging_manager.cpp @@ -33,30 +33,6 @@ ImeAgingManager &ImeAgingManager::GetInstance() return ImeAgingManager; } -bool ImeAgingManager::Push(const std::string &imeName, const std::shared_ptr &imeCache) -{ - if (imeName.empty() || imeCache == nullptr) { - IMSA_HILOGE("ime name invalid or imeCache is nullptr"); - return false; - } - imeCache->timestamp = std::chrono::system_clock::now(); - - std::lock_guard lock(cacheMutex_); - auto it = imeCaches_.find(imeName); - if (it != imeCaches_.end()) { - it->second = imeCache; - return true; - } - if (imeCaches_.empty()) { - StartAging(); - } - if (imeCaches_.size() == MAX_CACHES_SIZE) { - ClearOldest(); - } - imeCaches_.insert({ imeName, imeCache }); - return true; -} - bool ImeAgingManager::Push(const std::string &imeName, const std::shared_ptr &imeData) { if (imeName.empty() || imeData == nullptr) { -- Gitee From 39f9fafc4a470f65e2be62e5358d69035f11ce2b Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Wed, 17 Jan 2024 11:49:00 +0800 Subject: [PATCH 04/13] modify code Signed-off-by: zhaolinglan --- services/src/ime_aging_manager.cpp | 14 +++++++++++++- services/src/input_method_system_ability.cpp | 1 - services/src/peruser_session.cpp | 5 +++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/services/src/ime_aging_manager.cpp b/services/src/ime_aging_manager.cpp index 27a7e51c6..589f7fae0 100644 --- a/services/src/ime_aging_manager.cpp +++ b/services/src/ime_aging_manager.cpp @@ -35,6 +35,7 @@ ImeAgingManager &ImeAgingManager::GetInstance() bool ImeAgingManager::Push(const std::string &imeName, const std::shared_ptr &imeData) { + IMSA_HILOGI("zll start Push imeName: %{public}s", imeName.c_str()); if (imeName.empty() || imeData == nullptr) { IMSA_HILOGE("ime name invalid or imeData is nullptr"); return false; @@ -54,16 +55,20 @@ bool ImeAgingManager::Push(const std::string &imeName, const std::shared_ptr ImeAgingManager::Pop(const std::string &imeName) { std::lock_guard lock(cacheMutex_); + IMSA_HILOGI("zll start Pop imeName: %{public}s", imeName.c_str()); auto it = imeCaches_.find(imeName); if (it == imeCaches_.end()) { + IMSA_HILOGI("zll not found ime: %{public}s", imeName.c_str()); return nullptr; } + IMSA_HILOGI("zll find ime: %{public}s", imeName.c_str()); auto ime = it->second->data; if (ime.core->AsObject() != nullptr && ime.deathRecipient != nullptr) { ime.core->AsObject()->RemoveDeathRecipient(ime.deathRecipient); @@ -73,12 +78,14 @@ std::shared_ptr ImeAgingManager::Pop(const std::string &imeName) if (imeCaches_.empty()) { StopAging(); } + IMSA_HILOGI("zll end Pop imeName: %{public}s", imeName.c_str()); return std::make_shared(ime); } void ImeAgingManager::ClearOldest() { std::lock_guard lock(cacheMutex_); + IMSA_HILOGI("zll run in"); auto oldestIme = imeCaches_.begin(); for (auto it = imeCaches_.begin(); it != imeCaches_.end(); it++) { if (it->second->timestamp < oldestIme->second->timestamp) { @@ -96,6 +103,7 @@ void ImeAgingManager::ClearOldest() void ImeAgingManager::AgingCache() { std::lock_guard lock(cacheMutex_); + IMSA_HILOGI("zll run in"); for (auto it = imeCaches_.begin(); it != imeCaches_.end();) { // each IME can be kept for 60 seconds, and then be stopped. auto now = std::chrono::system_clock::now(); @@ -105,7 +113,7 @@ void ImeAgingManager::AgingCache() } auto core = it->second->data.core; if (core != nullptr) { - IMSA_HILOGI("clear ime: %{public}s", it->first.c_str()); + IMSA_HILOGI("zll clear ime: %{public}s", it->first.c_str()); ClearIme(it->second); } it = imeCaches_.erase(it); @@ -117,11 +125,13 @@ void ImeAgingManager::AgingCache() void ImeAgingManager::ClearIme(const std::shared_ptr &ime) { + IMSA_HILOGI("zll run in"); auto imeData = ime->data; if (imeData.core == nullptr) { return; } if (imeData.core->AsObject() != nullptr && imeData.deathRecipient != nullptr) { + IMSA_HILOGI("zll RemoveDeathRecipient"); imeData.core->AsObject()->RemoveDeathRecipient(imeData.deathRecipient); } imeData.core->StopInputService(); @@ -130,6 +140,7 @@ void ImeAgingManager::ClearIme(const std::shared_ptr &ime) void ImeAgingManager::StartAging() { std::lock_guard lock(timerMutex_); + IMSA_HILOGI("zll run in"); uint32_t ret = timer_.Setup(); if (ret != Utils::TIMER_ERR_OK) { IMSA_HILOGE("failed to create timer"); @@ -141,6 +152,7 @@ void ImeAgingManager::StartAging() void ImeAgingManager::StopAging() { std::lock_guard lock(timerMutex_); + IMSA_HILOGI("zll run in"); timer_.Unregister(timerId_); timer_.Shutdown(false); } diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 4199ae269..ad4ef8b77 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -508,7 +508,6 @@ int32_t InputMethodSystemAbility::OnSwitchInputMethod(const SwitchInfo &switchIn if (!switchQueue_.IsReady(switchInfo)) { IMSA_HILOGD("start wait"); switchQueue_.Wait(switchInfo); - usleep(SWITCH_BLOCK_TIME); } IMSA_HILOGI("start switch %{public}s|%{public}s", switchInfo.bundleName.c_str(), switchInfo.subName.c_str()); int32_t ret = CheckSwitchPermission(switchInfo, trigger); diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 5d599bc7e..56763f275 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -658,12 +658,13 @@ void PerUserSession::StopInputService(const std::string &imeName) data->deathRecipient->SetDeathRecipient( [this, imeName](const wptr &) { ImeAgingManager::GetInstance().Pop(imeName); }); ImeAgingManager::GetInstance().Push(imeName, data); - RemoveImeData(ImeType::IME, false); auto client = GetCurrentClient(); auto clientInfo = client != nullptr ? GetClientInfo(client->AsObject()) : nullptr; if (clientInfo != nullptr && clientInfo->bindImeType == ImeType::IME) { StopClientInput(client); + StopImeInput(clientInfo->bindImeType, clientInfo->channel); } + RemoveImeData(ImeType::IME, false); } bool PerUserSession::IsRestartIme() @@ -890,7 +891,7 @@ bool PerUserSession::StartIme(const std::string &imeName, bool isRetry) { auto ime = ImeAgingManager::GetInstance().Pop(imeName); if (ime != nullptr) { - IMSA_HILOGI("hit the ime cache"); + IMSA_HILOGI("zll hit the ime cache"); return OnSetCoreAndAgent(ime->core, ime->agent); } return StartInputService(imeName, isRetry); -- Gitee From 517f88a9f60c7b80e1f8a859ad774cdf9f23f83d Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Wed, 17 Jan 2024 21:02:57 +0800 Subject: [PATCH 05/13] modify code Signed-off-by: zhaolinglan --- services/src/ime_aging_manager.cpp | 18 +++++------------- services/src/peruser_session.cpp | 2 +- .../perusersession_fuzzer.cpp | 2 +- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/services/src/ime_aging_manager.cpp b/services/src/ime_aging_manager.cpp index 589f7fae0..bad1e6dd3 100644 --- a/services/src/ime_aging_manager.cpp +++ b/services/src/ime_aging_manager.cpp @@ -35,7 +35,6 @@ ImeAgingManager &ImeAgingManager::GetInstance() bool ImeAgingManager::Push(const std::string &imeName, const std::shared_ptr &imeData) { - IMSA_HILOGI("zll start Push imeName: %{public}s", imeName.c_str()); if (imeName.empty() || imeData == nullptr) { IMSA_HILOGE("ime name invalid or imeData is nullptr"); return false; @@ -55,20 +54,17 @@ bool ImeAgingManager::Push(const std::string &imeName, const std::shared_ptr ImeAgingManager::Pop(const std::string &imeName) { std::lock_guard lock(cacheMutex_); - IMSA_HILOGI("zll start Pop imeName: %{public}s", imeName.c_str()); auto it = imeCaches_.find(imeName); if (it == imeCaches_.end()) { - IMSA_HILOGI("zll not found ime: %{public}s", imeName.c_str()); return nullptr; } - IMSA_HILOGI("zll find ime: %{public}s", imeName.c_str()); auto ime = it->second->data; if (ime.core->AsObject() != nullptr && ime.deathRecipient != nullptr) { ime.core->AsObject()->RemoveDeathRecipient(ime.deathRecipient); @@ -78,14 +74,13 @@ std::shared_ptr ImeAgingManager::Pop(const std::string &imeName) if (imeCaches_.empty()) { StopAging(); } - IMSA_HILOGI("zll end Pop imeName: %{public}s", imeName.c_str()); + IMSA_HILOGI("pop ime: %{public}s", imeName.c_str()); return std::make_shared(ime); } void ImeAgingManager::ClearOldest() { std::lock_guard lock(cacheMutex_); - IMSA_HILOGI("zll run in"); auto oldestIme = imeCaches_.begin(); for (auto it = imeCaches_.begin(); it != imeCaches_.end(); it++) { if (it->second->timestamp < oldestIme->second->timestamp) { @@ -103,7 +98,6 @@ void ImeAgingManager::ClearOldest() void ImeAgingManager::AgingCache() { std::lock_guard lock(cacheMutex_); - IMSA_HILOGI("zll run in"); for (auto it = imeCaches_.begin(); it != imeCaches_.end();) { // each IME can be kept for 60 seconds, and then be stopped. auto now = std::chrono::system_clock::now(); @@ -113,7 +107,7 @@ void ImeAgingManager::AgingCache() } auto core = it->second->data.core; if (core != nullptr) { - IMSA_HILOGI("zll clear ime: %{public}s", it->first.c_str()); + IMSA_HILOGI("clear ime: %{public}s", it->first.c_str()); ClearIme(it->second); } it = imeCaches_.erase(it); @@ -125,13 +119,11 @@ void ImeAgingManager::AgingCache() void ImeAgingManager::ClearIme(const std::shared_ptr &ime) { - IMSA_HILOGI("zll run in"); auto imeData = ime->data; if (imeData.core == nullptr) { return; } if (imeData.core->AsObject() != nullptr && imeData.deathRecipient != nullptr) { - IMSA_HILOGI("zll RemoveDeathRecipient"); imeData.core->AsObject()->RemoveDeathRecipient(imeData.deathRecipient); } imeData.core->StopInputService(); @@ -140,7 +132,7 @@ void ImeAgingManager::ClearIme(const std::shared_ptr &ime) void ImeAgingManager::StartAging() { std::lock_guard lock(timerMutex_); - IMSA_HILOGI("zll run in"); + IMSA_HILOGD("run in"); uint32_t ret = timer_.Setup(); if (ret != Utils::TIMER_ERR_OK) { IMSA_HILOGE("failed to create timer"); @@ -152,7 +144,7 @@ void ImeAgingManager::StartAging() void ImeAgingManager::StopAging() { std::lock_guard lock(timerMutex_); - IMSA_HILOGI("zll run in"); + IMSA_HILOGD("run in"); timer_.Unregister(timerId_); timer_.Shutdown(false); } diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 56763f275..9e576895d 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -891,7 +891,7 @@ bool PerUserSession::StartIme(const std::string &imeName, bool isRetry) { auto ime = ImeAgingManager::GetInstance().Pop(imeName); if (ime != nullptr) { - IMSA_HILOGI("zll hit the ime cache"); + IMSA_HILOGI("hit the ime cache"); return OnSetCoreAndAgent(ime->core, ime->agent); } return StartInputService(imeName, isRetry); diff --git a/test/fuzztest/perusersession_fuzzer/perusersession_fuzzer.cpp b/test/fuzztest/perusersession_fuzzer/perusersession_fuzzer.cpp index c942d2ad2..f86bd566b 100644 --- a/test/fuzztest/perusersession_fuzzer/perusersession_fuzzer.cpp +++ b/test/fuzztest/perusersession_fuzzer/perusersession_fuzzer.cpp @@ -109,7 +109,7 @@ bool FuzzPerUserSession(const uint8_t *rawData, size_t size) userSessions->OnHideCurrentInput(); userSessions->OnHideInput(client); userSessions->OnReleaseInput(client); - userSessions->StopInputService(); + userSessions->StopInputService(""); return true; } } // namespace OHOS -- Gitee From 6d4f3f698a89d4f90eef73ace7a206778582a94a Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Wed, 17 Jan 2024 22:09:19 +0800 Subject: [PATCH 06/13] modify code Signed-off-by: zhaolinglan --- services/src/peruser_session.cpp | 2 +- test/unittest/cpp_test/src/input_method_private_member_test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 9e576895d..5e9de9244 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -892,7 +892,7 @@ bool PerUserSession::StartIme(const std::string &imeName, bool isRetry) auto ime = ImeAgingManager::GetInstance().Pop(imeName); if (ime != nullptr) { IMSA_HILOGI("hit the ime cache"); - return OnSetCoreAndAgent(ime->core, ime->agent); + return OnSetCoreAndAgent(ime->core, ime->agent) == ErrorCode::NO_ERROR; } return StartInputService(imeName, isRetry); } diff --git a/test/unittest/cpp_test/src/input_method_private_member_test.cpp b/test/unittest/cpp_test/src/input_method_private_member_test.cpp index 829f38e12..47ece5c87 100644 --- a/test/unittest/cpp_test/src/input_method_private_member_test.cpp +++ b/test/unittest/cpp_test/src/input_method_private_member_test.cpp @@ -262,7 +262,7 @@ HWTEST_F(InputMethodPrivateMemberTest, PerUserSessionCoreOrAgentNullptr, TestSiz EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND); ret = userSession->InitInputControlChannel(); EXPECT_EQ(ret, ErrorCode::ERROR_IME_NOT_STARTED); - userSession->StopInputService(); + userSession->StopInputService(""); ret = userSession->SwitchSubtype({}); EXPECT_EQ(ret, ErrorCode::ERROR_IME_NOT_STARTED); } -- Gitee From 51e5bfbb3d539080e9a30e5b7a74162f53a78556 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Fri, 19 Jan 2024 15:51:31 +0800 Subject: [PATCH 07/13] modify code Signed-off-by: zhaolinglan --- .../include/i_input_method_core.h | 2 +- .../include/input_method_ability.h | 1 + .../include/input_method_core_proxy.h | 2 +- .../include/input_method_core_stub.h | 2 +- .../src/input_method_ability.cpp | 16 +++-- .../src/input_method_core_proxy.cpp | 5 +- .../src/input_method_core_stub.cpp | 12 +++- services/include/ime_aging_manager.h | 4 +- services/include/ime_info_inquirer.h | 7 +- .../include/input_method_system_ability.h | 2 +- services/include/peruser_session.h | 7 +- services/src/ime_aging_manager.cpp | 22 +++--- services/src/ime_info_inquirer.cpp | 45 +++++++----- services/src/input_method_system_ability.cpp | 26 +++---- services/src/peruser_session.cpp | 71 +++++++++++-------- .../perusersession_fuzzer.cpp | 2 +- 16 files changed, 134 insertions(+), 92 deletions(-) diff --git a/frameworks/native/inputmethod_ability/include/i_input_method_core.h b/frameworks/native/inputmethod_ability/include/i_input_method_core.h index 2c5c472b8..18bfbc86c 100644 --- a/frameworks/native/inputmethod_ability/include/i_input_method_core.h +++ b/frameworks/native/inputmethod_ability/include/i_input_method_core.h @@ -57,7 +57,7 @@ public: virtual int32_t ShowKeyboard() = 0; virtual int32_t HideKeyboard() = 0; virtual int32_t InitInputControlChannel(const sptr &inputControlChannel) = 0; - virtual void StopInputService() = 0; + virtual void StopInputService(bool isTerminateIme) = 0; virtual int32_t SetSubtype(const SubProperty &property) = 0; virtual bool IsEnable() = 0; virtual int32_t IsPanelShown(const PanelInfo &panelInfo, bool &isShown) = 0; diff --git a/frameworks/native/inputmethod_ability/include/input_method_ability.h b/frameworks/native/inputmethod_ability/include/input_method_ability.h index 83fbcf9ce..d6361eb34 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_ability.h +++ b/frameworks/native/inputmethod_ability/include/input_method_ability.h @@ -127,6 +127,7 @@ private: void OnCursorUpdate(Message *msg); void OnSelectionChange(Message *msg); void OnConfigurationChange(Message *msg); + void OnStopInputService(Message *msg); int32_t HideKeyboard(Trigger trigger); std::shared_ptr GetSoftKeyboardPanel(); diff --git a/frameworks/native/inputmethod_ability/include/input_method_core_proxy.h b/frameworks/native/inputmethod_ability/include/input_method_core_proxy.h index 28aca47ad..26c152519 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_core_proxy.h +++ b/frameworks/native/inputmethod_ability/include/input_method_core_proxy.h @@ -40,7 +40,7 @@ public: int32_t ShowKeyboard() override; int32_t HideKeyboard() override; int32_t InitInputControlChannel(const sptr &inputControlChannel) override; - void StopInputService() override; + void StopInputService(bool isTerminateIme) override; int32_t SetSubtype(const SubProperty &property) override; bool IsEnable() override; int32_t IsPanelShown(const PanelInfo &panelInfo, bool &isShown) override; diff --git a/frameworks/native/inputmethod_ability/include/input_method_core_stub.h b/frameworks/native/inputmethod_ability/include/input_method_core_stub.h index a6631e82e..3c97a2833 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_core_stub.h +++ b/frameworks/native/inputmethod_ability/include/input_method_core_stub.h @@ -43,7 +43,7 @@ public: int32_t ShowKeyboard() override; int32_t HideKeyboard() override; int32_t InitInputControlChannel(const sptr &inputControlChannel) override; - void StopInputService() override; + void StopInputService(bool isTerminateIme) override; int32_t SetSubtype(const SubProperty &property) override; bool IsEnable() override; int32_t IsPanelShown(const PanelInfo &panelInfo, bool &isShown) override; diff --git a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp index bdaa11bec..8f7c7a8ec 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp @@ -201,10 +201,7 @@ void InputMethodAbility::WorkThread() break; } case MSG_ID_STOP_INPUT_SERVICE: { - if (imeListener_ != nullptr) { - imeListener_->OnInputStop(); - } - isBound_.store(false); + OnStopInputService(msg); break; } case MSG_ID_SET_SUBTYPE: { @@ -374,6 +371,17 @@ void InputMethodAbility::OnConfigurationChange(Message *msg) kdListener_->OnEditorAttributeChange(attribute); } +void InputMethodAbility::OnStopInputService(Message *msg) +{ + MessageParcel *data = msg->msgContent_; + bool isTerminateIme = data->ReadBool(); + IMSA_HILOGI("isTerminateIme: %{public}d", isTerminateIme); + if (isTerminateIme && imeListener_ != nullptr) { + imeListener_->OnInputStop(); + } + isBound_.store(false); +} + int32_t InputMethodAbility::ShowKeyboard() { if (imeListener_ == nullptr) { diff --git a/frameworks/native/inputmethod_ability/src/input_method_core_proxy.cpp b/frameworks/native/inputmethod_ability/src/input_method_core_proxy.cpp index d45a10590..6a02f7e78 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_core_proxy.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_core_proxy.cpp @@ -53,9 +53,10 @@ int32_t InputMethodCoreProxy::OnSecurityChange(int32_t security) }); } -void InputMethodCoreProxy::StopInputService() +void InputMethodCoreProxy::StopInputService(bool isTerminateIme) { - SendRequest(STOP_INPUT_SERVICE); + SendRequest(STOP_INPUT_SERVICE, + [isTerminateIme](MessageParcel &data) { return ITypesUtil::Marshal(data, isTerminateIme); }); } int32_t InputMethodCoreProxy::ShowKeyboard() diff --git a/frameworks/native/inputmethod_ability/src/input_method_core_stub.cpp b/frameworks/native/inputmethod_ability/src/input_method_core_stub.cpp index 276bc0da9..726cf03be 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_core_stub.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_core_stub.cpp @@ -71,9 +71,10 @@ int32_t InputMethodCoreStub::HideKeyboard() return InputMethodAbility::GetInstance()->HideKeyboard(); } -void InputMethodCoreStub::StopInputService() +void InputMethodCoreStub::StopInputService(bool isTerminateIme) { - SendMessage(MessageID::MSG_ID_STOP_INPUT_SERVICE); + SendMessage(MessageID::MSG_ID_STOP_INPUT_SERVICE, + [isTerminateIme](MessageParcel &data) { return ITypesUtil::Marshal(data, isTerminateIme); }); } void InputMethodCoreStub::SetMessageHandler(MessageHandler *msgHandler) @@ -163,7 +164,12 @@ int32_t InputMethodCoreStub::HideKeyboardOnRemote(MessageParcel &data, MessagePa int32_t InputMethodCoreStub::StopInputServiceOnRemote(MessageParcel &data, MessageParcel &reply) { - StopInputService(); + bool isTerminateIme = false; + if (ITypesUtil::Unmarshal(data, isTerminateIme)) { + IMSA_HILOGE("unmarshal failed"); + return ErrorCode::ERROR_EX_PARCELABLE; + } + StopInputService(isTerminateIme); return ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE; } diff --git a/services/include/ime_aging_manager.h b/services/include/ime_aging_manager.h index a16703f42..b010f0f85 100644 --- a/services/include/ime_aging_manager.h +++ b/services/include/ime_aging_manager.h @@ -41,8 +41,8 @@ struct AgingIme { class ImeAgingManager { public: static ImeAgingManager &GetInstance(); - bool Push(const std::string &imeName, const std::shared_ptr &imeData); - std::shared_ptr Pop(const std::string &imeName); + bool Push(const std::string &bundleName, const std::shared_ptr &imeData); + std::shared_ptr Pop(const std::string &bundleName); private: ImeAgingManager(); diff --git a/services/include/ime_info_inquirer.h b/services/include/ime_info_inquirer.h index 969dd8f0a..3b499e933 100644 --- a/services/include/ime_info_inquirer.h +++ b/services/include/ime_info_inquirer.h @@ -24,8 +24,9 @@ #include #include "bundle_mgr_proxy.h" -#include "enable_ime_data_parser.h" #include "element_name.h" +#include "enable_ime_data_parser.h" +#include "ime_cfg_manager.h" #include "input_method_info.h" #include "input_method_property.h" #include "input_method_status.h" @@ -61,7 +62,7 @@ public: using CompareHandler = std::function; static ImeInfoInquirer &GetInstance(); std::string GetDumpInfo(int32_t userId); - std::string GetImeToBeStarted(int32_t userId); + std::shared_ptr GetImeToBeStarted(int32_t userId); std::shared_ptr GetImeByBundleName(int32_t userId, const std::string &bundleName); std::shared_ptr GetCurrentInputMethod(int32_t userId); std::shared_ptr GetCurrentSubtype(int32_t userId); @@ -89,7 +90,7 @@ private: OHOS::sptr GetBundleMgr(); void InitCache(int32_t userId); SubProperty GetExtends(const std::vector &metaData); - std::string GetDefaultIme(); + ImeNativeCfg GetDefaultIme(); std::string GetStringById( const std::string &bundleName, const std::string &moduleName, const int32_t labelId, const int32_t userId); std::shared_ptr GetImeInfoFromCache( diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index b04207fe7..7eef66065 100644 --- a/services/include/input_method_system_ability.h +++ b/services/include/input_method_system_ability.h @@ -102,7 +102,7 @@ private: std::shared_ptr identityChecker_ = nullptr; int32_t PrepareInput(InputClientInfo &clientInfo); void WorkThread(); - bool StartInputService(const std::string &imeId); + bool StartInputService(const std::shared_ptr &imeId); int32_t OnUserStarted(const Message *msg); int32_t OnUserRemoved(const Message *msg); int32_t OnPackageRemoved(const Message *msg); diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index f8b745697..f17150d44 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -32,6 +32,7 @@ #include "i_input_data_channel.h" #include "i_input_method_agent.h" #include "i_input_method_core.h" +#include "ime_info_inquirer.h" #include "input_attribute.h" #include "input_client_info.h" #include "input_control_channel_stub.h" @@ -80,7 +81,7 @@ public: int32_t OnRequestHideInput(); void OnSecurityChange(int32_t &security); void OnHideSoftKeyBoardSelf(); - void StopInputService(const std::string &imeName); + void StopInputService(const std::string &bundleName, const std::string &subName); void NotifyImeChangeToClients(const Property &property, const SubProperty &subProperty); int32_t SwitchSubtype(const SubProperty &subProperty); void UpdateCurrentUserId(int32_t userId); @@ -89,7 +90,7 @@ public: int64_t GetCurrentClientPid(); int32_t OnPanelStatusChange(const InputWindowStatus &status, const InputWindowInfo &windowInfo); int32_t OnUpdateListenEventFlag(const InputClientInfo &clientInfo); - bool StartIme(const std::string &imeName, bool isRetry); + bool StartIme(const std::shared_ptr &ime, bool isRetry); int32_t OnRegisterProxyIme(const sptr &core, const sptr &agent); int32_t OnUnRegisteredProxyIme(UnRegisteredType type, const sptr &core); bool IsProxyImeEnable(); @@ -141,7 +142,7 @@ private: int32_t RemoveIme(const sptr &core, ImeType type); std::shared_ptr GetImeData(ImeType type); std::shared_ptr GetValidIme(ImeType type); - bool StartInputService(const std::string &imeName, bool isRetry); + bool StartInputService(const std::shared_ptr &ime, bool isRetry); int32_t BindClientWithIme( const std::shared_ptr &clientInfo, ImeType type, bool isBindFromClient = false); diff --git a/services/src/ime_aging_manager.cpp b/services/src/ime_aging_manager.cpp index bad1e6dd3..ca5741c78 100644 --- a/services/src/ime_aging_manager.cpp +++ b/services/src/ime_aging_manager.cpp @@ -33,16 +33,16 @@ ImeAgingManager &ImeAgingManager::GetInstance() return ImeAgingManager; } -bool ImeAgingManager::Push(const std::string &imeName, const std::shared_ptr &imeData) +bool ImeAgingManager::Push(const std::string &bundleName, const std::shared_ptr &imeData) { - if (imeName.empty() || imeData == nullptr) { - IMSA_HILOGE("ime name invalid or imeData is nullptr"); + if (bundleName.empty() || imeData == nullptr || imeData->core == nullptr || imeData->agent == nullptr) { + IMSA_HILOGE("invalid ime data"); return false; } auto imeCache = std::make_shared(*imeData, std::chrono::system_clock::now()); std::lock_guard lock(cacheMutex_); - auto it = imeCaches_.find(imeName); + auto it = imeCaches_.find(bundleName); if (it != imeCaches_.end()) { it->second = imeCache; return true; @@ -53,15 +53,15 @@ bool ImeAgingManager::Push(const std::string &imeName, const std::shared_ptr ImeAgingManager::Pop(const std::string &imeName) +std::shared_ptr ImeAgingManager::Pop(const std::string &bundleName) { std::lock_guard lock(cacheMutex_); - auto it = imeCaches_.find(imeName); + auto it = imeCaches_.find(bundleName); if (it == imeCaches_.end()) { return nullptr; } @@ -70,11 +70,11 @@ std::shared_ptr ImeAgingManager::Pop(const std::string &imeName) ime.core->AsObject()->RemoveDeathRecipient(ime.deathRecipient); ime.deathRecipient = nullptr; } - imeCaches_.erase(imeName); + imeCaches_.erase(bundleName); if (imeCaches_.empty()) { StopAging(); } - IMSA_HILOGI("pop ime: %{public}s", imeName.c_str()); + IMSA_HILOGI("pop ime: %{public}s", bundleName.c_str()); return std::make_shared(ime); } @@ -126,7 +126,7 @@ void ImeAgingManager::ClearIme(const std::shared_ptr &ime) if (imeData.core->AsObject() != nullptr && imeData.deathRecipient != nullptr) { imeData.core->AsObject()->RemoveDeathRecipient(imeData.deathRecipient); } - imeData.core->StopInputService(); + imeData.core->StopInputService(true); } void ImeAgingManager::StartAging() diff --git a/services/src/ime_info_inquirer.cpp b/services/src/ime_info_inquirer.cpp index 5c2fcd1c5..5ba1d969d 100644 --- a/services/src/ime_info_inquirer.cpp +++ b/services/src/ime_info_inquirer.cpp @@ -655,28 +655,28 @@ bool ImeInfoInquirer::IsImeInstalled(const int32_t userId, const std::string &bu return true; } -std::string ImeInfoInquirer::GetImeToBeStarted(int32_t userId) +std::shared_ptr ImeInfoInquirer::GetImeToBeStarted(int32_t userId) { auto currentImeCfg = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId); IMSA_HILOGD("userId: %{public}d, currentIme: %{public}s", userId, currentImeCfg->imeId.c_str()); if (currentImeCfg->imeId.empty() || !IsImeInstalled(userId, currentImeCfg->bundleName, currentImeCfg->extName)) { - auto newUserIme = GetDefaultIme(); - std::string subName; + auto newIme = GetDefaultIme(); auto info = GetDefaultImeInfo(userId); if (info == nullptr) { IMSA_HILOGE("GetDefaultImeInfo failed"); - subName = ""; + newIme.subName = ""; } else { - subName = info->subProp.id; + newIme.subName = info->subProp.id; SetCurrentImeInfo(info); } - currentImeCfg->imeId.empty() ? ImeCfgManager::GetInstance().AddImeCfg({ userId, newUserIme, subName }) - : ImeCfgManager::GetInstance().ModifyImeCfg({ userId, newUserIme, subName }); - return newUserIme; + currentImeCfg->imeId.empty() + ? ImeCfgManager::GetInstance().AddImeCfg({ userId, newIme.imeId, newIme.imeId }) + : ImeCfgManager::GetInstance().ModifyImeCfg({ userId, newIme.imeId, newIme.imeId }); + return std::make_shared(newIme); } // service start, user switch, set the currentImeInfo. InitCache(userId); - return currentImeCfg->imeId; + return currentImeCfg; } int32_t ImeInfoInquirer::GetInputMethodConfig(const int32_t userId, AppExecFwk::ElementName &inputMethodConfig) @@ -745,15 +745,23 @@ std::shared_ptr ImeInfoInquirer::GetDefaultImeInfo(int32_t userId) return info; } -std::string ImeInfoInquirer::GetDefaultIme() +ImeNativeCfg ImeInfoInquirer::GetDefaultIme() { + std::string ime; if (!imeConfig_.defaultInputMethod.empty()) { IMSA_HILOGI("defaultInputMethod: %{public}s", imeConfig_.defaultInputMethod.c_str()); - return imeConfig_.defaultInputMethod; + ime = imeConfig_.defaultInputMethod; + } else { + char value[CONFIG_LEN] = { 0 }; + auto code = GetParameter(DEFAULT_IME_KEY, "", value, CONFIG_LEN); + ime = code > 0 ? value : ""; } - char value[CONFIG_LEN] = { 0 }; - auto code = GetParameter(DEFAULT_IME_KEY, "", value, CONFIG_LEN); - return code > 0 ? value : ""; + auto pos = ime.find('/'); + if (pos == std::string::npos || pos + 1 >= ime.size()) { + IMSA_HILOGE("defaultIme: %{public}s is abnormal", ime.c_str()); + return {}; + } + return { .imeId = ime, .bundleName = ime.substr(0, pos), .extName = ime.substr(pos + 1) }; } sptr ImeInfoInquirer::GetBundleMgr() @@ -865,14 +873,13 @@ void ImeInfoInquirer::ParseSubProp(const json &jsonSubProp, SubProperty &subProp std::shared_ptr ImeInfoInquirer::GetDefaultImeCfgProp() { auto ime = GetDefaultIme(); - auto pos = ime.find('/'); - if (pos == std::string::npos || pos + 1 >= ime.size()) { - IMSA_HILOGE("defaultIme: %{public}s is abnormal", ime.c_str()); + if (ime.bundleName.empty() || ime.extName.empty()) { + IMSA_HILOGE("defaultIme is abnormal", ime.bundleName.c_str()); return nullptr; } auto defaultIme = std::make_shared(); - defaultIme->name = ime.substr(0, pos); - defaultIme->id = ime.substr(pos + 1); + defaultIme->name = ime.bundleName; + defaultIme->id = ime.extName; return defaultIme; } } // namespace MiscServices diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index ad4ef8b77..d5811344c 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -208,7 +208,7 @@ void InputMethodSystemAbility::StartUserIdListener() serviceHandler_->PostTask(callback, INIT_INTERVAL); } -bool InputMethodSystemAbility::StartInputService(const std::string &imeId) +bool InputMethodSystemAbility::StartInputService(const std::shared_ptr &imeId) { return userSession_->StartIme(imeId, true); } @@ -595,12 +595,13 @@ int32_t InputMethodSystemAbility::Switch(const std::string &bundleName, const st // Switch the current InputMethodExtension to the new InputMethodExtension int32_t InputMethodSystemAbility::SwitchExtension(const std::shared_ptr &info) { - auto currentIme = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_)->imeId; - userSession_->StopInputService(currentIme); - std::string targetIme = info->prop.name + "/" + info->prop.id; - ImeCfgManager::GetInstance().ModifyImeCfg({ userId_, targetIme, info->subProp.id }); + auto currentIme = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_); + userSession_->StopInputService(currentIme->bundleName, currentIme->subName); + std::string targetImeName = info->prop.name + "/" + info->prop.id; + ImeCfgManager::GetInstance().ModifyImeCfg({ userId_, targetImeName, info->subProp.id }); ImeInfoInquirer::GetInstance().SetCurrentImeInfo(info); - if (!StartInputService(targetIme)) { + ImeNativeCfg targetIme = { targetImeName, info->prop.name, info->subProp.id, info->prop.id }; + if (!StartInputService(std::make_shared(targetIme))) { IMSA_HILOGE("start input method failed"); return ErrorCode::ERROR_IME_START_FAILED; } @@ -643,10 +644,11 @@ int32_t InputMethodSystemAbility::SwitchInputType(const SwitchInfo &switchInfo) return ErrorCode::ERROR_NULL_POINTER; } - userSession_->StopInputService(currentIme->imeId); - std::string targetIme = switchInfo.bundleName + '/' + targetImeProperty->id; + userSession_->StopInputService(currentIme->bundleName, currentIme->subName); + std::string targetName = switchInfo.bundleName + "/" + targetImeProperty->id; + ImeNativeCfg targetIme = { targetName, switchInfo.bundleName, switchInfo.subName, targetImeProperty->id }; InputTypeManager::GetInstance().Set(true, { switchInfo.bundleName, switchInfo.subName }); - if (!StartInputService(targetIme)) { + if (!StartInputService(std::make_shared(targetIme))) { IMSA_HILOGE("start input method failed"); InputTypeManager::GetInstance().Set(false); return ErrorCode::ERROR_IME_START_FAILED; @@ -779,8 +781,8 @@ int32_t InputMethodSystemAbility::OnUserStarted(const Message *msg) if (enableSecurityMode_) { SecurityModeParser::GetInstance()->GetFullModeList(userId_); } - auto currentIme = ImeCfgManager::GetInstance().GetCurrentImeCfg(oldUserId)->imeId; - userSession_->StopInputService(currentIme); + auto currentIme = ImeCfgManager::GetInstance().GetCurrentImeCfg(oldUserId); + userSession_->StopInputService(currentIme->bundleName, currentIme->subName); // user switch, reset currentImeInfo_ = nullptr ImeInfoInquirer::GetInstance().SetCurrentImeInfo(nullptr); auto newIme = ImeInfoInquirer::GetInstance().GetImeToBeStarted(userId_); @@ -788,7 +790,7 @@ int32_t InputMethodSystemAbility::OnUserStarted(const Message *msg) if (!StartInputService(newIme)) { IMSA_HILOGE("start input method failed"); InputMethodSysEvent::GetInstance().InputmethodFaultReporter( - ErrorCode::ERROR_IME_START_FAILED, newIme, "user start ime failed!"); + ErrorCode::ERROR_IME_START_FAILED, newIme->imeId, "user start ime failed!"); return ErrorCode::ERROR_IME_START_FAILED; } return ErrorCode::NO_ERROR; diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 5e9de9244..adb151093 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -647,22 +647,26 @@ int32_t PerUserSession::InitInputControlChannel() return data->core->InitInputControlChannel(inputControlChannel); } -void PerUserSession::StopInputService(const std::string &imeName) +void PerUserSession::StopInputService(const std::string &bundleName, const std::string &subName) { auto data = GetImeData(ImeType::IME); if (data == nullptr) { IMSA_HILOGE("ime: %{public}d is not exist", ImeType::IME); return; } - IMSA_HILOGI("imeName: %{public}s", imeName.c_str()); + IMSA_HILOGI("ime: %{public}s", bundleName.c_str()); data->deathRecipient->SetDeathRecipient( - [this, imeName](const wptr &) { ImeAgingManager::GetInstance().Pop(imeName); }); - ImeAgingManager::GetInstance().Push(imeName, data); + [this, bundleName](const wptr &) { ImeAgingManager::GetInstance().Pop(bundleName); }); + ImeAgingManager::GetInstance().Push(bundleName, data); auto client = GetCurrentClient(); auto clientInfo = client != nullptr ? GetClientInfo(client->AsObject()) : nullptr; if (clientInfo != nullptr && clientInfo->bindImeType == ImeType::IME) { - StopClientInput(client); - StopImeInput(clientInfo->bindImeType, clientInfo->channel); + UnBindClientWithIme(clientInfo, false); + } + auto info = ImeInfoInquirer::GetInstance().GetImeInfo(userId_, bundleName, subName); + if (info != nullptr && !info->isNewIme && data->core != nullptr) { + IMSA_HILOGD("old ime, need to StopInputService"); + data->core->StopInputService(false); } RemoveImeData(ImeType::IME, false); } @@ -887,33 +891,45 @@ bool PerUserSession::IsSameClient(sptr source, sptr return source != nullptr && dest != nullptr && source->AsObject() == dest->AsObject(); } -bool PerUserSession::StartIme(const std::string &imeName, bool isRetry) +bool PerUserSession::StartIme(const std::shared_ptr &ime, bool isRetry) { - auto ime = ImeAgingManager::GetInstance().Pop(imeName); - if (ime != nullptr) { - IMSA_HILOGI("hit the ime cache"); - return OnSetCoreAndAgent(ime->core, ime->agent) == ErrorCode::NO_ERROR; + if (ime == nullptr) { + IMSA_HILOGE("target ime is nullptr"); + return false; + } + auto cacheData = ImeAgingManager::GetInstance().Pop(ime->bundleName); + if (cacheData == nullptr) { + return StartInputService(ime, isRetry); } - return StartInputService(imeName, isRetry); + IMSA_HILOGI("hit the ime cache"); + auto info = ImeInfoInquirer::GetInstance().GetImeInfo(userId_, ime->bundleName, ime->subName); + if (info == nullptr) { + IMSA_HILOGE("failed to get ime info"); + return false; + } + if (!info->isNewIme) { + IMSA_HILOGD("old ime, need to start ability"); + return StartInputService(ime, isRetry); + } + if (cacheData->core != nullptr) { + IMSA_HILOGD("inform subtype: %{public}s", ime->subName.c_str()); + cacheData->core->SetSubtype(info->subProp); + } + return OnSetCoreAndAgent(cacheData->core, cacheData->agent); } -bool PerUserSession::StartInputService(const std::string &imeName, bool isRetry) +bool PerUserSession::StartInputService(const std::shared_ptr &ime, bool isRetry) { - std::string::size_type pos = imeName.find('/'); - if (pos == std::string::npos) { - IMSA_HILOGE("invalid ime name"); - return false; - } - IMSA_HILOGI("start ime: %{public}s with isRetry: %{public}d", imeName.c_str(), isRetry); + IMSA_HILOGI("start %{public}s with isRetry: %{public}d", ime->imeId.c_str(), isRetry); AAFwk::Want want; - want.SetElementName(imeName.substr(0, pos), imeName.substr(pos + 1)); + want.SetElementName(ime->bundleName, ime->extName); isImeStarted_.Clear(false); auto ret = AAFwk::AbilityManagerClient::GetInstance()->StartExtensionAbility( want, nullptr, userId_, AppExecFwk::ExtensionAbilityType::INPUTMETHOD); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("failed to start ability"); InputMethodSysEvent::GetInstance().InputmethodFaultReporter( - ErrorCode::ERROR_IME_START_FAILED, imeName, "StartInputService, failed to start ability."); + ErrorCode::ERROR_IME_START_FAILED, ime->imeId, "StartInputService, failed to start ability."); } else if (isImeStarted_.GetValue()) { IMSA_HILOGI("ime started successfully"); InputMethodSysEvent::GetInstance().RecordEvent(IMEBehaviour::START_IME); @@ -921,10 +937,10 @@ bool PerUserSession::StartInputService(const std::string &imeName, bool isRetry) } if (isRetry) { IMSA_HILOGE("failed to start ime, begin to retry five times"); - auto retryTask = [this, imeName]() { + auto retryTask = [this, ime]() { pthread_setname_np(pthread_self(), "ImeRestart"); - BlockRetry(IME_RESTART_INTERVAL, IME_RESTART_TIMES, - [this, imeName]() { return StartInputService(imeName, false); }); + BlockRetry( + IME_RESTART_INTERVAL, IME_RESTART_TIMES, [this, ime]() { return StartInputService(ime, false); }); }; std::thread(retryTask).detach(); } @@ -1071,11 +1087,10 @@ int32_t PerUserSession::ExitCurrentInputType() } return ret; } - IMSA_HILOGI("need switch ime to: %{public}s/%{public}s", cfgIme->bundleName.c_str(), cfgIme->subName.c_str()); - std::string typeImeName = typeIme.bundleName + '/' + typeIme.subName; - StopInputService(typeImeName); + IMSA_HILOGI("need switch ime to: %{public}s", cfgIme->imeId.c_str()); + StopInputService(typeIme.bundleName, typeIme.subName); InputTypeManager::GetInstance().Set(false); - if (!StartInputService(cfgIme->imeId, true)) { + if (!StartIme(cfgIme, true)) { IMSA_HILOGE("failed to start ime"); return ErrorCode::ERROR_IME_START_FAILED; } diff --git a/test/fuzztest/perusersession_fuzzer/perusersession_fuzzer.cpp b/test/fuzztest/perusersession_fuzzer/perusersession_fuzzer.cpp index f86bd566b..44866ab82 100644 --- a/test/fuzztest/perusersession_fuzzer/perusersession_fuzzer.cpp +++ b/test/fuzztest/perusersession_fuzzer/perusersession_fuzzer.cpp @@ -109,7 +109,7 @@ bool FuzzPerUserSession(const uint8_t *rawData, size_t size) userSessions->OnHideCurrentInput(); userSessions->OnHideInput(client); userSessions->OnReleaseInput(client); - userSessions->StopInputService(""); + userSessions->StopInputService("", ""); return true; } } // namespace OHOS -- Gitee From 8ae4de1f18d698c64e0c40b0a68bf0eaf15f6864 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Fri, 19 Jan 2024 16:06:06 +0800 Subject: [PATCH 08/13] modify code Signed-off-by: zhaolinglan --- services/include/peruser_session.h | 2 +- services/src/peruser_session.cpp | 11 ++++++----- .../cpp_test/src/input_method_private_member_test.cpp | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index f17150d44..191e875d6 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -138,7 +138,7 @@ private: &updateInfos); int32_t AddImeData(ImeType type, sptr core, sptr agent); - void RemoveImeData(ImeType type, bool isImeDied = true); + void RemoveImeData(ImeType type, bool isImeDied); int32_t RemoveIme(const sptr &core, ImeType type); std::shared_ptr GetImeData(ImeType type); std::shared_ptr GetValidIme(ImeType type); diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index adb151093..e9bbd82d0 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -226,7 +226,7 @@ void PerUserSession::OnImeDied(const sptr &remote, ImeType typ return; } IMSA_HILOGI("type: %{public}d", type); - RemoveImeData(type); + RemoveImeData(type, true); auto client = GetCurrentClient(); auto clientInfo = client != nullptr ? GetClientInfo(client->AsObject()) : nullptr; if (clientInfo != nullptr && clientInfo->bindImeType == type) { @@ -253,7 +253,7 @@ int32_t PerUserSession::RemoveIme(const sptr &core, ImeType ty if (clientInfo != nullptr && clientInfo->bindImeType == type) { UnBindClientWithIme(clientInfo); } - RemoveImeData(type); + RemoveImeData(type, true); return ErrorCode::NO_ERROR; } @@ -654,7 +654,7 @@ void PerUserSession::StopInputService(const std::string &bundleName, const std:: IMSA_HILOGE("ime: %{public}d is not exist", ImeType::IME); return; } - IMSA_HILOGI("ime: %{public}s", bundleName.c_str()); + IMSA_HILOGI("ime: %{public}s/%{public}s", bundleName.c_str(), subName.c_str()); data->deathRecipient->SetDeathRecipient( [this, bundleName](const wptr &) { ImeAgingManager::GetInstance().Pop(bundleName); }); ImeAgingManager::GetInstance().Push(bundleName, data); @@ -828,8 +828,8 @@ void PerUserSession::RemoveImeData(ImeType type, bool isImeDied) auto data = it->second; if (isImeDied && data->core != nullptr && data->core->AsObject() != nullptr) { data->core->AsObject()->RemoveDeathRecipient(data->deathRecipient); + data->deathRecipient = nullptr; } - data->deathRecipient = nullptr; imeData_.erase(type); } @@ -899,6 +899,7 @@ bool PerUserSession::StartIme(const std::shared_ptr &ime, bool isR } auto cacheData = ImeAgingManager::GetInstance().Pop(ime->bundleName); if (cacheData == nullptr) { + IMSA_HILOGD("miss the ime cache"); return StartInputService(ime, isRetry); } IMSA_HILOGI("hit the ime cache"); @@ -915,7 +916,7 @@ bool PerUserSession::StartIme(const std::shared_ptr &ime, bool isR IMSA_HILOGD("inform subtype: %{public}s", ime->subName.c_str()); cacheData->core->SetSubtype(info->subProp); } - return OnSetCoreAndAgent(cacheData->core, cacheData->agent); + return OnSetCoreAndAgent(cacheData->core, cacheData->agent) == ErrorCode::NO_ERROR; } bool PerUserSession::StartInputService(const std::shared_ptr &ime, bool isRetry) diff --git a/test/unittest/cpp_test/src/input_method_private_member_test.cpp b/test/unittest/cpp_test/src/input_method_private_member_test.cpp index 47ece5c87..71201ba18 100644 --- a/test/unittest/cpp_test/src/input_method_private_member_test.cpp +++ b/test/unittest/cpp_test/src/input_method_private_member_test.cpp @@ -262,7 +262,7 @@ HWTEST_F(InputMethodPrivateMemberTest, PerUserSessionCoreOrAgentNullptr, TestSiz EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND); ret = userSession->InitInputControlChannel(); EXPECT_EQ(ret, ErrorCode::ERROR_IME_NOT_STARTED); - userSession->StopInputService(""); + userSession->StopInputService("", ""); ret = userSession->SwitchSubtype({}); EXPECT_EQ(ret, ErrorCode::ERROR_IME_NOT_STARTED); } -- Gitee From eec1f5aaf2f0d8948132191da291fc0e61fa829f Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Fri, 19 Jan 2024 17:22:21 +0800 Subject: [PATCH 09/13] modify code Signed-off-by: zhaolinglan --- .../native/inputmethod_ability/src/input_method_core_stub.cpp | 2 +- services/src/ime_info_inquirer.cpp | 2 +- services/src/peruser_session.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frameworks/native/inputmethod_ability/src/input_method_core_stub.cpp b/frameworks/native/inputmethod_ability/src/input_method_core_stub.cpp index 726cf03be..c40686288 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_core_stub.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_core_stub.cpp @@ -165,7 +165,7 @@ int32_t InputMethodCoreStub::HideKeyboardOnRemote(MessageParcel &data, MessagePa int32_t InputMethodCoreStub::StopInputServiceOnRemote(MessageParcel &data, MessageParcel &reply) { bool isTerminateIme = false; - if (ITypesUtil::Unmarshal(data, isTerminateIme)) { + if (!ITypesUtil::Unmarshal(data, isTerminateIme)) { IMSA_HILOGE("unmarshal failed"); return ErrorCode::ERROR_EX_PARCELABLE; } diff --git a/services/src/ime_info_inquirer.cpp b/services/src/ime_info_inquirer.cpp index 5ba1d969d..28c2e24bd 100644 --- a/services/src/ime_info_inquirer.cpp +++ b/services/src/ime_info_inquirer.cpp @@ -874,7 +874,7 @@ std::shared_ptr ImeInfoInquirer::GetDefaultImeCfgProp() { auto ime = GetDefaultIme(); if (ime.bundleName.empty() || ime.extName.empty()) { - IMSA_HILOGE("defaultIme is abnormal", ime.bundleName.c_str()); + IMSA_HILOGE("defaultIme is abnormal"); return nullptr; } auto defaultIme = std::make_shared(); diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index e9bbd82d0..ed16aaf5b 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -908,9 +908,9 @@ bool PerUserSession::StartIme(const std::shared_ptr &ime, bool isR IMSA_HILOGE("failed to get ime info"); return false; } - if (!info->isNewIme) { + if (!info->isNewIme && StartInputService(ime, false)) { IMSA_HILOGD("old ime, need to start ability"); - return StartInputService(ime, isRetry); + return true; } if (cacheData->core != nullptr) { IMSA_HILOGD("inform subtype: %{public}s", ime->subName.c_str()); -- Gitee From d92127b4dd7f22cf97c6df722483c3971033eac8 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Fri, 19 Jan 2024 22:17:29 +0800 Subject: [PATCH 10/13] modify code Signed-off-by: zhaolinglan --- services/src/ime_info_inquirer.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/services/src/ime_info_inquirer.cpp b/services/src/ime_info_inquirer.cpp index 28c2e24bd..be70f8d12 100644 --- a/services/src/ime_info_inquirer.cpp +++ b/services/src/ime_info_inquirer.cpp @@ -747,21 +747,23 @@ std::shared_ptr ImeInfoInquirer::GetDefaultImeInfo(int32_t userId) ImeNativeCfg ImeInfoInquirer::GetDefaultIme() { - std::string ime; + ImeNativeCfg imeCfg; if (!imeConfig_.defaultInputMethod.empty()) { IMSA_HILOGI("defaultInputMethod: %{public}s", imeConfig_.defaultInputMethod.c_str()); - ime = imeConfig_.defaultInputMethod; + imeCfg.imeId = imeConfig_.defaultInputMethod; } else { char value[CONFIG_LEN] = { 0 }; auto code = GetParameter(DEFAULT_IME_KEY, "", value, CONFIG_LEN); - ime = code > 0 ? value : ""; + imeCfg.imeId = code > 0 ? value : ""; } - auto pos = ime.find('/'); - if (pos == std::string::npos || pos + 1 >= ime.size()) { - IMSA_HILOGE("defaultIme: %{public}s is abnormal", ime.c_str()); + auto pos = imeCfg.imeId.find('/'); + if (pos == std::string::npos || pos + 1 >= imeCfg.imeId.size()) { + IMSA_HILOGE("defaultIme: %{public}s is abnormal", imeCfg.imeId.c_str()); return {}; } - return { .imeId = ime, .bundleName = ime.substr(0, pos), .extName = ime.substr(pos + 1) }; + imeCfg.bundleName = imeCfg.imeId.substr(0, pos); + imeCfg.extName = imeCfg.imeId.substr(pos + 1); + return imeCfg; } sptr ImeInfoInquirer::GetBundleMgr() -- Gitee From 6844291b1ddd800428dce93f557955c3b31242ac Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Fri, 19 Jan 2024 22:51:03 +0800 Subject: [PATCH 11/13] modify code Signed-off-by: zhaolinglan --- services/include/peruser_session.h | 2 +- test/unittest/cpp_test/src/security_mode_parser_test.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index 191e875d6..0a92610a8 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -32,7 +32,7 @@ #include "i_input_data_channel.h" #include "i_input_method_agent.h" #include "i_input_method_core.h" -#include "ime_info_inquirer.h" +#include "ime_cfg_manager.h" #include "input_attribute.h" #include "input_client_info.h" #include "input_control_channel_stub.h" diff --git a/test/unittest/cpp_test/src/security_mode_parser_test.cpp b/test/unittest/cpp_test/src/security_mode_parser_test.cpp index 2ab22c6fe..029e06397 100644 --- a/test/unittest/cpp_test/src/security_mode_parser_test.cpp +++ b/test/unittest/cpp_test/src/security_mode_parser_test.cpp @@ -16,6 +16,8 @@ #define private public #define protected public #include "security_mode_parser.h" + +#include "ime_cfg_manager.h" #include "ime_info_inquirer.h" #include "input_method_system_ability.h" #undef private -- Gitee From c9b44603b9e55fba8d88f71bd5a75da2b561584d Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Fri, 19 Jan 2024 22:51:27 +0800 Subject: [PATCH 12/13] modify code Signed-off-by: zhaolinglan --- services/include/peruser_session.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index 0a92610a8..191e875d6 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -32,7 +32,7 @@ #include "i_input_data_channel.h" #include "i_input_method_agent.h" #include "i_input_method_core.h" -#include "ime_cfg_manager.h" +#include "ime_info_inquirer.h" #include "input_attribute.h" #include "input_client_info.h" #include "input_control_channel_stub.h" -- Gitee From 4ee230f2321256aedd38fa1fa19e7acda4039056 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Fri, 19 Jan 2024 23:07:03 +0800 Subject: [PATCH 13/13] modify code Signed-off-by: zhaolinglan --- services/include/peruser_session.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index 191e875d6..0a92610a8 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -32,7 +32,7 @@ #include "i_input_data_channel.h" #include "i_input_method_agent.h" #include "i_input_method_core.h" -#include "ime_info_inquirer.h" +#include "ime_cfg_manager.h" #include "input_attribute.h" #include "input_client_info.h" #include "input_control_channel_stub.h" -- Gitee