From 3a71bd0afb2e86ea3f53352f73c1f901adb131fd Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Thu, 3 Nov 2022 12:27:23 +0800 Subject: [PATCH 001/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/include/im_common_event_manager.h | 1 + services/src/im_common_event_manager.cpp | 19 +++++++++++ services/src/input_method_system_ability.cpp | 33 +++++++------------- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/services/include/im_common_event_manager.h b/services/include/im_common_event_manager.h index ebfa4fc0..3f8c1f22 100644 --- a/services/include/im_common_event_manager.h +++ b/services/include/im_common_event_manager.h @@ -47,6 +47,7 @@ public: { } void OnReceiveEvent(const EventFwk::CommonEventData &data); + void DealWithRemoveEvent(const AAFwk::Want &want, const std::string action); void startUser(int32_t newUserId); }; diff --git a/services/src/im_common_event_manager.cpp b/services/src/im_common_event_manager.cpp index de2a1b20..95a7c14f 100644 --- a/services/src/im_common_event_manager.cpp +++ b/services/src/im_common_event_manager.cpp @@ -59,6 +59,7 @@ bool ImCommonEventManager::SubscribeEvent(const std::string &event) { EventFwk::MatchingSkills matchingSkills; matchingSkills.AddEvent(event); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); @@ -129,6 +130,9 @@ void ImCommonEventManager::EventSubscriber::OnReceiveEvent(const EventFwk::Commo if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED) { IMSA_HILOGI("ImCommonEventManager::OnReceiveEvent user switched!!!"); startUser(data.GetCode()); + } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED) { + IMSA_HILOGI("ImCommonEventManager::OnReceiveEvent package removed!!!"); + DealWithRemoveEvent(want, action); } } @@ -145,6 +149,21 @@ void ImCommonEventManager::EventSubscriber::startUser(int newUserId) IMSA_HILOGI("ImCommonEventManager::startUser 3"); } +void ImCommonEventManager::EventSubscriber::DealWithRemoveEvent(const AAFwk::Want &want, const std::string action) +{ + auto element = want.GetElement(); + std::string bundleName = element.GetBundleName(); + int32_t userId = want.GetIntParam("userId", 0); + int32_t appIndex = 0; + IMSA_HILOGI("bundleName = %{public}s. appIndex = %{public}d, userId = %{public}d", bundleName.c_str(), appIndex, userId); + + MessageParcel *parcel = new MessageParcel(); + parcel->WriteInt32(userId); + parcel->WriteString16(Str8ToStr16(bundleName)); + Message *msg = new Message(MessageID::MSG_ID_PACKAGE_REMOVED, parcel); + MessageHandler::Instance()->SendMessage(msg); +} + ImCommonEventManager::SystemAbilityStatusChangeListener::SystemAbilityStatusChangeListener(std::function func) : func_(std::move(func)) { diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 42c87268..b007cbc6 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -1179,34 +1179,23 @@ namespace MiscServices { return ErrorCode::ERROR_NULL_POINTER; } int32_t userId = data->ReadInt32(); - int32_t size = data->ReadInt32(); - - if (size <= 0) { - IMSA_HILOGE("Aborted! %s\n", ErrorCode::ToString(ErrorCode::ERROR_BAD_PARAMETERS)); - return ErrorCode::ERROR_BAD_PARAMETERS; - } std::u16string packageName = data->ReadString16(); + PerUserSetting *setting = GetUserSetting(userId); if (!setting || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); return ErrorCode::ERROR_USER_NOT_UNLOCKED; } - auto session = GetUserSession(userId); - if (session == nullptr) { - IMSA_HILOGI("InputMethodSystemAbility::OnPackageRemoved session is nullptr"); - return ErrorCode::ERROR_NULL_POINTER; - } - session->OnPackageRemoved(packageName); - bool securityImeFlag = false; - int32_t ret = setting->OnPackageRemoved(packageName, securityImeFlag); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGI("End...\n"); - return ret; - } - if (securityImeFlag) { - InputMethodInfo *securityIme = setting->GetSecurityInputMethod(); - InputMethodInfo *defaultIme = setting->GetCurrentInputMethod(); - session->ResetIme(defaultIme, securityIme); + + std::string defaultIme = ParaHandle::GetDefaultIme(userId); + std::string::size_type pos = defaultIme.find("/"); + std::u16string currentIme = Str8ToStr16(defaultIme.substr(0, pos)); + if (packageName == currentIme) { + InputMethodProperty target; + std::string packageName = "com.example.kikakeyboard"; + std::string abilityName = "ServiceExtAbility"; + int32_t ret = OnSwitchInputMethod(packageName, abilityName); + IMSA_HILOGI("InputMethodSystemAbility::OnPackageRemoved ret = %{public}d", ret); } return 0; } From 544a35faec3170431ca4482811b4875f951be033 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Thu, 3 Nov 2022 12:30:03 +0800 Subject: [PATCH 002/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/src/im_common_event_manager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/src/im_common_event_manager.cpp b/services/src/im_common_event_manager.cpp index 95a7c14f..3289dff8 100644 --- a/services/src/im_common_event_manager.cpp +++ b/services/src/im_common_event_manager.cpp @@ -154,8 +154,7 @@ void ImCommonEventManager::EventSubscriber::DealWithRemoveEvent(const AAFwk::Wan auto element = want.GetElement(); std::string bundleName = element.GetBundleName(); int32_t userId = want.GetIntParam("userId", 0); - int32_t appIndex = 0; - IMSA_HILOGI("bundleName = %{public}s. appIndex = %{public}d, userId = %{public}d", bundleName.c_str(), appIndex, userId); + IMSA_HILOGI("bundleName = %{public}s, userId = %{public}d", bundleName.c_str(), userId); MessageParcel *parcel = new MessageParcel(); parcel->WriteInt32(userId); From 2886f6e8f3b5574807a82909b5dba507ef528c30 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Thu, 3 Nov 2022 12:45:13 +0800 Subject: [PATCH 003/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/src/input_method_system_ability.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index b007cbc6..d2f3467e 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -1191,7 +1191,6 @@ namespace MiscServices { std::string::size_type pos = defaultIme.find("/"); std::u16string currentIme = Str8ToStr16(defaultIme.substr(0, pos)); if (packageName == currentIme) { - InputMethodProperty target; std::string packageName = "com.example.kikakeyboard"; std::string abilityName = "ServiceExtAbility"; int32_t ret = OnSwitchInputMethod(packageName, abilityName); From 7e725e52e7a5aa2dc55182d929c522bce54de6eb Mon Sep 17 00:00:00 2001 From: "zhangyafei.echo" Date: Thu, 3 Nov 2022 21:20:52 +0800 Subject: [PATCH 004/112] IssueNo:#I5Z8AZ Description:the dependency of libinputmethod_service.z.so to libabilityms.z.so didn't approprite. Sig:SIG_ApplicationFramework Feature or BugFix: Feature Binary Source: No Signed-off-by: zhangyafei.echo Change-Id: Ia5e07171afa03675ba3d80aab0005c7fc70fe02d --- services/BUILD.gn | 1 - services/src/input_method_system_ability.cpp | 15 ++++++++++----- services/src/peruser_session.cpp | 16 +++++++++++----- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/services/BUILD.gn b/services/BUILD.gn index b70afced..9097a23e 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -57,7 +57,6 @@ ohos_shared_library("inputmethod_service") { deps = [ "${ability_runtime_inner_api_path}/ability_manager:ability_manager", - "${ability_runtime_services_path}/abilitymgr:abilityms", "${inputmethod_path}/services/adapter/keyboard:keboard_event_static", "${inputmethod_path}/services/dfx:inputmethod_dfx_static", "//base/global/resource_management/frameworks/resmgr:global_resmgr", diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 42c87268..5fb59938 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -35,7 +35,6 @@ #include "os_account_manager.h" #include "para_handle.h" #include "resource_manager.h" -#include "sa_mgr_client.h" #include "system_ability.h" #include "system_ability_definition.h" #include "ui_service_mgr_client.h" @@ -1374,12 +1373,18 @@ namespace MiscServices { sptr InputMethodSystemAbility::GetAbilityManagerService() { IMSA_HILOGE("InputMethodSystemAbility::GetAbilityManagerService start"); - sptr abilityMsObj = - OHOS::DelayedSingleton::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID); - if (!abilityMsObj) { - IMSA_HILOGE("failed to get ability manager service"); + auto systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (systemAbilityManager == nullptr) { + IMSA_HILOGE("SystemAbilityManager is nullptr."); return nullptr; } + + auto abilityMsObj = systemAbilityManager->GetSystemAbility(ABILITY_MGR_SERVICE_ID); + if (abilityMsObj == nullptr) { + IMSA_HILOGE("Failed to get ability manager service."); + return nullptr; + } + return iface_cast(abilityMsObj); } diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 8a1a834f..7beb5dc2 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -31,7 +31,7 @@ #include "para_handle.h" #include "parcel.h" #include "platform.h" -#include "sa_mgr_client.h" +#include "iservice_registry.h" #include "system_ability_definition.h" #include "unistd.h" #include "utils.h" @@ -1030,12 +1030,18 @@ namespace MiscServices { sptr PerUserSession::GetAbilityManagerService() { IMSA_HILOGE("GetAbilityManagerService start"); - sptr abilityMsObj = - OHOS::DelayedSingleton::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID); - if (!abilityMsObj) { - IMSA_HILOGE("failed to get ability manager service"); + auto systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (systemAbilityManager == nullptr) { + IMSA_HILOGE("SystemAbilityManager is nullptr."); return nullptr; } + + auto abilityMsObj = systemAbilityManager->GetSystemAbility(ABILITY_MGR_SERVICE_ID); + if (abilityMsObj == nullptr) { + IMSA_HILOGE("Failed to get ability manager service."); + return nullptr; + } + return iface_cast(abilityMsObj); } From acd77d5b2123549961644e8e1f2d093e40bcdff7 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Fri, 4 Nov 2022 10:08:17 +0800 Subject: [PATCH 005/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/src/im_common_event_manager.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/src/im_common_event_manager.cpp b/services/src/im_common_event_manager.cpp index 3289dff8..91011f64 100644 --- a/services/src/im_common_event_manager.cpp +++ b/services/src/im_common_event_manager.cpp @@ -157,8 +157,10 @@ void ImCommonEventManager::EventSubscriber::DealWithRemoveEvent(const AAFwk::Wan IMSA_HILOGI("bundleName = %{public}s, userId = %{public}d", bundleName.c_str(), userId); MessageParcel *parcel = new MessageParcel(); - parcel->WriteInt32(userId); - parcel->WriteString16(Str8ToStr16(bundleName)); + if (!ITypesUtil::Marshal(*parcel, userId, Str8ToStr16(bundleName))) { + IMSA_HILOGE("Failed to write message parcel"); + return; + } Message *msg = new Message(MessageID::MSG_ID_PACKAGE_REMOVED, parcel); MessageHandler::Instance()->SendMessage(msg); } From acb00f237d4517a74b2234f282000e6dbc800910 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Fri, 4 Nov 2022 10:25:56 +0800 Subject: [PATCH 006/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/src/im_common_event_manager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/src/im_common_event_manager.cpp b/services/src/im_common_event_manager.cpp index 91011f64..c60f17c7 100644 --- a/services/src/im_common_event_manager.cpp +++ b/services/src/im_common_event_manager.cpp @@ -24,6 +24,7 @@ #include "iservice_registry.h" #include "message_handler.h" #include "system_ability_definition.h" +#include "itypes_util.h" namespace OHOS { namespace MiscServices { From 30e93d803231d4feb2dc8ee47ad9ff53de64d77a Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Fri, 4 Nov 2022 16:17:18 +0800 Subject: [PATCH 007/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/src/input_method_system_ability.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index d2f3467e..b70889de 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -1178,11 +1178,15 @@ namespace MiscServices { IMSA_HILOGI("InputMethodSystemAbility::OnPackageRemoved data is nullptr"); return ErrorCode::ERROR_NULL_POINTER; } - int32_t userId = data->ReadInt32(); - std::u16string packageName = data->ReadString16(); + int32_t userId; + std::u16string packageName; + if (!ITypesUtil::Unmarshal(*parcel, userId, packageName)) { + IMSA_HILOGE("Failed to write message parcel"); + return ErrorCode::ERROR_EX_PARCELABLE; + } PerUserSetting *setting = GetUserSetting(userId); - if (!setting || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { + if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); return ErrorCode::ERROR_USER_NOT_UNLOCKED; } From 054a526b7990d869267d94966363f93c61525672 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Fri, 4 Nov 2022 17:28:26 +0800 Subject: [PATCH 008/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/src/input_method_system_ability.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index b70889de..34c1cbce 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -1180,7 +1180,7 @@ namespace MiscServices { } int32_t userId; std::u16string packageName; - if (!ITypesUtil::Unmarshal(*parcel, userId, packageName)) { + if (!ITypesUtil::Unmarshal(*data, userId, packageName)) { IMSA_HILOGE("Failed to write message parcel"); return ErrorCode::ERROR_EX_PARCELABLE; } From 427ae8fbdc7092e39566d83a44d86a333586ac16 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Fri, 4 Nov 2022 18:23:36 +0800 Subject: [PATCH 009/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/src/input_method_system_ability.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 34c1cbce..ebbb07c7 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -39,6 +39,7 @@ #include "system_ability.h" #include "system_ability_definition.h" #include "ui_service_mgr_client.h" +#include "itypes_util.h" namespace OHOS { namespace MiscServices { From 61c7cbf402e5bdd05f8e75aa5c6d0e75d27ab838 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Sat, 5 Nov 2022 10:06:43 +0800 Subject: [PATCH 010/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/src/input_method_system_ability.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index ebbb07c7..cd95c5a8 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -1175,14 +1175,14 @@ namespace MiscServices { { IMSA_HILOGI("Start...\n"); MessageParcel *data = msg->msgContent_; - if (!data) { + if (data == nullptr) { IMSA_HILOGI("InputMethodSystemAbility::OnPackageRemoved data is nullptr"); return ErrorCode::ERROR_NULL_POINTER; } - int32_t userId; - std::u16string packageName; + int32_t userId = 0; + std::u16string packageName = ""; if (!ITypesUtil::Unmarshal(*data, userId, packageName)) { - IMSA_HILOGE("Failed to write message parcel"); + IMSA_HILOGE("Failed to read message parcel"); return ErrorCode::ERROR_EX_PARCELABLE; } From 9c79adcda203f34265539c44bb5fd2a3e637384a Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Sat, 5 Nov 2022 10:28:57 +0800 Subject: [PATCH 011/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/src/input_method_system_ability.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index cd95c5a8..990cbe57 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -1180,7 +1180,7 @@ namespace MiscServices { return ErrorCode::ERROR_NULL_POINTER; } int32_t userId = 0; - std::u16string packageName = ""; + std::u16string packageName = Utils::ToStr16(""); if (!ITypesUtil::Unmarshal(*data, userId, packageName)) { IMSA_HILOGE("Failed to read message parcel"); return ErrorCode::ERROR_EX_PARCELABLE; From 6d78ec43fe737b6860e22866e33f22aaa67fbeaa Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Mon, 7 Nov 2022 21:29:59 +0800 Subject: [PATCH 012/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/src/im_common_event_manager.cpp | 2 +- services/src/input_method_system_ability.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/src/im_common_event_manager.cpp b/services/src/im_common_event_manager.cpp index c60f17c7..d0078169 100644 --- a/services/src/im_common_event_manager.cpp +++ b/services/src/im_common_event_manager.cpp @@ -158,7 +158,7 @@ void ImCommonEventManager::EventSubscriber::DealWithRemoveEvent(const AAFwk::Wan IMSA_HILOGI("bundleName = %{public}s, userId = %{public}d", bundleName.c_str(), userId); MessageParcel *parcel = new MessageParcel(); - if (!ITypesUtil::Marshal(*parcel, userId, Str8ToStr16(bundleName))) { + if (!ITypesUtil::Marshal(*parcel, userId,bundleName)) { IMSA_HILOGE("Failed to write message parcel"); return; } diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 990cbe57..9c46db70 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -1180,7 +1180,7 @@ namespace MiscServices { return ErrorCode::ERROR_NULL_POINTER; } int32_t userId = 0; - std::u16string packageName = Utils::ToStr16(""); + std::string packageName = ""; if (!ITypesUtil::Unmarshal(*data, userId, packageName)) { IMSA_HILOGE("Failed to read message parcel"); return ErrorCode::ERROR_EX_PARCELABLE; @@ -1194,7 +1194,7 @@ namespace MiscServices { std::string defaultIme = ParaHandle::GetDefaultIme(userId); std::string::size_type pos = defaultIme.find("/"); - std::u16string currentIme = Str8ToStr16(defaultIme.substr(0, pos)); + std::string currentIme = defaultIme.substr(0, pos); if (packageName == currentIme) { std::string packageName = "com.example.kikakeyboard"; std::string abilityName = "ServiceExtAbility"; From 2f9d4fe62b5f82caa02409f2e07f3ffe0a682aeb Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Tue, 8 Nov 2022 09:16:45 +0800 Subject: [PATCH 013/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/src/input_method_system_ability.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 9c46db70..be6785bf 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -879,7 +879,9 @@ namespace MiscServices { } case MSG_ID_PACKAGE_REMOVED: { OnPackageRemoved(msg); - break; + delete msg; + msg = nullptr; + return; } case MSG_ID_SETTING_CHANGED: { OnSettingChanged(msg); From 1ea25b65c950a9d2fff47a15a8e5d90707d06f89 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Tue, 8 Nov 2022 14:30:02 +0800 Subject: [PATCH 014/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/src/im_common_event_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/src/im_common_event_manager.cpp b/services/src/im_common_event_manager.cpp index d0078169..e5745e6d 100644 --- a/services/src/im_common_event_manager.cpp +++ b/services/src/im_common_event_manager.cpp @@ -158,7 +158,7 @@ void ImCommonEventManager::EventSubscriber::DealWithRemoveEvent(const AAFwk::Wan IMSA_HILOGI("bundleName = %{public}s, userId = %{public}d", bundleName.c_str(), userId); MessageParcel *parcel = new MessageParcel(); - if (!ITypesUtil::Marshal(*parcel, userId,bundleName)) { + if (!ITypesUtil::Marshal(*parcel, userId, bundleName)) { IMSA_HILOGE("Failed to write message parcel"); return; } From d262ecff3cb2657583dda39abd5aafeebe2df99e Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Wed, 9 Nov 2022 15:31:46 +0800 Subject: [PATCH 015/112] Signed-off-by: ma-shaoyin Changes to be committed: --- etc/para/src/para_handle.cpp | 9 +++++---- services/src/input_method_system_ability.cpp | 4 +--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/etc/para/src/para_handle.cpp b/etc/para/src/para_handle.cpp index 44922058..3ea1dd93 100644 --- a/etc/para/src/para_handle.cpp +++ b/etc/para/src/para_handle.cpp @@ -19,7 +19,8 @@ namespace OHOS { namespace MiscServices { const char *ParaHandle::DEFAULT_IME_KEY = "persist.sys.default_ime"; - const char *ParaHandle::DEFAULT_IME_NAME = "com.example.kikakeyboard/ServiceExtAbility"; + const std::string ParaHandle::CURRENT_PACKAGE_NAME = "com.example.kikakeyboard"; + const std::string ParaHandle::CURRRET_ABILITY_NAME = "ServiceExtAbility"; bool ParaHandle::SetDefaultIme(int32_t userId, const std::string &imeName) { if (userId != main_userId) { @@ -41,9 +42,9 @@ namespace OHOS { if (code > 0) { return value; } - - SetDefaultIme(userId, DEFAULT_IME_NAME); - return DEFAULT_IME_NAME; + std::string defaultName = CURRENT_PACKAGE_NAME + "/" + CURRRET_ABILITY_NAME; + SetDefaultIme(userId, defaultName); + return defaultName; } } // namespace MiscServices } // namespace OHOS diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index be6785bf..a8fdc5f9 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -1198,9 +1198,7 @@ namespace MiscServices { std::string::size_type pos = defaultIme.find("/"); std::string currentIme = defaultIme.substr(0, pos); if (packageName == currentIme) { - std::string packageName = "com.example.kikakeyboard"; - std::string abilityName = "ServiceExtAbility"; - int32_t ret = OnSwitchInputMethod(packageName, abilityName); + int32_t ret = OnSwitchInputMethod(ParaHandle::CURRENT_PACKAGE_NAME, ParaHandle::CURRRET_ABILITY_NAME); IMSA_HILOGI("InputMethodSystemAbility::OnPackageRemoved ret = %{public}d", ret); } return 0; From db48e8c3a9d6e120598492e7e0b53f3eb6feac02 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Wed, 9 Nov 2022 16:05:00 +0800 Subject: [PATCH 016/112] Signed-off-by: ma-shaoyin Changes to be committed: --- etc/para/include/para_handle.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/etc/para/include/para_handle.h b/etc/para/include/para_handle.h index 5c10a451..6cb5de98 100644 --- a/etc/para/include/para_handle.h +++ b/etc/para/include/para_handle.h @@ -27,7 +27,8 @@ namespace OHOS { private: static const char *DEFAULT_IME_KEY; - static const char *DEFAULT_IME_NAME; + static const std::string CURRENT_PACKAGE_NAME; + static const std::string CURRRET_ABILITY_NAME; static constexpr int CONFIG_LEN = 128; static const int32_t main_userId = 100; }; From e7fb669bcf6fb3bb60610a9376c5802fb8a8fdea Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Wed, 9 Nov 2022 16:36:17 +0800 Subject: [PATCH 017/112] Signed-off-by: ma-shaoyin Changes to be committed: --- etc/para/include/para_handle.h | 2 ++ etc/para/src/para_handle.cpp | 10 ++++++++++ services/src/input_method_system_ability.cpp | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/etc/para/include/para_handle.h b/etc/para/include/para_handle.h index 6cb5de98..4f8dd9b6 100644 --- a/etc/para/include/para_handle.h +++ b/etc/para/include/para_handle.h @@ -24,6 +24,8 @@ namespace OHOS { virtual ~ParaHandle() = default; static bool SetDefaultIme(int32_t userId, const std::string &imeName); static std::string GetDefaultIme(int32_t userId); + static std::string GetPackageName(); + static std::string GetAbilityName(); private: static const char *DEFAULT_IME_KEY; diff --git a/etc/para/src/para_handle.cpp b/etc/para/src/para_handle.cpp index 3ea1dd93..9dee727c 100644 --- a/etc/para/src/para_handle.cpp +++ b/etc/para/src/para_handle.cpp @@ -46,5 +46,15 @@ namespace OHOS { SetDefaultIme(userId, defaultName); return defaultName; } + + static std::string GetPackageName() + { + return CURRENT_PACKAGE_NAME; + } + + static std::string GetAbilityName() + { + return CURRRET_ABILITY_NAME; + } } // namespace MiscServices } // namespace OHOS diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index a8fdc5f9..01f2e07e 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -1198,7 +1198,7 @@ namespace MiscServices { std::string::size_type pos = defaultIme.find("/"); std::string currentIme = defaultIme.substr(0, pos); if (packageName == currentIme) { - int32_t ret = OnSwitchInputMethod(ParaHandle::CURRENT_PACKAGE_NAME, ParaHandle::CURRRET_ABILITY_NAME); + int32_t ret = OnSwitchInputMethod(ParaHandle::GetPackageName(), ParaHandle::GetAbilityName()); IMSA_HILOGI("InputMethodSystemAbility::OnPackageRemoved ret = %{public}d", ret); } return 0; From 8ae9b2d4d46cf71a7ac5c52dc55dd942038e4a7b Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Wed, 9 Nov 2022 16:50:17 +0800 Subject: [PATCH 018/112] Signed-off-by: ma-shaoyin Changes to be committed: --- etc/para/src/para_handle.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/para/src/para_handle.cpp b/etc/para/src/para_handle.cpp index 9dee727c..b4b46cfa 100644 --- a/etc/para/src/para_handle.cpp +++ b/etc/para/src/para_handle.cpp @@ -47,12 +47,12 @@ namespace OHOS { return defaultName; } - static std::string GetPackageName() + static std::string ParaHandle::GetPackageName() { return CURRENT_PACKAGE_NAME; } - static std::string GetAbilityName() + static std::string ParaHandle::GetAbilityName() { return CURRRET_ABILITY_NAME; } From cc0c801c14e45887cc9dffc2254d539c6726c2ab Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Wed, 9 Nov 2022 17:06:51 +0800 Subject: [PATCH 019/112] Signed-off-by: ma-shaoyin Changes to be committed: --- etc/para/src/para_handle.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/para/src/para_handle.cpp b/etc/para/src/para_handle.cpp index b4b46cfa..795e9a9b 100644 --- a/etc/para/src/para_handle.cpp +++ b/etc/para/src/para_handle.cpp @@ -47,12 +47,12 @@ namespace OHOS { return defaultName; } - static std::string ParaHandle::GetPackageName() + std::string ParaHandle::GetPackageName() { return CURRENT_PACKAGE_NAME; } - static std::string ParaHandle::GetAbilityName() + std::string ParaHandle::GetAbilityName() { return CURRRET_ABILITY_NAME; } From 8e9af6beae4437335fc2f6864000c79ae0cc0d7a Mon Sep 17 00:00:00 2001 From: cy7717 Date: Wed, 9 Nov 2022 17:32:18 +0800 Subject: [PATCH 020/112] =?UTF-8?q?=E8=A7=A3=E6=B1=BAtdd=E6=B8=AC=E8=A9=A6?= =?UTF-8?q?=E5=A5=97InputMethodControllerTest=E5=9F=B7=E8=A1=8C=E5=AE=8C?= =?UTF-8?q?=E5=8D=A1=E6=AD=BB=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cy7717 --- .../include/input_method_controller.h | 1 + .../src/input_method_controller.cpp | 21 +++++++++++++++---- services/include/message_handler.h | 2 ++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/frameworks/inputmethod_controller/include/input_method_controller.h b/frameworks/inputmethod_controller/include/input_method_controller.h index ee6200a7..b1bbc8b0 100644 --- a/frameworks/inputmethod_controller/include/input_method_controller.h +++ b/frameworks/inputmethod_controller/include/input_method_controller.h @@ -94,6 +94,7 @@ private: InputMethodController(); ~InputMethodController(); + void ExitSubThread(); bool Initialize(); sptr GetSystemAbilityProxy(); void PrepareInput( diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index 57f216a9..da46e2f7 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -43,11 +43,19 @@ using namespace MessageID; InputMethodController::~InputMethodController() { - if (msgHandler) { + ExitSubThread(); + if (msgHandler != nullptr) { delete msgHandler; msgHandler = nullptr; - stop_ = false; } + } + + void InputMethodController::ExitSubThread() + { + stop_ = true; + MessageParcel *parcel = new MessageParcel(); + Message *msg = new Message(MessageID::MSG_ID_EXIT_SUB_THREAD, parcel); + msgHandler->SendMessage(msg); if (workThreadHandler.joinable()) { workThreadHandler.join(); } @@ -93,8 +101,8 @@ using namespace MessageID; channel->SetHandler(msgHandler); mInputDataChannel = channel; - workThreadHandler = std::thread([this] {WorkThread();}); - mAttribute.inputPattern = InputAttribute::PATTERN_TEXT; + workThreadHandler = std::thread([this] { WorkThread(); }); + mAttribute.inputPattern = InputAttribute::PATTERN_TEXT; textListener = nullptr; IMSA_HILOGI("InputMethodController::Initialize textListener is nullptr"); @@ -232,6 +240,11 @@ using namespace MessageID; break; } OnSwitchInput(property, subProperty); + break; + } + case MSG_ID_EXIT_SUB_THREAD: { + IMSA_HILOGD("the message is used to exit sub thread"); + break; } default: { break; diff --git a/services/include/message_handler.h b/services/include/message_handler.h index dd352692..5b334ce1 100644 --- a/services/include/message_handler.h +++ b/services/include/message_handler.h @@ -89,6 +89,8 @@ enum { // the request from IMC to IMA MSG_ID_ON_CURSOR_UPDATE, MSG_ID_ON_SELECTION_CHANGE, + + MSG_ID_EXIT_SUB_THREAD, }; } From 6d511b3f96eb7133dc62dbf911944d0b07ebf43c Mon Sep 17 00:00:00 2001 From: cy7717 Date: Wed, 9 Nov 2022 18:12:33 +0800 Subject: [PATCH 021/112] mod Signed-off-by: cy7717 --- .../inputmethod_controller/src/input_method_controller.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index da46e2f7..6fdb2eb0 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -242,11 +242,8 @@ using namespace MessageID; OnSwitchInput(property, subProperty); break; } - case MSG_ID_EXIT_SUB_THREAD: { - IMSA_HILOGD("the message is used to exit sub thread"); - break; - } default: { + IMSA_HILOGD("the message is %{public}d.", msg->msgId_); break; } } From ffb0f2c8f6a5983caf3b78b9ba41248a9d7eaa10 Mon Sep 17 00:00:00 2001 From: cy7717 Date: Wed, 9 Nov 2022 20:23:22 +0800 Subject: [PATCH 022/112] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cy7717 --- .../include/input_method_controller.h | 2 +- .../src/input_method_controller.cpp | 30 +++++++++---------- services/include/message_handler.h | 2 +- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/frameworks/inputmethod_controller/include/input_method_controller.h b/frameworks/inputmethod_controller/include/input_method_controller.h index b1bbc8b0..ab4b58f6 100644 --- a/frameworks/inputmethod_controller/include/input_method_controller.h +++ b/frameworks/inputmethod_controller/include/input_method_controller.h @@ -94,7 +94,6 @@ private: InputMethodController(); ~InputMethodController(); - void ExitSubThread(); bool Initialize(); sptr GetSystemAbilityProxy(); void PrepareInput( @@ -106,6 +105,7 @@ private: void OnSwitchInput(const Property &property, const SubProperty &subProperty); std::shared_ptr GetInputMethodAgent(); void WorkThread(); + void QuitWorkThread(); int32_t ListInputMethodCommon(InputMethodStatus status, std::vector &props); sptr mInputDataChannel; diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index 6fdb2eb0..3d6110bf 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -43,22 +43,9 @@ using namespace MessageID; InputMethodController::~InputMethodController() { - ExitSubThread(); - if (msgHandler != nullptr) { - delete msgHandler; - msgHandler = nullptr; - } - } - - void InputMethodController::ExitSubThread() - { - stop_ = true; - MessageParcel *parcel = new MessageParcel(); - Message *msg = new Message(MessageID::MSG_ID_EXIT_SUB_THREAD, parcel); - msgHandler->SendMessage(msg); - if (workThreadHandler.joinable()) { - workThreadHandler.join(); - } + QuitWorkThread(); + delete msgHandler; + msgHandler = nullptr; } sptr InputMethodController::GetInstance() @@ -252,6 +239,17 @@ using namespace MessageID; } } + void InputMethodController::QuitWorkThread() + { + stop_ = true; + MessageParcel *parcel = new MessageParcel(); + Message *msg = new Message(MessageID::MSG_ID_QUIT_WORKER_THREAD, parcel); + msgHandler->SendMessage(msg); + if (workThreadHandler.joinable()) { + workThreadHandler.join(); + } + } + void InputMethodController::OnSwitchInput(const Property &property, const SubProperty &subProperty) { IMSA_HILOGE("InputMethodController::OnSwitchInput"); diff --git a/services/include/message_handler.h b/services/include/message_handler.h index 5b334ce1..c999b3de 100644 --- a/services/include/message_handler.h +++ b/services/include/message_handler.h @@ -90,7 +90,7 @@ enum { MSG_ID_ON_CURSOR_UPDATE, MSG_ID_ON_SELECTION_CHANGE, - MSG_ID_EXIT_SUB_THREAD, + MSG_ID_QUIT_WORKER_THREAD, }; } From b880f17b3e015b7d0bd7416fc97ef7337d26a45d Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Wed, 9 Nov 2022 21:11:35 +0800 Subject: [PATCH 023/112] Signed-off-by: ma-shaoyin Changes to be committed: --- etc/para/include/para_handle.h | 6 ++---- etc/para/src/para_handle.cpp | 16 +++------------- services/include/im_common_event_manager.h | 2 +- services/src/im_common_event_manager.cpp | 4 ++-- services/src/input_method_system_ability.cpp | 2 +- 5 files changed, 9 insertions(+), 21 deletions(-) diff --git a/etc/para/include/para_handle.h b/etc/para/include/para_handle.h index 4f8dd9b6..45b7b74c 100644 --- a/etc/para/include/para_handle.h +++ b/etc/para/include/para_handle.h @@ -24,13 +24,11 @@ namespace OHOS { virtual ~ParaHandle() = default; static bool SetDefaultIme(int32_t userId, const std::string &imeName); static std::string GetDefaultIme(int32_t userId); - static std::string GetPackageName(); - static std::string GetAbilityName(); + static constexpr const char *DEFAULT_PACKAGE_NAME; + static constexpr const char *DEFAULT_ABILITY_NAME; private: static const char *DEFAULT_IME_KEY; - static const std::string CURRENT_PACKAGE_NAME; - static const std::string CURRRET_ABILITY_NAME; static constexpr int CONFIG_LEN = 128; static const int32_t main_userId = 100; }; diff --git a/etc/para/src/para_handle.cpp b/etc/para/src/para_handle.cpp index 795e9a9b..fd73ba0e 100644 --- a/etc/para/src/para_handle.cpp +++ b/etc/para/src/para_handle.cpp @@ -19,8 +19,8 @@ namespace OHOS { namespace MiscServices { const char *ParaHandle::DEFAULT_IME_KEY = "persist.sys.default_ime"; - const std::string ParaHandle::CURRENT_PACKAGE_NAME = "com.example.kikakeyboard"; - const std::string ParaHandle::CURRRET_ABILITY_NAME = "ServiceExtAbility"; + constexpr const char *ParaHandle::CURRENT_PACKAGE_NAME = "com.example.kikakeyboard"; + constexpr const char *ParaHandle::CURRRET_ABILITY_NAME = "ServiceExtAbility"; bool ParaHandle::SetDefaultIme(int32_t userId, const std::string &imeName) { if (userId != main_userId) { @@ -42,19 +42,9 @@ namespace OHOS { if (code > 0) { return value; } - std::string defaultName = CURRENT_PACKAGE_NAME + "/" + CURRRET_ABILITY_NAME; + std::string defaultName = std::string(CURRENT_PACKAGE_NAME) + "/" + std::string(CURRRET_ABILITY_NAME); SetDefaultIme(userId, defaultName); return defaultName; } - - std::string ParaHandle::GetPackageName() - { - return CURRENT_PACKAGE_NAME; - } - - std::string ParaHandle::GetAbilityName() - { - return CURRRET_ABILITY_NAME; - } } // namespace MiscServices } // namespace OHOS diff --git a/services/include/im_common_event_manager.h b/services/include/im_common_event_manager.h index 3f8c1f22..c7265a0d 100644 --- a/services/include/im_common_event_manager.h +++ b/services/include/im_common_event_manager.h @@ -47,7 +47,7 @@ public: { } void OnReceiveEvent(const EventFwk::CommonEventData &data); - void DealWithRemoveEvent(const AAFwk::Want &want, const std::string action); + void HandlePackageRemove(const AAFwk::Want &want, const std::string action); void startUser(int32_t newUserId); }; diff --git a/services/src/im_common_event_manager.cpp b/services/src/im_common_event_manager.cpp index e5745e6d..5f651af3 100644 --- a/services/src/im_common_event_manager.cpp +++ b/services/src/im_common_event_manager.cpp @@ -133,7 +133,7 @@ void ImCommonEventManager::EventSubscriber::OnReceiveEvent(const EventFwk::Commo startUser(data.GetCode()); } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED) { IMSA_HILOGI("ImCommonEventManager::OnReceiveEvent package removed!!!"); - DealWithRemoveEvent(want, action); + HandlePackageRemove(want, action); } } @@ -150,7 +150,7 @@ void ImCommonEventManager::EventSubscriber::startUser(int newUserId) IMSA_HILOGI("ImCommonEventManager::startUser 3"); } -void ImCommonEventManager::EventSubscriber::DealWithRemoveEvent(const AAFwk::Want &want, const std::string action) +void ImCommonEventManager::EventSubscriber::HandlePackageRemove(const AAFwk::Want &want, const std::string action) { auto element = want.GetElement(); std::string bundleName = element.GetBundleName(); diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 01f2e07e..5344f2f4 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -1198,7 +1198,7 @@ namespace MiscServices { std::string::size_type pos = defaultIme.find("/"); std::string currentIme = defaultIme.substr(0, pos); if (packageName == currentIme) { - int32_t ret = OnSwitchInputMethod(ParaHandle::GetPackageName(), ParaHandle::GetAbilityName()); + int32_t ret = OnSwitchInputMethod(ParaHandle::DEFAULT_PACKAGE_NAME, ParaHandle::DEFAULT_ABILITY_NAME); IMSA_HILOGI("InputMethodSystemAbility::OnPackageRemoved ret = %{public}d", ret); } return 0; From e1737346e4988f7b92d32e9de080ec1eb2f6575e Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Wed, 9 Nov 2022 21:44:18 +0800 Subject: [PATCH 024/112] Signed-off-by: ma-shaoyin Changes to be committed: --- etc/para/src/para_handle.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/etc/para/src/para_handle.cpp b/etc/para/src/para_handle.cpp index fd73ba0e..94b6277a 100644 --- a/etc/para/src/para_handle.cpp +++ b/etc/para/src/para_handle.cpp @@ -19,8 +19,8 @@ namespace OHOS { namespace MiscServices { const char *ParaHandle::DEFAULT_IME_KEY = "persist.sys.default_ime"; - constexpr const char *ParaHandle::CURRENT_PACKAGE_NAME = "com.example.kikakeyboard"; - constexpr const char *ParaHandle::CURRRET_ABILITY_NAME = "ServiceExtAbility"; + constexpr const char *ParaHandle::DEFAULT_PACKAGE_NAME = "com.example.kikakeyboard"; + constexpr const char *ParaHandle::DEFAULT_ABILITY_NAME = "ServiceExtAbility"; bool ParaHandle::SetDefaultIme(int32_t userId, const std::string &imeName) { if (userId != main_userId) { @@ -42,7 +42,7 @@ namespace OHOS { if (code > 0) { return value; } - std::string defaultName = std::string(CURRENT_PACKAGE_NAME) + "/" + std::string(CURRRET_ABILITY_NAME); + std::string defaultName = std::string(DEFAULT_PACKAGE_NAME) + "/" + std::string(DEFAULT_ABILITY_NAME); SetDefaultIme(userId, defaultName); return defaultName; } From dc427e527740e50e5123c1b696a0788cb0e7d9d7 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Wed, 9 Nov 2022 22:12:15 +0800 Subject: [PATCH 025/112] Signed-off-by: ma-shaoyin Changes to be committed: --- etc/para/include/para_handle.h | 4 ++-- etc/para/src/para_handle.cpp | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/etc/para/include/para_handle.h b/etc/para/include/para_handle.h index 45b7b74c..6ecd2dd8 100644 --- a/etc/para/include/para_handle.h +++ b/etc/para/include/para_handle.h @@ -25,8 +25,8 @@ namespace OHOS { static bool SetDefaultIme(int32_t userId, const std::string &imeName); static std::string GetDefaultIme(int32_t userId); - static constexpr const char *DEFAULT_PACKAGE_NAME; - static constexpr const char *DEFAULT_ABILITY_NAME; + static constexpr const char *DEFAULT_PACKAGE_NAME = "com.example.kikakeyboard"; + static constexpr const char *DEFAULT_ABILITY_NAME = "ServiceExtAbility"; private: static const char *DEFAULT_IME_KEY; static constexpr int CONFIG_LEN = 128; diff --git a/etc/para/src/para_handle.cpp b/etc/para/src/para_handle.cpp index 94b6277a..dcc26a92 100644 --- a/etc/para/src/para_handle.cpp +++ b/etc/para/src/para_handle.cpp @@ -19,8 +19,6 @@ namespace OHOS { namespace MiscServices { const char *ParaHandle::DEFAULT_IME_KEY = "persist.sys.default_ime"; - constexpr const char *ParaHandle::DEFAULT_PACKAGE_NAME = "com.example.kikakeyboard"; - constexpr const char *ParaHandle::DEFAULT_ABILITY_NAME = "ServiceExtAbility"; bool ParaHandle::SetDefaultIme(int32_t userId, const std::string &imeName) { if (userId != main_userId) { From 61c07c7e2b637750dfe7e65a858d42407f699ab8 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Thu, 10 Nov 2022 14:54:04 +0800 Subject: [PATCH 026/112] modify code Signed-off-by: zhaolinglan --- etc/init/inputmethodservice.cfg | 1 + .../adapter/keyboard/input_event_callback.h | 51 +++++++++++++++++++ services/adapter/keyboard/keyboard_event.cpp | 24 +++++++-- services/adapter/keyboard/keyboard_event.h | 10 +++- services/include/im_common_event_manager.h | 2 +- services/src/im_common_event_manager.cpp | 13 ++--- services/src/input_method_system_ability.cpp | 44 ++-------------- 7 files changed, 90 insertions(+), 55 deletions(-) create mode 100644 services/adapter/keyboard/input_event_callback.h diff --git a/etc/init/inputmethodservice.cfg b/etc/init/inputmethodservice.cfg index ec97081c..61228b60 100644 --- a/etc/init/inputmethodservice.cfg +++ b/etc/init/inputmethodservice.cfg @@ -4,6 +4,7 @@ "path" : ["/system/bin/sa_main", "/system/profile/inputmethod_service.xml"], "uid" : "inputmethod", "gid" : ["inputmethod", "shell"], + "permission" : ["ohos.permission.INPUT_MONITORING"], "caps" : [], "secon" : "u:r:inputmethod_service:s0" } diff --git a/services/adapter/keyboard/input_event_callback.h b/services/adapter/keyboard/input_event_callback.h new file mode 100644 index 00000000..8478b416 --- /dev/null +++ b/services/adapter/keyboard/input_event_callback.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022 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 INPUTMETHOD_IMF_INPUT_EVENT_CALLBACK_H +#define INPUTMETHOD_IMF_INPUT_EVENT_CALLBACK_H + +#include +#include + +#include "global.h" + +namespace OHOS { +namespace MiscServices { +class InputEventCallback : public MMI::IInputEventConsumer { + virtual void OnInputEvent(std::shared_ptr keyEvent) const; + virtual void OnInputEvent(std::shared_ptr pointerEvent) const; + virtual void OnInputEvent(std::shared_ptr axisEvent) const; +}; + +void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) const +{ + IMSA_HILOGI("OnInputEvent"); + auto pressKeys = keyEvent->GetPressedKeys(); + for (const auto key : pressKeys) { + IMSA_HILOGI("OnInputEvent key code: %{public}d", key); + } +} + +void InputEventCallback::OnInputEvent(std::shared_ptr pointerEvent) const +{ +} + +void InputEventCallback::OnInputEvent(std::shared_ptr axisEvent) const +{ +} +} // namespace MiscServices +} // namespace OHOS + +#endif //INPUTMETHOD_IMF_INPUT_EVENT_CALLBACK_H diff --git a/services/adapter/keyboard/keyboard_event.cpp b/services/adapter/keyboard/keyboard_event.cpp index 93da2434..66ac2ed9 100644 --- a/services/adapter/keyboard/keyboard_event.cpp +++ b/services/adapter/keyboard/keyboard_event.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -16,15 +16,15 @@ #include "keyboard_event.h" #include -#include #include #include #include "global.h" +#include "input_event_callback.h" -namespace OHOS::MiscServices { - +namespace OHOS { +namespace MiscServices { using namespace MMI; KeyboardEvent &KeyboardEvent::GetInstance() @@ -33,6 +33,19 @@ KeyboardEvent &KeyboardEvent::GetInstance() return keyboardEvent; } +int32_t KeyboardEvent::InitKeyEventMonitor() +{ + IMSA_HILOGI("KeyboardEvent::InitKeyMonitor"); + std::shared_ptr callback = std::make_shared(); + int32_t monitorId = + InputManager::GetInstance()->AddMonitor(std::static_pointer_cast(callback)); + if (monitorId < 0) { + IMSA_HILOGE("Add monitor failed, id: %{public}d", monitorId); + return ErrorCode::ERROR_STATUS_UNKNOWN_ERROR; + } + return ErrorCode::NO_ERROR; +} + int32_t KeyboardEvent::SubscribeKeyboardEvent(const CombineKey &combine, KeyHandle handle) { std::shared_ptr keyOption = std::make_shared(); @@ -53,4 +66,5 @@ int32_t KeyboardEvent::SubscribeKeyboardEvent(const CombineKey &combine, KeyHand IMSA_HILOGI("subscribe %{public}d key event %{public}s", combine.finalKey, ret >= 0 ? "OK" : "ERROR"); return ret >= 0 ? ErrorCode::NO_ERROR : ErrorCode::ERROR_SUBSCRIBE_KEYBOARD_EVENT; } -} // namespace OHOS::MiscServices +} // namespace MiscServices +} // namespace OHOS diff --git a/services/adapter/keyboard/keyboard_event.h b/services/adapter/keyboard/keyboard_event.h index 624f54b5..603479bc 100644 --- a/services/adapter/keyboard/keyboard_event.h +++ b/services/adapter/keyboard/keyboard_event.h @@ -16,12 +16,16 @@ #ifndef IMF_KEYBOARD_EVENT_H #define IMF_KEYBOARD_EVENT_H +#include + #include #include #include -namespace OHOS ::MiscServices { +#include "global.h" +namespace OHOS { +namespace MiscServices { struct CombineKey { std::set preKeys; int32_t finalKey; @@ -35,6 +39,7 @@ class KeyboardEvent { public: static KeyboardEvent &GetInstance(); int32_t SubscribeKeyboardEvent(const CombineKey &combine, KeyHandle handle); + int32_t InitKeyEventMonitor(); private: static constexpr int32_t PRESS_KEY_DELAY_MS = 200; @@ -50,5 +55,6 @@ struct KeyboardEventHandler { KeyHandle handle; }; -} // namespace OHOS::MiscServices +} // namespace MiscServices +} // namespace OHOS #endif // IMF_KEYBOARD_EVENT_H diff --git a/services/include/im_common_event_manager.h b/services/include/im_common_event_manager.h index c7265a0d..5f3402b6 100644 --- a/services/include/im_common_event_manager.h +++ b/services/include/im_common_event_manager.h @@ -37,7 +37,7 @@ public: ~ImCommonEventManager(); static sptr GetInstance(); bool SubscribeEvent(const std::string &event); - bool SubscribeKeyboardEvent(const std::vector &handlers); + bool SubscribeKeyboardEvent(); bool UnsubscribeEvent(); class EventSubscriber : public EventFwk::CommonEventSubscriber { diff --git a/services/src/im_common_event_manager.cpp b/services/src/im_common_event_manager.cpp index 5f651af3..87e6b539 100644 --- a/services/src/im_common_event_manager.cpp +++ b/services/src/im_common_event_manager.cpp @@ -17,7 +17,6 @@ #include -#include "../adapter/keyboard/keyboard_event.h" #include "global.h" #include "input_method_system_ability_stub.h" #include "ipc_skeleton.h" @@ -91,19 +90,17 @@ bool ImCommonEventManager::SubscribeEvent(const std::string &event) return true; } -bool ImCommonEventManager::SubscribeKeyboardEvent(const std::vector &handlers) +bool ImCommonEventManager::SubscribeKeyboardEvent() { + IMSA_HILOGI("ImCommonEventManager::SubscribeKeyboardEvent"); auto abilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (abilityManager == nullptr) { IMSA_HILOGE("SubscribeEvent abilityManager is nullptr"); return false; } - sptr listener = new (std::nothrow) SystemAbilityStatusChangeListener([handlers]() { - for (const auto &handler : handlers) { - int32_t ret = KeyboardEvent::GetInstance().SubscribeKeyboardEvent(handler.combine, handler.handle); - IMSA_HILOGI("subscribe %{public}d key event %{public}s", handler.combine.finalKey, - ret == ErrorCode::NO_ERROR ? "OK" : "ERROR"); - } + sptr listener = new (std::nothrow) SystemAbilityStatusChangeListener([]() { + int32_t ret = KeyboardEvent::GetInstance().InitKeyEventMonitor(); + IMSA_HILOGI("InitKeyEventMonitor init monitor %{public}s", ret == ErrorCode::NO_ERROR ? "success" : "failed"); }); if (listener == nullptr) { IMSA_HILOGE("SubscribeEvent listener is nullptr"); diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index ab372385..22643126 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -16,8 +16,8 @@ #include "input_method_system_ability.h" #include -#include #include +#include #include "../adapter/keyboard/keyboard_event.h" #include "ability_connect_callback_proxy.h" @@ -185,7 +185,7 @@ namespace MiscServices { StartInputService(defaultIme); StartUserIdListener(); int32_t ret = SubscribeKeyboardEvent(); - IMSA_HILOGI("subscribe key event ret %{public}d", ret); + IMSA_HILOGI("subscribe key event ret %{public}s", ret == ErrorCode::NO_ERROR ? "success" : "failed"); return ErrorCode::NO_ERROR; } @@ -1446,43 +1446,9 @@ namespace MiscServices { int32_t InputMethodSystemAbility::SubscribeKeyboardEvent() { - ImCommonEventManager::GetInstance()->SubscribeKeyboardEvent( - { { { - .preKeys = {}, - .finalKey = MMI::KeyEvent::KEYCODE_CAPS_LOCK, - }, - [this]() { SwitchByCombinedKey(CombineKeyCode::COMBINE_KEYCODE_CAPS); } }, - { { - .preKeys = {}, - .finalKey = MMI::KeyEvent::KEYCODE_SHIFT_LEFT, - }, - [this]() { SwitchByCombinedKey(CombineKeyCode::COMBINE_KEYCODE_SHIFT); } }, - { { - .preKeys = {}, - .finalKey = MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, - }, - [this]() { SwitchByCombinedKey(CombineKeyCode::COMBINE_KEYCODE_SHIFT); } }, - { { - .preKeys = { MMI::KeyEvent::KEYCODE_CTRL_LEFT }, - .finalKey = MMI::KeyEvent::KEYCODE_SHIFT_LEFT, - }, - [this]() { SwitchByCombinedKey(CombineKeyCode::COMBINE_KEYCODE_CTRL_SHIFT); } }, - { { - .preKeys = { MMI::KeyEvent::KEYCODE_CTRL_LEFT }, - .finalKey = MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, - }, - [this]() { SwitchByCombinedKey(CombineKeyCode::COMBINE_KEYCODE_CTRL_SHIFT); } }, - { { - .preKeys = { MMI::KeyEvent::KEYCODE_CTRL_RIGHT }, - .finalKey = MMI::KeyEvent::KEYCODE_SHIFT_LEFT, - }, - [this]() { SwitchByCombinedKey(CombineKeyCode::COMBINE_KEYCODE_CTRL_SHIFT); } }, - { { - .preKeys = { MMI::KeyEvent::KEYCODE_CTRL_RIGHT }, - .finalKey = MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, - }, - [this]() { SwitchByCombinedKey(CombineKeyCode::COMBINE_KEYCODE_CTRL_SHIFT); } } }); - return 0; + IMSA_HILOGI("InputMethodSystemAbility::SubscribeKeyboardEvent"); + bool ret = ImCommonEventManager::GetInstance()->SubscribeKeyboardEvent(); + return ret ? ErrorCode::NO_ERROR : ErrorCode::ERROR_SERVICE_START_FAILED; } } // namespace MiscServices } // namespace OHOS From 7a144ba7f9492f7d55efaed9c071184c3014a06b Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Fri, 11 Nov 2022 11:11:54 +0800 Subject: [PATCH 027/112] modify code Signed-off-by: zhaolinglan --- .../adapter/keyboard/input_event_callback.h | 37 +++++++++++++++++-- services/adapter/keyboard/keyboard_event.cpp | 29 +++------------ services/adapter/keyboard/keyboard_event.h | 5 +-- services/include/im_common_event_manager.h | 2 +- .../include/input_method_system_ability.h | 2 +- services/src/im_common_event_manager.cpp | 14 +++---- services/src/input_method_system_ability.cpp | 10 ++--- 7 files changed, 55 insertions(+), 44 deletions(-) diff --git a/services/adapter/keyboard/input_event_callback.h b/services/adapter/keyboard/input_event_callback.h index 8478b416..4274c8d8 100644 --- a/services/adapter/keyboard/input_event_callback.h +++ b/services/adapter/keyboard/input_event_callback.h @@ -19,23 +19,49 @@ #include #include +#include +#include + #include "global.h" +#include "keyboard_event.h" namespace OHOS { namespace MiscServices { class InputEventCallback : public MMI::IInputEventConsumer { +public: virtual void OnInputEvent(std::shared_ptr keyEvent) const; virtual void OnInputEvent(std::shared_ptr pointerEvent) const; virtual void OnInputEvent(std::shared_ptr axisEvent) const; + void SetKeyHandle(KeyHandle handle); + +private: + KeyHandle keyHandler_ = nullptr; + std::map, CombineKeyCode> keyMap_ = { + { { MMI::KeyEvent::KEYCODE_CAPS_LOCK }, CombineKeyCode::COMBINE_KEYCODE_CAPS }, + { { MMI::KeyEvent::KEYCODE_SHIFT_LEFT }, CombineKeyCode::COMBINE_KEYCODE_SHIFT }, + { { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT }, CombineKeyCode::COMBINE_KEYCODE_SHIFT }, + { { MMI::KeyEvent::KEYCODE_CTRL_LEFT, MMI::KeyEvent::KEYCODE_SHIFT_LEFT }, + CombineKeyCode::COMBINE_KEYCODE_CTRL_SHIFT }, + { { MMI::KeyEvent::KEYCODE_CTRL_LEFT, MMI::KeyEvent::KEYCODE_SHIFT_RIGHT }, + CombineKeyCode::COMBINE_KEYCODE_CTRL_SHIFT }, + { { MMI::KeyEvent::KEYCODE_CTRL_RIGHT, MMI::KeyEvent::KEYCODE_SHIFT_LEFT }, + CombineKeyCode::COMBINE_KEYCODE_CTRL_SHIFT }, + { { MMI::KeyEvent::KEYCODE_CTRL_RIGHT, MMI::KeyEvent::KEYCODE_SHIFT_RIGHT }, + CombineKeyCode::COMBINE_KEYCODE_CTRL_SHIFT }, + }; }; void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) const { - IMSA_HILOGI("OnInputEvent"); + IMSA_HILOGI("InputEventCallback::OnInputEvent"); auto pressKeys = keyEvent->GetPressedKeys(); - for (const auto key : pressKeys) { - IMSA_HILOGI("OnInputEvent key code: %{public}d", key); + auto it = keyMap_.find(pressKeys); + if (it == keyMap_.end()) { + IMSA_HILOGD("keyEvent undefined"); + return; } + int32_t ret = keyHandler_(it->second); + IMSA_HILOGI("handle keyevent %{public}s", ret == ErrorCode::NO_ERROR ? "success" : "failed"); } void InputEventCallback::OnInputEvent(std::shared_ptr pointerEvent) const @@ -45,6 +71,11 @@ void InputEventCallback::OnInputEvent(std::shared_ptr pointer void InputEventCallback::OnInputEvent(std::shared_ptr axisEvent) const { } + +void InputEventCallback::SetKeyHandle(KeyHandle handle) +{ + keyHandler_ = std::move(handle); +} } // namespace MiscServices } // namespace OHOS diff --git a/services/adapter/keyboard/keyboard_event.cpp b/services/adapter/keyboard/keyboard_event.cpp index 66ac2ed9..b8bf7997 100644 --- a/services/adapter/keyboard/keyboard_event.cpp +++ b/services/adapter/keyboard/keyboard_event.cpp @@ -33,38 +33,19 @@ KeyboardEvent &KeyboardEvent::GetInstance() return keyboardEvent; } -int32_t KeyboardEvent::InitKeyEventMonitor() +int32_t KeyboardEvent::AddKeyEventMonitor(const KeyHandle &handle) { - IMSA_HILOGI("KeyboardEvent::InitKeyMonitor"); + IMSA_HILOGI("KeyboardEvent::AddKeyEventMonitor"); std::shared_ptr callback = std::make_shared(); + callback->SetKeyHandle(handle); int32_t monitorId = InputManager::GetInstance()->AddMonitor(std::static_pointer_cast(callback)); if (monitorId < 0) { - IMSA_HILOGE("Add monitor failed, id: %{public}d", monitorId); + IMSA_HILOGE("add monitor failed, id: %{public}d", monitorId); return ErrorCode::ERROR_STATUS_UNKNOWN_ERROR; } + IMSA_HILOGD("add monitor success, id: %{public}d", monitorId); return ErrorCode::NO_ERROR; } - -int32_t KeyboardEvent::SubscribeKeyboardEvent(const CombineKey &combine, KeyHandle handle) -{ - std::shared_ptr keyOption = std::make_shared(); - keyOption->SetPreKeys(combine.preKeys); - keyOption->SetFinalKey(combine.finalKey); - keyOption->SetFinalKeyDown(true); - keyOption->SetFinalKeyDownDuration(0); - auto ret = - InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [this, handle](std::shared_ptr keyEvent) { - auto pressKeys = keyEvent->GetPressedKeys(); - for (auto &key : pressKeys) { - IMSA_HILOGI("key code: %{public}d", key); - } - if (handle != nullptr) { - handle(); - } - }); - IMSA_HILOGI("subscribe %{public}d key event %{public}s", combine.finalKey, ret >= 0 ? "OK" : "ERROR"); - return ret >= 0 ? ErrorCode::NO_ERROR : ErrorCode::ERROR_SUBSCRIBE_KEYBOARD_EVENT; -} } // namespace MiscServices } // namespace OHOS diff --git a/services/adapter/keyboard/keyboard_event.h b/services/adapter/keyboard/keyboard_event.h index 603479bc..cf2fb7eb 100644 --- a/services/adapter/keyboard/keyboard_event.h +++ b/services/adapter/keyboard/keyboard_event.h @@ -33,13 +33,12 @@ struct CombineKey { enum CombineKeyCode : uint32_t { COMBINE_KEYCODE_CAPS = 0, COMBINE_KEYCODE_SHIFT, COMBINE_KEYCODE_CTRL_SHIFT }; -using KeyHandle = std::function; +using KeyHandle = std::function; class KeyboardEvent { public: static KeyboardEvent &GetInstance(); - int32_t SubscribeKeyboardEvent(const CombineKey &combine, KeyHandle handle); - int32_t InitKeyEventMonitor(); + static int32_t AddKeyEventMonitor(const KeyHandle& handle); private: static constexpr int32_t PRESS_KEY_DELAY_MS = 200; diff --git a/services/include/im_common_event_manager.h b/services/include/im_common_event_manager.h index 5f3402b6..af0360c8 100644 --- a/services/include/im_common_event_manager.h +++ b/services/include/im_common_event_manager.h @@ -37,7 +37,7 @@ public: ~ImCommonEventManager(); static sptr GetInstance(); bool SubscribeEvent(const std::string &event); - bool SubscribeKeyboardEvent(); + bool SubscribeKeyboardEvent(KeyHandle handle); bool UnsubscribeEvent(); class EventSubscriber : public EventFwk::CommonEventSubscriber { diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index 8518aa0b..abca1130 100644 --- a/services/include/input_method_system_ability.h +++ b/services/include/input_method_system_ability.h @@ -136,7 +136,7 @@ private: static constexpr const char *SELECT_DIALOG_HAP = "cn.openharmony.inputmethodchoosedialog"; static constexpr const char *SELECT_DIALOG_ABILITY = "InputMethod"; - int32_t SubscribeKeyboardEvent(); + static int32_t InitKeyEventMonitor(); using CompareHandler = std::function; SubProperty FindSubPropertyByCompare(const std::string &bundleName, CompareHandler compare); SubProperty GetExtends(const std::vector &metaData); diff --git a/services/src/im_common_event_manager.cpp b/services/src/im_common_event_manager.cpp index 87e6b539..d73a06b7 100644 --- a/services/src/im_common_event_manager.cpp +++ b/services/src/im_common_event_manager.cpp @@ -90,25 +90,25 @@ bool ImCommonEventManager::SubscribeEvent(const std::string &event) return true; } -bool ImCommonEventManager::SubscribeKeyboardEvent() +bool ImCommonEventManager::SubscribeKeyboardEvent(KeyHandle handle) { IMSA_HILOGI("ImCommonEventManager::SubscribeKeyboardEvent"); auto abilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (abilityManager == nullptr) { - IMSA_HILOGE("SubscribeEvent abilityManager is nullptr"); + IMSA_HILOGE("SubscribeKeyboardEvent abilityManager is nullptr"); return false; } - sptr listener = new (std::nothrow) SystemAbilityStatusChangeListener([]() { - int32_t ret = KeyboardEvent::GetInstance().InitKeyEventMonitor(); - IMSA_HILOGI("InitKeyEventMonitor init monitor %{public}s", ret == ErrorCode::NO_ERROR ? "success" : "failed"); + sptr listener = new (std::nothrow) SystemAbilityStatusChangeListener([&handle]() { + int32_t ret = KeyboardEvent::GetInstance().AddKeyEventMonitor(handle); + IMSA_HILOGI("SubscribeKeyboardEvent add monitor %{public}s", ret == ErrorCode::NO_ERROR ? "success" : "failed"); }); if (listener == nullptr) { - IMSA_HILOGE("SubscribeEvent listener is nullptr"); + IMSA_HILOGE("SubscribeKeyboardEvent listener is nullptr"); return false; } int32_t ret = abilityManager->SubscribeSystemAbility(MULTIMODAL_INPUT_SERVICE_ID, listener); if (ret != ERR_OK) { - IMSA_HILOGE("SubscribeEvent SubscribeSystemAbility failed. ret = %{public}d", ret); + IMSA_HILOGE("SubscribeKeyboardEvent SubscribeSystemAbility failed. ret = %{public}d", ret); return false; } keyboardEventListener_ = listener; diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 22643126..e1796be5 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -184,8 +184,8 @@ namespace MiscServices { std::string defaultIme = ParaHandle::GetDefaultIme(userId_); StartInputService(defaultIme); StartUserIdListener(); - int32_t ret = SubscribeKeyboardEvent(); - IMSA_HILOGI("subscribe key event ret %{public}s", ret == ErrorCode::NO_ERROR ? "success" : "failed"); + int32_t ret = InitKeyEventMonitor(); + IMSA_HILOGI("init KeyEvent monitor %{public}s", ret == ErrorCode::NO_ERROR ? "success" : "failed"); return ErrorCode::NO_ERROR; } @@ -1440,13 +1440,13 @@ namespace MiscServices { } } } - IMSA_HILOGI("keycode undefined"); + IMSA_HILOGD("keycode undefined"); return ErrorCode::ERROR_EX_UNSUPPORTED_OPERATION; } - int32_t InputMethodSystemAbility::SubscribeKeyboardEvent() + int32_t InputMethodSystemAbility::InitKeyEventMonitor() { - IMSA_HILOGI("InputMethodSystemAbility::SubscribeKeyboardEvent"); + IMSA_HILOGI("InputMethodSystemAbility::InitKeyEventMonitor"); bool ret = ImCommonEventManager::GetInstance()->SubscribeKeyboardEvent(); return ret ? ErrorCode::NO_ERROR : ErrorCode::ERROR_SERVICE_START_FAILED; } From 78dac8d515b2cbf89bbe9e6266027f678fea9775 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Fri, 11 Nov 2022 11:51:27 +0800 Subject: [PATCH 028/112] modify code Signed-off-by: zhaolinglan --- services/include/input_method_system_ability.h | 2 +- services/src/input_method_system_ability.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index abca1130..d58fc830 100644 --- a/services/include/input_method_system_ability.h +++ b/services/include/input_method_system_ability.h @@ -136,7 +136,7 @@ private: static constexpr const char *SELECT_DIALOG_HAP = "cn.openharmony.inputmethodchoosedialog"; static constexpr const char *SELECT_DIALOG_ABILITY = "InputMethod"; - static int32_t InitKeyEventMonitor(); + int32_t InitKeyEventMonitor(); using CompareHandler = std::function; SubProperty FindSubPropertyByCompare(const std::string &bundleName, CompareHandler compare); SubProperty GetExtends(const std::vector &metaData); diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index e1796be5..80a20a54 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -1447,7 +1447,8 @@ namespace MiscServices { int32_t InputMethodSystemAbility::InitKeyEventMonitor() { IMSA_HILOGI("InputMethodSystemAbility::InitKeyEventMonitor"); - bool ret = ImCommonEventManager::GetInstance()->SubscribeKeyboardEvent(); + bool ret = ImCommonEventManager::GetInstance()->SubscribeKeyboardEvent( + [this](const CombineKeyCode &keyCode) { return SwitchByCombinedKey(keyCode); }); return ret ? ErrorCode::NO_ERROR : ErrorCode::ERROR_SERVICE_START_FAILED; } } // namespace MiscServices From caedce4c41b05f836bda4cb42314844a8127bf14 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Fri, 11 Nov 2022 15:41:14 +0800 Subject: [PATCH 029/112] modify code Signed-off-by: zhaolinglan --- services/adapter/keyboard/input_event_callback.h | 5 +++++ services/adapter/keyboard/keyboard_event.cpp | 2 +- services/adapter/keyboard/keyboard_event.h | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/services/adapter/keyboard/input_event_callback.h b/services/adapter/keyboard/input_event_callback.h index 4274c8d8..fc173945 100644 --- a/services/adapter/keyboard/input_event_callback.h +++ b/services/adapter/keyboard/input_event_callback.h @@ -60,6 +60,10 @@ void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) c IMSA_HILOGD("keyEvent undefined"); return; } + if (keyHandler_ == nullptr) { + IMSA_HILOGE("keyHandler_ is nullptr"); + return; + } int32_t ret = keyHandler_(it->second); IMSA_HILOGI("handle keyevent %{public}s", ret == ErrorCode::NO_ERROR ? "success" : "failed"); } @@ -74,6 +78,7 @@ void InputEventCallback::OnInputEvent(std::shared_ptr axisEvent) void InputEventCallback::SetKeyHandle(KeyHandle handle) { + IMSA_HILOGI("set key handle"); keyHandler_ = std::move(handle); } } // namespace MiscServices diff --git a/services/adapter/keyboard/keyboard_event.cpp b/services/adapter/keyboard/keyboard_event.cpp index b8bf7997..4b29adda 100644 --- a/services/adapter/keyboard/keyboard_event.cpp +++ b/services/adapter/keyboard/keyboard_event.cpp @@ -33,7 +33,7 @@ KeyboardEvent &KeyboardEvent::GetInstance() return keyboardEvent; } -int32_t KeyboardEvent::AddKeyEventMonitor(const KeyHandle &handle) +int32_t KeyboardEvent::AddKeyEventMonitor(KeyHandle handle) { IMSA_HILOGI("KeyboardEvent::AddKeyEventMonitor"); std::shared_ptr callback = std::make_shared(); diff --git a/services/adapter/keyboard/keyboard_event.h b/services/adapter/keyboard/keyboard_event.h index cf2fb7eb..002ba8b6 100644 --- a/services/adapter/keyboard/keyboard_event.h +++ b/services/adapter/keyboard/keyboard_event.h @@ -38,7 +38,7 @@ using KeyHandle = std::function; class KeyboardEvent { public: static KeyboardEvent &GetInstance(); - static int32_t AddKeyEventMonitor(const KeyHandle& handle); + static int32_t AddKeyEventMonitor(KeyHandle handle); private: static constexpr int32_t PRESS_KEY_DELAY_MS = 200; From 71b8aa2e59830a5f5ef1c4a8aab70f2b0d1f11ff Mon Sep 17 00:00:00 2001 From: cy7717 Date: Sun, 13 Nov 2022 12:58:05 +0800 Subject: [PATCH 030/112] bugfix Signed-off-by: cy7717 --- .../napi/inputmethodability/js_input_method_engine_setting.cpp | 2 +- .../js/napi/inputmethodability/js_keyboard_delegate_setting.cpp | 2 +- .../js/napi/inputmethodclient/js_get_input_method_setting.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/js/napi/inputmethodability/js_input_method_engine_setting.cpp b/interfaces/kits/js/napi/inputmethodability/js_input_method_engine_setting.cpp index 3d7de195..cd2c9e7a 100644 --- a/interfaces/kits/js/napi/inputmethodability/js_input_method_engine_setting.cpp +++ b/interfaces/kits/js/napi/inputmethodability/js_input_method_engine_setting.cpp @@ -255,7 +255,7 @@ void JsInputMethodEngineSetting::UnRegisterListener(napi_value callback, std::st return; } - for (auto item = jsCbMap_[type].begin(); item != jsCbMap_[type].end();) { + for (auto item = jsCbMap_[type].begin(); item != jsCbMap_[type].end(); item++) { if (Equals((*item)->env_, callback, (*item)->callback_, (*item)->threadId_)) { jsCbMap_[type].erase(item); break; diff --git a/interfaces/kits/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp b/interfaces/kits/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp index c592ef3b..dcc5bf5d 100644 --- a/interfaces/kits/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp +++ b/interfaces/kits/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp @@ -205,7 +205,7 @@ void JsKeyboardDelegateSetting::UnRegisterListener(napi_value callback, std::str return; } - for (auto item = jsCbMap_[type].begin(); item != jsCbMap_[type].end();) { + for (auto item = jsCbMap_[type].begin(); item != jsCbMap_[type].end(); item++) { if ((callback != nullptr) && (Equals((*item)->env_, callback, (*item)->callback_, (*item)->threadId_))) { jsCbMap_[type].erase(item); break; diff --git a/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_setting.cpp b/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_setting.cpp index 8151f903..492dc6c9 100644 --- a/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_setting.cpp +++ b/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_setting.cpp @@ -484,7 +484,7 @@ void JsGetInputMethodSetting::UnRegisterListener(napi_value callback, std::strin return; } - for (auto item = jsCbMap_[type].begin(); item != jsCbMap_[type].end();) { + for (auto item = jsCbMap_[type].begin(); item != jsCbMap_[type].end(); item++) { if (Equals((*item)->env_, callback, (*item)->callback_, (*item)->threadId_)) { jsCbMap_[type].erase(item); break; From 306054acebd0803b1defe7ce55f1f207f4739166 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Mon, 14 Nov 2022 09:14:29 +0800 Subject: [PATCH 031/112] Signed-off-by: ma-shaoyin Changes to be committed: --- .../inputmethodsetting_fuzzer/BUILD.gn | 69 +++++++++++++ .../inputmethodsetting_fuzzer.cpp | 97 +++++++++++++++++++ .../inputmethodsetting_fuzzer.h | 21 ++++ .../inputmethodsetting_fuzzer/project.xml | 25 +++++ .../systemabilitystub_fuzzer/BUILD.gn | 6 +- .../systemabilitystub_fuzzer.cpp | 62 +++++++++++- 6 files changed, 278 insertions(+), 2 deletions(-) create mode 100644 test/fuzztest/inputmethodsetting_fuzzer/BUILD.gn create mode 100644 test/fuzztest/inputmethodsetting_fuzzer/inputmethodsetting_fuzzer.cpp create mode 100644 test/fuzztest/inputmethodsetting_fuzzer/inputmethodsetting_fuzzer.h create mode 100644 test/fuzztest/inputmethodsetting_fuzzer/project.xml diff --git a/test/fuzztest/inputmethodsetting_fuzzer/BUILD.gn b/test/fuzztest/inputmethodsetting_fuzzer/BUILD.gn new file mode 100644 index 00000000..0f64bb7d --- /dev/null +++ b/test/fuzztest/inputmethodsetting_fuzzer/BUILD.gn @@ -0,0 +1,69 @@ +# Copyright (c) 2021 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. + +import("//base/inputmethod/imf/inputmethod.gni") + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("InputMethodSettingFuzzTest") { + module_out_path = "inputmethod/inputmethod" + + fuzz_config_file = + "//base/inputmethod/imf/test/fuzztest/inputmethodsetting_fuzzer" + + include_dirs = [ + "//base/inputmethod/imf/services/include", + "//foundation/ability/ability_runtime/interfaces/inner_api/app_manager/include/appmgr", + "//foundation/ability/ability_runtime/services/abilitymgr/include", + "//foundation/ability/ability_runtime/interfaces/inner_api/ability_manager/include/", + "//third_party/jsoncpp/include/", + "//foundation/bundlemanager/bundle_framework/interfaces/inner_api/appexecfwk_core/include/bundlemgr", + "//foundation/multimedia/image_framework/interfaces/innerkits/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "inputmethodsetting_fuzzer.cpp" ] + + deps = [ + "//base/inputmethod/imf/services:inputmethod_service", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//base/inputmethod/imf/frameworks/inputmethod_controller:inputmethod_client", + ] + + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "bundle_framework:appexecfwk_core", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":InputMethodSettingFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/inputmethodsetting_fuzzer/inputmethodsetting_fuzzer.cpp b/test/fuzztest/inputmethodsetting_fuzzer/inputmethodsetting_fuzzer.cpp new file mode 100644 index 00000000..62a410bb --- /dev/null +++ b/test/fuzztest/inputmethodsetting_fuzzer/inputmethodsetting_fuzzer.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2021 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 "inputmethodsetting_fuzzer.h" + +#include +#include + +#include "peruser_session.h" +#include "peruser_setting.h" +#include "input_method_system_ability.h" +#include "input_method_setting.h" +#include "input_method_controller.h" +#include "global.h" + +#include "message_parcel.h" + +using namespace OHOS::MiscServices; +namespace OHOS { + class TextListener : public OnTextChangedListener { + public: + TextListener() {} + ~TextListener() {} + void InsertText(const std::u16string& text) + { + } + void DeleteBackward(int32_t length) + { + } + void SetKeyboardStatus(bool status) + { + } + void DeleteForward(int32_t length) + { + } + void SendKeyEventFromInputMethod(const KeyEvent& event) + { + } + void SendKeyboardInfo(const KeyboardInfo& status) + { + } + void MoveCursor(const Direction direction) + { + } + }; + bool FuzzInputMethodSetting(const uint8_t* rawData, size_t size) + { + sptr imc = InputMethodController::GetInstance(); + sptr textListener = new TextListener(); + imc->Attach(textListener); + + constexpr int32_t MAIN_USER_ID = 100; + PerUserSetting *setting = new PerUserSetting(MAIN_USER_ID); + InputMethodSetting *methodSetting = setting->GetInputMethodSetting(); + + InputMethodSetting setting_ = *methodSetting; + std::u16string imeId = Str8ToStr16(std::string(rawData, rawData + size)); + std::vector types; + for (size_t i = 0; i < size; ++i) { + types.push_back(static_cast(*rawData)); + } + setting_.GetCurrentInputMethod(); + setting_.SetCurrentInputMethod(imeId); + setting_.GetEnabledInputMethodList(); + setting_.AddEnabledInputMethod(imeId, types); + setting_.RemoveEnabledInputMethod(imeId); + setting_.GetEnabledKeyboardTypes(imeId); + setting_.GetCurrentKeyboardType(); + setting_.SetCurrentKeyboardType(static_cast(*rawData)); + setting_.GetCurrentSysKeyboardType(); + setting_.SetCurrentSysKeyboardType(static_cast(*rawData)); + setting_.FindKey(imeId); + setting_.ClearData(); + + return true; + } +} +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzInputMethodSetting(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/inputmethodsetting_fuzzer/inputmethodsetting_fuzzer.h b/test/fuzztest/inputmethodsetting_fuzzer/inputmethodsetting_fuzzer.h new file mode 100644 index 00000000..59c628f5 --- /dev/null +++ b/test/fuzztest/inputmethodsetting_fuzzer/inputmethodsetting_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2021 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 TEST_FUZZTEST_INPUTMETHODSETTING_FUZZER_INPUTMETHODSETTING_FUZZER_H +#define TEST_FUZZTEST_INPUTMETHODSETTING_FUZZER_INPUTMETHODSETTING_FUZZER_H + +#define FUZZ_PROJECT_NAME "inputmethodsetting_fuzzer" + +#endif // TEST_FUZZTEST_INPUTMETHODSETTING_FUZZER_INPUTMETHODSETTING_FUZZER_H diff --git a/test/fuzztest/inputmethodsetting_fuzzer/project.xml b/test/fuzztest/inputmethodsetting_fuzzer/project.xml new file mode 100644 index 00000000..85e7ef2c --- /dev/null +++ b/test/fuzztest/inputmethodsetting_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/systemabilitystub_fuzzer/BUILD.gn b/test/fuzztest/systemabilitystub_fuzzer/BUILD.gn index fc62d4c4..63b5b4f7 100644 --- a/test/fuzztest/systemabilitystub_fuzzer/BUILD.gn +++ b/test/fuzztest/systemabilitystub_fuzzer/BUILD.gn @@ -48,13 +48,17 @@ ohos_fuzztest("SystemAbilityStubFuzzTest") { "//base/inputmethod/imf/services:inputmethod_service", "//foundation/ability/ability_runtime/services/abilitymgr:abilityms", "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", - "//foundation/communication/ipc/interfaces/innerkits/ipc_single:ipc_single", + "//foundation/communication/ipc/interfaces/innerkits/ipc_single:ipc_single",s + "//base/inputmethod/imf/frameworks/inputmethod_controller:inputmethod_client", + "//base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc", ] external_deps = [ "bundle_framework:appexecfwk_core", "c_utils:utils", "hiviewdfx_hilog_native:libhilog", + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", ] } diff --git a/test/fuzztest/systemabilitystub_fuzzer/systemabilitystub_fuzzer.cpp b/test/fuzztest/systemabilitystub_fuzzer/systemabilitystub_fuzzer.cpp index cd02e5ed..c7e9b948 100644 --- a/test/fuzztest/systemabilitystub_fuzzer/systemabilitystub_fuzzer.cpp +++ b/test/fuzztest/systemabilitystub_fuzzer/systemabilitystub_fuzzer.cpp @@ -13,19 +13,74 @@ * limitations under the License. */ - #include "systemabilitystub_fuzzer.h" #include #include #include "input_method_system_ability.h" +#include "input_method_controller.h" +#include "accesstoken_kit.h" +#include "token_setproc.h" +#include "nativetoken_kit.h" #include "global.h" #include "message_parcel.h" +using namespace OHOS::Security::AccessToken; using namespace OHOS::MiscServices; namespace OHOS { + void GrantNativePermission() + { + const char **perms = new const char *[1]; + perms[0] = "ohos.permission.CONNECT_IME_ABILITY"; + TokenInfoParams infoInstance = { + .dcapsNum = 0, + .permsNum = 1, + .aclsNum = 0, + .dcaps = nullptr, + .perms = perms, + .acls = nullptr, + .processName = "inputmethod_imf", + .aplStr = "system_core", + }; + uint64_t tokenId = GetAccessTokenId(&infoInstance); + int res = SetSelfTokenID(tokenId); + if (res == 0) { + IMSA_HILOGI("SetSelfTokenID success!"); + } else { + IMSA_HILOGE("SetSelfTokenID fail!"); + } + AccessTokenKit::ReloadNativeTokenInfo(); + delete[] perms; + } + + class TextListener : public OnTextChangedListener { + public: + TextListener() {} + ~TextListener() {} + void InsertText(const std::u16string& text) + { + } + void DeleteBackward(int32_t length) + { + } + void SetKeyboardStatus(bool status) + { + } + void DeleteForward(int32_t length) + { + } + void SendKeyEventFromInputMethod(const KeyEvent& event) + { + } + void SendKeyboardInfo(const KeyboardInfo& status) + { + } + void MoveCursor(const Direction direction) + { + } + }; constexpr size_t THRESHOLD = 10; constexpr int32_t OFFSET = 4; const std::u16string SYSTEMABILITY_INTERFACE_TOKEN = u"ohos.miscservices.inputmethod.IInputMethodSystemAbility"; @@ -40,10 +95,15 @@ namespace OHOS { } bool FuzzInputMethodSystemAbility(const uint8_t* rawData, size_t size) { + GrantNativePermission(); uint32_t code = ConvertToUint32(rawData); rawData = rawData + OFFSET; size = size - OFFSET; + sptr imc = InputMethodController::GetInstance(); + sptr textListener = new TextListener(); + imc->Attach(textListener); + MessageParcel data; data.WriteInterfaceToken(SYSTEMABILITY_INTERFACE_TOKEN); data.WriteBuffer(rawData, size); From faa7aeeda0a97a037fc791325372964ee3095126 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Mon, 14 Nov 2022 09:23:43 +0800 Subject: [PATCH 032/112] Signed-off-by: ma-shaoyin Changes to be committed: --- .../fuzztest/inputmethodsetting_fuzzer/corpus/init | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 test/fuzztest/inputmethodsetting_fuzzer/corpus/init diff --git a/test/fuzztest/inputmethodsetting_fuzzer/corpus/init b/test/fuzztest/inputmethodsetting_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/test/fuzztest/inputmethodsetting_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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. + +FUZZ \ No newline at end of file From 151ac4e1d2df1eb4e084130e2348bffdf0326590 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Mon, 14 Nov 2022 09:25:06 +0800 Subject: [PATCH 033/112] Signed-off-by: ma-shaoyin Changes to be committed: --- test/fuzztest/systemabilitystub_fuzzer/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fuzztest/systemabilitystub_fuzzer/BUILD.gn b/test/fuzztest/systemabilitystub_fuzzer/BUILD.gn index 63b5b4f7..6595d20b 100644 --- a/test/fuzztest/systemabilitystub_fuzzer/BUILD.gn +++ b/test/fuzztest/systemabilitystub_fuzzer/BUILD.gn @@ -48,7 +48,7 @@ ohos_fuzztest("SystemAbilityStubFuzzTest") { "//base/inputmethod/imf/services:inputmethod_service", "//foundation/ability/ability_runtime/services/abilitymgr:abilityms", "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", - "//foundation/communication/ipc/interfaces/innerkits/ipc_single:ipc_single",s + "//foundation/communication/ipc/interfaces/innerkits/ipc_single:ipc_single", "//base/inputmethod/imf/frameworks/inputmethod_controller:inputmethod_client", "//base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc", ] From 7571852dc8433cb2d04b3b65dc3dcd5b52edc4d5 Mon Sep 17 00:00:00 2001 From: cy7717 Date: Mon, 14 Nov 2022 10:05:35 +0800 Subject: [PATCH 034/112] mod Signed-off-by: cy7717 --- .../inputmethod_controller/src/input_method_controller.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index 3d6110bf..ec2d0a6a 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -242,8 +242,7 @@ using namespace MessageID; void InputMethodController::QuitWorkThread() { stop_ = true; - MessageParcel *parcel = new MessageParcel(); - Message *msg = new Message(MessageID::MSG_ID_QUIT_WORKER_THREAD, parcel); + Message *msg = new Message(MessageID::MSG_ID_QUIT_WORKER_THREAD, nullptr); msgHandler->SendMessage(msg); if (workThreadHandler.joinable()) { workThreadHandler.join(); From 6e59d7e1721b81eabd848bfb8b4527efd3bd0065 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Mon, 14 Nov 2022 15:29:11 +0800 Subject: [PATCH 035/112] Signed-off-by: ma-shaoyin Changes to be committed: --- test/fuzztest/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 23f56c7b..06fec6d9 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -22,6 +22,7 @@ group("fuzztest") { "corestub_fuzzer:fuzztest", "datachannelstub_fuzzer:fuzztest", "inputclientstub_fuzzer:fuzztest", + "inputmethodsetting_fuzzer:fuzztest", "platformcallbackstub_fuzzer:fuzztest", "systemabilitystub_fuzzer:fuzztest", ] From 5261dad98e86d11334353bb82e20d197ab4d866b Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Mon, 14 Nov 2022 16:33:29 +0800 Subject: [PATCH 036/112] Signed-off-by: ma-shaoyin Changes to be committed: --- test/fuzztest/inputmethodsetting_fuzzer/BUILD.gn | 2 +- .../inputmethodsetting_fuzzer/inputmethodsetting_fuzzer.cpp | 3 +-- .../inputmethodsetting_fuzzer/inputmethodsetting_fuzzer.h | 2 +- test/fuzztest/inputmethodsetting_fuzzer/project.xml | 2 +- test/fuzztest/systemabilitystub_fuzzer/project.xml | 2 +- .../systemabilitystub_fuzzer/systemabilitystub_fuzzer.h | 2 +- 6 files changed, 6 insertions(+), 7 deletions(-) diff --git a/test/fuzztest/inputmethodsetting_fuzzer/BUILD.gn b/test/fuzztest/inputmethodsetting_fuzzer/BUILD.gn index 0f64bb7d..300cce15 100644 --- a/test/fuzztest/inputmethodsetting_fuzzer/BUILD.gn +++ b/test/fuzztest/inputmethodsetting_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2022 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 diff --git a/test/fuzztest/inputmethodsetting_fuzzer/inputmethodsetting_fuzzer.cpp b/test/fuzztest/inputmethodsetting_fuzzer/inputmethodsetting_fuzzer.cpp index 62a410bb..c95bc6dd 100644 --- a/test/fuzztest/inputmethodsetting_fuzzer/inputmethodsetting_fuzzer.cpp +++ b/test/fuzztest/inputmethodsetting_fuzzer/inputmethodsetting_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -13,7 +13,6 @@ * limitations under the License. */ - #include "inputmethodsetting_fuzzer.h" #include diff --git a/test/fuzztest/inputmethodsetting_fuzzer/inputmethodsetting_fuzzer.h b/test/fuzztest/inputmethodsetting_fuzzer/inputmethodsetting_fuzzer.h index 59c628f5..af1ebb2d 100644 --- a/test/fuzztest/inputmethodsetting_fuzzer/inputmethodsetting_fuzzer.h +++ b/test/fuzztest/inputmethodsetting_fuzzer/inputmethodsetting_fuzzer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 diff --git a/test/fuzztest/inputmethodsetting_fuzzer/project.xml b/test/fuzztest/inputmethodsetting_fuzzer/project.xml index 85e7ef2c..6e8ad2cf 100644 --- a/test/fuzztest/inputmethodsetting_fuzzer/project.xml +++ b/test/fuzztest/inputmethodsetting_fuzzer/project.xml @@ -1,5 +1,5 @@ - + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/perusersetting_fuzzer/BUILD.gn b/test/fuzztest/perusersetting_fuzzer/BUILD.gn new file mode 100644 index 00000000..9a66b758 --- /dev/null +++ b/test/fuzztest/perusersetting_fuzzer/BUILD.gn @@ -0,0 +1,73 @@ +# Copyright (c) 2021 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. + +import("//base/inputmethod/imf/inputmethod.gni") + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("PerUserSettingFuzzTest") { + module_out_path = "inputmethod/inputmethod" + + fuzz_config_file = + "//base/inputmethod/imf/test/fuzztest/perusersetting_fuzzer" + + include_dirs = [ + "//base/inputmethod/imf/services/include", + "//base/inputmethod/imf/frameworks/inputmethod_controller/include", + "//base/inputmethod/imf/services/include", + "//foundation/ability/ability_runtime/services/abilitymgr/include", + "//foundation/ability/ability_runtime/interfaces/inner_api/ability_manager/include", + "//third_party/jsoncpp/include", + "//foundation/ability/ability_runtime/interfaces/inner_api/app_manager/include/appmgr", + "//foundation/multimedia/image_framework/interfaces/innerkits/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "perusersetting_fuzzer.cpp" ] + + deps = [ + "//base/inputmethod/imf/frameworks/inputmethod_ability:inputmethod_ability", + "//base/inputmethod/imf/frameworks/inputmethod_controller:inputmethod_client", + "//base/inputmethod/imf/services:inputmethod_service", + "//foundation/ability/ability_runtime/services/abilitymgr:abilityms", + "//foundation/arkui/napi:ace_napi", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + ] + + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":PerUserSettingFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/perusersetting_fuzzer/corpus/init b/test/fuzztest/perusersetting_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/test/fuzztest/perusersetting_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/perusersetting_fuzzer/perusersetting_fuzzer.cpp b/test/fuzztest/perusersetting_fuzzer/perusersetting_fuzzer.cpp new file mode 100644 index 00000000..50562c83 --- /dev/null +++ b/test/fuzztest/perusersetting_fuzzer/perusersetting_fuzzer.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2022-2022 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 "perusersetting_fuzzer.h" + +#include +#include +#include +#include + +#include "global.h" +#include "input_method_agent_stub.h" +#include "input_method_info.h" +#include "message_parcel.h" +#include "peruser_setting.h" + +using namespace OHOS::MiscServices; +namespace OHOS { + constexpr size_t THRESHOLD = 10; + constexpr int32_t OFFSET = 4; + + uint32_t ConvertToUint32(const uint8_t *ptr) + { + if (ptr == nullptr) { + return 0; + } + uint32_t bigVar = (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | (ptr[3]); + return bigVar; + } + bool FuzzAgentStub(const uint8_t *rawData, size_t size) + { + uint32_t code = ConvertToUint32(rawData); + rawData = rawData + OFFSET; + size = size - OFFSET; + + std::string str(reinterpret_cast(rawData), size); + std::u16string imeId = Str8ToStr16(str); + std::u16string packageName = Str8ToStr16(str); + std::u16string key = Str8ToStr16(str); + std::u16string value = Str8ToStr16(str); + bool isSecurityIme = true; + + constexpr int32_t MAIN_USER_ID = 100; + std::shared_ptr userSetting = std::make_shared(MAIN_USER_ID); + + userSetting->Initialize(); + userSetting->GetUserState(); + userSetting->GetCurrentInputMethod(); + userSetting->GetSecurityInputMethod(); + userSetting->GetNextInputMethod(); + userSetting->GetInputMethodSetting(); + userSetting->GetInputMethodProperty(imeId); + userSetting->OnPackageAdded(packageName, isSecurityIme); + userSetting->OnPackageRemoved(packageName, isSecurityIme); + userSetting->OnSettingChanged(key, value); + userSetting->OnAdvanceToNext(); + userSetting->OnUserLocked(); + userSetting->Dump(code); + + return true; + } +} +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + if (size < OHOS::THRESHOLD) { + return 0; + } + /* Run your code on data */ + OHOS::FuzzAgentStub(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/perusersetting_fuzzer/perusersetting_fuzzer.h b/test/fuzztest/perusersetting_fuzzer/perusersetting_fuzzer.h new file mode 100644 index 00000000..e9e61583 --- /dev/null +++ b/test/fuzztest/perusersetting_fuzzer/perusersetting_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2021 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 TEST_FUZZTEST_PERUSERSETTING_FUZZER_AGENTSTUB_FUZZER_H +#define TEST_FUZZTEST_PERUSERSETTING_FUZZER_AGENTSTUB_FUZZER_H + +#define FUZZ_PROJECT_NAME "perusersetting_fuzzer" + +#endif // TEST_FUZZTEST_PERUSERSETTING_FUZZER_AGENTSTUB_FUZZER_H diff --git a/test/fuzztest/perusersetting_fuzzer/project.xml b/test/fuzztest/perusersetting_fuzzer/project.xml new file mode 100644 index 00000000..85e7ef2c --- /dev/null +++ b/test/fuzztest/perusersetting_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + From 592e3cc3e91c96ebae33400113bd354968699efe Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Tue, 15 Nov 2022 10:30:15 +0800 Subject: [PATCH 044/112] Signed-off-by: ma-shaoyin Changes to be committed: --- test/fuzztest/systemabilitystub_fuzzer/BUILD.gn | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/fuzztest/systemabilitystub_fuzzer/BUILD.gn b/test/fuzztest/systemabilitystub_fuzzer/BUILD.gn index 6595d20b..c03b422b 100644 --- a/test/fuzztest/systemabilitystub_fuzzer/BUILD.gn +++ b/test/fuzztest/systemabilitystub_fuzzer/BUILD.gn @@ -45,20 +45,20 @@ ohos_fuzztest("SystemAbilityStubFuzzTest") { sources = [ "systemabilitystub_fuzzer.cpp" ] deps = [ + "//base/inputmethod/imf/frameworks/inputmethod_controller:inputmethod_client", "//base/inputmethod/imf/services:inputmethod_service", + "//base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc", "//foundation/ability/ability_runtime/services/abilitymgr:abilityms", "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", "//foundation/communication/ipc/interfaces/innerkits/ipc_single:ipc_single", - "//base/inputmethod/imf/frameworks/inputmethod_controller:inputmethod_client", - "//base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc", ] external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", "bundle_framework:appexecfwk_core", "c_utils:utils", "hiviewdfx_hilog_native:libhilog", - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", ] } From 56bc7967374251e0be38e5f54293c72667359e1a Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Tue, 15 Nov 2022 14:26:16 +0800 Subject: [PATCH 045/112] Signed-off-by: ma-shaoyin Changes to be committed: --- .../inputmethodsetting_fuzzer.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/fuzztest/inputmethodsetting_fuzzer/inputmethodsetting_fuzzer.cpp b/test/fuzztest/inputmethodsetting_fuzzer/inputmethodsetting_fuzzer.cpp index da138471..e9850f16 100644 --- a/test/fuzztest/inputmethodsetting_fuzzer/inputmethodsetting_fuzzer.cpp +++ b/test/fuzztest/inputmethodsetting_fuzzer/inputmethodsetting_fuzzer.cpp @@ -48,8 +48,14 @@ namespace OHOS { imc->Attach(textListener); constexpr int32_t MAIN_USER_ID = 100; - PerUserSetting *setting = new PerUserSetting(MAIN_USER_ID); + PerUserSetting *setting = new (std::nothrow) PerUserSetting(MAIN_USER_ID); + if (setting == nullptr) { + return true; + } InputMethodSetting *methodSetting = setting->GetInputMethodSetting(); + if (methodSetting == nullptr) { + return true; + } InputMethodSetting setting_ = *methodSetting; std::u16string imeId = Str8ToStr16(std::string(rawData, rawData + size)); From bc106d50e7153397835b3ca439d3017bc3ae6d8d Mon Sep 17 00:00:00 2001 From: Hollokin Date: Tue, 15 Nov 2022 16:40:36 +0800 Subject: [PATCH 046/112] =?UTF-8?q?=E3=80=90FUZZ=E3=80=91ability=E5=8F=8Ac?= =?UTF-8?q?ontroller=E7=9B=B8=E5=85=B3=E7=9A=84FUZZ=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hollokin --- test/fuzztest/BUILD.gn | 2 + .../agentstub_fuzzer/agentstub_fuzzer.cpp | 2 + .../corestub_fuzzer/corestub_fuzzer.cpp | 2 + test/fuzztest/inputclientstub_fuzzer/BUILD.gn | 1 + .../inputclientstub_fuzzer.cpp | 104 +++++++--- .../inputmethodability_fuzzer/BUILD.gn | 62 ++++++ .../inputmethodability_fuzzer/corpus/init | 14 ++ .../inputmethodability_fuzzer.cpp | 173 ++++++++++++++++ .../inputmethodability_fuzzer.h | 21 ++ .../inputmethodability_fuzzer/project.xml | 25 +++ .../inputmethodcontroller_fuzzer/BUILD.gn | 62 ++++++ .../inputmethodcontroller_fuzzer/corpus/init | 14 ++ .../inputmethodcontroller_fuzzer.cpp | 189 ++++++++++++++++++ .../inputmethodcontroller_fuzzer.h | 21 ++ .../inputmethodcontroller_fuzzer/project.xml | 25 +++ 15 files changed, 685 insertions(+), 32 deletions(-) create mode 100644 test/fuzztest/inputmethodability_fuzzer/BUILD.gn create mode 100644 test/fuzztest/inputmethodability_fuzzer/corpus/init create mode 100644 test/fuzztest/inputmethodability_fuzzer/inputmethodability_fuzzer.cpp create mode 100644 test/fuzztest/inputmethodability_fuzzer/inputmethodability_fuzzer.h create mode 100644 test/fuzztest/inputmethodability_fuzzer/project.xml create mode 100644 test/fuzztest/inputmethodcontroller_fuzzer/BUILD.gn create mode 100644 test/fuzztest/inputmethodcontroller_fuzzer/corpus/init create mode 100644 test/fuzztest/inputmethodcontroller_fuzzer/inputmethodcontroller_fuzzer.cpp create mode 100644 test/fuzztest/inputmethodcontroller_fuzzer/inputmethodcontroller_fuzzer.h create mode 100644 test/fuzztest/inputmethodcontroller_fuzzer/project.xml diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 23f56c7b..87a7292e 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -22,6 +22,8 @@ group("fuzztest") { "corestub_fuzzer:fuzztest", "datachannelstub_fuzzer:fuzztest", "inputclientstub_fuzzer:fuzztest", + "inputmethodability_fuzzer:fuzztest", + "inputmethodcontroller_fuzzer:fuzztest", "platformcallbackstub_fuzzer:fuzztest", "systemabilitystub_fuzzer:fuzztest", ] diff --git a/test/fuzztest/agentstub_fuzzer/agentstub_fuzzer.cpp b/test/fuzztest/agentstub_fuzzer/agentstub_fuzzer.cpp index 843b8457..db828906 100644 --- a/test/fuzztest/agentstub_fuzzer/agentstub_fuzzer.cpp +++ b/test/fuzztest/agentstub_fuzzer/agentstub_fuzzer.cpp @@ -52,6 +52,8 @@ namespace OHOS { MessageOption option; sptr stub = new InputMethodAgentStub(); + MessageHandler *handler = MessageHandler::Instance(); + stub->SetMessageHandler(handler); stub->OnRemoteRequest(code, data, reply, option); return true; diff --git a/test/fuzztest/corestub_fuzzer/corestub_fuzzer.cpp b/test/fuzztest/corestub_fuzzer/corestub_fuzzer.cpp index d63a615e..4dceefbe 100644 --- a/test/fuzztest/corestub_fuzzer/corestub_fuzzer.cpp +++ b/test/fuzztest/corestub_fuzzer/corestub_fuzzer.cpp @@ -53,6 +53,8 @@ namespace OHOS { MessageOption option; sptr stub = new InputMethodCoreStub(MAIN_USER_ID); + MessageHandler *handler = MessageHandler::Instance(); + stub->SetMessageHandler(handler); stub->OnRemoteRequest(code, data, reply, option); return true; diff --git a/test/fuzztest/inputclientstub_fuzzer/BUILD.gn b/test/fuzztest/inputclientstub_fuzzer/BUILD.gn index b252972c..4ad4716a 100644 --- a/test/fuzztest/inputclientstub_fuzzer/BUILD.gn +++ b/test/fuzztest/inputclientstub_fuzzer/BUILD.gn @@ -41,6 +41,7 @@ ohos_fuzztest("InputClientStubFuzzTest") { sources = [ "inputclientstub_fuzzer.cpp" ] deps = [ + "//base/inputmethod/imf/frameworks/inputmethod_ability:inputmethod_ability", "//base/inputmethod/imf/frameworks/inputmethod_controller:inputmethod_client", "//base/inputmethod/imf/services:inputmethod_service", "//foundation/ability/ability_runtime/services/abilitymgr:abilityms", diff --git a/test/fuzztest/inputclientstub_fuzzer/inputclientstub_fuzzer.cpp b/test/fuzztest/inputclientstub_fuzzer/inputclientstub_fuzzer.cpp index f00d9bcf..73a6def1 100644 --- a/test/fuzztest/inputclientstub_fuzzer/inputclientstub_fuzzer.cpp +++ b/test/fuzztest/inputclientstub_fuzzer/inputclientstub_fuzzer.cpp @@ -13,57 +13,97 @@ * limitations under the License. */ - #include "inputclientstub_fuzzer.h" #include #include +#include -#include "input_client_stub.h" #include "global.h" - +#include "input_client_stub.h" #include "message_parcel.h" using namespace OHOS::MiscServices; namespace OHOS { - constexpr size_t THRESHOLD = 10; - constexpr int32_t OFFSET = 4; - const std::u16string INPUTCLIENTSTUB_INTERFACE_TOKEN = u"ohos.miscservices.inputmethod.InputClient"; +constexpr size_t THRESHOLD = 10; +constexpr int32_t OFFSET = 4; +const std::u16string INPUTCLIENTSTUB_INTERFACE_TOKEN = u"ohos.miscservices.inputmethod.InputClient"; - uint32_t ConvertToUint32(const uint8_t *ptr) - { - if (ptr == nullptr) { - return 0; - } - uint32_t bigVar = (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | (ptr[3]); - return bigVar; - } - bool FuzzInputClientStub(const uint8_t* rawData, size_t size) - { - uint32_t code = ConvertToUint32(rawData); - rawData = rawData + OFFSET; - size = size - OFFSET; - - MessageParcel data; - data.WriteInterfaceToken(INPUTCLIENTSTUB_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - MessageParcel reply; - MessageOption option; - - sptr mClient = new InputClientStub; - mClient->OnRemoteRequest(code, data, reply, option); - - return true; +uint32_t ConvertToUint32(const uint8_t *ptr) +{ + if (ptr == nullptr) { + return 0; } + uint32_t bigVar = (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | (ptr[3]); + return bigVar; } + +void FuzzInputClientStub(const uint8_t *rawData, size_t size) +{ + uint32_t code = ConvertToUint32(rawData); + rawData = rawData + OFFSET; + size = size - OFFSET; + + MessageParcel data; + data.WriteInterfaceToken(INPUTCLIENTSTUB_INTERFACE_TOKEN); + data.WriteBuffer(rawData, size); + data.RewindRead(0); + MessageParcel reply; + MessageOption option; + + sptr mClient = new InputClientStub(); + MessageHandler *handler = MessageHandler::Instance(); + mClient->SetHandler(handler); + mClient->OnRemoteRequest(code, data, reply, option); +} + +void TextOnInputReady() +{ + sptr mClient = new InputClientStub(); + sptr mInputMethodAgentStub = new InputMethodAgentStub(); + MessageParcel data; + data.WriteRemoteObject(mInputMethodAgentStub->AsObject()); + auto remoteObject = data.ReadRemoteObject(); + sptr iface = iface_cast(remoteObject); + mClient->onInputReady(iface); +} + +void TestOnInputReleased(int32_t fuzzedInt32) +{ + sptr mClient = new InputClientStub(); + mClient->onInputReleased(fuzzedInt32); +} + +void TestSetDisplayMode(int32_t fuzzedInt32) +{ + sptr mClient = new InputClientStub(); + mClient->setDisplayMode(fuzzedInt32); +} + +void TestOnSwitchInput() +{ + sptr mClient = new InputClientStub(); + Property property = {}; + SubProperty subProperty = {}; + + mClient->OnSwitchInput(property, subProperty); +} +} // namespace OHOS + /* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { if (size < OHOS::THRESHOLD) { return 0; } /* Run your code on data */ + auto fuzzedInt32 = static_cast(size); + std::string fuzzedString(reinterpret_cast(data), size); + OHOS::FuzzInputClientStub(data, size); + OHOS::TextOnInputReady(); + OHOS::TestOnInputReleased(fuzzedInt32); + OHOS::TestSetDisplayMode(fuzzedInt32); + OHOS::TestOnSwitchInput(); return 0; } \ No newline at end of file diff --git a/test/fuzztest/inputmethodability_fuzzer/BUILD.gn b/test/fuzztest/inputmethodability_fuzzer/BUILD.gn new file mode 100644 index 00000000..6c9d5d6c --- /dev/null +++ b/test/fuzztest/inputmethodability_fuzzer/BUILD.gn @@ -0,0 +1,62 @@ +# Copyright (c) 2021 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. + +import("//base/inputmethod/imf/inputmethod.gni") + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("InputMethodAbilityFuzzTest") { + module_out_path = "inputmethod/inputmethod" + + fuzz_config_file = + "//base/inputmethod/imf/test/fuzztest/inputmethodability_fuzzer" + + include_dirs = [ + "//base/inputmethod/imf/services/include", + "//foundation/ability/ability_runtime/interfaces/inner_api/app_manager/include/appmgr", + "//foundation/ability/ability_runtime/services/abilitymgr/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "inputmethodability_fuzzer.cpp" ] + + deps = [ + "//base/inputmethod/imf/frameworks/inputmethod_ability:inputmethod_ability", + "//base/inputmethod/imf/services:inputmethod_service", + "//foundation/ability/ability_runtime/services/abilitymgr:abilityms", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + ] + + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":InputMethodAbilityFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/inputmethodability_fuzzer/corpus/init b/test/fuzztest/inputmethodability_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/test/fuzztest/inputmethodability_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/inputmethodability_fuzzer/inputmethodability_fuzzer.cpp b/test/fuzztest/inputmethodability_fuzzer/inputmethodability_fuzzer.cpp new file mode 100644 index 00000000..1a1d2ac4 --- /dev/null +++ b/test/fuzztest/inputmethodability_fuzzer/inputmethodability_fuzzer.cpp @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2022 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 "inputmethodability_fuzzer.h" + +#include + +#include "input_method_ability.h" + +using namespace OHOS::MiscServices; +namespace OHOS { +class EngineListener : public InputMethodEngineListener { + void OnKeyboardStatus(bool isShow) {} + void OnInputStart() {} + void OnInputStop(std::string imeId) {} + void OnSetCallingWindow(uint32_t windowId) {} + void OnSetSubtype(const SubProperty &property) {} +}; + +class KeyboardListenerImpl : public KeyboardListener { + bool OnKeyEvent(int32_t keyCode, int32_t keyStatus) + { + return true; + } + void OnCursorUpdate(int32_t positionX, int32_t positionY, int32_t height) {} + void OnSelectionChange(int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd) {} + void OnTextChange(std::string text) {} +}; + +void TestInsertText(std::string fuzzedString) +{ + sptr ability = InputMethodAbility::GetInstance(); + ability->InsertText(std::move(fuzzedString)); +} + +void TestSetImeListener() +{ + sptr ability = InputMethodAbility::GetInstance(); + auto engineListener = std::make_shared(); + ability->setImeListener(engineListener); +} + +void TestSetKdListener() +{ + sptr ability = InputMethodAbility::GetInstance(); + auto keyBoardListener = std::make_shared(); + ability->setKdListener(keyBoardListener); +} + +void TestDeleteForward(int32_t fuzzedInt32) +{ + sptr ability = InputMethodAbility::GetInstance(); + ability->DeleteForward(fuzzedInt32); +} + +void TestDeleteBackward(int32_t fuzzedInt32) +{ + sptr ability = InputMethodAbility::GetInstance(); + ability->DeleteBackward(fuzzedInt32); +} + +void TestHideKeyboardSelf() +{ + sptr ability = InputMethodAbility::GetInstance(); + ability->HideKeyboardSelf(); +} + +void TestGetTextBeforeCursor(int32_t fuzzedInt32) +{ + sptr ability = InputMethodAbility::GetInstance(); + std::u16string text; + ability->GetTextBeforeCursor(fuzzedInt32, text); +} + +void TestGetTextAfterCursor(int32_t fuzzedInt32) +{ + sptr ability = InputMethodAbility::GetInstance(); + std::u16string text; + ability->GetTextAfterCursor(fuzzedInt32, text); +} + +void TestSendFunctionKey(int32_t fuzzedInt32) +{ + sptr ability = InputMethodAbility::GetInstance(); + ability->SendFunctionKey(fuzzedInt32); +} + +void TestMoveCursor(int32_t fuzzedInt32) +{ + sptr ability = InputMethodAbility::GetInstance(); + ability->MoveCursor(fuzzedInt32); +} + +void TestDispatchKeyEvent(int32_t fuzzedInt32) +{ + sptr ability = InputMethodAbility::GetInstance(); + ability->DispatchKeyEvent(fuzzedInt32, fuzzedInt32); +} + +void TestSetCallingWindow(int32_t fuzzedInt32) +{ + sptr ability = InputMethodAbility::GetInstance(); + ability->SetCallingWindow(fuzzedInt32); +} + +void TestGetEnterKeyType() +{ + sptr ability = InputMethodAbility::GetInstance(); + int32_t keyType; + ability->GetEnterKeyType(keyType); +} + +void TestGetInputPattern() +{ + sptr ability = InputMethodAbility::GetInstance(); + int32_t inputPattern; + ability->GetInputPattern(inputPattern); +} + +void TestStopInput() +{ + sptr ability = InputMethodAbility::GetInstance(); + ability->StopInput(); +} + +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + std::string fuzzedString(reinterpret_cast(data), size); + auto fuzzedInt32 = static_cast(size); + + OHOS::TestInsertText(fuzzedString); + + OHOS::TestSetImeListener(); + + OHOS::TestSetKdListener(); + + OHOS::TestDeleteForward(fuzzedInt32); + OHOS::TestDeleteBackward(fuzzedInt32); + + OHOS::TestHideKeyboardSelf(); + + OHOS::TestGetTextBeforeCursor(fuzzedInt32); + OHOS::TestGetTextAfterCursor(fuzzedInt32); + + OHOS::TestSendFunctionKey(fuzzedInt32); + OHOS::TestMoveCursor(fuzzedInt32); + + OHOS::TestDispatchKeyEvent(fuzzedInt32); + + OHOS::TestSetCallingWindow(fuzzedInt32); + + OHOS::TestGetEnterKeyType(); + OHOS::TestGetInputPattern(); + + OHOS::TestStopInput(); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/inputmethodability_fuzzer/inputmethodability_fuzzer.h b/test/fuzztest/inputmethodability_fuzzer/inputmethodability_fuzzer.h new file mode 100644 index 00000000..6941a92a --- /dev/null +++ b/test/fuzztest/inputmethodability_fuzzer/inputmethodability_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 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 INPUTMETHOD_IMF_CHOOSEDIALOG_INPUTMETHODABILITY_FUZZER_H +#define INPUTMETHOD_IMF_CHOOSEDIALOG_INPUTMETHODABILITY_FUZZER_H + +#define FUZZ_PROJECT_NAME "inputmethodability_fuzzer" + +#endif // INPUTMETHOD_IMF_CHOOSEDIALOG_INPUTMETHODABILITY_FUZZER_H diff --git a/test/fuzztest/inputmethodability_fuzzer/project.xml b/test/fuzztest/inputmethodability_fuzzer/project.xml new file mode 100644 index 00000000..85e7ef2c --- /dev/null +++ b/test/fuzztest/inputmethodability_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/inputmethodcontroller_fuzzer/BUILD.gn b/test/fuzztest/inputmethodcontroller_fuzzer/BUILD.gn new file mode 100644 index 00000000..7d1b1439 --- /dev/null +++ b/test/fuzztest/inputmethodcontroller_fuzzer/BUILD.gn @@ -0,0 +1,62 @@ +# Copyright (c) 2022 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. + +import("//base/inputmethod/imf/inputmethod.gni") + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("InputMethodControllerFuzzTest") { + module_out_path = "inputmethod/inputmethod" + + fuzz_config_file = + "//base/inputmethod/imf/test/fuzztest/inputmethodcontroller_fuzzer" + + include_dirs = [ + "//base/inputmethod/imf/services/include", + "//foundation/ability/ability_runtime/interfaces/inner_api/app_manager/include/appmgr", + "//foundation/ability/ability_runtime/services/abilitymgr/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "inputmethodcontroller_fuzzer.cpp" ] + + deps = [ + "//base/inputmethod/imf/frameworks/inputmethod_controller:inputmethod_client", + "//base/inputmethod/imf/services:inputmethod_service", + "//foundation/ability/ability_runtime/services/abilitymgr:abilityms", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + ] + + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":InputMethodControllerFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/inputmethodcontroller_fuzzer/corpus/init b/test/fuzztest/inputmethodcontroller_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/test/fuzztest/inputmethodcontroller_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/inputmethodcontroller_fuzzer/inputmethodcontroller_fuzzer.cpp b/test/fuzztest/inputmethodcontroller_fuzzer/inputmethodcontroller_fuzzer.cpp new file mode 100644 index 00000000..0671589b --- /dev/null +++ b/test/fuzztest/inputmethodcontroller_fuzzer/inputmethodcontroller_fuzzer.cpp @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2022 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 "inputmethodcontroller_fuzzer.h" + +#include +#include + +#include "global.h" +#include "input_method_controller.h" +#include "key_event.h" +#include "message_parcel.h" + +using namespace OHOS::MiscServices; +namespace OHOS { +class TextListener : public OnTextChangedListener { +public: + TextListener() {} + ~TextListener() {} + void InsertText(const std::u16string &text) {} + void DeleteBackward(int32_t length) {} + void SetKeyboardStatus(bool status) {} + void DeleteForward(int32_t length) {} + void SendKeyEventFromInputMethod(const KeyEvent &event) {} + void SendKeyboardInfo(const KeyboardInfo &status) {} + void MoveCursor(const Direction direction) {} +}; + +class SettingListener : public InputMethodSettingListener { + void OnImeChange(const Property &property, const SubProperty &subProperty) {} +}; + +void TestListInputMethod(sptr imc) +{ + std::vector properties = {}; + imc->ListInputMethod(properties); + imc->ListInputMethod(false, properties); + imc->ListInputMethod(true, properties); + imc->DisplayOptionalInputMethod(); +} + +void TestListInputMethodSubtype(sptr imc, std::string fuzzedString, int32_t fuzzedInt32) +{ + std::vector subProperties = {}; + Property property; + property.name = fuzzedString; + property.id = fuzzedString; + property.label = fuzzedString; + property.icon = fuzzedString; + property.iconId = fuzzedInt32; + imc->ListInputMethodSubtype(property, subProperties); +} + +void TestDispatchKeyEvent(sptr imc, int32_t fuzzedInt32) +{ + sptr textListener = new TextListener(); + imc->Attach(textListener); + + std::shared_ptr keyEvent = MMI::KeyEvent::Create(); + keyEvent->SetKeyAction(fuzzedInt32); + keyEvent->SetKeyCode(fuzzedInt32); + imc->dispatchKeyEvent(keyEvent); +} + +void TestOnSelectionChange( + sptr imc, std::u16string fuzzedU16String, int fuzzedInt, double fuzzedDouble) +{ + sptr textListener = new TextListener(); + imc->Attach(textListener); + + CursorInfo cursorInfo; + cursorInfo.height = fuzzedDouble; + cursorInfo.left = fuzzedDouble; + cursorInfo.top = fuzzedDouble; + cursorInfo.width = fuzzedDouble; + imc->OnCursorUpdate(cursorInfo); + + imc->OnSelectionChange(fuzzedU16String, fuzzedInt, fuzzedInt); +} + +void TestOnConfigurationChange(sptr imc) +{ + sptr textListener = new TextListener(); + imc->Attach(textListener); + + Configuration info; + EnterKeyType keyType = EnterKeyType::DONE; + info.SetEnterKeyType(keyType); + TextInputType textInputType = TextInputType::DATETIME; + info.SetTextInputType(textInputType); + imc->OnConfigurationChange(info); + int32_t enterKeyType; + int32_t inputPattern; + imc->GetEnterKeyType(enterKeyType); + imc->GetInputPattern(inputPattern); +} + +void TestSwitchInputMethod(sptr imc, std::string fuzzedString) +{ + imc->SwitchInputMethod(fuzzedString, fuzzedString); + imc->ShowOptionalInputMethod(); +} + +void TestSetCallingWindow(sptr imc, uint32_t fuzzedUInt32) +{ + sptr textListener = new TextListener(); + imc->Attach(textListener); + + imc->SetCallingWindow(fuzzedUInt32); + imc->ShowSoftKeyboard(); + imc->HideSoftKeyboard(); +} + +void TestShowSomething(sptr imc) +{ + sptr textListener = new TextListener(); + imc->Attach(textListener); + imc->ShowCurrentInput(); + imc->HideCurrentInput(); + + imc->ShowTextInput(); + imc->HideTextInput(); + + imc->GetCurrentInputMethod(); + imc->GetCurrentInputMethodSubtype(); + + auto settingListener = std::make_shared(); + imc->setImeListener(settingListener); + + imc->StopInputSession(); + imc->Close(); +} + +void TestGetTextBeforeCursor(sptr imc, int32_t fuzzedInt32) +{ + sptr textListener = new TextListener(); + imc->Attach(textListener); + + std::u16string text; + imc->GetTextBeforeCursor(fuzzedInt32, text); +} + +void TestTextAfterCursor(sptr imc, int32_t fuzzedInt32) +{ + sptr textListener = new TextListener(); + imc->Attach(textListener); + + std::u16string text; + imc->GetTextAfterCursor(fuzzedInt32, text); +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + std::string fuzzedString(data, data + size); + std::u16string fuzzedU16String = u"insert text"; + + auto fuzzedInt = static_cast(size); + auto fuzzedInt32 = static_cast(size); + auto fuzzedUInt32 = static_cast(size); + auto fuzzedDouble = static_cast(size); + + OHOS::sptr imc = InputMethodController::GetInstance(); + + OHOS::TestListInputMethod(imc); + OHOS::TestListInputMethodSubtype(imc, fuzzedString, fuzzedInt32); + OHOS::TestOnSelectionChange(imc, fuzzedU16String, fuzzedInt, fuzzedDouble); + OHOS::TestOnConfigurationChange(imc); + OHOS::TestSwitchInputMethod(imc, fuzzedString); + OHOS::TestGetTextBeforeCursor(imc, fuzzedInt32); + OHOS::TestSetCallingWindow(imc, fuzzedUInt32); + OHOS::TestDispatchKeyEvent(imc, fuzzedInt32); + OHOS::TestShowSomething(imc); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/inputmethodcontroller_fuzzer/inputmethodcontroller_fuzzer.h b/test/fuzztest/inputmethodcontroller_fuzzer/inputmethodcontroller_fuzzer.h new file mode 100644 index 00000000..6ba3e566 --- /dev/null +++ b/test/fuzztest/inputmethodcontroller_fuzzer/inputmethodcontroller_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 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 TEST_FUZZTEST_INPUTMETHODCONTROLLER_FUZZER_INPUTMETHODCONTROLLER_FUZZER_H +#define TEST_FUZZTEST_INPUTMETHODCONTROLLER_FUZZER_INPUTMETHODCONTROLLER_FUZZER_H + +#define FUZZ_PROJECT_NAME "inputmethodcontroller_fuzzer" + +#endif // TEST_FUZZTEST_INPUTMETHODCONTROLLER_FUZZER_INPUTMETHODCONTROLLER_FUZZER_H diff --git a/test/fuzztest/inputmethodcontroller_fuzzer/project.xml b/test/fuzztest/inputmethodcontroller_fuzzer/project.xml new file mode 100644 index 00000000..85e7ef2c --- /dev/null +++ b/test/fuzztest/inputmethodcontroller_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + From 69c092a5ffe4177fafafd3e3e0c59265497ca027 Mon Sep 17 00:00:00 2001 From: wangdongqi Date: Tue, 15 Nov 2022 17:43:14 +0800 Subject: [PATCH 047/112] Signed-off-by: wangdongqi Changes to be committed: --- .../perusersession_fuzzer.cpp | 24 ++++++------------- .../perusersetting_fuzzer.cpp | 12 +++------- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/test/fuzztest/perusersession_fuzzer/perusersession_fuzzer.cpp b/test/fuzztest/perusersession_fuzzer/perusersession_fuzzer.cpp index bbf781c8..2038216e 100644 --- a/test/fuzztest/perusersession_fuzzer/perusersession_fuzzer.cpp +++ b/test/fuzztest/perusersession_fuzzer/perusersession_fuzzer.cpp @@ -30,6 +30,7 @@ #include "input_method_core_proxy.h" #include "input_method_info.h" #include "input_method_property.h" +#include "iremote_broker.h" #include "message_parcel.h" #include "peruser_session.h" #include "peruser_setting.h" @@ -46,29 +47,22 @@ namespace OHOS { uint32_t bigVar = (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | (ptr[3]); return bigVar; } - bool perUserSession(const uint8_t *rawData, size_t size) + + bool FuzzPerUserSession(const uint8_t *rawData, size_t size) { - MessageParcel data; - ClientInfo clientInfo; Property property; SubProperty subProperty; - int retHeight = static_cast(*rawData); int flags = static_cast(*rawData); - std::string str(reinterpret_cast(rawData), size); + std::string str(rawData, rawData + size); std::u16string packageName = Str8ToStr16(str); - std::u16string key = Str8ToStr16(str); - std::u16string value = Str8ToStr16(str); bool isShowKeyboard = true; constexpr int32_t MAIN_USER_ID = 100; - sptr object = data.ReadRemoteObject(); - sptr client = new InputClientProxy(object); - + sptr client = new (std::nothrow) InputClientStub(); + sptr object = client->AsObject(); std::shared_ptr userSessions = std::make_shared(MAIN_USER_ID); - std::shared_ptr userSetting = std::make_shared(MAIN_USER_ID); sptr core = new InputMethodCoreProxy(object); sptr agent = new InputMethodAgentProxy(object); - InputMethodSetting *setting = userSetting->GetInputMethodSetting(); InputMethodInfo *ime = new InputMethodInfo(); userSessions->OnPackageRemoved(packageName); @@ -79,8 +73,6 @@ namespace OHOS { userSessions->SetCurrentSubProperty(subProperty); userSessions->StopInputService(str); userSessions->JoinWorkThread(); - userSessions->OnSettingChanged(key, value); - userSessions->OnGetKeyboardWindowHeight(retHeight); userSessions->OnHideKeyboardSelf(flags); userSessions->OnStartInput(client, isShowKeyboard); userSessions->OnStopInput(client); @@ -88,8 +80,6 @@ namespace OHOS { userSessions->SetCurrentIme(ime); userSessions->SetSecurityIme(ime); userSessions->ResetIme(ime, ime); - userSessions->SetInputMethodSetting(setting); - userSessions->OnPrepareInput(clientInfo); userSessions->OnSetCoreAndAgent(core, agent); delete ime; @@ -104,6 +94,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) return 0; } /* Run your code on data */ - OHOS::perUserSession(data, size); + OHOS::FuzzPerUserSession(data, size); return 0; } \ No newline at end of file diff --git a/test/fuzztest/perusersetting_fuzzer/perusersetting_fuzzer.cpp b/test/fuzztest/perusersetting_fuzzer/perusersetting_fuzzer.cpp index 50562c83..8ab13359 100644 --- a/test/fuzztest/perusersetting_fuzzer/perusersetting_fuzzer.cpp +++ b/test/fuzztest/perusersetting_fuzzer/perusersetting_fuzzer.cpp @@ -29,7 +29,6 @@ using namespace OHOS::MiscServices; namespace OHOS { constexpr size_t THRESHOLD = 10; - constexpr int32_t OFFSET = 4; uint32_t ConvertToUint32(const uint8_t *ptr) { @@ -39,20 +38,16 @@ namespace OHOS { uint32_t bigVar = (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | (ptr[3]); return bigVar; } - bool FuzzAgentStub(const uint8_t *rawData, size_t size) + bool FuzzPerUserSetting(const uint8_t *rawData, size_t size) { - uint32_t code = ConvertToUint32(rawData); - rawData = rawData + OFFSET; - size = size - OFFSET; - std::string str(reinterpret_cast(rawData), size); std::u16string imeId = Str8ToStr16(str); std::u16string packageName = Str8ToStr16(str); std::u16string key = Str8ToStr16(str); std::u16string value = Str8ToStr16(str); bool isSecurityIme = true; - constexpr int32_t MAIN_USER_ID = 100; + std::shared_ptr userSetting = std::make_shared(MAIN_USER_ID); userSetting->Initialize(); @@ -67,7 +62,6 @@ namespace OHOS { userSetting->OnSettingChanged(key, value); userSetting->OnAdvanceToNext(); userSetting->OnUserLocked(); - userSetting->Dump(code); return true; } @@ -79,6 +73,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) return 0; } /* Run your code on data */ - OHOS::FuzzAgentStub(data, size); + OHOS::FuzzPerUserSetting(data, size); return 0; } \ No newline at end of file From 6900fd929d8e1c9ed3a7e9d89c51b43ee62d7dfc Mon Sep 17 00:00:00 2001 From: wangdongqi Date: Tue, 15 Nov 2022 18:10:41 +0800 Subject: [PATCH 048/112] Signed-off-by: wangdongqi Changes to be committed: --- test/fuzztest/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 85dedd40..00c41a1b 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -22,9 +22,9 @@ group("fuzztest") { "corestub_fuzzer:fuzztest", "datachannelstub_fuzzer:fuzztest", "inputclientstub_fuzzer:fuzztest", + "inputmethodsetting_fuzzer:fuzztest", "perusersession_fuzzer:fuzztest", "perusersetting_fuzzer:fuzztest", - "inputmethodsetting_fuzzer:fuzztest", "platformcallbackstub_fuzzer:fuzztest", "systemabilitystub_fuzzer:fuzztest", ] From 4d0898a97b8cbe05352425756457d8a0cdc4d2cc Mon Sep 17 00:00:00 2001 From: cy7717 Date: Wed, 16 Nov 2022 16:34:44 +0800 Subject: [PATCH 049/112] =?UTF-8?q?=E8=87=AA=E6=B8=AC=E8=A9=A6=E5=95=8F?= =?UTF-8?q?=E9=A1=8C=E4=BF=AE=E6=94=B9=20Signed-off-by:=20cy7717=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../js/napi/inputmethodability/js_text_input_client_engine.cpp | 2 +- .../js/napi/inputmethodability/js_text_input_client_engine.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/js/napi/inputmethodability/js_text_input_client_engine.cpp b/interfaces/kits/js/napi/inputmethodability/js_text_input_client_engine.cpp index d1b4366b..1bfd5139 100644 --- a/interfaces/kits/js/napi/inputmethodability/js_text_input_client_engine.cpp +++ b/interfaces/kits/js/napi/inputmethodability/js_text_input_client_engine.cpp @@ -76,7 +76,7 @@ napi_value JsTextInputClientEngine::MoveCursor(napi_env env, napi_callback_info } }; ctxt->SetAction(std::move(input)); - AsyncCall asyncCall(env, info, std::dynamic_pointer_cast(ctxt), 0); + AsyncCall asyncCall(env, info, std::dynamic_pointer_cast(ctxt)); return asyncCall.Call(env, exec); } diff --git a/interfaces/kits/js/napi/inputmethodability/js_text_input_client_engine.h b/interfaces/kits/js/napi/inputmethodability/js_text_input_client_engine.h index 403d4cd0..2493b5cb 100644 --- a/interfaces/kits/js/napi/inputmethodability/js_text_input_client_engine.h +++ b/interfaces/kits/js/napi/inputmethodability/js_text_input_client_engine.h @@ -45,7 +45,7 @@ struct SendKeyFunctionContext : public AsyncCall::Context { }; struct MoveCursorContext : public AsyncCall::Context { - bool num = false; + int32_t num = 0; napi_status status = napi_generic_failure; MoveCursorContext() : Context(nullptr, nullptr){}; MoveCursorContext(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)){}; From 32311a28ce32e2f5b80dc7a7756083f328f96d1c Mon Sep 17 00:00:00 2001 From: cy7717 Date: Thu, 17 Nov 2022 16:11:17 +0800 Subject: [PATCH 050/112] mod Signed-off-by: cy7717 --- services/src/input_method_system_ability.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index ab372385..e1cadf38 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -739,6 +739,7 @@ namespace MiscServices { property.descriptionId = applicationInfo.descriptionId; property.label = Str8ToStr16(labelString); property.description = Str8ToStr16(descriptionString); + properties.emplace_back(property); } return properties; } From 41740b6583855364d666990cbce96bf1347d1e28 Mon Sep 17 00:00:00 2001 From: cy7717 Date: Thu, 17 Nov 2022 16:41:05 +0800 Subject: [PATCH 051/112] =?UTF-8?q?=E5=A2=9E=E5=8A=A0dfx=20tdd=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cy7717 --- bundle.json | 4 +- unitest/BUILD.gn | 17 ++++ unitest/src/input_method_dfx_test.cpp | 133 ++++++++++++++++++++++++++ 3 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 unitest/src/input_method_dfx_test.cpp diff --git a/bundle.json b/bundle.json index a0c2523d..0d10b290 100644 --- a/bundle.json +++ b/bundle.json @@ -84,9 +84,7 @@ } ], "test": [ - "//base/inputmethod/imf/unitest:InputMethodControllerTest", - "//base/inputmethod/imf/unitest:InputMethodAbilityTest", - "//base/inputmethod/imf/unitest:InputMethodServiceTest", + "//base/inputmethod/imf/unitest:unittest", "//base/inputmethod/imf/test/fuzztest:fuzztest", "//base/inputmethod/imf/test/unitest/src:unittest" ] diff --git a/unitest/BUILD.gn b/unitest/BUILD.gn index 0b2b0ed3..e8d03056 100644 --- a/unitest/BUILD.gn +++ b/unitest/BUILD.gn @@ -112,6 +112,22 @@ ohos_unittest("InputMethodServiceTest") { ] } +ohos_unittest("InputMethodDfxTest") { + module_out_path = module_output_path + + sources = [ "src/input_method_dfx_test.cpp" ] + + deps = [ + "//base/inputmethod/imf/services:inputmethod_service", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] +} + group("unittest") { testonly = true @@ -121,5 +137,6 @@ group("unittest") { ":InputMethodAbilityTest", ":InputMethodControllerTest", ":InputMethodServiceTest", + ":InputMethodDfxTest", ] } diff --git a/unitest/src/input_method_dfx_test.cpp b/unitest/src/input_method_dfx_test.cpp new file mode 100644 index 00000000..ceead747 --- /dev/null +++ b/unitest/src/input_method_dfx_test.cpp @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2022 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 +#include +#include + +#include +#include + +#include "global.h" +#include "securec.h" + +using namespace testing::ext; +namespace OHOS { +namespace MiscServices { +constexpr const uint16_t EACH_LINE_LENGTH = 100; +constexpr const uint16_t TOTAL_LENGTH = 1000; +class InputMethodDfxTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + static bool ExecuteCmd(const std::string &cmd, std::string &result); + void SetUp(); + void TearDown(); +}; + +void InputMethodDfxTest::SetUpTestCase(void) +{ + IMSA_HILOGI("InputMethodDfxTest::SetUpTestCase"); +} + +void InputMethodDfxTest::TearDownTestCase(void) +{ + IMSA_HILOGI("InputMethodDfxTest::TearDownTestCase"); +} + +void InputMethodDfxTest::SetUp(void) +{ + IMSA_HILOGI("InputMethodDfxTest::SetUp"); +} + +void InputMethodDfxTest::TearDown(void) +{ + IMSA_HILOGI("InputMethodDfxTest::TearDown"); +} + +bool InputMethodDfxTest::ExecuteCmd(const std::string &cmd, std::string &result) +{ + char buff[EACH_LINE_LENGTH] = { 0x00 }; + char output[TOTAL_LENGTH] = { 0x00 }; + FILE *ptr = NULL; + if ((ptr = popen(cmd.c_str(), "r")) != NULL) { + while (fgets(buff, sizeof(buff), ptr) != nullptr) { + if (strcat_s(output, sizeof(output), buff) != 0) { + pclose(ptr); + ptr = NULL; + return false; + } + } + pclose(ptr); + ptr = NULL; + } else { + return false; + } + result = std::string(output); + return true; +} + +/** +* @tc.name: InputMethodDfxTest_DumpAllMethod_001 +* @tc.desc: DumpAllMethod +* @tc.type: FUNC +* @tc.require: issueI61PMG +* @tc.author: chenyu +*/ +HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_DumpAllMethod_001, TestSize.Level0) +{ + std::string result; + constexpr const char *CMD = "hidumper -s 3703 -a -a"; + auto ret = InputMethodDfxTest::ExecuteCmd(CMD, result); + EXPECT_TRUE(ret); + EXPECT_TRUE(result.find("get input method") != std::string::npos); + EXPECT_TRUE(result.find("imeList") != std::string::npos); + EXPECT_TRUE(result.find("isDefaultIme") != std::string::npos); +} + +/** +* @tc.name: InputMethodDfxTest_Dump_ShowHelp_001 +* @tc.desc: Dump ShowHelp. +* @tc.type: FUNC +* @tc.require: issueI61PMG +* @tc.author: chenyu +*/ +HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Dump_ShowHelp_001, TestSize.Level0) +{ + std::string result; + constexpr const char *CMD = "hidumper -s 3703 -a -h"; + auto ret = InputMethodDfxTest::ExecuteCmd(CMD, result); + EXPECT_TRUE(ret); + EXPECT_TRUE(result.find("Description:") != std::string::npos); + EXPECT_TRUE(result.find("-h show help") != std::string::npos); + EXPECT_TRUE(result.find("-a dump all input methods") != std::string::npos); +} + +/** +* @tc.name: InputMethodDfxTest_Dump_ShowIllealInfomation_001 +* @tc.desc: Dump ShowIllealInfomation. +* @tc.type: FUNC +* @tc.require: issueI61PMG +* @tc.author: chenyu +*/ +HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Dump_ShowIllealInfomation_001, TestSize.Level0) +{ + std::string result; + constexpr const char *CMD = "hidumper -s 3703 -a -test"; + auto ret = InputMethodDfxTest::ExecuteCmd(CMD, result); + EXPECT_TRUE(ret); + EXPECT_TRUE(result.find("input dump parameter error,enter '-h' for usage.") != std::string::npos); +} +} // namespace MiscServices +} // namespace OHOS From 281be72a95a45c20c9f41bb8624dc10399594e58 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Thu, 17 Nov 2022 17:20:28 +0800 Subject: [PATCH 052/112] Signed-off-by: ma-shaoyin Changes to be committed: --- .../js/napi/inputmethodclient/js_utils.cpp | 143 +++++++++--------- test/fuzztest/agentstub_fuzzer/BUILD.gn | 2 +- .../agentstub_fuzzer/agentstub_fuzzer.h | 4 +- test/fuzztest/agentstub_fuzzer/project.xml | 2 +- .../controlchannelstub_fuzzer/BUILD.gn | 2 +- .../controlchannelstub_fuzzer.h | 6 +- .../controlchannelstub_fuzzer/project.xml | 2 +- test/fuzztest/corestub_fuzzer/BUILD.gn | 2 +- .../corestub_fuzzer/corestub_fuzzer.h | 6 +- test/fuzztest/corestub_fuzzer/project.xml | 2 +- test/fuzztest/datachannelstub_fuzzer/BUILD.gn | 2 +- .../datachannelstub_fuzzer.h | 5 +- .../datachannelstub_fuzzer/project.xml | 2 +- test/fuzztest/inputclientstub_fuzzer/BUILD.gn | 2 +- .../inputclientstub_fuzzer.cpp | 2 +- .../inputclientstub_fuzzer.h | 2 +- .../inputclientstub_fuzzer/project.xml | 2 +- .../inputmethodability_fuzzer/BUILD.gn | 2 +- .../inputmethodability_fuzzer/project.xml | 2 +- .../inputmethodcontroller_fuzzer.cpp | 2 +- .../inputmethodcontroller_fuzzer/project.xml | 2 +- .../inputmethodsetting_fuzzer/BUILD.gn | 2 +- test/fuzztest/perusersession_fuzzer/BUILD.gn | 2 +- .../perusersession_fuzzer.h | 2 +- .../perusersession_fuzzer/project.xml | 2 +- test/fuzztest/perusersetting_fuzzer/BUILD.gn | 2 +- .../perusersetting_fuzzer.h | 2 +- .../perusersetting_fuzzer/project.xml | 2 +- .../platformcallbackstub_fuzzer/BUILD.gn | 2 +- .../platformcallbackstub_fuzzer.h | 2 +- .../platformcallbackstub_fuzzer/project.xml | 2 +- 31 files changed, 105 insertions(+), 111 deletions(-) diff --git a/interfaces/kits/js/napi/inputmethodclient/js_utils.cpp b/interfaces/kits/js/napi/inputmethodclient/js_utils.cpp index 2a3b644e..945cf707 100644 --- a/interfaces/kits/js/napi/inputmethodclient/js_utils.cpp +++ b/interfaces/kits/js/napi/inputmethodclient/js_utils.cpp @@ -83,86 +83,85 @@ const std::map JsUtils::ERROR_CODE_MAP = { }; const std::map JsUtils::ERROR_CODE_CONVERT_MESSAGE_MAP = { - { EXCEPTION_PERMISSION, "the permissions check fails." }, - { EXCEPTION_PARAMCHECK, "the parameters check fails." }, - { EXCEPTION_UNSUPPORTED, "call unsupported api." }, - { EXCEPTION_PACKAGEMANAGER, "package manager error." }, - { EXCEPTION_IMENGINE, "input method engine error." }, - { EXCEPTION_IMCLIENT, "input method client error." }, - { EXCEPTION_KEYEVENT, "key event processing error." }, - { EXCEPTION_CONFPERSIST, "configuration persisting error." }, - { EXCEPTION_CONTROLLER, "input method controller error." }, - { EXCEPTION_SETTINGS, "input method settings extension error." }, - { EXCEPTION_IMMS, "input method manager service error." }, - { EXCEPTION_OTHERS, "others error." }, - }; + { EXCEPTION_PERMISSION, "the permissions check fails." }, + { EXCEPTION_PARAMCHECK, "the parameters check fails." }, + { EXCEPTION_UNSUPPORTED, "call unsupported api." }, + { EXCEPTION_PACKAGEMANAGER, "package manager error." }, + { EXCEPTION_IMENGINE, "input method engine error." }, + { EXCEPTION_IMCLIENT, "input method client error." }, + { EXCEPTION_KEYEVENT, "key event processing error." }, + { EXCEPTION_CONFPERSIST, "configuration persisting error." }, + { EXCEPTION_CONTROLLER, "input method controller error." }, + { EXCEPTION_SETTINGS, "input method settings extension error." }, + { EXCEPTION_IMMS, "input method manager service error." }, + { EXCEPTION_OTHERS, "others error." }, +}; - const std::map JsUtils::PARAMETER_TYPE = { - { TYPE_UNDEFINED, "napi_undefine." }, - { TYPE_NULL, "napi_null." }, - { TYPE_BOOLEAN, "napi_boolean." }, - { TYPE_NUMBER, "napi_number." }, - { TYPE_STRING, "napi_string." }, - { TYPE_SYMBOL, "napi_symbol." }, - { TYPE_OBJECT, "napi_object." }, - { TYPE_FUNCTION, "napi_function." }, - { TYPE_EXTERNAL, "napi_external." }, - { TYPE_BIGINT, "napi_bigint." }, - }; +const std::map JsUtils::PARAMETER_TYPE = { + { TYPE_UNDEFINED, "napi_undefine." }, + { TYPE_NULL, "napi_null." }, + { TYPE_BOOLEAN, "napi_boolean." }, + { TYPE_NUMBER, "napi_number." }, + { TYPE_STRING, "napi_string." }, + { TYPE_SYMBOL, "napi_symbol." }, + { TYPE_OBJECT, "napi_object." }, + { TYPE_FUNCTION, "napi_function." }, + { TYPE_EXTERNAL, "napi_external." }, + { TYPE_BIGINT, "napi_bigint." }, +}; - void JsUtils::ThrowException(napi_env env, int32_t err, const std::string &msg, TypeCode type) - { - std::string errMsg = ToMessage(err); - if (type == TypeCode::TYPE_NONE) { - errMsg = errMsg + msg; - IMSA_HILOGE("THROW_PARAMTER_ERROR message: %{public}s", errMsg.c_str()); - } else { - auto iter = PARAMETER_TYPE.find(type); - if (iter != PARAMETER_TYPE.end()) { - errMsg = errMsg + "The type of " + msg + " must be " + iter->second; - IMSA_HILOGE("THROW_PARAMTER_TYPE_ERROR message: %{public}s", errMsg.c_str()); - } +void JsUtils::ThrowException(napi_env env, int32_t err, const std::string &msg, TypeCode type) +{ + std::string errMsg = ToMessage(err); + if (type == TypeCode::TYPE_NONE) { + errMsg = errMsg + msg; + IMSA_HILOGE("THROW_PARAMTER_ERROR message: %{public}s", errMsg.c_str()); + } else { + auto iter = PARAMETER_TYPE.find(type); + if (iter != PARAMETER_TYPE.end()) { + errMsg = errMsg + "The type of " + msg + " must be " + iter->second; + IMSA_HILOGE("THROW_PARAMTER_TYPE_ERROR message: %{public}s", errMsg.c_str()); } - napi_throw_error(env, std::to_string(err).c_str(), errMsg.c_str()); } + napi_throw_error(env, std::to_string(err).c_str(), errMsg.c_str()); +} - napi_value JsUtils::ToError(napi_env env, int32_t code) - { - IMSA_HILOGE("ToError start"); - napi_value errorObj; - NAPI_CALL(env, napi_create_object(env, &errorObj)); - napi_value errorCode = nullptr; - NAPI_CALL( - env, napi_create_string_utf8(env, std::to_string(Convert(code)).c_str(), NAPI_AUTO_LENGTH, &errorCode)); - napi_value errorMessage = nullptr; - NAPI_CALL(env, napi_create_string_utf8(env, ToMessage(Convert(code)).c_str(), NAPI_AUTO_LENGTH, &errorMessage)); - NAPI_CALL(env, napi_set_named_property(env, errorObj, "code", errorCode)); - NAPI_CALL(env, napi_set_named_property(env, errorObj, "message", errorMessage)); - IMSA_HILOGE("ToError end"); - return errorObj; - } +napi_value JsUtils::ToError(napi_env env, int32_t code) +{ + IMSA_HILOGE("ToError start"); + napi_value errorObj; + NAPI_CALL(env, napi_create_object(env, &errorObj)); + napi_value errorCode = nullptr; + NAPI_CALL(env, napi_create_string_utf8(env, std::to_string(Convert(code)).c_str(), NAPI_AUTO_LENGTH, &errorCode)); + napi_value errorMessage = nullptr; + NAPI_CALL(env, napi_create_string_utf8(env, ToMessage(Convert(code)).c_str(), NAPI_AUTO_LENGTH, &errorMessage)); + NAPI_CALL(env, napi_set_named_property(env, errorObj, "code", errorCode)); + NAPI_CALL(env, napi_set_named_property(env, errorObj, "message", errorMessage)); + IMSA_HILOGE("ToError end"); + return errorObj; +} - int32_t JsUtils::Convert(int32_t code) - { - IMSA_HILOGI("Convert start"); - auto iter = ERROR_CODE_MAP.find(code); - if (iter != ERROR_CODE_MAP.end()) { - IMSA_HILOGE("ErrorCode: %{public}d", iter->second); - return iter->second; - } - IMSA_HILOGI("Convert end"); - return ERROR_CODE_QUERY_FAILED; +int32_t JsUtils::Convert(int32_t code) +{ + IMSA_HILOGI("Convert start"); + auto iter = ERROR_CODE_MAP.find(code); + if (iter != ERROR_CODE_MAP.end()) { + IMSA_HILOGE("ErrorCode: %{public}d", iter->second); + return iter->second; } + IMSA_HILOGI("Convert end"); + return ERROR_CODE_QUERY_FAILED; +} - const std::string JsUtils::ToMessage(int32_t code) - { - IMSA_HILOGI("ToMessage start"); - auto iter = ERROR_CODE_CONVERT_MESSAGE_MAP.find(code); - if (iter != ERROR_CODE_CONVERT_MESSAGE_MAP.end()) { - IMSA_HILOGI("ErrorMessage: %{public}s", (iter->second).c_str()); - return iter->second; - } - return "error is out of definition."; +const std::string JsUtils::ToMessage(int32_t code) +{ + IMSA_HILOGI("ToMessage start"); + auto iter = ERROR_CODE_CONVERT_MESSAGE_MAP.find(code); + if (iter != ERROR_CODE_CONVERT_MESSAGE_MAP.end()) { + IMSA_HILOGI("ErrorMessage: %{public}s", (iter->second).c_str()); + return iter->second; } + return "error is out of definition."; +} } } \ No newline at end of file diff --git a/test/fuzztest/agentstub_fuzzer/BUILD.gn b/test/fuzztest/agentstub_fuzzer/BUILD.gn index e8815da7..0dcf66bd 100644 --- a/test/fuzztest/agentstub_fuzzer/BUILD.gn +++ b/test/fuzztest/agentstub_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2022 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 diff --git a/test/fuzztest/agentstub_fuzzer/agentstub_fuzzer.h b/test/fuzztest/agentstub_fuzzer/agentstub_fuzzer.h index 81295dac..ad7d049a 100644 --- a/test/fuzztest/agentstub_fuzzer/agentstub_fuzzer.h +++ b/test/fuzztest/agentstub_fuzzer/agentstub_fuzzer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -18,4 +18,4 @@ #define FUZZ_PROJECT_NAME "agentstub_fuzzer" -#endif // TEST_FUZZTEST_AGENTSTUB_FUZZER_AGENTSTUB_FUZZER_H +#endif // TEST_FUZZTEST_AGENTSTUB_FUZZER_AGENTSTUB_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/agentstub_fuzzer/project.xml b/test/fuzztest/agentstub_fuzzer/project.xml index 85e7ef2c..6e8ad2cf 100644 --- a/test/fuzztest/agentstub_fuzzer/project.xml +++ b/test/fuzztest/agentstub_fuzzer/project.xml @@ -1,5 +1,5 @@ - + + + + 1000 + + 300 + + 4096 + + From 38f769c897a333b279d1c7820624cc1dfa738647 Mon Sep 17 00:00:00 2001 From: cy7717 Date: Thu, 17 Nov 2022 18:04:35 +0800 Subject: [PATCH 056/112] MOD Signed-off-by: cy7717 --- unitest/src/input_method_dfx_test.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/unitest/src/input_method_dfx_test.cpp b/unitest/src/input_method_dfx_test.cpp index 41cab55d..80e6ecdf 100644 --- a/unitest/src/input_method_dfx_test.cpp +++ b/unitest/src/input_method_dfx_test.cpp @@ -93,9 +93,9 @@ HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_DumpAllMethod_001, TestSize.Leve std::string result; auto ret = InputMethodDfxTest::ExecuteCmd(CMD1, result); EXPECT_TRUE(ret); - EXPECT_TRUE(result.find("get input method") != std::string::npos); - EXPECT_TRUE(result.find("imeList") != std::string::npos); - EXPECT_TRUE(result.find("isDefaultIme") != std::string::npos); + EXPECT_NE(result.find("get input method"), std::string::npos); + EXPECT_NE(result.find("imeList"), std::string::npos); + EXPECT_NE(result.find("isDefaultIme"), std::string::npos); } /** @@ -110,9 +110,9 @@ HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Dump_ShowHelp_001, TestSize.Leve std::string result; auto ret = InputMethodDfxTest::ExecuteCmd(CMD2, result); EXPECT_TRUE(ret); - EXPECT_TRUE(result.find("Description:") != std::string::npos); - EXPECT_TRUE(result.find("-h show help") != std::string::npos); - EXPECT_TRUE(result.find("-a dump all input methods") != std::string::npos); + EXPECT_NE(result.find("Description:"), std::string::npos); + EXPECT_NE(result.find("-h show help"), std::string::npos); + EXPECT_NE(result.find("-a dump all input methods"), std::string::npos); } /** @@ -127,7 +127,7 @@ HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Dump_ShowIllealInfomation_001, T std::string result; auto ret = InputMethodDfxTest::ExecuteCmd(CMD3, result); EXPECT_TRUE(ret); - EXPECT_TRUE(result.find("input dump parameter error,enter '-h' for usage.") != std::string::npos); + EXPECT_NE(result.find("input dump parameter error,enter '-h' for usage."), std::string::npos); } } // namespace MiscServices } // namespace OHOS From eb3c87a9400b25e9a671c51b0719448c996f4331 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Thu, 17 Nov 2022 21:56:50 +0800 Subject: [PATCH 057/112] Signed-off-by: ma-shaoyin Changes to be committed: --- .../include/input_method_controller.h | 1 + .../src/input_method_controller.cpp | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/frameworks/inputmethod_controller/include/input_method_controller.h b/frameworks/inputmethod_controller/include/input_method_controller.h index ab4b58f6..33acdc48 100644 --- a/frameworks/inputmethod_controller/include/input_method_controller.h +++ b/frameworks/inputmethod_controller/include/input_method_controller.h @@ -116,6 +116,7 @@ private: sptr deathRecipient_; std::mutex agentLock_; std::shared_ptr mAgent = nullptr; + std::mutex textListenerLock_; sptr textListener; InputAttribute mAttribute; std::u16string mTextString; diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index ec2d0a6a..2a78c002 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -90,8 +90,10 @@ using namespace MessageID; workThreadHandler = std::thread([this] { WorkThread(); }); mAttribute.inputPattern = InputAttribute::PATTERN_TEXT; - - textListener = nullptr; + { + std::lock_guard lock(textListenerLock_); + textListener = nullptr; + } IMSA_HILOGI("InputMethodController::Initialize textListener is nullptr"); PrepareInput(0, mClient, mInputDataChannel, mAttribute); return true; @@ -134,6 +136,7 @@ using namespace MessageID; { while (!stop_) { Message *msg = msgHandler->GetMessage(); + std::lock_guard lock(textListenerLock_); switch (msg->msgId_) { case MSG_ID_INSERT_CHAR: { MessageParcel *data = msg->msgContent_; @@ -266,6 +269,7 @@ using namespace MessageID; void InputMethodController::Attach(sptr &listener, bool isShowKeyboard) { + std::lock_guard lock(textListenerLock_); textListener = listener; IMSA_HILOGI("InputMethodController::Attach"); InputmethodTrace tracer("InputMethodController Attach trace."); @@ -312,7 +316,10 @@ using namespace MessageID; { ReleaseInput(mClient); InputmethodTrace tracer("InputMethodController Close trace."); - textListener = nullptr; + { + std::lock_guard lock(textListenerLock_); + textListener = nullptr; + } IMSA_HILOGI("InputMethodController::Close"); } From 447d8e49072bed2fdbd1e6ca69eb381aad1e5b92 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Thu, 17 Nov 2022 22:06:34 +0800 Subject: [PATCH 058/112] Signed-off-by: ma-shaoyin Changes to be committed: --- test/fuzztest/inputmethod_fuzzer/BUILD.gn | 7 +++---- test/fuzztest/inputmethod_fuzzer/inputmethod_fuzzer.cpp | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/fuzztest/inputmethod_fuzzer/BUILD.gn b/test/fuzztest/inputmethod_fuzzer/BUILD.gn index d3d2565a..6e12afad 100644 --- a/test/fuzztest/inputmethod_fuzzer/BUILD.gn +++ b/test/fuzztest/inputmethod_fuzzer/BUILD.gn @@ -22,8 +22,7 @@ import("//build/test.gni") ohos_fuzztest("InputMethodFuzzTest") { module_out_path = "inputmethod/inputmethod" - fuzz_config_file = - "//base/inputmethod/imf/test/fuzztest/inputmethod_fuzzer" + fuzz_config_file = "//base/inputmethod/imf/test/fuzztest/inputmethod_fuzzer" include_dirs = [ "//base/inputmethod/imf/services/include", @@ -44,12 +43,12 @@ ohos_fuzztest("InputMethodFuzzTest") { sources = [ "inputmethod_fuzzer.cpp" ] deps = [ + "//base/inputmethod/imf/etc/para:inputmethod_para", "//base/inputmethod/imf/frameworks/inputmethod_controller:inputmethod_client", "//base/inputmethod/imf/services:inputmethod_service", + "//foundation/ability/ability_base:want", "//foundation/ability/ability_runtime/services/abilitymgr:abilityms", "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", - "//base/inputmethod/imf/etc/para:inputmethod_para", - "//foundation/ability/ability_base:want", ] external_deps = [ diff --git a/test/fuzztest/inputmethod_fuzzer/inputmethod_fuzzer.cpp b/test/fuzztest/inputmethod_fuzzer/inputmethod_fuzzer.cpp index ecae76ea..3f848d44 100644 --- a/test/fuzztest/inputmethod_fuzzer/inputmethod_fuzzer.cpp +++ b/test/fuzztest/inputmethod_fuzzer/inputmethod_fuzzer.cpp @@ -27,6 +27,7 @@ #include "message_parcel.h" #include "para_handle.h" #include "platform.h" +#include "utils.h" using namespace OHOS::MiscServices; namespace OHOS { From 56dc78f9d6213ad22ed8a85adc205406980087b7 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Fri, 18 Nov 2022 10:02:05 +0800 Subject: [PATCH 059/112] Signed-off-by: ma-shaoyin Changes to be committed: --- test/unitest/src/config.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unitest/src/config.json b/test/unitest/src/config.json index 57e995ac..935c3be2 100644 --- a/test/unitest/src/config.json +++ b/test/unitest/src/config.json @@ -16,7 +16,8 @@ "package": "com.example.myapplication", "name": ".MyApplication", "deviceType": [ - "phone" + "default", + "tablet" ], "distro": { "deliveryWithInstall": true, From 2d388dd5ae0ef415c06d260ddc66f7d40ca335a1 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Fri, 18 Nov 2022 15:20:48 +0800 Subject: [PATCH 060/112] Signed-off-by: ma-shaoyin Changes to be committed: --- .../inputmethodcontroller_fuzzer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fuzztest/inputmethodcontroller_fuzzer/inputmethodcontroller_fuzzer.cpp b/test/fuzztest/inputmethodcontroller_fuzzer/inputmethodcontroller_fuzzer.cpp index 6ce43c3e..d07f1ef9 100644 --- a/test/fuzztest/inputmethodcontroller_fuzzer/inputmethodcontroller_fuzzer.cpp +++ b/test/fuzztest/inputmethodcontroller_fuzzer/inputmethodcontroller_fuzzer.cpp @@ -51,7 +51,7 @@ void TestListInputMethod(sptr imc) imc->DisplayOptionalInputMethod(); } -void TestListInputMethodSubtype(sptr imc,const std::string fuzzedString, int32_t fuzzedInt32) +void TestListInputMethodSubtype(sptr imc, const std::string &fuzzedString, int32_t fuzzedInt32) { std::vector subProperties = {}; Property property; From c068b9a92d356baf85f1c67dac53940068e38884 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Fri, 18 Nov 2022 15:27:04 +0800 Subject: [PATCH 061/112] modify debug code Signed-off-by: zhaolinglan --- services/adapter/keyboard/input_event_callback.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/adapter/keyboard/input_event_callback.h b/services/adapter/keyboard/input_event_callback.h index 8231ed1f..ef6a9322 100644 --- a/services/adapter/keyboard/input_event_callback.h +++ b/services/adapter/keyboard/input_event_callback.h @@ -54,7 +54,11 @@ private: void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) const { IMSA_HILOGI("InputEventCallback::OnInputEvent"); + IMSA_HILOGI("KeyCode: %{public}d, KeyAction: %{public}d", keyEvent->GetKeyCode(), keyEvent->GetKeyAction()); auto pressKeys = keyEvent->GetPressedKeys(); + for (const auto &key : pressKeys) { + IMSA_HILOGI("pressedkey: %{public}d", key); + } auto it = keyMap_.find(pressKeys); if (it == keyMap_.end()) { IMSA_HILOGD("keyEvent undefined"); From 5259bb1a91d3a69d1eb376c1bfb8289ab8b2c80a Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Fri, 18 Nov 2022 15:57:33 +0800 Subject: [PATCH 062/112] Signed-off-by: ma-shaoyin Changes to be committed: --- .../include/input_method_ability.h | 1 + .../src/input_method_ability.cpp | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/frameworks/inputmethod_ability/include/input_method_ability.h b/frameworks/inputmethod_ability/include/input_method_ability.h index 76dcbb02..11a51d7b 100644 --- a/frameworks/inputmethod_ability/include/input_method_ability.h +++ b/frameworks/inputmethod_ability/include/input_method_ability.h @@ -99,6 +99,7 @@ private: void Initialize(); void WorkThread(); + void QuitWorkThread(); void OnInitialInput(Message *msg); void OnStartInput(Message *msg); diff --git a/frameworks/inputmethod_ability/src/input_method_ability.cpp b/frameworks/inputmethod_ability/src/input_method_ability.cpp index d35afc1f..79601f17 100644 --- a/frameworks/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/inputmethod_ability/src/input_method_ability.cpp @@ -46,12 +46,12 @@ InputMethodAbility::InputMethodAbility() : stop_(false) InputMethodAbility::~InputMethodAbility() { IMSA_HILOGI("InputMethodAbility::~InputMethodAbility"); - instance_ = nullptr; + QuitWorkThread(); if (msgHandler) { delete msgHandler; msgHandler = nullptr; } - stop_ = true; + instance_ = nullptr; } sptr InputMethodAbility::GetInstance() @@ -196,6 +196,7 @@ void InputMethodAbility::WorkThread() break; } default: { + IMSA_HILOGD("the message is %{public}d.", msg->msgId_); break; } } @@ -574,5 +575,15 @@ void InputMethodAbility::BindServiceAndClient() sptr inputMethodAgent = sptr(new InputMethodAgentProxy(inputMethodAgentStub)); mImms->SetCoreAndAgent(stub, inputMethodAgent); } + +void InputMethodAbility::QuitWorkThread() +{ + stop_ = true; + Message *msg = new Message(MessageID::MSG_ID_QUIT_WORKER_THREAD, nullptr); + msgHandler->SendMessage(msg); + if (workThreadHandler.joinable()) { + workThreadHandler.join(); + } +} } // namespace MiscServices } // namespace OHOS From d4288aa44528745bbd674358fac5a98710c13314 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Mon, 21 Nov 2022 14:47:17 +0800 Subject: [PATCH 063/112] modify code Signed-off-by: zhaolinglan --- .../adapter/keyboard/input_event_callback.h | 54 +++++++++++++++---- services/adapter/keyboard/keyboard_event.cpp | 1 + 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/services/adapter/keyboard/input_event_callback.h b/services/adapter/keyboard/input_event_callback.h index ef6a9322..ea714f20 100644 --- a/services/adapter/keyboard/input_event_callback.h +++ b/services/adapter/keyboard/input_event_callback.h @@ -33,10 +33,13 @@ public: virtual void OnInputEvent(std::shared_ptr pointerEvent) const; virtual void OnInputEvent(std::shared_ptr axisEvent) const; void SetKeyHandle(KeyHandle handle); + void InitStatusMap(); private: KeyHandle keyHandler_ = nullptr; - std::map, CombineKeyCode> keyMap_ = { + std::mutex statusMapLock_; + static std::map keyStatusMap_; + std::map, CombineKeyCode> combinedKeyMap_ = { { { MMI::KeyEvent::KEYCODE_CAPS_LOCK }, CombineKeyCode::COMBINE_KEYCODE_CAPS }, { { MMI::KeyEvent::KEYCODE_SHIFT_LEFT }, CombineKeyCode::COMBINE_KEYCODE_SHIFT }, { { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT }, CombineKeyCode::COMBINE_KEYCODE_SHIFT }, @@ -53,23 +56,40 @@ private: void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) const { - IMSA_HILOGI("InputEventCallback::OnInputEvent"); - IMSA_HILOGI("KeyCode: %{public}d, KeyAction: %{public}d", keyEvent->GetKeyCode(), keyEvent->GetKeyAction()); - auto pressKeys = keyEvent->GetPressedKeys(); - for (const auto &key : pressKeys) { - IMSA_HILOGI("pressedkey: %{public}d", key); + IMSA_HILOGI("OnInputEvent"); + std::lock_guard lock(statusMapLock_); + auto keyCode = keyEvent->GetKeyCode(); + auto keyAction = keyEvent->GetKeyAction(); + + if (keyStatusMap_.find(keyCode) == keyStatusMap_.end() || keyAction == MMI::KeyEvent::KEY_ACTION_UNKNOWN) { + IMSA_HILOGD("keycode undefined"); + return; } - auto it = keyMap_.find(pressKeys); - if (it == keyMap_.end()) { - IMSA_HILOGD("keyEvent undefined"); + if (keyAction == MMI::KeyEvent::KEY_ACTION_DOWN) { + IMSA_HILOGD("key %{public}d pressed down", keyCode); + keyStatusMap_[keyCode] = true; + return; + } + + // keyUp event occurs + std::vector pressedKeys; + for (auto &key : keyStatusMap_) { + if (key.second) { + pressedKeys.push_back(key.first); + } + } + auto combinedKey = combinedKeyMap_.find(pressedKeys); + if (combinedKey == combinedKeyMap_.end()) { + IMSA_HILOGD("undefined combinedkey"); + keyStatusMap_[keyCode] = false; return; } if (keyHandler_ == nullptr) { IMSA_HILOGE("keyHandler_ is nullptr"); return; } - int32_t ret = keyHandler_(it->second); - IMSA_HILOGI("handle keyevent %{public}s", ret == ErrorCode::NO_ERROR ? "success" : "failed"); + int32_t ret = keyHandler_(combinedKey->second); + IMSA_HILOGI("handle keyevent ret: %{public}d", ret); } void InputEventCallback::OnInputEvent(std::shared_ptr pointerEvent) const @@ -85,6 +105,18 @@ void InputEventCallback::SetKeyHandle(KeyHandle handle) IMSA_HILOGI("set key handle"); keyHandler_ = std::move(handle); } + +void InputEventCallback::InitStatusMap() +{ + std::lock_guard lock(statusMapLock_); + keyStatusMap_ = { + { MMI::KeyEvent::KEYCODE_CAPS_LOCK, false }, + { MMI::KeyEvent::KEYCODE_SHIFT_LEFT, false }, + { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, false }, + { MMI::KeyEvent::KEYCODE_CTRL_LEFT, false }, + { MMI::KeyEvent::KEYCODE_CTRL_RIGHT, false }, + }; +} } // namespace MiscServices } // namespace OHOS diff --git a/services/adapter/keyboard/keyboard_event.cpp b/services/adapter/keyboard/keyboard_event.cpp index 4b29adda..3fd3fabb 100644 --- a/services/adapter/keyboard/keyboard_event.cpp +++ b/services/adapter/keyboard/keyboard_event.cpp @@ -38,6 +38,7 @@ int32_t KeyboardEvent::AddKeyEventMonitor(KeyHandle handle) IMSA_HILOGI("KeyboardEvent::AddKeyEventMonitor"); std::shared_ptr callback = std::make_shared(); callback->SetKeyHandle(handle); + callback->InitStatusMap(); int32_t monitorId = InputManager::GetInstance()->AddMonitor(std::static_pointer_cast(callback)); if (monitorId < 0) { From 27993563f551bb2de5549e0d4cc66f8e7ab94832 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Mon, 21 Nov 2022 15:15:35 +0800 Subject: [PATCH 064/112] modify code Signed-off-by: zhaolinglan --- services/adapter/keyboard/input_event_callback.h | 1 + 1 file changed, 1 insertion(+) diff --git a/services/adapter/keyboard/input_event_callback.h b/services/adapter/keyboard/input_event_callback.h index ea714f20..7d465082 100644 --- a/services/adapter/keyboard/input_event_callback.h +++ b/services/adapter/keyboard/input_event_callback.h @@ -20,6 +20,7 @@ #include #include +#include #include #include "global.h" From 5731db5ea6eb8d2d37e8c156ea451c97f9be28ce Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Mon, 21 Nov 2022 15:26:20 +0800 Subject: [PATCH 065/112] modify code Signed-off-by: zhaolinglan --- services/include/peruser_session.h | 1 + services/src/peruser_session.cpp | 30 +++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index ed29d5b9..9dfd97e7 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -183,6 +183,7 @@ private: void ClearImeData(uint32_t index); void SetCurrentClient(sptr client); sptr GetCurrentClient(); + int32_t SetClientState(bool state); std::mutex propertyLock_; SubProperty currentSubProperty; diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 7beb5dc2..a6525e99 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -507,6 +507,7 @@ namespace MiscServices { void PerUserSession::OnClientDied(sptr remote) { IMSA_HILOGI("PerUserSession::OnClientDied Start...[%{public}d]\n", userId_); + SetClientState(false); sptr client = GetCurrentClient(); if (client == nullptr) { IMSA_HILOGE("current client is nullptr"); @@ -1081,11 +1082,16 @@ namespace MiscServices { int32_t PerUserSession::OnReleaseInput(sptr client) { IMSA_HILOGI("PerUserSession::OnReleaseInput Start\n"); - if (imsCore[0] == nullptr) { - return ErrorCode::ERROR_IME_NOT_AVAILABLE; + int ret = SetClientState(false); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("failed to set client state, ret %{public}d", ret); + return ret; + } + ret = HideKeyboard(client); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("failed to hide keyboard ret %{public}d", ret); + return ret; } - imsCore[0]->SetClientState(false); - HideKeyboard(client); RemoveClient(client->AsObject()); IMSA_HILOGI("PerUserSession::OnReleaseInput End...[%{public}d]\n", userId_); return ErrorCode::NO_ERROR; @@ -1099,10 +1105,11 @@ namespace MiscServices { int32_t PerUserSession::OnStartInput(sptr client, bool isShowKeyboard) { IMSA_HILOGI("PerUserSession::OnStartInput"); - if (imsCore[0] == nullptr) { - return ErrorCode::ERROR_IME_NOT_AVAILABLE; + int32_t ret = SetClientState(true); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("failed to set client state"); + return ret; } - imsCore[0]->SetClientState(true); return ShowKeyboard(client, isShowKeyboard); } @@ -1265,5 +1272,14 @@ namespace MiscServices { std::lock_guard lock(propertyLock_); currentSubProperty = subProperty; } + + int32_t PerUserSession::SetClientState(bool state) + { + IMSA_HILOGI("set client state: %{public}s", state ? "true" : "false"); + if (imsCore[0] == nullptr) { + return ErrorCode::ERROR_IME_NOT_AVAILABLE; + } + imsCore[0]->SetClientState(state); + } } // namespace MiscServices } // namespace OHOS From bd8d776857c8d70aef8bf867592fb18ec8c0d882 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Mon, 21 Nov 2022 16:01:04 +0800 Subject: [PATCH 066/112] modify code Signed-off-by: zhaolinglan --- services/src/peruser_session.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index a6525e99..f63d2ba5 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -1280,6 +1280,7 @@ namespace MiscServices { return ErrorCode::ERROR_IME_NOT_AVAILABLE; } imsCore[0]->SetClientState(state); + return ErrorCode::NO_ERROR; } } // namespace MiscServices } // namespace OHOS From 6a58ac4029af1f7103b01142261a9b64e1d34ec8 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Mon, 21 Nov 2022 17:19:06 +0800 Subject: [PATCH 067/112] modify code Signed-off-by: zhaolinglan --- .../adapter/keyboard/input_event_callback.h | 34 ++++++++----------- services/adapter/keyboard/keyboard_event.cpp | 1 - 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/services/adapter/keyboard/input_event_callback.h b/services/adapter/keyboard/input_event_callback.h index 7d465082..64ca4ea4 100644 --- a/services/adapter/keyboard/input_event_callback.h +++ b/services/adapter/keyboard/input_event_callback.h @@ -34,11 +34,10 @@ public: virtual void OnInputEvent(std::shared_ptr pointerEvent) const; virtual void OnInputEvent(std::shared_ptr axisEvent) const; void SetKeyHandle(KeyHandle handle); - void InitStatusMap(); private: KeyHandle keyHandler_ = nullptr; - std::mutex statusMapLock_; + static std::mutex statusMapLock_; static std::map keyStatusMap_; std::map, CombineKeyCode> combinedKeyMap_ = { { { MMI::KeyEvent::KEYCODE_CAPS_LOCK }, CombineKeyCode::COMBINE_KEYCODE_CAPS }, @@ -55,15 +54,24 @@ private: }; }; +std::mutex InputEventCallback::statusMapLock_; +std::map InputEventCallback::keyStatusMap_ = { + { MMI::KeyEvent::KEYCODE_CAPS_LOCK, false }, + { MMI::KeyEvent::KEYCODE_SHIFT_LEFT, false }, + { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, false }, + { MMI::KeyEvent::KEYCODE_CTRL_LEFT, false }, + { MMI::KeyEvent::KEYCODE_CTRL_RIGHT, false }, +}; + void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) const { - IMSA_HILOGI("OnInputEvent"); - std::lock_guard lock(statusMapLock_); auto keyCode = keyEvent->GetKeyCode(); auto keyAction = keyEvent->GetKeyAction(); + IMSA_HILOGD("OnInputEvent keyCode: %{public}d, keyAction: %{public}d", keyCode, keyAction); + std::lock_guard lock(statusMapLock_); if (keyStatusMap_.find(keyCode) == keyStatusMap_.end() || keyAction == MMI::KeyEvent::KEY_ACTION_UNKNOWN) { - IMSA_HILOGD("keycode undefined"); + IMSA_HILOGD("keyevent undefined"); return; } if (keyAction == MMI::KeyEvent::KEY_ACTION_DOWN) { @@ -72,7 +80,7 @@ void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) c return; } - // keyUp event occurs + IMSA_HILOGI("key %{public}d pressed up", keyCode); std::vector pressedKeys; for (auto &key : keyStatusMap_) { if (key.second) { @@ -103,21 +111,9 @@ void InputEventCallback::OnInputEvent(std::shared_ptr axisEvent) void InputEventCallback::SetKeyHandle(KeyHandle handle) { - IMSA_HILOGI("set key handle"); + IMSA_HILOGD("set key handle"); keyHandler_ = std::move(handle); } - -void InputEventCallback::InitStatusMap() -{ - std::lock_guard lock(statusMapLock_); - keyStatusMap_ = { - { MMI::KeyEvent::KEYCODE_CAPS_LOCK, false }, - { MMI::KeyEvent::KEYCODE_SHIFT_LEFT, false }, - { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, false }, - { MMI::KeyEvent::KEYCODE_CTRL_LEFT, false }, - { MMI::KeyEvent::KEYCODE_CTRL_RIGHT, false }, - }; -} } // namespace MiscServices } // namespace OHOS diff --git a/services/adapter/keyboard/keyboard_event.cpp b/services/adapter/keyboard/keyboard_event.cpp index 3fd3fabb..4b29adda 100644 --- a/services/adapter/keyboard/keyboard_event.cpp +++ b/services/adapter/keyboard/keyboard_event.cpp @@ -38,7 +38,6 @@ int32_t KeyboardEvent::AddKeyEventMonitor(KeyHandle handle) IMSA_HILOGI("KeyboardEvent::AddKeyEventMonitor"); std::shared_ptr callback = std::make_shared(); callback->SetKeyHandle(handle); - callback->InitStatusMap(); int32_t monitorId = InputManager::GetInstance()->AddMonitor(std::static_pointer_cast(callback)); if (monitorId < 0) { From 48e7f765935322c5ae9a8eb444c43603c8cf4910 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Mon, 21 Nov 2022 19:56:59 +0800 Subject: [PATCH 068/112] Signed-off-by: ma-shaoyin Changes to be committed: --- test/fuzztest/inputclientstub_fuzzer/inputclientstub_fuzzer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test/fuzztest/inputclientstub_fuzzer/inputclientstub_fuzzer.cpp b/test/fuzztest/inputclientstub_fuzzer/inputclientstub_fuzzer.cpp index 336fdd2f..db765c13 100644 --- a/test/fuzztest/inputclientstub_fuzzer/inputclientstub_fuzzer.cpp +++ b/test/fuzztest/inputclientstub_fuzzer/inputclientstub_fuzzer.cpp @@ -98,7 +98,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) } /* Run your code on data */ auto fuzzedInt32 = static_cast(size); - std::string fuzzedString(reinterpret_cast(data), size); OHOS::FuzzInputClientStub(data, size); OHOS::TextOnInputReady(); From 56a011fd94e248cd9c907d6a90e6bc45dfd06307 Mon Sep 17 00:00:00 2001 From: Chao Liu Date: Mon, 21 Nov 2022 20:53:18 +0800 Subject: [PATCH 069/112] Fix warning find in code review make euqlity operation js way and fix var/let usage Signed-off-by: Chao Liu --- .../inputmethod_extension_context.js | 2 +- test/js/InputMethodTest.test.js | 20 ++++---- test/unitest/src/InputMethodTest.js | 48 +++++++++---------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/interfaces/kits/js/napi/inputmethod_extension_context/inputmethod_extension_context.js b/interfaces/kits/js/napi/inputmethod_extension_context/inputmethod_extension_context.js index 1b27a1b7..e50ea058 100644 --- a/interfaces/kits/js/napi/inputmethod_extension_context/inputmethod_extension_context.js +++ b/interfaces/kits/js/napi/inputmethod_extension_context/inputmethod_extension_context.js @@ -13,7 +13,7 @@ * limitations under the License. */ -var ExtensionContext = requireNapi("application.ExtensionContext") +const ExtensionContext = requireNapi("application.ExtensionContext"); class InputMethodExtensionContext extends ExtensionContext { constructor(obj) { diff --git a/test/js/InputMethodTest.test.js b/test/js/InputMethodTest.test.js index edc0d79e..09de0ae1 100644 --- a/test/js/InputMethodTest.test.js +++ b/test/js/InputMethodTest.test.js @@ -28,7 +28,7 @@ describe('appInfoTest_input_2', function () { console.info("inputmethoh_test_001 result:" + JSON.stringify(inputMethodSetting)); inputMethodSetting.listInputMethod((err, data) => { console.info("inputmethoh_test_001 listInputMethod result" + JSON.stringify(data)); - expect(err==undefined).assertTrue(); + expect(err===undefined).assertTrue(); }); done(); }); @@ -86,7 +86,7 @@ describe('appInfoTest_input_2', function () { console.info("inputmethod_test_displayOptionalInputMethod_001 result:" + JSON.stringify(inputMethodSetting)); inputMethodSetting.displayOptionalInputMethod((err) => { console.info("inputmethod_test_displayOptionalInputMethod_001 err:" + err); - expect(err==undefined).assertTrue(); + expect(err===undefined).assertTrue(); }); done(); }); @@ -139,8 +139,8 @@ describe('appInfoTest_input_2', function () { inputMethodCtrl.stopInput((err,res) => { console.info("inputmethod_test_stopInput_001 stopInput result" + res); console.info("inputmethod_test_stopInput_001 stopInput result" + err); - expect(res == true).assertTrue(); - expect(err==undefined).assertTrue(); + expect(res === true).assertTrue(); + expect(err===undefined).assertTrue(); }); done(); }); @@ -171,7 +171,7 @@ describe('appInfoTest_input_2', function () { console.info("inputmethod_test_stopInput_003 result:" + JSON.stringify(inputMethodCtrl)); await inputMethodCtrl.stopInput().then((res)=>{ console.info('inputmethod_test_stopInput_003 stopInput result' + res); - expect(res == true).assertTrue(); + expect(res === true).assertTrue(); }).catch((err) => { console.info('inputmethod_test_stopInput_003 stopInput err ' + err); expect(null).assertFail(); @@ -233,7 +233,7 @@ describe('appInfoTest_input_2', function () { expect().assertFail() } console.info("inputmethod_test_switchInputMethod_002 data:" + data) - expect(data == true).assertTrue(); + expect(data === true).assertTrue(); }); done(); }); @@ -288,7 +288,7 @@ describe('appInfoTest_input_2', function () { expect().assertFail() } console.info("inputmethod_test_switchCurrentInputMethodSubtype_002 data:" + data) - expect(data == true).assertTrue(); + expect(data === true).assertTrue(); }); }); @@ -333,7 +333,7 @@ describe('appInfoTest_input_2', function () { expect().assertFail() } console.info("inputmethod_test_switchCurrentInputMethodAndSubtype_002 data:" + data) - expect(data == true).assertTrue(); + expect(data === true).assertTrue(); }); }); @@ -354,7 +354,7 @@ describe('appInfoTest_input_2', function () { console.info("inputmethod_test_ListInputMethodSubtype_001 result:" + JSON.stringify(inputMethodSetting)); inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err, data) => { console.info("inputmethod_test_ListInputMethodSubtype_001 result" + JSON.stringify(data)); - expect(err==undefined).assertTrue(); + expect(err===undefined).assertTrue(); }); done(); }); @@ -395,7 +395,7 @@ describe('appInfoTest_input_2', function () { console.info("inputmethod_test_ListCurrentInputMethodSubtype_001 result:" + JSON.stringify(inputMethodSetting)); inputMethodSetting.listCurrentInputMethodSubtype((err, data) => { console.info("inputmethod_test_ListCurrentInputMethodSubtype_001 result" + JSON.stringify(data)); - expect(err==undefined).assertTrue(); + expect(err===undefined).assertTrue(); }); done(); }); diff --git a/test/unitest/src/InputMethodTest.js b/test/unitest/src/InputMethodTest.js index d576cb28..221e066d 100644 --- a/test/unitest/src/InputMethodTest.js +++ b/test/unitest/src/InputMethodTest.js @@ -51,7 +51,7 @@ describe("InputMethodTest", function () { let MAX_NUM = 128; let inputMethodSetting = inputMethod.MAX_TYPE_NUM; console.info("inputmethod_test_001 result:" + inputMethodSetting); - expect(inputMethodSetting == MAX_NUM).assertTrue(); + expect(inputMethodSetting === MAX_NUM).assertTrue(); console.info("************* inputmethod_test_MAX_TYPE_NUM_001 Test end*************"); done(); }); @@ -65,7 +65,7 @@ describe("InputMethodTest", function () { it('inputmethod_test_getInputMethodController_001', 0, async function (done) { console.info("************* inputmethod_test_getInputMethodController_001 Test start*************"); let controller = inputMethod.getInputMethodController(); - expect(controller != undefined).assertTrue(); + expect(controller !== undefined).assertTrue(); console.info("************* inputmethod_test_getInputMethodController_001 Test end*************"); done(); }); @@ -79,7 +79,7 @@ describe("InputMethodTest", function () { it('inputmethod_test_getController_001', 0, async function (done) { console.info("************* inputmethod_test_getController_001 Test start*************"); let controller = inputMethod.getController(); - expect(controller != undefined).assertTrue(); + expect(controller !== undefined).assertTrue(); console.info("************* inputmethod_test_getController_001 Test end*************"); done(); }); @@ -93,7 +93,7 @@ describe("InputMethodTest", function () { it('inputmethod_test_getInputMethodSetting_001', 0, async function (done) { console.info("************* inputmethod_test_getInputMethodSetting_001 Test start*************"); let setting = inputMethod.getInputMethodSetting(); - expect(setting != undefined).assertTrue(); + expect(setting !== undefined).assertTrue(); console.info("************* inputmethod_test_getInputMethodSetting_001 Test end*************"); done(); }); @@ -107,7 +107,7 @@ describe("InputMethodTest", function () { it('inputmethod_test_getSetting_001', 0, async function (done) { console.info("************* inputmethod_test_getSetting_001 Test start*************"); let setting = inputMethod.getSetting(); - expect(setting != undefined).assertTrue(); + expect(setting !== undefined).assertTrue(); console.info("************* inputmethod_test_getSetting_001 Test end*************"); done(); }); @@ -145,7 +145,7 @@ describe("InputMethodTest", function () { } inputMethod.switchInputMethod(inputMethodProperty).then(data => { console.info("inputmethod_test_switchInputMethod_001 data:" + data) - expect(data == true).assertTrue(); + expect(data === true).assertTrue(); }).catch( err=> { console.info("inputmethod_test_switchInputMethod_001 err:" + JSON.stringify(err.message)) }) @@ -164,7 +164,7 @@ describe("InputMethodTest", function () { let property = inputMethod.getCurrentInputMethod(); console.info("getCurrentInputMethod_test_001 result property:" + property.packageName); console.info("getCurrentInputMethod_test_001 result property:" + property.methodId); - expect(property != undefined).assertTrue(); + expect(property !== undefined).assertTrue(); console.info("************* inputmethod_test_getCurrentInputMethod_001 Test end*************"); done(); }); @@ -185,7 +185,7 @@ describe("InputMethodTest", function () { expect().assertFail(); } console.info("listInputMethod_001 listInputMethod result" + JSON.stringify(data)); - expect(err == undefined).assertTrue(); + expect(err === undefined).assertTrue(); }); console.info("************* inputmethod_test_listInputMethod_001 Test end*************"); done(); @@ -249,7 +249,7 @@ describe("InputMethodTest", function () { expect().assertFail(); } console.info("inputmethoh_test_004 listInputMethod result" + JSON.stringify(data)); - expect(err == undefined).assertTrue(); + expect(err === undefined).assertTrue(); }); console.info("************* inputmethod_test_listInputMethod_004 Test end*************"); done(); @@ -271,7 +271,7 @@ describe("InputMethodTest", function () { } inputMethod.switchCurrentInputMethodSubtype(InputMethodSubtype).then(data => { console.info("inputmethod_test_switchCurrentInputMethodSubtype_001 data:" + data) - expect(data == true).assertTrue(); + expect(data === true).assertTrue(); }).catch( err=> { console.info("inputmethod_test_switchCurrentInputMethodSubtype_001 err:" + JSON.stringify(err.message)) }) @@ -300,7 +300,7 @@ describe("InputMethodTest", function () { expect().assertFail(); } console.info("inputmethod_test_switchCurrentInputMethodSubtype data:" + data) - expect(data == true).assertTrue(); + expect(data === true).assertTrue(); }); console.info("************* inputmethod_test_switchCurrentInputMethodSubtype Test end*************"); done(); @@ -327,7 +327,7 @@ describe("InputMethodTest", function () { } inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, InputMethodSubtype).then(data => { console.info("inputmethod_test_switchCurrentInputMethodAndSubtype_001 data:" + data) - expect(data == true).assertTrue(); + expect(data === true).assertTrue(); }).catch( err=> { console.info("inputmethod_test_switchCurrentInputMethodAndSubtype_001 err:" + JSON.stringify(err.message)) }) @@ -360,7 +360,7 @@ describe("InputMethodTest", function () { expect().assertFail(); } console.info("inputmethod_test_switchCurrentInputMethodAndSubtype data:" + data) - expect(data == true).assertTrue(); + expect(data === true).assertTrue(); }); console.info("************* inputmethod_test_switchCurrentInputMethodAndSubtype Test end*************"); done(); @@ -427,7 +427,7 @@ describe("InputMethodTest", function () { it('inputmethod_test_getCurrentInputMethodSubtype_001', 0, async function (done) { console.info("************* inputmethod_test_getCurrentInputMethodSubtype_001 Test start*************"); let property = inputMethod.getCurrentInputMethodSubtype(); - expect(property != undefined).assertTrue(); + expect(property !== undefined).assertTrue(); console.info("************* inputmethod_test_getCurrentInputMethodSubtype_001 Test end*************"); done(); }); @@ -448,7 +448,7 @@ describe("InputMethodTest", function () { expect().assertFail(); } console.info("listCurrentInputMethodSubtype_001 listCurrentInputMethodSubtype result" + JSON.stringify(data)); - expect(err == undefined).assertTrue(); + expect(err === undefined).assertTrue(); }); console.info("************* inputmethod_test_listCurrentInputMethodSubtype_001 Test end*************"); done(); @@ -512,7 +512,7 @@ describe("InputMethodTest", function () { expect().assertFail(); } console.info("inputmethod_test_getInputMethods_002 getInputMethods result" + JSON.stringify(data)); - expect(err == undefined).assertTrue(); + expect(err === undefined).assertTrue(); }); console.info("************* inputmethod_test_getInputMethods_002 Test end*************"); done(); @@ -530,7 +530,7 @@ describe("InputMethodTest", function () { console.info("inputmethod_test_displayOptionalInputMethod_001 result:" + JSON.stringify(inputMethodSetting)); inputMethodSetting.displayOptionalInputMethod((err) => { console.info("inputmethod_test_displayOptionalInputMethod_001 err:" + JSON.stringify(err.message)); - expect(err == undefined).assertTrue(); + expect(err === undefined).assertTrue(); }); console.info("************* inputmethod_test_displayOptionalInputMethod_001 Test end*************"); done(); @@ -569,7 +569,7 @@ describe("InputMethodTest", function () { console.info("inputmethod_test_showOptionalInputMethods_001 result:" + JSON.stringify(inputMethodSetting)); inputMethodSetting.showOptionalInputMethods((err) => { console.info("inputmethod_test_showOptionalInputMethods_001 err:" + JSON.stringify(err.message)); - expect(err == undefined).assertTrue(); + expect(err === undefined).assertTrue(); }); console.info("************* inputmethod_test_showOptionalInputMethods_001 Test end*************"); done(); @@ -606,7 +606,7 @@ describe("InputMethodTest", function () { console.info("************* inputmethod_test_showSoftKeyboard_001 Test start*************"); let inputMethodCtrl = inputMethod.getInputMethodController() inputMethodCtrl.showSoftKeyboard((err)=>{ - if (err == undefined) { + if (err === undefined) { console.info("showSoftKeyboard callbace success" ); } else { console.info('showSoftKeyboard callbace failed : ' + JSON.stringify(err.message)); @@ -646,7 +646,7 @@ describe("InputMethodTest", function () { console.info("************* inputmethod_test_hideSoftKeyboard_001 Test start*************"); let inputMethodCtrl = inputMethod.getInputMethodController() inputMethodCtrl.hideSoftKeyboard((data)=>{ - if(data == undefined){ + if(data === undefined){ console.info("hideSoftKeyboard callbace success" ); }else{ console.info('hideSoftKeyboard callbace failed : ' + JSON.stringify(err.message)) @@ -693,7 +693,7 @@ describe("InputMethodTest", function () { return; } console.info("inputmethod_test_stopInputSession_001 callback success" ); - expect(res == true).assertTrue(); + expect(res === true).assertTrue(); }); console.info("************* inputmethod_test_stopInputSession_001 Test end*************"); done(); @@ -1153,7 +1153,7 @@ describe("InputMethodTest", function () { expect(kbController == null).assertEqual(true); } else { kbController.hideKeyboard((err) => { - if (err == undefined) { + if (err === undefined) { console.info("inputMethodEngine_test_039 hideKeyboard success."); } else { console.info('inputMethodEngine_test_039 hideKeyboard callbace failed : ' + JSON.stringify(err.message)); @@ -1210,7 +1210,7 @@ describe("InputMethodTest", function () { it('inputMethodEngine_test_043', 0, async function (done) { let keyType = inputMethodEngine.WINDOW_TYPE_INPUT_METHOD_FLOAT; console.error("inputMethodEngine_test_043 result:" + keyType); - expect(keyType == 2105).assertTrue(); + expect(keyType === 2105).assertTrue(); done(); }); @@ -1273,7 +1273,7 @@ describe("InputMethodTest", function () { expect(kbController == null).assertEqual(true); } else { kbController.hide((err) => { - if (err == undefined) { + if (err === undefined) { console.info("inputMethodEngine_test_048 hide success."); } else { console.info('inputMethodEngine_test_048 hide callbace failed : ' + JSON.stringify(err.message)); From b2df284d15f4a4ff30c2f2a0edc6af4065dbb20d Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Mon, 21 Nov 2022 21:11:22 +0800 Subject: [PATCH 070/112] modify code Signed-off-by: zhaolinglan --- services/adapter/keyboard/input_event_callback.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/adapter/keyboard/input_event_callback.h b/services/adapter/keyboard/input_event_callback.h index 64ca4ea4..8b4074bf 100644 --- a/services/adapter/keyboard/input_event_callback.h +++ b/services/adapter/keyboard/input_event_callback.h @@ -84,7 +84,9 @@ void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) c std::vector pressedKeys; for (auto &key : keyStatusMap_) { if (key.second) { + IMSA_HILOGD("key %{public}d is pressed", key.first); pressedKeys.push_back(key.first); + key.second = false; } } auto combinedKey = combinedKeyMap_.find(pressedKeys); From c80dc5faaaed36d886131b2cdacf1ee435895537 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Mon, 21 Nov 2022 21:12:14 +0800 Subject: [PATCH 071/112] modify code Signed-off-by: zhaolinglan --- services/adapter/keyboard/input_event_callback.h | 1 - 1 file changed, 1 deletion(-) diff --git a/services/adapter/keyboard/input_event_callback.h b/services/adapter/keyboard/input_event_callback.h index 8b4074bf..be7ad0aa 100644 --- a/services/adapter/keyboard/input_event_callback.h +++ b/services/adapter/keyboard/input_event_callback.h @@ -92,7 +92,6 @@ void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) c auto combinedKey = combinedKeyMap_.find(pressedKeys); if (combinedKey == combinedKeyMap_.end()) { IMSA_HILOGD("undefined combinedkey"); - keyStatusMap_[keyCode] = false; return; } if (keyHandler_ == nullptr) { From c64d71fa2db699a4ce87b01c69726da8f4b900c4 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Mon, 21 Nov 2022 21:36:36 +0800 Subject: [PATCH 072/112] modify code Signed-off-by: zhaolinglan --- services/adapter/keyboard/input_event_callback.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/adapter/keyboard/input_event_callback.h b/services/adapter/keyboard/input_event_callback.h index be7ad0aa..19473844 100644 --- a/services/adapter/keyboard/input_event_callback.h +++ b/services/adapter/keyboard/input_event_callback.h @@ -57,17 +57,17 @@ private: std::mutex InputEventCallback::statusMapLock_; std::map InputEventCallback::keyStatusMap_ = { { MMI::KeyEvent::KEYCODE_CAPS_LOCK, false }, - { MMI::KeyEvent::KEYCODE_SHIFT_LEFT, false }, - { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, false }, { MMI::KeyEvent::KEYCODE_CTRL_LEFT, false }, { MMI::KeyEvent::KEYCODE_CTRL_RIGHT, false }, + { MMI::KeyEvent::KEYCODE_SHIFT_LEFT, false }, + { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, false }, }; void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) const { auto keyCode = keyEvent->GetKeyCode(); auto keyAction = keyEvent->GetKeyAction(); - IMSA_HILOGD("OnInputEvent keyCode: %{public}d, keyAction: %{public}d", keyCode, keyAction); + IMSA_HILOGD("keyCode: %{public}d, keyAction: %{public}d", keyCode, keyAction); std::lock_guard lock(statusMapLock_); if (keyStatusMap_.find(keyCode) == keyStatusMap_.end() || keyAction == MMI::KeyEvent::KEY_ACTION_UNKNOWN) { @@ -99,7 +99,7 @@ void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) c return; } int32_t ret = keyHandler_(combinedKey->second); - IMSA_HILOGI("handle keyevent ret: %{public}d", ret); + IMSA_HILOGI("handle keyevent ret: %{public}s", ErrorCode::ToString(ret)); } void InputEventCallback::OnInputEvent(std::shared_ptr pointerEvent) const From e03e32862d4e944e1ef42e945208e4bf5b91ff7c Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Mon, 21 Nov 2022 21:55:52 +0800 Subject: [PATCH 073/112] modify code Signed-off-by: zhaolinglan --- services/adapter/keyboard/input_event_callback.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/services/adapter/keyboard/input_event_callback.h b/services/adapter/keyboard/input_event_callback.h index 19473844..ac2dfb2c 100644 --- a/services/adapter/keyboard/input_event_callback.h +++ b/services/adapter/keyboard/input_event_callback.h @@ -43,13 +43,13 @@ private: { { MMI::KeyEvent::KEYCODE_CAPS_LOCK }, CombineKeyCode::COMBINE_KEYCODE_CAPS }, { { MMI::KeyEvent::KEYCODE_SHIFT_LEFT }, CombineKeyCode::COMBINE_KEYCODE_SHIFT }, { { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT }, CombineKeyCode::COMBINE_KEYCODE_SHIFT }, - { { MMI::KeyEvent::KEYCODE_CTRL_LEFT, MMI::KeyEvent::KEYCODE_SHIFT_LEFT }, + { { MMI::KeyEvent::KEYCODE_SHIFT_LEFT, MMI::KeyEvent::KEYCODE_CTRL_LEFT }, CombineKeyCode::COMBINE_KEYCODE_CTRL_SHIFT }, - { { MMI::KeyEvent::KEYCODE_CTRL_LEFT, MMI::KeyEvent::KEYCODE_SHIFT_RIGHT }, + { { MMI::KeyEvent::KEYCODE_SHIFT_LEFT, MMI::KeyEvent::KEYCODE_CTRL_RIGHT }, CombineKeyCode::COMBINE_KEYCODE_CTRL_SHIFT }, - { { MMI::KeyEvent::KEYCODE_CTRL_RIGHT, MMI::KeyEvent::KEYCODE_SHIFT_LEFT }, + { { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, MMI::KeyEvent::KEYCODE_CTRL_LEFT }, CombineKeyCode::COMBINE_KEYCODE_CTRL_SHIFT }, - { { MMI::KeyEvent::KEYCODE_CTRL_RIGHT, MMI::KeyEvent::KEYCODE_SHIFT_RIGHT }, + { { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, MMI::KeyEvent::KEYCODE_CTRL_RIGHT }, CombineKeyCode::COMBINE_KEYCODE_CTRL_SHIFT }, }; }; @@ -84,7 +84,6 @@ void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) c std::vector pressedKeys; for (auto &key : keyStatusMap_) { if (key.second) { - IMSA_HILOGD("key %{public}d is pressed", key.first); pressedKeys.push_back(key.first); key.second = false; } @@ -99,7 +98,7 @@ void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) c return; } int32_t ret = keyHandler_(combinedKey->second); - IMSA_HILOGI("handle keyevent ret: %{public}s", ErrorCode::ToString(ret)); + IMSA_HILOGI("handle keyevent ret: %{public}d", ret); } void InputEventCallback::OnInputEvent(std::shared_ptr pointerEvent) const From 9f0ce0c34a8ebccd5bdfb1056b839411445e4f4f Mon Sep 17 00:00:00 2001 From: Chao Liu Date: Mon, 21 Nov 2022 22:12:56 +0800 Subject: [PATCH 074/112] Fix typo in code review of imf repo Signed-off-by: Chao Liu --- OAT.xml | 8 +++---- README_zh.md | 2 +- .../include/input_method_ability.h | 4 ++-- .../src/input_method_ability.cpp | 24 +++++++++---------- .../js_inputmethod_extension_context.h | 6 ++--- .../src/js_inputmethod_extension_context.cpp | 8 +++---- .../inputmethod_extension_ability_module.cpp | 2 +- .../inputmethodability/js_callback_object.h | 6 ++--- .../js_input_method_engine_setting.cpp | 6 ++--- .../js_keyboard_delegate_setting.cpp | 4 ++-- .../js_get_input_method_controller.h | 6 ++--- .../js_get_input_method_setting.cpp | 4 ++-- .../js/napi/inputmethodclient/js_utils.cpp | 4 ++-- services/dfx/include/inputmethod_dump.h | 2 +- services/dfx/include/inputmethod_sysevent.h | 2 +- services/dfx/src/inputmethod_dump.cpp | 10 ++++---- services/dfx/src/inputmethod_sysevent.cpp | 6 ++--- .../dialog/entry/src/main/ets/pages/index.ets | 8 +++---- services/src/peruser_setting.cpp | 2 +- .../controlchannelstub_fuzzer.cpp | 8 +++---- .../controlchannelstub_fuzzer.h | 6 ++--- test/js/InputMethodTest.test.js | 12 +++++----- test/unitest/src/InputMethodTest.js | 22 ++++++++--------- unitest/src/input_method_dfx_test.cpp | 6 ++--- unitest/src/input_method_switch_test.cpp | 4 ++-- 25 files changed, 86 insertions(+), 86 deletions(-) diff --git a/OAT.xml b/OAT.xml index 2e3e8eb9..83f92a23 100644 --- a/OAT.xml +++ b/OAT.xml @@ -20,9 +20,9 @@ licensefile: tasklist(only for batch mode): 1. task: Define oat check thread, each task will start a new thread. -2. task name: Only an name, no practical effect. -3. task policy: Default policy for projects under this task, this field is required and the specified policy must defined in policylist. -4. task filter: Default filefilter for projects under this task, this field is required and the specified filefilter must defined in filefilterlist. +2. task name: Only a name, no practical effect. +3. task policy: Default policy for projects under this task, this field is required and the specified policy must be defined in policylist. +4. task filter: Default filefilter for projects under this task, this field is required and the specified filefilter must be defined in filefilterlist. 5. task project: Projects to be checked, the path field define the source root dir of the project. @@ -39,7 +39,7 @@ policyList: "filename" is used to check whether the specified file exists in the specified path(support projectroot in default OAT.xml), supported file names: LICENSE, README, README.OpenSource 4. policyitem name: This field is used for define the license, copyright, "*" means match all, the "!" prefix means could not match this value. For example, "!GPL" means can not use GPL license. -5. policyitem path: This field is used for define the source file scope to apply this policyitem, the "!" prefix means exclude the files. For example, "!.*/lib/.*" means files in lib dir will be exclude while process this policyitem. +5. policyitem path: This field is used for define the source file scope to apply this policyitem, the "!" prefix means exclude the files. For example, "!.*/lib/.*" means files in lib dir will be excluded while process this policyitem. 6. policyitem rule and group: These two fields are used together to merge policy results. "may" policyitems in the same group means any one in this group passed, the result will be passed. 7. policyitem filefilter: Used to bind filefilter which define filter rules. 8. filefilter: Filter rules, the type filename is used to filter file name, the type filepath is used to filter file path. diff --git a/README_zh.md b/README_zh.md index de1489cb..f50bc53b 100644 --- a/README_zh.md +++ b/README_zh.md @@ -583,7 +583,7 @@ keyboardDelegate.off('textChange', (text) => {

hideKeyboard(): Promise<void>;

-

隐藏输入法,使用peomise形式返回结果。参数个数为0,否则抛出异常。

+

隐藏输入法,使用promise形式返回结果。参数个数为0,否则抛出异常。

diff --git a/frameworks/inputmethod_ability/include/input_method_ability.h b/frameworks/inputmethod_ability/include/input_method_ability.h index 11a51d7b..bad9566b 100644 --- a/frameworks/inputmethod_ability/include/input_method_ability.h +++ b/frameworks/inputmethod_ability/include/input_method_ability.h @@ -65,7 +65,7 @@ private: MessageHandler *msgHandler; bool mSupportPhysicalKbd = false; InputAttribute editorAttribute; - int32_t displyId = 0; + int32_t displayId = 0; sptr startInputToken; InputChannel *writeInputChannel; bool stop_; @@ -114,7 +114,7 @@ private: void InitialInputWindow(); void ShowInputWindow(bool isShowKeyboard, const SubProperty &subProperty); - void DissmissInputWindow(); + void DismissInputWindow(); void BindServiceAndClient(); }; diff --git a/frameworks/inputmethod_ability/src/input_method_ability.cpp b/frameworks/inputmethod_ability/src/input_method_ability.cpp index 79601f17..93956630 100644 --- a/frameworks/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/inputmethod_ability/src/input_method_ability.cpp @@ -209,7 +209,7 @@ void InputMethodAbility::OnInitialInput(Message *msg) { IMSA_HILOGI("InputMethodAbility::OnInitialInput"); MessageParcel *data = msg->msgContent_; - displyId = data->ReadInt32(); + displayId = data->ReadInt32(); sptr channelObject = data->ReadRemoteObject(); if (channelObject == nullptr) { IMSA_HILOGI("InputMethodAbility::OnInitialInput channelObject is nullptr"); @@ -269,7 +269,7 @@ void InputMethodAbility::OnShowKeyboard(Message *msg) void InputMethodAbility::OnHideKeyboard(Message *msg) { IMSA_HILOGI("InputMethodAbility::OnHideKeyboard"); - DissmissInputWindow(); + DismissInputWindow(); } void InputMethodAbility::OnStopInput(Message *msg) @@ -377,17 +377,17 @@ void InputMethodAbility::ShowInputWindow(bool isShowKeyboard, const SubProperty channel->SendKeyboardStatus(KEYBOARD_SHOW); } -void InputMethodAbility::DissmissInputWindow() +void InputMethodAbility::DismissInputWindow() { - IMSA_HILOGI("InputMethodAbility::DissmissInputWindow"); + IMSA_HILOGI("InputMethodAbility::DismissInputWindow"); if (!imeListener_) { - IMSA_HILOGI("InputMethodAbility::DissmissInputWindow imeListener_ is nullptr"); + IMSA_HILOGI("InputMethodAbility::DismissInputWindow imeListener_ is nullptr"); return; } imeListener_->OnKeyboardStatus(false); std::shared_ptr channel = GetInputDataChannel(); if (channel == nullptr) { - IMSA_HILOGI("InputMethodAbility::DissmissInputWindow channel is nullptr"); + IMSA_HILOGI("InputMethodAbility::DismissInputWindow channel is nullptr"); return; } channel->SendKeyboardStatus(KEYBOARD_HIDE); @@ -519,12 +519,12 @@ void InputMethodAbility::SetInputDataChannel(sptr &object) { IMSA_HILOGI("run in SetInputDataChannel"); std::lock_guard lock(dataChannelLock_); - std::shared_ptr channalProxy = std::make_shared(object); - if (channalProxy == nullptr) { + std::shared_ptr channelProxy = std::make_shared(object); + if (channelProxy == nullptr) { IMSA_HILOGI("InputMethodAbility::SetInputDataChannel inputDataChannel is nullptr"); return; } - dataChannel_ = channalProxy; + dataChannel_ = channelProxy; } std::shared_ptr InputMethodAbility::GetInputDataChannel() @@ -537,12 +537,12 @@ void InputMethodAbility::SetInputControlChannel(sptr &object) { IMSA_HILOGI("run in SetInputControlChannel"); std::lock_guard lock(controlChannelLock_); - std::shared_ptr channalProxy = std::make_shared(object); - if (channalProxy == nullptr) { + std::shared_ptr channelProxy = std::make_shared(object); + if (channelProxy == nullptr) { IMSA_HILOGI("InputMethodAbility::SetInputControlChannel inputDataChannel is nullptr"); return; } - controlChannel_ = channalProxy; + controlChannel_ = channelProxy; } std::shared_ptr InputMethodAbility::GetInputControlChannel() diff --git a/frameworks/kits/extension/include/js_inputmethod_extension_context.h b/frameworks/kits/extension/include/js_inputmethod_extension_context.h index be74c6da..eea4d3f5 100644 --- a/frameworks/kits/extension/include/js_inputmethod_extension_context.h +++ b/frameworks/kits/extension/include/js_inputmethod_extension_context.h @@ -47,19 +47,19 @@ private: std::unique_ptr jsConnectionObject_ = nullptr; }; -struct ConnecttionKey { +struct ConnectionKey { AAFwk::Want want; int64_t id; }; struct key_compare { - bool operator()(const ConnecttionKey &key1, const ConnecttionKey &key2) const + bool operator()(const ConnectionKey &key1, const ConnectionKey &key2) const { return key1.id < key2.id; } }; -static std::map, key_compare> connects_; +static std::map, key_compare> connects_; static int64_t serialNumber_ = 0; static std::shared_ptr handler_ = nullptr; } // namespace AbilityRuntime diff --git a/frameworks/kits/extension/src/js_inputmethod_extension_context.cpp b/frameworks/kits/extension/src/js_inputmethod_extension_context.cpp index 717fccf2..57e09e24 100644 --- a/frameworks/kits/extension/src/js_inputmethod_extension_context.cpp +++ b/frameworks/kits/extension/src/js_inputmethod_extension_context.cpp @@ -260,7 +260,7 @@ private: sptr connection = new JSInputMethodExtensionConnection(engine); connection->SetJsConnectionObject(info.argv[1]); int64_t connectId = serialNumber_; - ConnecttionKey key; + ConnectionKey key; key.id = serialNumber_; key.want = want; connects_.emplace(key, connection); @@ -316,7 +316,7 @@ private: sptr connection = new JSInputMethodExtensionConnection(engine); connection->SetJsConnectionObject(info.argv[1]); int64_t connectId = serialNumber_; - ConnecttionKey key; + ConnectionKey key; key.id = serialNumber_; key.want = want; connects_.emplace(key, connection); @@ -363,7 +363,7 @@ private: reinterpret_cast(&engine), reinterpret_cast(info.argv[INDEX_ZERO]), &connectId); IMSA_HILOGI("OnDisconnectAbility connection:%{public}d", static_cast(connectId)); auto item = std::find_if(connects_.begin(), connects_.end(), - [&connectId](const std::map>::value_type &obj) { return connectId == obj.first.id; }); @@ -596,7 +596,7 @@ void JSInputMethodExtensionConnection::HandleOnAbilityDisconnectDone( std::string abilityName = element.GetAbilityName(); auto item = std::find_if(connects_.begin(), connects_.end(), [bundleName, abilityName]( - const std::map>::value_type &obj) { + const std::map>::value_type &obj) { return (bundleName == obj.first.want.GetBundle()) && (abilityName == obj.first.want.GetElement().GetAbilityName()); }); diff --git a/interfaces/kits/js/napi/inputmethod_extension_ability/inputmethod_extension_ability_module.cpp b/interfaces/kits/js/napi/inputmethod_extension_ability/inputmethod_extension_ability_module.cpp index 4234dc2a..f06ee45a 100644 --- a/interfaces/kits/js/napi/inputmethod_extension_ability/inputmethod_extension_ability_module.cpp +++ b/interfaces/kits/js/napi/inputmethod_extension_ability/inputmethod_extension_ability_module.cpp @@ -41,7 +41,7 @@ extern "C" __attribute__((visibility("default"))) void NAPI_inputmethodextension } } -// inputmethod_extension_abiltiy JS register +// inputmethod_extension_ability JS register extern "C" __attribute__((visibility("default"))) void NAPI_inputmethodextensionability_GetABCCode( const char **buf, int *buflen) { diff --git a/interfaces/kits/js/napi/inputmethodability/js_callback_object.h b/interfaces/kits/js/napi/inputmethodability/js_callback_object.h index 197ff0f8..0376ec78 100644 --- a/interfaces/kits/js/napi/inputmethodability/js_callback_object.h +++ b/interfaces/kits/js/napi/inputmethodability/js_callback_object.h @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef CALLBAKC_OBJECT_H -#define CALLBAKC_OBJECT_H +#ifndef CALLBACK_OBJECT_H +#define CALLBACK_OBJECT_H #include @@ -32,4 +32,4 @@ public: }; } // namespace MiscServices } // namespace OHOS -#endif // CALLBAKC_OBJECT_H \ No newline at end of file +#endif // CALLBACK_OBJECT_H \ No newline at end of file diff --git a/interfaces/kits/js/napi/inputmethodability/js_input_method_engine_setting.cpp b/interfaces/kits/js/napi/inputmethodability/js_input_method_engine_setting.cpp index cd2c9e7a..9209205e 100644 --- a/interfaces/kits/js/napi/inputmethodability/js_input_method_engine_setting.cpp +++ b/interfaces/kits/js/napi/inputmethodability/js_input_method_engine_setting.cpp @@ -226,7 +226,7 @@ void JsInputMethodEngineSetting::RegisterListener(napi_value callback, std::stri IMSA_HILOGI("RegisterListener %{public}s", type.c_str()); std::lock_guard lock(mutex_); if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) { - IMSA_HILOGE("methodName: %{public}s not registertd!", type.c_str()); + IMSA_HILOGE("methodName: %{public}s not registered!", type.c_str()); } for (auto &item : jsCbMap_[type]) { @@ -245,7 +245,7 @@ void JsInputMethodEngineSetting::UnRegisterListener(napi_value callback, std::st IMSA_HILOGI("UnRegisterListener %{public}s", type.c_str()); std::lock_guard lock(mutex_); if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) { - IMSA_HILOGE("methodName: %{public}s already unRegisterted!", type.c_str()); + IMSA_HILOGE("methodName: %{public}s already unRegistered!", type.c_str()); return; } @@ -734,7 +734,7 @@ void JsInputMethodEngineSetting::OnSetSubtype(const SubProperty &property) for (auto item : entry->vecCopy) { napi_value jsObject = GetResultOnSetSubtype(item->env_, entry->subProperty); if (jsObject == nullptr) { - IMSA_HILOGE("get GetResultOnSetSubtype failed: %{punlic}p", jsObject); + IMSA_HILOGE("get GetResultOnSetSubtype failed: %{public}p", jsObject); continue; } napi_value callback = nullptr; diff --git a/interfaces/kits/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp b/interfaces/kits/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp index dcc5bf5d..7d806668 100644 --- a/interfaces/kits/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp +++ b/interfaces/kits/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp @@ -195,7 +195,7 @@ void JsKeyboardDelegateSetting::UnRegisterListener(napi_value callback, std::str IMSA_HILOGI("UnRegisterListener %{public}s", type.c_str()); std::lock_guard lock(mutex_); if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) { - IMSA_HILOGE("methodName %{public}s not unRegisterted!", type.c_str()); + IMSA_HILOGE("methodName %{public}s not unRegistered!", type.c_str()); return; } @@ -375,7 +375,7 @@ bool JsKeyboardDelegateSetting::OnKeyEvent(int32_t keyCode, int32_t keyStatus) napi_value jsObject = GetResultOnKeyEvent(item->env_, entry->keyEventPara.keyCode, entry->keyEventPara.keyStatus); if (jsObject == nullptr) { - IMSA_HILOGE("get GetResultOnKeyEvent failed: %{punlic}p", jsObject); + IMSA_HILOGE("get GetResultOnKeyEvent failed: %{public}p", jsObject); continue; } napi_value callback = nullptr; diff --git a/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_controller.h b/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_controller.h index f916d9fc..a8c4dbc2 100644 --- a/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_controller.h +++ b/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_controller.h @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef INTERFACE_KITS_JS_GETINPUT_METHOD_CCONTROLLER_H -#define INTERFACE_KITS_JS_GETINPUT_METHOD_CCONTROLLER_H +#ifndef INTERFACE_KITS_JS_GETINPUT_METHOD_CONTROLLER_H +#define INTERFACE_KITS_JS_GETINPUT_METHOD_CONTROLLER_H #include "async_call.h" #include "global.h" @@ -63,4 +63,4 @@ private: }; } // namespace MiscServices } // namespace OHOS -#endif // INTERFACE_KITS_JS_GETINPUT_METHOD_CCONTROLLER_H +#endif // INTERFACE_KITS_JS_GETINPUT_METHOD_CONTROLLER_H diff --git a/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_setting.cpp b/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_setting.cpp index 492dc6c9..fc9c8566 100644 --- a/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_setting.cpp +++ b/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_setting.cpp @@ -423,7 +423,7 @@ void JsGetInputMethodSetting::RegisterListener( IMSA_HILOGI("RegisterListener %{public}s", type.c_str()); std::lock_guard lock(mutex_); if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) { - IMSA_HILOGE("methodName: %{public}s not registertd!", type.c_str()); + IMSA_HILOGE("methodName: %{public}s not registered!", type.c_str()); } for (auto &item : jsCbMap_[type]) { @@ -474,7 +474,7 @@ void JsGetInputMethodSetting::UnRegisterListener(napi_value callback, std::strin IMSA_HILOGI("UnRegisterListener %{public}s", type.c_str()); std::lock_guard lock(mutex_); if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) { - IMSA_HILOGE("methodName: %{public}s already unRegisterted!", type.c_str()); + IMSA_HILOGE("methodName: %{public}s already unRegistered!", type.c_str()); return; } diff --git a/interfaces/kits/js/napi/inputmethodclient/js_utils.cpp b/interfaces/kits/js/napi/inputmethodclient/js_utils.cpp index 945cf707..a5e04e5c 100644 --- a/interfaces/kits/js/napi/inputmethodclient/js_utils.cpp +++ b/interfaces/kits/js/napi/inputmethodclient/js_utils.cpp @@ -115,12 +115,12 @@ void JsUtils::ThrowException(napi_env env, int32_t err, const std::string &msg, std::string errMsg = ToMessage(err); if (type == TypeCode::TYPE_NONE) { errMsg = errMsg + msg; - IMSA_HILOGE("THROW_PARAMTER_ERROR message: %{public}s", errMsg.c_str()); + IMSA_HILOGE("THROW_PARAMETER_ERROR message: %{public}s", errMsg.c_str()); } else { auto iter = PARAMETER_TYPE.find(type); if (iter != PARAMETER_TYPE.end()) { errMsg = errMsg + "The type of " + msg + " must be " + iter->second; - IMSA_HILOGE("THROW_PARAMTER_TYPE_ERROR message: %{public}s", errMsg.c_str()); + IMSA_HILOGE("THROW_PARAMETER_TYPE_ERROR message: %{public}s", errMsg.c_str()); } } napi_throw_error(env, std::to_string(err).c_str(), errMsg.c_str()); diff --git a/services/dfx/include/inputmethod_dump.h b/services/dfx/include/inputmethod_dump.h index a525792b..5f7098b4 100644 --- a/services/dfx/include/inputmethod_dump.h +++ b/services/dfx/include/inputmethod_dump.h @@ -38,7 +38,7 @@ public: private: void ShowHelp(int fd); - void ShowIllealInfomation(int fd); + void ShowIllealInformation(int fd); mutable std::mutex hidumperMutex_; std::list errorInfo_; DumpNoParamFunc dumpAllMethod_; diff --git a/services/dfx/include/inputmethod_sysevent.h b/services/dfx/include/inputmethod_sysevent.h index 9cd32b6d..a5cbba5e 100644 --- a/services/dfx/include/inputmethod_sysevent.h +++ b/services/dfx/include/inputmethod_sysevent.h @@ -22,7 +22,7 @@ namespace OHOS { namespace MiscServices { -void FaultReporter(int32_t userId, std::string bundname, int32_t errCode); +void FaultReporter(int32_t userId, std::string bundleName, int32_t errCode); void CreateComponentFailed(int32_t userId, int32_t errCode); void BehaviourReporter(std::string ActiveName, const std::string &inputmethodName); } // namespace MiscServices diff --git a/services/dfx/src/inputmethod_dump.cpp b/services/dfx/src/inputmethod_dump.cpp index 61dbe14b..703f4471 100644 --- a/services/dfx/src/inputmethod_dump.cpp +++ b/services/dfx/src/inputmethod_dump.cpp @@ -25,7 +25,7 @@ namespace OHOS { namespace MiscServices { -constexpr int32_t MAX_RECORED_ERROR = 10; +constexpr int32_t MAX_RECORD_ERROR = 10; constexpr int32_t SUB_CMD_NAME = 0; constexpr int32_t CMD_ONE_PARAM = 1; constexpr const char *CMD_HELP = "-h"; @@ -43,7 +43,7 @@ void InputmethodDump::AddDumpAllMethod(const DumpNoParamFunc dumpAllMethod) void InputmethodDump::AddErrorInfo(const std::string &error) { std::lock_guard lock(hidumperMutex_); - if (errorInfo_.size() + 1 > MAX_RECORED_ERROR) { + if (errorInfo_.size() + 1 > MAX_RECORD_ERROR) { errorInfo_.pop_front(); errorInfo_.push_back(error); } else { @@ -58,7 +58,7 @@ bool InputmethodDump::Dump(int fd, const std::vector &args) if (args.size() == CMD_ONE_PARAM) { command = args.at(SUB_CMD_NAME); } else { - ShowIllealInfomation(fd); + ShowIllealInformation(fd); } if (command == CMD_HELP) { ShowHelp(fd); @@ -68,7 +68,7 @@ bool InputmethodDump::Dump(int fd, const std::vector &args) } dumpAllMethod_(fd); } else { - ShowIllealInfomation(fd); + ShowIllealInformation(fd); } IMSA_HILOGI("InputmethodDump::Dump command=%{public}s.", command.c_str()); return true; @@ -84,7 +84,7 @@ void InputmethodDump::ShowHelp(int fd) dprintf(fd, "%s\n", result.c_str()); } -void InputmethodDump::ShowIllealInfomation(int fd) +void InputmethodDump::ShowIllealInformation(int fd) { dprintf(fd, "%s\n", ILLEGAL_INFO.c_str()); } diff --git a/services/dfx/src/inputmethod_sysevent.cpp b/services/dfx/src/inputmethod_sysevent.cpp index 51970eea..ebbe54d3 100644 --- a/services/dfx/src/inputmethod_sysevent.cpp +++ b/services/dfx/src/inputmethod_sysevent.cpp @@ -24,10 +24,10 @@ using HiSysEventNameSpace = OHOS::HiviewDFX::HiSysEvent; const std::string DOMAIN_STR = std::string(HiSysEventNameSpace::Domain::INPUTMETHOD); } // namespace -void FaultReporter(int32_t userId, std::string bundname, int32_t errCode) +void FaultReporter(int32_t userId, std::string bundleName, int32_t errCode) { int ret = HiSysEventNameSpace::Write(DOMAIN_STR, "SERVICE_INIT_FAILED", HiSysEventNameSpace::EventType::FAULT, - "USER_ID", userId, "COMPONENT_ID", bundname, "ERROR_CODE", errCode); + "USER_ID", userId, "COMPONENT_ID", bundleName, "ERROR_CODE", errCode); if (ret != 0) { IMSA_HILOGE("hisysevent FaultReporter failed! ret %{public}d,errCode %{public}d", ret, errCode); } @@ -51,4 +51,4 @@ void BehaviourReporter(std::string ActiveName, const std::string &inputmethodNam } } } // namespace MiscServices -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/dialog/entry/src/main/ets/pages/index.ets b/services/dialog/entry/src/main/ets/pages/index.ets index 57e44022..ab2d1a9c 100644 --- a/services/dialog/entry/src/main/ets/pages/index.ets +++ b/services/dialog/entry/src/main/ets/pages/index.ets @@ -18,7 +18,7 @@ import inputMethod from '@ohos.inputmethod'; @Component struct Dialog { private arr: string[] = [] - private properityMap: Map = new Map(); + private propertyMap: Map = new Map(); @State private win: any = undefined @State private context: any = undefined private inputMethods: Array = null @@ -33,7 +33,7 @@ struct Dialog { for (let inputmethod of this.inputMethods) { let name = inputmethod.packageName this.arr.push(name) - this.properityMap.set(name, inputmethod) + this.propertyMap.set(name, inputmethod) } } @@ -67,8 +67,8 @@ struct Dialog { .borderRadius(10) .backgroundColor($r("app.color.btn_default")) .onClick(async () => { - if (this.properityMap.has(item)) { - let prop = this.properityMap.get(item) + if (this.propertyMap.has(item)) { + let prop = this.propertyMap.get(item) globalThis.chooseInputMethods(prop) } setTimeout(() => { diff --git a/services/src/peruser_setting.cpp b/services/src/peruser_setting.cpp index 8d449834..55efd27e 100644 --- a/services/src/peruser_setting.cpp +++ b/services/src/peruser_setting.cpp @@ -167,7 +167,7 @@ namespace MiscServices { return ErrorCode::NO_ERROR; } Platform::Instance()->SetInputMethodSetting(userId_, imSetting); - // wait for some time so that the setting change will not be overrided by the followed transact + // wait for some time so that the setting change will not be override by the followed transact usleep(COMMON_COUNT_ONE_HUNDRED_THOUSAND); return ErrorCode::NO_ERROR; } diff --git a/test/fuzztest/controlchannelstub_fuzzer/controlchannelstub_fuzzer.cpp b/test/fuzztest/controlchannelstub_fuzzer/controlchannelstub_fuzzer.cpp index ffef0f46..e54efd16 100644 --- a/test/fuzztest/controlchannelstub_fuzzer/controlchannelstub_fuzzer.cpp +++ b/test/fuzztest/controlchannelstub_fuzzer/controlchannelstub_fuzzer.cpp @@ -28,7 +28,7 @@ using namespace OHOS::MiscServices; namespace OHOS { constexpr size_t THRESHOLD = 10; constexpr int32_t OFFSET = 4; - const std::u16string CONTROLLCHANNEL_INTERFACE_TOKEN = u"ohos.miscservices.inputmethod.InputControlChannel"; + const std::u16string CONTROLCHANNEL_INTERFACE_TOKEN = u"ohos.miscservices.inputmethod.InputControlChannel"; uint32_t ConvertToUint32(const uint8_t *ptr) { @@ -46,14 +46,14 @@ namespace OHOS { size = size - OFFSET; MessageParcel data; - data.WriteInterfaceToken(CONTROLLCHANNEL_INTERFACE_TOKEN); + data.WriteInterfaceToken(CONTROLCHANNEL_INTERFACE_TOKEN); data.WriteBuffer(rawData, size); data.RewindRead(0); MessageParcel reply; MessageOption option; - sptr controllChannel = new InputControlChannelStub(MAIN_USER_ID); - controllChannel->OnRemoteRequest(code, data, reply, option); + sptr controlChannel = new InputControlChannelStub(MAIN_USER_ID); + controlChannel->OnRemoteRequest(code, data, reply, option); return true; } diff --git a/test/fuzztest/controlchannelstub_fuzzer/controlchannelstub_fuzzer.h b/test/fuzztest/controlchannelstub_fuzzer/controlchannelstub_fuzzer.h index 568b535f..a7cf9b8d 100644 --- a/test/fuzztest/controlchannelstub_fuzzer/controlchannelstub_fuzzer.h +++ b/test/fuzztest/controlchannelstub_fuzzer/controlchannelstub_fuzzer.h @@ -13,9 +13,9 @@ * limitations under the License. */ -#ifndef TEST_FUZZTEST_CONTROLLCHANNELSTUB_FUZZER_CONTROLLCHANNELSTUB_FUZZER_H -#define TEST_FUZZTEST_CONTROLLCHANNELSTUB_FUZZER_CONTROLLCHANNELSTUB_FUZZER_H +#ifndef TEST_FUZZTEST_CONTROLCHANNELSTUB_FUZZER_CONTROLCHANNELSTUB_FUZZER_H +#define TEST_FUZZTEST_CONTROLCHANNELSTUB_FUZZER_CONTROLCHANNELSTUB_FUZZER_H #define FUZZ_PROJECT_NAME "controlchannelstub_fuzzer" -#endif // TEST_FUZZTEST_CONTROLLCHANNELSTUB_FUZZER_CONTROLLCHANNELSTUB_FUZZER_H \ No newline at end of file +#endif // TEST_FUZZTEST_CONTROLCHANNELSTUB_FUZZER_CONTROLCHANNELSTUB_FUZZER_H \ No newline at end of file diff --git a/test/js/InputMethodTest.test.js b/test/js/InputMethodTest.test.js index 09de0ae1..4e1f18db 100644 --- a/test/js/InputMethodTest.test.js +++ b/test/js/InputMethodTest.test.js @@ -25,9 +25,9 @@ describe('appInfoTest_input_2', function () { */ it('inputmethod_test_listInputMethod_001', 0, async function (done) { let inputMethodSetting = inputMethod.getInputMethodSetting(); - console.info("inputmethoh_test_001 result:" + JSON.stringify(inputMethodSetting)); + console.info("inputmethod_test_001 result:" + JSON.stringify(inputMethodSetting)); inputMethodSetting.listInputMethod((err, data) => { - console.info("inputmethoh_test_001 listInputMethod result" + JSON.stringify(data)); + console.info("inputmethod_test_001 listInputMethod result" + JSON.stringify(data)); expect(err===undefined).assertTrue(); }); done(); @@ -41,16 +41,16 @@ describe('appInfoTest_input_2', function () { */ it('inputmethod_test_listInputMethod_002', 0, async function (done) { let inputMethodSetting = inputMethod.getInputMethodSetting(); - console.info("inputmethoh_test_002 result:" + JSON.stringify(inputMethodSetting)); + console.info("inputmethod_test_002 result:" + JSON.stringify(inputMethodSetting)); let promise = await inputMethodSetting.listInputMethod(); - console.info("inputmethoh_test_002 listInputMethod result" + JSON.stringify(promise)); + console.info("inputmethod_test_002 listInputMethod result" + JSON.stringify(promise)); if (promise.length > 0){ let obj = promise[0] - console.info("inputmethoh_test_002 listInputMethod obj" + JSON.stringify(obj)); + console.info("inputmethod_test_002 listInputMethod obj" + JSON.stringify(obj)); expect(obj.packageName != null).assertTrue(); expect(obj.methodId != null).assertTrue(); }else{ - console.info("inputmethoh_test_002 listInputMethod is null"); + console.info("inputmethod_test_002 listInputMethod is null"); expect().assertFail(); } done(); diff --git a/test/unitest/src/InputMethodTest.js b/test/unitest/src/InputMethodTest.js index 221e066d..17441f9a 100644 --- a/test/unitest/src/InputMethodTest.js +++ b/test/unitest/src/InputMethodTest.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 XXXX Device Co., Ltd. + * Copyright (C) 2021 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 @@ -242,13 +242,13 @@ describe("InputMethodTest", function () { it('inputmethod_test_listInputMethod_004', 0, async function (done) { console.info("************* inputmethod_test_listInputMethod_004 Test start*************"); let inputMethodSetting = inputMethod.getInputMethodSetting(); - console.info("inputmethoh_test_004 result:" + JSON.stringify(inputMethodSetting)); + console.info("inputmethod_test_004 result:" + JSON.stringify(inputMethodSetting)); inputMethodSetting.listInputMethod(true, (err, data) => { if (err) { console.error("listInputMethod callback result---err: " + JSON.stringify(err.message)); expect().assertFail(); } - console.info("inputmethoh_test_004 listInputMethod result" + JSON.stringify(data)); + console.info("inputmethod_test_004 listInputMethod result" + JSON.stringify(data)); expect(err === undefined).assertTrue(); }); console.info("************* inputmethod_test_listInputMethod_004 Test end*************"); @@ -598,7 +598,7 @@ describe("InputMethodTest", function () { /* * @tc.number inputmethod_test_showSoftKeyboard_001 - * @tc.name Test Indicates the input method which will show softboard with calback. + * @tc.name Test Indicates the input method which will show softboard with callback. * @tc.desc Function test * @tc.level 2 */ @@ -607,9 +607,9 @@ describe("InputMethodTest", function () { let inputMethodCtrl = inputMethod.getInputMethodController() inputMethodCtrl.showSoftKeyboard((err)=>{ if (err === undefined) { - console.info("showSoftKeyboard callbace success" ); + console.info("showSoftKeyboard callback success" ); } else { - console.info('showSoftKeyboard callbace failed : ' + JSON.stringify(err.message)); + console.info('showSoftKeyboard callback failed : ' + JSON.stringify(err.message)); expect().assertFail(); } }); @@ -638,7 +638,7 @@ describe("InputMethodTest", function () { /* * @tc.number inputmethod_test_hideSoftKeyboard_001 - * @tc.name Test Indicates the input method which will hide softboard with calback. + * @tc.name Test Indicates the input method which will hide softboard with callback. * @tc.desc Function test * @tc.level 2 */ @@ -647,9 +647,9 @@ describe("InputMethodTest", function () { let inputMethodCtrl = inputMethod.getInputMethodController() inputMethodCtrl.hideSoftKeyboard((data)=>{ if(data === undefined){ - console.info("hideSoftKeyboard callbace success" ); + console.info("hideSoftKeyboard callback success" ); }else{ - console.info('hideSoftKeyboard callbace failed : ' + JSON.stringify(err.message)) + console.info('hideSoftKeyboard callback failed : ' + JSON.stringify(err.message)) expect().assertFail(); } }); @@ -1156,7 +1156,7 @@ describe("InputMethodTest", function () { if (err === undefined) { console.info("inputMethodEngine_test_039 hideKeyboard success."); } else { - console.info('inputMethodEngine_test_039 hideKeyboard callbace failed : ' + JSON.stringify(err.message)); + console.info('inputMethodEngine_test_039 hideKeyboard callback failed : ' + JSON.stringify(err.message)); expect().assertFail(); } }); @@ -1276,7 +1276,7 @@ describe("InputMethodTest", function () { if (err === undefined) { console.info("inputMethodEngine_test_048 hide success."); } else { - console.info('inputMethodEngine_test_048 hide callbace failed : ' + JSON.stringify(err.message)); + console.info('inputMethodEngine_test_048 hide callback failed : ' + JSON.stringify(err.message)); expect().assertFail(); } }); diff --git a/unitest/src/input_method_dfx_test.cpp b/unitest/src/input_method_dfx_test.cpp index 80e6ecdf..7f07b230 100644 --- a/unitest/src/input_method_dfx_test.cpp +++ b/unitest/src/input_method_dfx_test.cpp @@ -116,13 +116,13 @@ HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Dump_ShowHelp_001, TestSize.Leve } /** -* @tc.name: InputMethodDfxTest_Dump_ShowIllealInfomation_001 -* @tc.desc: Dump ShowIllealInfomation. +* @tc.name: InputMethodDfxTest_Dump_ShowIllealInformation_001 +* @tc.desc: Dump ShowIllealInformation. * @tc.type: FUNC * @tc.require: issueI61PMG * @tc.author: chenyu */ -HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Dump_ShowIllealInfomation_001, TestSize.Level0) +HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Dump_ShowIllealInformation_001, TestSize.Level0) { std::string result; auto ret = InputMethodDfxTest::ExecuteCmd(CMD3, result); diff --git a/unitest/src/input_method_switch_test.cpp b/unitest/src/input_method_switch_test.cpp index 24f0be4d..96ccd685 100644 --- a/unitest/src/input_method_switch_test.cpp +++ b/unitest/src/input_method_switch_test.cpp @@ -58,11 +58,11 @@ void InputMethodSwitchTest::TearDown(void) } /** -* @tc.name: intputMethodSwitch_sub_001 +* @tc.name: inputMethodSwitch_sub_001 * @tc.desc: Checkout SwitchInputMethod. * @tc.type: FUNC */ -HWTEST_F(InputMethodSwitchTest, intputMethodSwitch_sub_001, TestSize.Level0) +HWTEST_F(InputMethodSwitchTest, inputMethodSwitch_sub_001, TestSize.Level0) { InputMethodProperty *target = new InputMethodProperty(); std::string packageName = "com.ohos.inputApp"; From d6bdcb83a7fcfc83d3b565c0d4d3c91b51514c2d Mon Sep 17 00:00:00 2001 From: Hollokin Date: Tue, 22 Nov 2022 10:42:16 +0800 Subject: [PATCH 075/112] =?UTF-8?q?=E3=80=90=E9=97=A8=E7=A6=81=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E3=80=91=E5=AF=B9utils.h=E5=A4=B4=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E4=BE=9D=E8=B5=96=E9=A1=BA=E5=BA=8F=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hollokin --- unitest/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unitest/BUILD.gn b/unitest/BUILD.gn index 7992dda4..42c14bff 100644 --- a/unitest/BUILD.gn +++ b/unitest/BUILD.gn @@ -17,7 +17,7 @@ import("//build/test.gni") config("module_private_config") { visibility = [ ":*" ] - include_dirs = [ "include" ] + include_dirs = [ "//base/inputmethod/imf/services/include" ] } module_output_path = "imf/inputmethod_service" From 07496bf549777388340a3a5dfcb22083a1e56b02 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Tue, 22 Nov 2022 14:48:06 +0800 Subject: [PATCH 076/112] modify code Signed-off-by: zhaolinglan --- .../adapter/keyboard/input_event_callback.h | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/services/adapter/keyboard/input_event_callback.h b/services/adapter/keyboard/input_event_callback.h index ac2dfb2c..fb7daf20 100644 --- a/services/adapter/keyboard/input_event_callback.h +++ b/services/adapter/keyboard/input_event_callback.h @@ -38,7 +38,7 @@ public: private: KeyHandle keyHandler_ = nullptr; static std::mutex statusMapLock_; - static std::map keyStatusMap_; + static std::map statusMap_; std::map, CombineKeyCode> combinedKeyMap_ = { { { MMI::KeyEvent::KEYCODE_CAPS_LOCK }, CombineKeyCode::COMBINE_KEYCODE_CAPS }, { { MMI::KeyEvent::KEYCODE_SHIFT_LEFT }, CombineKeyCode::COMBINE_KEYCODE_SHIFT }, @@ -55,12 +55,12 @@ private: }; std::mutex InputEventCallback::statusMapLock_; -std::map InputEventCallback::keyStatusMap_ = { - { MMI::KeyEvent::KEYCODE_CAPS_LOCK, false }, - { MMI::KeyEvent::KEYCODE_CTRL_LEFT, false }, - { MMI::KeyEvent::KEYCODE_CTRL_RIGHT, false }, +std::map InputEventCallback::statusMap_ = { { MMI::KeyEvent::KEYCODE_SHIFT_LEFT, false }, { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, false }, + { MMI::KeyEvent::KEYCODE_CTRL_LEFT, false }, + { MMI::KeyEvent::KEYCODE_CTRL_RIGHT, false }, + { MMI::KeyEvent::KEYCODE_CAPS_LOCK, false }, }; void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) const @@ -70,25 +70,25 @@ void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) c IMSA_HILOGD("keyCode: %{public}d, keyAction: %{public}d", keyCode, keyAction); std::lock_guard lock(statusMapLock_); - if (keyStatusMap_.find(keyCode) == keyStatusMap_.end() || keyAction == MMI::KeyEvent::KEY_ACTION_UNKNOWN) { + if (statusMap_.find(keyCode) == statusMap_.end() || keyAction == MMI::KeyEvent::KEY_ACTION_UNKNOWN) { IMSA_HILOGD("keyevent undefined"); return; } if (keyAction == MMI::KeyEvent::KEY_ACTION_DOWN) { IMSA_HILOGD("key %{public}d pressed down", keyCode); - keyStatusMap_[keyCode] = true; + statusMap_[keyCode] = true; return; } - IMSA_HILOGI("key %{public}d pressed up", keyCode); - std::vector pressedKeys; - for (auto &key : keyStatusMap_) { + IMSA_HILOGD("key %{public}d pressed up", keyCode); + std::vector downKeys; + for (auto &key : statusMap_) { if (key.second) { - pressedKeys.push_back(key.first); + downKeys.push_back(key.first); key.second = false; } } - auto combinedKey = combinedKeyMap_.find(pressedKeys); + auto combinedKey = combinedKeyMap_.find(downKeys); if (combinedKey == combinedKeyMap_.end()) { IMSA_HILOGD("undefined combinedkey"); return; From d39414e681f29b5e013d7792375a1d6858d5273c Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Tue, 22 Nov 2022 15:03:36 +0800 Subject: [PATCH 077/112] modify code Signed-off-by: zhaolinglan --- services/src/input_method_system_ability.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 80a20a54..a1fe1460 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -553,7 +553,8 @@ namespace MiscServices { int32_t InputMethodSystemAbility::SwitchInputMethod(const std::string &name, const std::string &subName) { - IMSA_HILOGI("InputMethodSystemAbility::SwitchInputMethod"); + IMSA_HILOGD("InputMethodSystemAbility name: %{public}s, subName: %{public}s", name.c_str(), + subName.c_str()); return subName.empty() ? SwitchInputMethodType(name) : SwitchInputMethodSubtype(name, subName); } @@ -1436,7 +1437,7 @@ namespace MiscServices { } for (const auto &prop : props) { if (prop.name != current->id) { - return SwitchInputMethod(current->name, current->id); + return SwitchInputMethod(prop.name, prop.id); } } } From e67cb583ddd91f87a73d5bb0d6a42724f24521f9 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Tue, 22 Nov 2022 15:41:01 +0800 Subject: [PATCH 078/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/include/peruser_session.h | 2 +- services/src/peruser_session.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index ed29d5b9..c2420cfa 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -130,7 +130,7 @@ private: sptr imsCore[MAX_IME]; // the remote handlers of input method service sptr inputMethodToken[MAX_IME]; // the window token of keyboard int currentKbdIndex[MAX_IME]; // current keyboard index - int lastImeIndex; // The last ime which showed keyboard + int lastImeIndex = 0; // The last ime which showed keyboard InputMethodSetting *inputMethodSetting; // The pointer referred to the object in PerUserSetting int currentDisplayMode; // the display mode of the current keyboard diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 7beb5dc2..fb02c798 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -457,15 +457,15 @@ namespace MiscServices { */ int PerUserSession::OnGetKeyboardWindowHeight(int &retHeight) { - if (imsCore[lastImeIndex]) { - int ret = imsCore[lastImeIndex]->getKeyboardWindowHeight(retHeight); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("getKeyboardWindowHeight return : %{public}s", ErrorCode::ToString(ret)); - } - return ret; + if (imsCore[lastImeIndex] == nullptr) { + IMSA_HILOGE("imsCore[0] is nullptr"); + return ErrorCode::ERROR_IME_NOT_AVAILABLE; } - IMSA_HILOGW("No IME is started [%{public}d]\n", userId_); - return ErrorCode::ERROR_IME_NOT_STARTED; + int ret = imsCore[lastImeIndex]->getKeyboardWindowHeight(retHeight); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("getKeyboardWindowHeight return : %{public}s", ErrorCode::ToString(ret)); + } + return ret; } /*! Get the current keyboard type From e8a89144506b43c29a76451d7cb1ba83b0c57422 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Tue, 22 Nov 2022 17:02:14 +0800 Subject: [PATCH 079/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/include/peruser_session.h | 3 + services/src/peruser_session.cpp | 114 +++++++++++++++++++---------- 2 files changed, 79 insertions(+), 38 deletions(-) diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index c2420cfa..0142d21c 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -127,6 +127,7 @@ private: InputControlChannelStub *localControlChannel[MAX_IME]; sptr inputControlChannel[MAX_IME]; + std::mutex imsCoreLock_; sptr imsCore[MAX_IME]; // the remote handlers of input method service sptr inputMethodToken[MAX_IME]; // the window token of keyboard int currentKbdIndex[MAX_IME]; // current keyboard index @@ -182,6 +183,8 @@ private: bool IsRestartIme(uint32_t index); void ClearImeData(uint32_t index); void SetCurrentClient(sptr client); + sptr GetImsCore(int32_t index); + void SetImsCore(int32_t index, sptr &core); sptr GetCurrentClient(); std::mutex propertyLock_; diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index fb02c798..6161d979 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -185,7 +185,8 @@ namespace MiscServices { if (currentIme[i] == ime[i] && ime[i]) { continue; } - if (imsCore[i]) { + sptr core = GetImsCore(i); + if (core != nullptr) { StopInputMethod(i); } ResetImeError(i); @@ -311,17 +312,17 @@ namespace MiscServices { int PerUserSession::StartInputMethod(int index) { IMSA_HILOGI("PerUserSession::StartInputMethod index = %{public}d [%{public}d]\n", index, userId_); - - if (!imsCore[index]) { + sptr core = GetImsCore(index); + if (core == nullptr) { IMSA_HILOGI("PerUserSession::StartInputMethod imscore is null"); return ErrorCode::ERROR_IME_BIND_FAILED; } - sptr b = imsCore[index]->AsObject(); + sptr b = core->AsObject(); inputMethodToken[index] = IPCSkeleton::GetInstance().GetContextObject(); localControlChannel[index] = new InputControlChannelStub(userId_); inputControlChannel[index] = localControlChannel[index]; - int ret_init = imsCore[index]->initializeInput(inputMethodToken[index], displayId, inputControlChannel[index]); + int ret_init = core->initializeInput(inputMethodToken[index], displayId, inputControlChannel[index]); if (ret_init != ErrorCode::NO_ERROR) { IMSA_HILOGE("PerUserSession::StartInputMethod initializeInput fail %{public}s", ErrorCode::ToString(ret_init)); localControlChannel[index] = nullptr; @@ -346,12 +347,14 @@ namespace MiscServices { IMSA_HILOGE("Aborted! %{public}s", ErrorCode::ToString(ErrorCode::ERROR_BAD_PARAMETERS)); return ErrorCode::ERROR_BAD_PARAMETERS; } - if (!imsCore[index] || !currentIme[index]) { + sptr core = GetImsCore(index); + if (core == nullptr || currentIme[index] == nullptr) { IMSA_HILOGE("Aborted! %{public}s", ErrorCode::ToString(ErrorCode::ERROR_IME_NOT_STARTED)); return ErrorCode::ERROR_IME_NOT_STARTED; } - if (currentIme[index] == currentIme[1 - index] && imsCore[1 - index]) { - imsCore[index] = nullptr; + sptr core_ = GetImsCore((1 - index)); + if (currentIme[index] == currentIme[1 - index] && core_ != nullptr) { + SetImsCore(index, nullptr); inputControlChannel[index] = nullptr; localControlChannel[index] = nullptr; IMSA_HILOGI("End...[%{public}d]\n", userId_); @@ -368,12 +371,12 @@ namespace MiscServices { IMSA_HILOGE("destroyWindowTaskId return : %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); errorCode = ErrorCode::ERROR_TOKEN_DESTROY_FAILED; } - sptr b = imsCore[index]->AsObject(); + sptr b = core->AsObject(); ret = b->RemoveDeathRecipient(imsDeathRecipient); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("RemoveDeathRecipient return : %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); } - imsCore[index] = nullptr; + SetImsCore(index, nullptr); inputControlChannel[index] = nullptr; localControlChannel[index] = nullptr; IMSA_HILOGI("End...[%{public}d]\n", userId_); @@ -399,14 +402,15 @@ namespace MiscServices { IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! index = -1 or clientInfo is nullptr"); return ErrorCode::ERROR_CLIENT_NOT_FOUND; } - - if (imsCore[0] == nullptr) { + sptr core = GetImsCore(index); + if (core == nullptr) { IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! imsCore[%{public}d] is nullptr", index); return ErrorCode::ERROR_NULL_POINTER; } auto subProperty = GetCurrentSubProperty(); - int32_t ret = imsCore[0]->showKeyboard(clientInfo->channel, isShowKeyboard, subProperty); + sptr core_ = GetImsCore(0); + int32_t ret = core_->showKeyboard(clientInfo->channel, isShowKeyboard, subProperty); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("PerUserSession::showKeyboard failed ret: %{public}d", ret); return ErrorCode::ERROR_KBD_SHOW_FAILED; @@ -437,12 +441,13 @@ namespace MiscServices { if (clientInfo == nullptr) { IMSA_HILOGE("PerUserSession::HideKeyboard GetClientInfo pointer nullptr"); } - if (imsCore[0] == nullptr) { + sptr core = GetImsCore(0); + if (core == nullptr) { IMSA_HILOGE("PerUserSession::HideKeyboard imsCore[index] is nullptr"); return ErrorCode::ERROR_IME_NOT_STARTED; } - bool ret = imsCore[0]->hideKeyboard(1); + bool ret = core->hideKeyboard(1); if (!ret) { IMSA_HILOGE("PerUserSession::HideKeyboard [imsCore->hideKeyboard] failed"); return ErrorCode::ERROR_KBD_HIDE_FAILED; @@ -457,11 +462,12 @@ namespace MiscServices { */ int PerUserSession::OnGetKeyboardWindowHeight(int &retHeight) { - if (imsCore[lastImeIndex] == nullptr) { + sptr core = GetImsCore(lastImeIndex); + if (core == nullptr) { IMSA_HILOGE("imsCore[0] is nullptr"); return ErrorCode::ERROR_IME_NOT_AVAILABLE; } - int ret = imsCore[lastImeIndex]->getKeyboardWindowHeight(retHeight); + int ret = core->getKeyboardWindowHeight(retHeight); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("getKeyboardWindowHeight return : %{public}s", ErrorCode::ToString(ret)); } @@ -530,7 +536,8 @@ namespace MiscServices { IMSA_HILOGI("Start...[%{public}d]\n", userId_); int index = 0; for (int i = 0; i < MAX_IME; i++) { - if (imsCore[i] == remote) { + sptr core = GetImsCore(i); + if (core == remote) { index = i; break; } @@ -659,12 +666,14 @@ namespace MiscServices { if (type) { sptr client = GetCurrentClient(); if (client != nullptr) { - int ret = imsCore[index]->setKeyboardType(*type); + sptr core = GetImsCore(index); + int ret = core->setKeyboardType(*type); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("setKeyboardType ret: %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); } } - if (imsCore[index] == imsCore[1 - index]) { + sptr core_ = GetImsCore((1 - index)); + if (core == core_) { inputMethodSetting->SetCurrentKeyboardType(type->getHashCode()); inputMethodSetting->SetCurrentSysKeyboardType(type->getHashCode()); currentKbdIndex[1 - index] = currentKbdIndex[index]; @@ -740,7 +749,9 @@ namespace MiscServices { return; } InputMethodSetting tmpSetting; - if (imsCore[index] == imsCore[1 - index]) { + sptr core = GetImsCore(index); + sptr core_ = GetImsCore((1- index)); + if (core == core_) { tmpSetting.SetCurrentKeyboardType(type->getHashCode()); tmpSetting.SetCurrentSysKeyboardType(type->getHashCode()); } @@ -910,16 +921,20 @@ namespace MiscServices { } } } + sptr core = GetImsCore(imeIndex); + sptr core_ = GetImsCore((1 - imeIndex)); if (!flag) { IMSA_HILOGW("The current keyboard type is not found in the current IME. Reset it!"); type = GetKeyboardType(imeIndex, currentKbdIndex[imeIndex]); - } else if (imsCore[imeIndex] == imsCore[1 - imeIndex]) { + } else if (core == core_) { currentKbdIndex[1 - imeIndex] = currentKbdIndex[imeIndex]; } } if (type) { InputMethodSetting tmpSetting; - if (imsCore[imeIndex] == imsCore[1 - imeIndex]) { + sptr core = GetImsCore(imeIndex); + sptr core_ = GetImsCore((1 - imeIndex)); + if (core == core_) { inputMethodSetting->SetCurrentKeyboardType(type->getHashCode()); inputMethodSetting->SetCurrentSysKeyboardType(type->getHashCode()); currentKbdIndex[1 - imeIndex] = currentKbdIndex[imeIndex]; @@ -967,7 +982,8 @@ namespace MiscServices { */ void PerUserSession::CopyInputMethodService(int imeIndex) { - imsCore[imeIndex] = imsCore[1 - imeIndex]; + sptr core = GetImsCore((1 - imeIndex)); + SetImsCore(imeIndex, core); localControlChannel[imeIndex] = localControlChannel[1 - imeIndex]; inputControlChannel[imeIndex] = inputControlChannel[1 - imeIndex]; inputMethodToken[imeIndex] = inputMethodToken[1 - imeIndex]; @@ -1081,10 +1097,11 @@ namespace MiscServices { int32_t PerUserSession::OnReleaseInput(sptr client) { IMSA_HILOGI("PerUserSession::OnReleaseInput Start\n"); - if (imsCore[0] == nullptr) { + sptr core = GetImsCore(0); + if (core == nullptr) { return ErrorCode::ERROR_IME_NOT_AVAILABLE; } - imsCore[0]->SetClientState(false); + core->SetClientState(false); HideKeyboard(client); RemoveClient(client->AsObject()); IMSA_HILOGI("PerUserSession::OnReleaseInput End...[%{public}d]\n", userId_); @@ -1099,10 +1116,11 @@ namespace MiscServices { int32_t PerUserSession::OnStartInput(sptr client, bool isShowKeyboard) { IMSA_HILOGI("PerUserSession::OnStartInput"); - if (imsCore[0] == nullptr) { + sptr core = GetImsCore(0); + if (core == nullptr) { return ErrorCode::ERROR_IME_NOT_AVAILABLE; } - imsCore[0]->SetClientState(true); + core->SetClientState(true); return ShowKeyboard(client, isShowKeyboard); } @@ -1113,7 +1131,7 @@ namespace MiscServices { IMSA_HILOGE("PerUserSession::SetCoreAndAgent core or agent nullptr"); return ErrorCode::ERROR_EX_NULL_POINTER; } - imsCore[0] = core; + SetImsCore(index, core); if (imsDeathRecipient != nullptr) { imsDeathRecipient->SetDeathRecipient([this, core](const wptr &) { this->OnImsDied(core); }); bool ret = core->AsObject()->AddDeathRecipient(imsDeathRecipient); @@ -1146,7 +1164,12 @@ namespace MiscServices { { IMSA_HILOGI("PerUserSession::InitInputControlChannel"); sptr inputControlChannel = new InputControlChannelStub(userId_); - int ret = imsCore[0]->InitInputControlChannel(inputControlChannel); + sptr core = GetImsCore(0); + if (core == nullptr) { + IMSA_HILOGE("PerUserSession::InitInputControlChannel core is nullptr"); + return; + } + int ret = core->InitInputControlChannel(inputControlChannel); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGI("PerUserSession::InitInputControlChannel fail %{public}s", ErrorCode::ToString(ret)); } @@ -1166,13 +1189,14 @@ namespace MiscServices { void PerUserSession::StopInputService(std::string imeId) { IMSA_HILOGI("PerUserSession::StopInputService"); - if (imsCore[0] == nullptr) { + sptr core = GetImsCore(0); + if (core == nullptr) { IMSA_HILOGE("imsCore[0] is nullptr"); return; } IMSA_HILOGI("Remove death recipient"); - imsCore[0]->AsObject()->RemoveDeathRecipient(imsDeathRecipient); - imsCore[0]->StopInputService(imeId); + core->AsObject()->RemoveDeathRecipient(imsDeathRecipient); + core->StopInputService(imeId); } bool PerUserSession::IsRestartIme(uint32_t index) @@ -1197,9 +1221,10 @@ namespace MiscServices { void PerUserSession::ClearImeData(uint32_t index) { IMSA_HILOGI("Clear ime...index = %{public}d", index); - if (imsCore[index] != nullptr) { - imsCore[index]->AsObject()->RemoveDeathRecipient(imsDeathRecipient); - imsCore[index] = nullptr; + sptr core = GetImsCore(index); + if (core != nullptr) { + core->AsObject()->RemoveDeathRecipient(imsDeathRecipient); + SetImsCore(index, nullptr); } inputControlChannel[index] = nullptr; localControlChannel[index] = nullptr; @@ -1240,11 +1265,12 @@ namespace MiscServices { return ErrorCode::NO_ERROR; } SetCurrentSubProperty(subProperty); - if (imsCore[0] == nullptr) { + sptr core = GetImsCore(0); + if (core == nullptr) { IMSA_HILOGE("imsCore is nullptr"); return ErrorCode::ERROR_EX_NULL_POINTER; } - int32_t ret = imsCore[0]->SetSubtype(subProperty); + int32_t ret = core->SetSubtype(subProperty); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("PerUserSession::SetSubtype failed, ret %{public}d", ret); return ret; @@ -1265,5 +1291,17 @@ namespace MiscServices { std::lock_guard lock(propertyLock_); currentSubProperty = subProperty; } + + sptr PerUserSession::GetImsCore(int32_t index) + { + std::lock_guard &core) + { + std::lock_guard Date: Tue, 22 Nov 2022 18:06:47 +0800 Subject: [PATCH 080/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/src/peruser_session.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 6161d979..d743433d 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -353,8 +353,9 @@ namespace MiscServices { return ErrorCode::ERROR_IME_NOT_STARTED; } sptr core_ = GetImsCore((1 - index)); + sptr nullCore = nullptr; if (currentIme[index] == currentIme[1 - index] && core_ != nullptr) { - SetImsCore(index, nullptr); + SetImsCore(index, nullCore); inputControlChannel[index] = nullptr; localControlChannel[index] = nullptr; IMSA_HILOGI("End...[%{public}d]\n", userId_); @@ -376,7 +377,7 @@ namespace MiscServices { if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("RemoveDeathRecipient return : %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); } - SetImsCore(index, nullptr); + SetImsCore(index, nullCore); inputControlChannel[index] = nullptr; localControlChannel[index] = nullptr; IMSA_HILOGI("End...[%{public}d]\n", userId_); @@ -1224,7 +1225,8 @@ namespace MiscServices { sptr core = GetImsCore(index); if (core != nullptr) { core->AsObject()->RemoveDeathRecipient(imsDeathRecipient); - SetImsCore(index, nullptr); + sptr nullCore = nullptr; + SetImsCore(index, nullCore); } inputControlChannel[index] = nullptr; localControlChannel[index] = nullptr; @@ -1294,13 +1296,13 @@ namespace MiscServices { sptr PerUserSession::GetImsCore(int32_t index) { - std::lock_guard lock(imsCoreLock_); return imsCore[index]; } void PerUserSession::SetImsCore(int32_t index, sptr &core) { - std::lock_guard lock(imsCoreLock_); imsCore[index] = core; } } // namespace MiscServices From 77c87e6ca709ee6c329292239a22f6d464f0f281 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Tue, 22 Nov 2022 19:22:52 +0800 Subject: [PATCH 081/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/src/peruser_session.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index d743433d..575fa525 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -666,8 +666,8 @@ namespace MiscServices { KeyboardType *type = GetKeyboardType(index, currentKbdIndex[index]); if (type) { sptr client = GetCurrentClient(); + sptr core = GetImsCore(index); if (client != nullptr) { - sptr core = GetImsCore(index); int ret = core->setKeyboardType(*type); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("setKeyboardType ret: %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); @@ -1132,7 +1132,7 @@ namespace MiscServices { IMSA_HILOGE("PerUserSession::SetCoreAndAgent core or agent nullptr"); return ErrorCode::ERROR_EX_NULL_POINTER; } - SetImsCore(index, core); + SetImsCore(0, core); if (imsDeathRecipient != nullptr) { imsDeathRecipient->SetDeathRecipient([this, core](const wptr &) { this->OnImsDied(core); }); bool ret = core->AsObject()->AddDeathRecipient(imsDeathRecipient); From 3e1cdea2e223d1ac669ba5b3951407a1eeeeebb8 Mon Sep 17 00:00:00 2001 From: Chao Liu Date: Tue, 22 Nov 2022 21:33:37 +0800 Subject: [PATCH 082/112] Fix online code review issue Signed-off-by: Chao Liu --- .../inputmethodability/js_callback_object.h | 6 +++--- .../js_input_method_engine_setting.cpp | 2 +- .../js_keyboard_delegate_setting.cpp | 4 ++-- .../js_get_input_method_controller.h | 6 +++--- test/js/InputMethodTest.test.js | 17 +++++++---------- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/interfaces/kits/js/napi/inputmethodability/js_callback_object.h b/interfaces/kits/js/napi/inputmethodability/js_callback_object.h index 0376ec78..60f7309e 100644 --- a/interfaces/kits/js/napi/inputmethodability/js_callback_object.h +++ b/interfaces/kits/js/napi/inputmethodability/js_callback_object.h @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef CALLBACK_OBJECT_H -#define CALLBACK_OBJECT_H +#ifndef JS_CALLBACK_OBJECT_H +#define JS_CALLBACK_OBJECT_H #include @@ -32,4 +32,4 @@ public: }; } // namespace MiscServices } // namespace OHOS -#endif // CALLBACK_OBJECT_H \ No newline at end of file +#endif // JS_CALLBACK_OBJECT_H diff --git a/interfaces/kits/js/napi/inputmethodability/js_input_method_engine_setting.cpp b/interfaces/kits/js/napi/inputmethodability/js_input_method_engine_setting.cpp index 9209205e..9338920e 100644 --- a/interfaces/kits/js/napi/inputmethodability/js_input_method_engine_setting.cpp +++ b/interfaces/kits/js/napi/inputmethodability/js_input_method_engine_setting.cpp @@ -734,7 +734,7 @@ void JsInputMethodEngineSetting::OnSetSubtype(const SubProperty &property) for (auto item : entry->vecCopy) { napi_value jsObject = GetResultOnSetSubtype(item->env_, entry->subProperty); if (jsObject == nullptr) { - IMSA_HILOGE("get GetResultOnSetSubtype failed: %{public}p", jsObject); + IMSA_HILOGE("get GetResultOnSetSubtype failed: jsObject is nullptr"); continue; } napi_value callback = nullptr; diff --git a/interfaces/kits/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp b/interfaces/kits/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp index 7d806668..30d9ecb9 100644 --- a/interfaces/kits/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp +++ b/interfaces/kits/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp @@ -375,7 +375,7 @@ bool JsKeyboardDelegateSetting::OnKeyEvent(int32_t keyCode, int32_t keyStatus) napi_value jsObject = GetResultOnKeyEvent(item->env_, entry->keyEventPara.keyCode, entry->keyEventPara.keyStatus); if (jsObject == nullptr) { - IMSA_HILOGE("get GetResultOnKeyEvent failed: %{public}p", jsObject); + IMSA_HILOGE("get GetResultOnKeyEvent failed: jsObject is nullptr"); continue; } napi_value callback = nullptr; @@ -643,4 +643,4 @@ void JsKeyboardDelegateSetting::OnTextChange(std::string text) }); } } // namespace MiscServices -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_controller.h b/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_controller.h index a8c4dbc2..1b9e9c5a 100644 --- a/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_controller.h +++ b/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_controller.h @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef INTERFACE_KITS_JS_GETINPUT_METHOD_CONTROLLER_H -#define INTERFACE_KITS_JS_GETINPUT_METHOD_CONTROLLER_H +#ifndef INTERFACE_KITS_JS_GET_INPUT_METHOD_CONTROLLER_H +#define INTERFACE_KITS_JS_GET_INPUT_METHOD_CONTROLLER_H #include "async_call.h" #include "global.h" @@ -63,4 +63,4 @@ private: }; } // namespace MiscServices } // namespace OHOS -#endif // INTERFACE_KITS_JS_GETINPUT_METHOD_CONTROLLER_H +#endif // INTERFACE_KITS_JS_GET_INPUT_METHOD_CONTROLLER_H diff --git a/test/js/InputMethodTest.test.js b/test/js/InputMethodTest.test.js index 4e1f18db..ed308862 100644 --- a/test/js/InputMethodTest.test.js +++ b/test/js/InputMethodTest.test.js @@ -28,11 +28,11 @@ describe('appInfoTest_input_2', function () { console.info("inputmethod_test_001 result:" + JSON.stringify(inputMethodSetting)); inputMethodSetting.listInputMethod((err, data) => { console.info("inputmethod_test_001 listInputMethod result" + JSON.stringify(data)); - expect(err===undefined).assertTrue(); + expect(err === undefined).assertTrue(); }); done(); }); - + /* * @tc.number inputmethod_test_listInputMethod_002 * @tc.name Test Indicates the input method which will replace the current one. @@ -86,7 +86,7 @@ describe('appInfoTest_input_2', function () { console.info("inputmethod_test_displayOptionalInputMethod_001 result:" + JSON.stringify(inputMethodSetting)); inputMethodSetting.displayOptionalInputMethod((err) => { console.info("inputmethod_test_displayOptionalInputMethod_001 err:" + err); - expect(err===undefined).assertTrue(); + expect(err === undefined).assertTrue(); }); done(); }); @@ -140,7 +140,7 @@ describe('appInfoTest_input_2', function () { console.info("inputmethod_test_stopInput_001 stopInput result" + res); console.info("inputmethod_test_stopInput_001 stopInput result" + err); expect(res === true).assertTrue(); - expect(err===undefined).assertTrue(); + expect(err === undefined).assertTrue(); }); done(); }); @@ -311,7 +311,7 @@ describe('appInfoTest_input_2', function () { }); done(); }); - + /* * @tc.number inputmethod_test_switchCurrentInputMethodAndSubtype_002 * @tc.name Test Indicates the input method which will replace the current one. @@ -354,7 +354,7 @@ describe('appInfoTest_input_2', function () { console.info("inputmethod_test_ListInputMethodSubtype_001 result:" + JSON.stringify(inputMethodSetting)); inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err, data) => { console.info("inputmethod_test_ListInputMethodSubtype_001 result" + JSON.stringify(data)); - expect(err===undefined).assertTrue(); + expect(err === undefined).assertTrue(); }); done(); }); @@ -395,7 +395,7 @@ describe('appInfoTest_input_2', function () { console.info("inputmethod_test_ListCurrentInputMethodSubtype_001 result:" + JSON.stringify(inputMethodSetting)); inputMethodSetting.listCurrentInputMethodSubtype((err, data) => { console.info("inputmethod_test_ListCurrentInputMethodSubtype_001 result" + JSON.stringify(data)); - expect(err===undefined).assertTrue(); + expect(err === undefined).assertTrue(); }); done(); }); @@ -419,7 +419,4 @@ describe('appInfoTest_input_2', function () { done(); }); - - - }) From 2541ac461dea9c69226c4b303ddbba6be1c35231 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Wed, 23 Nov 2022 14:33:52 +0800 Subject: [PATCH 083/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/src/peruser_session.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 575fa525..f0453c72 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -403,15 +403,14 @@ namespace MiscServices { IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! index = -1 or clientInfo is nullptr"); return ErrorCode::ERROR_CLIENT_NOT_FOUND; } - sptr core = GetImsCore(index); + sptr core = GetImsCore(0); if (core == nullptr) { IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! imsCore[%{public}d] is nullptr", index); return ErrorCode::ERROR_NULL_POINTER; } auto subProperty = GetCurrentSubProperty(); - sptr core_ = GetImsCore(0); - int32_t ret = core_->showKeyboard(clientInfo->channel, isShowKeyboard, subProperty); + int32_t ret = core->showKeyboard(clientInfo->channel, isShowKeyboard, subProperty); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("PerUserSession::showKeyboard failed ret: %{public}d", ret); return ErrorCode::ERROR_KBD_SHOW_FAILED; @@ -667,13 +666,13 @@ namespace MiscServices { if (type) { sptr client = GetCurrentClient(); sptr core = GetImsCore(index); + sptr core_ = GetImsCore((1 - index)); if (client != nullptr) { int ret = core->setKeyboardType(*type); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("setKeyboardType ret: %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); } } - sptr core_ = GetImsCore((1 - index)); if (core == core_) { inputMethodSetting->SetCurrentKeyboardType(type->getHashCode()); inputMethodSetting->SetCurrentSysKeyboardType(type->getHashCode()); From c5417efe47bce11f7882cb61bafd2588952b0cb3 Mon Sep 17 00:00:00 2001 From: Hollokin Date: Wed, 23 Nov 2022 16:29:11 +0800 Subject: [PATCH 084/112] =?UTF-8?q?=E3=80=90=E6=97=A5=E5=BF=97=E3=80=91?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=B3=95=E6=A1=86=E6=9E=B6=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E9=87=8F=E8=B6=85=E6=A0=87=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hollokin --- .../src/input_method_core_proxy.cpp | 24 +++---- .../src/input_method_core_stub.cpp | 26 +++---- .../src/input_method_controller.cpp | 14 ++-- .../src/input_method_system_ability_proxy.cpp | 36 +++++----- services/include/peruser_session.h | 6 -- services/src/im_common_event_manager.cpp | 13 ++-- services/src/input_method_system_ability.cpp | 5 +- services/src/peruser_session.cpp | 70 ++++++++----------- 8 files changed, 86 insertions(+), 108 deletions(-) diff --git a/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp b/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp index 419d8a01..7aa253a1 100644 --- a/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp +++ b/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp @@ -34,7 +34,7 @@ InputMethodCoreProxy::~InputMethodCoreProxy() = default; int32_t InputMethodCoreProxy::initializeInput( sptr &startInputToken, int32_t displayId, sptr &inputControlChannel) { - IMSA_HILOGI("InputMethodCoreProxy::initializeInput"); + IMSA_HILOGD("InputMethodCoreProxy::initializeInput"); auto remote = Remote(); if (!remote) { IMSA_HILOGI("remote is nullptr"); @@ -75,7 +75,7 @@ int32_t InputMethodCoreProxy::initializeInput( int32_t InputMethodCoreProxy::InitInputControlChannel(sptr &inputControlChannel) { - IMSA_HILOGI("InputMethodCoreProxy::InitInputControlChannel"); + IMSA_HILOGD("InputMethodCoreProxy::InitInputControlChannel"); auto remote = Remote(); if (!remote) { IMSA_HILOGI("remote is nullptr"); @@ -105,7 +105,7 @@ int32_t InputMethodCoreProxy::InitInputControlChannel(sptr void InputMethodCoreProxy::SetClientState(bool state) { - IMSA_HILOGI("InputMethodCoreProxy::SetClientState"); + IMSA_HILOGD("InputMethodCoreProxy::SetClientState"); auto remote = Remote(); if (!remote) { IMSA_HILOGI("remote is nullptr"); @@ -127,7 +127,7 @@ void InputMethodCoreProxy::SetClientState(bool state) bool InputMethodCoreProxy::startInput( const sptr &inputDataChannel, const InputAttribute &editorAttribute, bool supportPhysicalKbd) { - IMSA_HILOGI("InputMethodCoreProxy::startInput"); + IMSA_HILOGD("InputMethodCoreProxy::startInput"); auto remote = Remote(); if (!remote) { IMSA_HILOGI("remote is nullptr"); @@ -159,7 +159,7 @@ bool InputMethodCoreProxy::startInput( int32_t InputMethodCoreProxy::stopInput() { - IMSA_HILOGI("InputMethodCoreProxy::stopInput"); + IMSA_HILOGD("InputMethodCoreProxy::stopInput"); auto remote = Remote(); if (!remote) { IMSA_HILOGI("remote is nullptr"); @@ -184,7 +184,7 @@ int32_t InputMethodCoreProxy::stopInput() int32_t InputMethodCoreProxy::showKeyboard( const sptr &inputDataChannel, bool isShowKeyboard, const SubProperty &subProperty) { - IMSA_HILOGI("InputMethodCoreProxy::showKeyboard"); + IMSA_HILOGD("InputMethodCoreProxy::showKeyboard"); return SendRequest(SHOW_KEYBOARD, [&inputDataChannel, &isShowKeyboard, &subProperty](MessageParcel &data) { return ITypesUtil::Marshal(data, inputDataChannel->AsObject(), isShowKeyboard, subProperty); }); @@ -192,7 +192,7 @@ int32_t InputMethodCoreProxy::showKeyboard( void InputMethodCoreProxy::StopInputService(std::string imeId) { - IMSA_HILOGI("InputMethodCoreProxy::StopInputService"); + IMSA_HILOGD("InputMethodCoreProxy::StopInputService"); auto remote = Remote(); if (!remote) { IMSA_HILOGI("InputMethodCoreProxy::StopInputService remote is nullptr"); @@ -213,7 +213,7 @@ void InputMethodCoreProxy::StopInputService(std::string imeId) bool InputMethodCoreProxy::hideKeyboard(int32_t flags) { - IMSA_HILOGI("InputMethodCoreProxy::hideKeyboard"); + IMSA_HILOGD("InputMethodCoreProxy::hideKeyboard"); auto remote = Remote(); if (!remote) { return false; @@ -235,7 +235,7 @@ bool InputMethodCoreProxy::hideKeyboard(int32_t flags) int32_t InputMethodCoreProxy::setKeyboardType(const KeyboardType &type) { - IMSA_HILOGI("InputMethodCoreProxy::setKeyboardType"); + IMSA_HILOGD("InputMethodCoreProxy::setKeyboardType"); auto remote = Remote(); if (!remote) { IMSA_HILOGI("remote is nullptr"); @@ -255,7 +255,7 @@ int32_t InputMethodCoreProxy::setKeyboardType(const KeyboardType &type) int32_t InputMethodCoreProxy::getKeyboardWindowHeight(int32_t &retHeight) { - IMSA_HILOGI("InputMethodCoreProxy::getKeyboardWindowHeight"); + IMSA_HILOGD("InputMethodCoreProxy::getKeyboardWindowHeight"); auto remote = Remote(); if (!remote) { IMSA_HILOGI("remote is nullptr"); @@ -278,13 +278,13 @@ int32_t InputMethodCoreProxy::getKeyboardWindowHeight(int32_t &retHeight) int32_t InputMethodCoreProxy::SetSubtype(const SubProperty &property) { - IMSA_HILOGI("InputMethodCoreProxy::SetSubtype"); + IMSA_HILOGD("InputMethodCoreProxy::SetSubtype"); return SendRequest(SET_SUBTYPE, [&property](MessageParcel &data) { return ITypesUtil::Marshal(data, property); }); } int32_t InputMethodCoreProxy::SendRequest(int code, ParcelHandler input, ParcelHandler output) { - IMSA_HILOGI("InputMethodCoreProxy::%{public}s in", __func__); + IMSA_HILOGD("InputMethodCoreProxy::%{public}s in", __func__); MessageParcel data; MessageParcel reply; MessageOption option{ MessageOption::TF_SYNC }; diff --git a/frameworks/inputmethod_ability/src/input_method_core_stub.cpp b/frameworks/inputmethod_ability/src/input_method_core_stub.cpp index 3a668ad8..49c58adc 100644 --- a/frameworks/inputmethod_ability/src/input_method_core_stub.cpp +++ b/frameworks/inputmethod_ability/src/input_method_core_stub.cpp @@ -46,7 +46,7 @@ InputMethodCoreStub::~InputMethodCoreStub() int32_t InputMethodCoreStub::OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - IMSA_HILOGI("InputMethodCoreStub::OnRemoteRequest"); + IMSA_HILOGD("InputMethodCoreStub::OnRemoteRequest"); auto descriptorToken = data.ReadInterfaceToken(); if (descriptorToken != GetDescriptor()) { IMSA_HILOGI("InputMethodCoreStub::OnRemoteRequest descriptorToken is invalid"); @@ -146,7 +146,7 @@ int32_t InputMethodCoreStub::OnRemoteRequest( int32_t InputMethodCoreStub::initializeInput( sptr &startInputToken, int32_t displayId, sptr &inputControlChannel) { - IMSA_HILOGI("InputMethodCoreStub::initializeInput"); + IMSA_HILOGD("InputMethodCoreStub::initializeInput"); if (!msgHandler_) { return ErrorCode::ERROR_NULL_POINTER; } @@ -168,7 +168,7 @@ int32_t InputMethodCoreStub::initializeInput( int32_t InputMethodCoreStub::InitInputControlChannel(sptr &inputControlChannel) { - IMSA_HILOGI("InputMethodCoreStub::initializeInput"); + IMSA_HILOGD("InputMethodCoreStub::initializeInput"); if (!msgHandler_) { return ErrorCode::ERROR_NULL_POINTER; } @@ -186,7 +186,7 @@ int32_t InputMethodCoreStub::InitInputControlChannel(sptr bool InputMethodCoreStub::startInput( const sptr &inputDataChannel, const InputAttribute &editorAttribute, bool supportPhysicalKbd) { - IMSA_HILOGI("InputMethodCoreStub::startInput"); + IMSA_HILOGD("InputMethodCoreStub::startInput"); if (!msgHandler_) { return ErrorCode::ERROR_NULL_POINTER; } @@ -204,7 +204,7 @@ bool InputMethodCoreStub::startInput( int32_t InputMethodCoreStub::stopInput() { - IMSA_HILOGI("InputMethodCoreStub::stopInput"); + IMSA_HILOGD("InputMethodCoreStub::stopInput"); if (!msgHandler_) { return ErrorCode::ERROR_NULL_POINTER; } @@ -216,7 +216,7 @@ int32_t InputMethodCoreStub::stopInput() void InputMethodCoreStub::SetClientState(bool state) { - IMSA_HILOGI("InputMethodCoreStub::SetClientState"); + IMSA_HILOGD("InputMethodCoreStub::SetClientState"); if (!msgHandler_) { return; } @@ -229,7 +229,7 @@ void InputMethodCoreStub::SetClientState(bool state) bool InputMethodCoreStub::hideKeyboard(int32_t flags) { - IMSA_HILOGI("InputMethodCoreStub::hideKeyboard"); + IMSA_HILOGD("InputMethodCoreStub::hideKeyboard"); if (!msgHandler_) { return ErrorCode::ERROR_NULL_POINTER; } @@ -244,7 +244,7 @@ bool InputMethodCoreStub::hideKeyboard(int32_t flags) int32_t InputMethodCoreStub::setKeyboardType(const KeyboardType &type) { - IMSA_HILOGI("InputMethodCoreStub::setKeyboardType"); + IMSA_HILOGD("InputMethodCoreStub::setKeyboardType"); if (!msgHandler_) { return ErrorCode::ERROR_NULL_POINTER; } @@ -258,7 +258,7 @@ int32_t InputMethodCoreStub::setKeyboardType(const KeyboardType &type) void InputMethodCoreStub::StopInputService(std::string imeId) { - IMSA_HILOGI("InputMethodCoreStub::StopInputService"); + IMSA_HILOGD("InputMethodCoreStub::StopInputService"); if (!msgHandler_) { return; } @@ -271,7 +271,7 @@ void InputMethodCoreStub::StopInputService(std::string imeId) int32_t InputMethodCoreStub::getKeyboardWindowHeight(int32_t &retHeight) { - IMSA_HILOGI("InputMethodCoreStub::getKeyboardWindowHeight"); + IMSA_HILOGD("InputMethodCoreStub::getKeyboardWindowHeight"); if (!msgHandler_) { return ErrorCode::ERROR_NULL_POINTER; } @@ -289,7 +289,7 @@ void InputMethodCoreStub::SetMessageHandler(MessageHandler *msgHandler) void InputMethodCoreStub::ShowKeyboardOnRemote(MessageParcel &data, MessageParcel &reply) { - IMSA_HILOGI("InputMethodCoreStub::ShowKeyboardOnRemote"); + IMSA_HILOGD("InputMethodCoreStub::ShowKeyboardOnRemote"); sptr channel; bool isShowKeyboard = false; SubProperty subProperty; @@ -303,7 +303,7 @@ void InputMethodCoreStub::ShowKeyboardOnRemote(MessageParcel &data, MessageParce void InputMethodCoreStub::SetSubtypeOnRemote(MessageParcel &data, MessageParcel &reply) { - IMSA_HILOGI("InputMethodCoreStub::SetSubtypeOnRemote"); + IMSA_HILOGD("InputMethodCoreStub::SetSubtypeOnRemote"); SubProperty property; int32_t ret = SendMessage(MessageID::MSG_ID_SET_SUBTYPE, [&data, &property](MessageParcel &parcel) { return ITypesUtil::Unmarshal(data, property) && ITypesUtil::Marshal(parcel, property); @@ -324,7 +324,7 @@ int32_t InputMethodCoreStub::SetSubtype(const SubProperty &property) int32_t InputMethodCoreStub::SendMessage(int code, ParcelHandler input) { - IMSA_HILOGI("InputMethodCoreStub::SendMessage"); + IMSA_HILOGD("InputMethodCoreStub::SendMessage"); if (msgHandler_ == nullptr) { IMSA_HILOGE("InputMethodCoreStub::msgHandler_ is nullptr"); return ErrorCode::ERROR_EX_NULL_POINTER; diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index 2a78c002..2be67c01 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -286,13 +286,13 @@ using namespace MessageID; void InputMethodController::HideTextInput() { - IMSA_HILOGI("InputMethodController::HideTextInput"); + IMSA_HILOGD("InputMethodController::HideTextInput"); StopInput(mClient); } int32_t InputMethodController::HideCurrentInput() { - IMSA_HILOGI("InputMethodController::HideCurrentInput"); + IMSA_HILOGD("InputMethodController::HideCurrentInput"); auto proxy = GetSystemAbilityProxy(); if (proxy == nullptr) { IMSA_HILOGE("proxy is nullptr"); @@ -320,7 +320,7 @@ using namespace MessageID; std::lock_guard lock(textListenerLock_); textListener = nullptr; } - IMSA_HILOGI("InputMethodController::Close"); + IMSA_HILOGD("InputMethodController::Close"); } void InputMethodController::PrepareInput(int32_t displayId, sptr &client, @@ -371,7 +371,7 @@ using namespace MessageID; std::shared_ptr InputMethodController::GetCurrentInputMethod() { - IMSA_HILOGI("InputMethodController::GetCurrentInputMethod"); + IMSA_HILOGD("InputMethodController::GetCurrentInputMethod"); auto proxy = GetSystemAbilityProxy(); if (proxy == nullptr) { IMSA_HILOGE("proxy is nullptr"); @@ -387,7 +387,7 @@ using namespace MessageID; std::shared_ptr InputMethodController::GetCurrentInputMethodSubtype() { - IMSA_HILOGI("InputMethodController::GetCurrentInputMethod"); + IMSA_HILOGD("InputMethodController::GetCurrentInputMethod"); auto proxy = GetSystemAbilityProxy(); if (proxy == nullptr) { IMSA_HILOGE("proxy is nullptr"); @@ -415,7 +415,7 @@ using namespace MessageID; void InputMethodController::ReleaseInput(sptr &client) { - IMSA_HILOGI("InputMethodController::ReleaseInput"); + IMSA_HILOGD("InputMethodController::ReleaseInput"); isStopInput = true; auto proxy = GetSystemAbilityProxy(); if (proxy == nullptr) { @@ -427,7 +427,7 @@ using namespace MessageID; void InputMethodController::StopInput(sptr &client) { - IMSA_HILOGI("InputMethodController::StopInput"); + IMSA_HILOGD("InputMethodController::StopInput"); isStopInput = true; auto proxy = GetSystemAbilityProxy(); if (proxy == nullptr) { diff --git a/frameworks/inputmethod_controller/src/input_method_system_ability_proxy.cpp b/frameworks/inputmethod_controller/src/input_method_system_ability_proxy.cpp index 18c03325..58189c19 100644 --- a/frameworks/inputmethod_controller/src/input_method_system_ability_proxy.cpp +++ b/frameworks/inputmethod_controller/src/input_method_system_ability_proxy.cpp @@ -39,7 +39,7 @@ int32_t InputMethodSystemAbilityProxy::PrepareInput(int32_t displayId, sptr client, bool isShowKeyboard) { - IMSA_HILOGI("%{public}s in", __func__); + IMSA_HILOGD("%{public}s in", __func__); return SendRequest(START_INPUT, [isShowKeyboard, client](MessageParcel &data) { return data.WriteRemoteObject(client->AsObject()) && data.WriteBool(isShowKeyboard); }); @@ -47,25 +47,25 @@ int32_t InputMethodSystemAbilityProxy::StartInput(sptr client, boo int32_t InputMethodSystemAbilityProxy::ShowCurrentInput() { - IMSA_HILOGI("%{public}s in", __func__); + IMSA_HILOGD("%{public}s in", __func__); return SendRequest(SHOW_CURRENT_INPUT); } int32_t InputMethodSystemAbilityProxy::HideCurrentInput() { - IMSA_HILOGI("%{public}s in", __func__); + IMSA_HILOGD("%{public}s in", __func__); return SendRequest(HIDE_CURRENT_INPUT); } int32_t InputMethodSystemAbilityProxy::StopInputSession() { - IMSA_HILOGI("%{public}s in", __func__); + IMSA_HILOGD("%{public}s in", __func__); return SendRequest(STOP_INPUT_SESSION); } int32_t InputMethodSystemAbilityProxy::StopInput(sptr client) { - IMSA_HILOGI("%{public}s in", __func__); + IMSA_HILOGD("%{public}s in", __func__); return SendRequest(STOP_INPUT, [client](MessageParcel &data) { return data.WriteRemoteObject(client->AsObject()); }); } @@ -84,7 +84,7 @@ int32_t InputMethodSystemAbilityProxy::DisplayOptionalInputMethod() int32_t InputMethodSystemAbilityProxy::SetCoreAndAgent(sptr core, sptr agent) { - IMSA_HILOGI("%{public}s in", __func__); + IMSA_HILOGD("%{public}s in", __func__); return SendRequest(SET_CORE_AND_AGENT, [core, agent](MessageParcel &data) { return data.WriteRemoteObject(core->AsObject()) && data.WriteRemoteObject(agent->AsObject()); }); @@ -92,14 +92,14 @@ int32_t InputMethodSystemAbilityProxy::SetCoreAndAgent(sptr co int32_t InputMethodSystemAbilityProxy::GetKeyboardWindowHeight(int32_t &retHeight) { - IMSA_HILOGI("%{public}s in", __func__); + IMSA_HILOGD("%{public}s in", __func__); return SendRequest(GET_KEYBOARD_WINDOW_HEIGHT, nullptr, [&retHeight](MessageParcel &reply) { return reply.ReadInt32(retHeight); }); } std::shared_ptr InputMethodSystemAbilityProxy::GetCurrentInputMethod() { - IMSA_HILOGI("%{public}s in", __func__); + IMSA_HILOGD("%{public}s in", __func__); std::shared_ptr property = nullptr; int32_t ret = SendRequest(GET_CURRENT_INPUT_METHOD, nullptr, [&property](MessageParcel &reply) { property = std::make_shared(); @@ -118,7 +118,7 @@ std::shared_ptr InputMethodSystemAbilityProxy::GetCurrentInputMethod() std::shared_ptr InputMethodSystemAbilityProxy::GetCurrentInputMethodSubtype() { - IMSA_HILOGI("%{public}s in", __func__); + IMSA_HILOGD("%{public}s in", __func__); std::shared_ptr property = nullptr; int32_t ret = SendRequest(GET_CURRENT_INPUT_METHOD_SUBTYPE, nullptr, [&property](MessageParcel &reply) { property = std::make_shared(); @@ -137,7 +137,7 @@ std::shared_ptr InputMethodSystemAbilityProxy::GetCurrentInputMetho int32_t InputMethodSystemAbilityProxy::ListInputMethod(InputMethodStatus status, std::vector &props) { - IMSA_HILOGI("%{public}s in", __func__); + IMSA_HILOGD("%{public}s in", __func__); int32_t ret = SendRequest( LIST_INPUT_METHOD, [status](MessageParcel &data) { return ITypesUtil::Marshal(data, uint32_t(status)); }, [&props](MessageParcel &reply) { return ITypesUtil::Unmarshal(reply, props); }); @@ -149,26 +149,26 @@ int32_t InputMethodSystemAbilityProxy::ListInputMethod(InputMethodStatus status, int32_t InputMethodSystemAbilityProxy::ShowCurrentInputDeprecated() { - IMSA_HILOGI("%{public}s in", __func__); + IMSA_HILOGD("%{public}s in", __func__); return SendRequest(SHOW_CURRENT_INPUT_DEPRECATED); } int32_t InputMethodSystemAbilityProxy::HideCurrentInputDeprecated() { - IMSA_HILOGI("%{public}s in", __func__); + IMSA_HILOGD("%{public}s in", __func__); return SendRequest(HIDE_CURRENT_INPUT_DEPRECATED); } int32_t InputMethodSystemAbilityProxy::DisplayOptionalInputMethodDeprecated() { - IMSA_HILOGI("%{public}s in", __func__); + IMSA_HILOGD("%{public}s in", __func__); return SendRequest(DISPLAY_OPTIONAL_INPUT_DEPRECATED); } int32_t InputMethodSystemAbilityProxy::SetCoreAndAgentDeprecated(sptr core, sptr agent) { - IMSA_HILOGI("%{public}s in", __func__); + IMSA_HILOGD("%{public}s in", __func__); return SendRequest(SET_CORE_AND_AGENT_DEPRECATED, [core, agent](MessageParcel &data) { return data.WriteRemoteObject(core->AsObject()) && data.WriteRemoteObject(agent->AsObject()); }); @@ -177,7 +177,7 @@ int32_t InputMethodSystemAbilityProxy::SetCoreAndAgentDeprecated(sptr &subProps) { - IMSA_HILOGI("InputMethodSystemAbilityProxy::ListInputMethodSubtype"); + IMSA_HILOGD("InputMethodSystemAbilityProxy::ListInputMethodSubtype"); int32_t ret = SendRequest( LIST_INPUT_METHOD_SUBTYPE, [&name](MessageParcel &data) { return ITypesUtil::Marshal(data, name); }, [&subProps](MessageParcel &reply) { return ITypesUtil::Unmarshal(reply, subProps); }); @@ -189,7 +189,7 @@ int32_t InputMethodSystemAbilityProxy::ListInputMethodSubtype( int32_t InputMethodSystemAbilityProxy::ListCurrentInputMethodSubtype(std::vector &subProps) { - IMSA_HILOGI("InputMethodSystemAbilityProxy::ListCurrentInputMethodSubtype"); + IMSA_HILOGD("InputMethodSystemAbilityProxy::ListCurrentInputMethodSubtype"); int32_t ret = SendRequest(LIST_CURRENT_INPUT_METHOD_SUBTYPE, nullptr, [&subProps](MessageParcel &reply) { return ITypesUtil::Unmarshal(reply, subProps); }); if (ret != ErrorCode::NO_ERROR) { @@ -200,14 +200,14 @@ int32_t InputMethodSystemAbilityProxy::ListCurrentInputMethodSubtype(std::vector int32_t InputMethodSystemAbilityProxy::SwitchInputMethod(const std::string &name, const std::string &subName) { - IMSA_HILOGI("InputMethodSystemAbilityProxy::SwitchInputMethod"); + IMSA_HILOGD("InputMethodSystemAbilityProxy::SwitchInputMethod"); return SendRequest(SWITCH_INPUT_METHOD, [&name, &subName](MessageParcel &data) { return ITypesUtil::Marshal(data, name, subName); }); } int32_t InputMethodSystemAbilityProxy::SendRequest(int code, ParcelHandler input, ParcelHandler output) { - IMSA_HILOGI("%{public}s in", __func__); + IMSA_HILOGD("%{public}s in", __func__); MessageParcel data; MessageParcel reply; MessageOption option{ MessageOption::TF_SYNC }; diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index ed29d5b9..8050cde9 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -115,13 +115,11 @@ private: int userId_; // the id of the user to whom the object is linking int userState = UserState::USER_STATE_STARTED; // the state of the user to whom the object is linking int displayId; // the id of the display screen on which the user is - int currentIndex; std::map, std::shared_ptr> mapClients; static const int MIN_IME = 2; static const int MAX_RESTART_NUM = 3; static const int IME_RESET_TIME_OUT = 300; static const int MAX_RESET_WAIT_TIME = 1600000; - static const int SLEEP_TIME = 300000; InputMethodInfo *currentIme[MAX_IME] = { nullptr, nullptr }; // 0 - the default ime. 1 - security ime @@ -132,10 +130,8 @@ private: int currentKbdIndex[MAX_IME]; // current keyboard index int lastImeIndex; // The last ime which showed keyboard InputMethodSetting *inputMethodSetting; // The pointer referred to the object in PerUserSetting - int currentDisplayMode; // the display mode of the current keyboard sptr imsAgent; - InputChannel *imsChannel; // the write channel created by input method service std::mutex clientLock_; sptr currentClient; // the current input client sptr needReshowClient = nullptr; // the input client for which keyboard need to re-show @@ -144,7 +140,6 @@ private: MessageHandler *msgHandler = nullptr; // message handler working with Work Thread std::thread workThreadHandler; // work thread handler std::recursive_mutex mtx; // mutex to lock the operations among multi work threads - sptr connCallback; std::mutex resetLock; ResetManager manager[MAX_IME]; @@ -172,7 +167,6 @@ private: int StopInputMethod(int index); int ShowKeyboard(const sptr &inputClient, bool isShowKeyboard); int HideKeyboard(const sptr &inputClient); - void SetDisplayId(int displayId); int GetImeIndex(const sptr &inputClient); static sptr GetAbilityManagerService(); void SendAgentToSingleClient(const ClientInfo &clientInfo); diff --git a/services/src/im_common_event_manager.cpp b/services/src/im_common_event_manager.cpp index 5f651af3..6855d931 100644 --- a/services/src/im_common_event_manager.cpp +++ b/services/src/im_common_event_manager.cpp @@ -22,9 +22,9 @@ #include "input_method_system_ability_stub.h" #include "ipc_skeleton.h" #include "iservice_registry.h" +#include "itypes_util.h" #include "message_handler.h" #include "system_ability_definition.h" -#include "itypes_util.h" namespace OHOS { namespace MiscServices { @@ -34,15 +34,11 @@ std::mutex ImCommonEventManager::instanceLock_; /*! Constructor */ -ImCommonEventManager::ImCommonEventManager() -{ -} +ImCommonEventManager::ImCommonEventManager() {} /*! Destructor */ -ImCommonEventManager::~ImCommonEventManager() -{ -} +ImCommonEventManager::~ImCommonEventManager() {} sptr ImCommonEventManager::GetInstance() { @@ -155,8 +151,7 @@ void ImCommonEventManager::EventSubscriber::HandlePackageRemove(const AAFwk::Wan auto element = want.GetElement(); std::string bundleName = element.GetBundleName(); int32_t userId = want.GetIntParam("userId", 0); - IMSA_HILOGI("bundleName = %{public}s, userId = %{public}d", bundleName.c_str(), userId); - + IMSA_HILOGD("bundleName = %{public}s, userId = %{public}d", bundleName.c_str(), userId); MessageParcel *parcel = new MessageParcel(); if (!ITypesUtil::Marshal(*parcel, userId, bundleName)) { IMSA_HILOGE("Failed to write message parcel"); diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index e1cadf38..0700af0b 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -739,7 +739,6 @@ namespace MiscServices { property.descriptionId = applicationInfo.descriptionId; property.label = Str8ToStr16(labelString); property.description = Str8ToStr16(descriptionString); - properties.emplace_back(property); } return properties; } @@ -881,7 +880,7 @@ namespace MiscServices { OnPackageRemoved(msg); delete msg; msg = nullptr; - return; + break; } case MSG_ID_SETTING_CHANGED: { OnSettingChanged(msg); @@ -1366,7 +1365,7 @@ namespace MiscServices { sptr InputMethodSystemAbility::GetAbilityManagerService() { - IMSA_HILOGE("InputMethodSystemAbility::GetAbilityManagerService start"); + IMSA_HILOGD("InputMethodSystemAbility::GetAbilityManagerService start"); auto systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (systemAbilityManager == nullptr) { IMSA_HILOGE("SystemAbilityManager is nullptr."); diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 7beb5dc2..5b5bf2a6 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -137,14 +137,6 @@ namespace MiscServices { } } - /*! Set display Id - \param displayId the Id of display screen on which the input method keyboard show. - */ - void PerUserSession::SetDisplayId(int displayId) - { - this->displayId = displayId; - } - /*! Set the current input method engine \param ime the current (default) IME pointer referred to the instance in PerUserSetting. */ @@ -178,7 +170,7 @@ namespace MiscServices { */ void PerUserSession::ResetIme(InputMethodInfo *defaultIme, InputMethodInfo *securityIme) { - IMSA_HILOGI("PerUserSession::ResetIme"); + IMSA_HILOGD("PerUserSession::ResetIme"); std::lock_guard lock(mtx); InputMethodInfo *ime[] = {defaultIme, securityIme}; for (int i = 0; i < MIN_IME; i++) { @@ -224,7 +216,7 @@ namespace MiscServices { */ void PerUserSession::OnPackageRemoved(const std::u16string& packageName) { - IMSA_HILOGI("PerUserSession::OnPackageRemoved"); + IMSA_HILOGD("PerUserSession::OnPackageRemoved"); InputMethodSetting tmpSetting; bool flag = false; std::lock_guard lock(mtx); @@ -255,7 +247,7 @@ namespace MiscServices { int PerUserSession::AddClient(sptr inputClient, const ClientInfo &clientInfo) { - IMSA_HILOGI("PerUserSession::AddClient"); + IMSA_HILOGD("PerUserSession::AddClient"); std::lock_guard lock(mtx); auto cacheClient = GetClientInfo(inputClient); if (cacheClient != nullptr) { @@ -287,7 +279,7 @@ namespace MiscServices { */ void PerUserSession::RemoveClient(sptr inputClient) { - IMSA_HILOGE("PerUserSession::RemoveClient"); + IMSA_HILOGD("PerUserSession::RemoveClient"); std::lock_guard lock(mtx); auto it = mapClients.find(inputClient); if (it == mapClients.end()) { @@ -392,7 +384,7 @@ namespace MiscServices { */ int PerUserSession::ShowKeyboard(const sptr& inputClient, bool isShowKeyboard) { - IMSA_HILOGI("PerUserSession::ShowKeyboard"); + IMSA_HILOGD("PerUserSession::ShowKeyboard"); auto clientInfo = GetClientInfo(inputClient->AsObject()); int index = GetImeIndex(inputClient); if (index == -1 || clientInfo == nullptr) { @@ -427,7 +419,7 @@ namespace MiscServices { */ int PerUserSession::HideKeyboard(const sptr& inputClient) { - IMSA_HILOGI("PerUserSession::HideKeyboard"); + IMSA_HILOGD("PerUserSession::HideKeyboard"); int index = GetImeIndex(inputClient); if (index == -1) { IMSA_HILOGE("PerUserSession::HideKeyboard Aborted! ErrorCode::ERROR_CLIENT_NOT_FOUND"); @@ -556,7 +548,7 @@ namespace MiscServices { } usleep(MAX_RESET_WAIT_TIME); MessageHandler::Instance()->SendMessage(msg); - IMSA_HILOGI("End...[%{public}d]\n", userId_); + IMSA_HILOGD("End...[%{public}d]\n", userId_); } /*! It's called when input method setting data in the system is changed @@ -567,16 +559,15 @@ namespace MiscServices { */ int PerUserSession::OnSettingChanged(const std::u16string& key, const std::u16string& value) { - IMSA_HILOGI("Start...[%{public}d]\n", userId_); + IMSA_HILOGD("Start...[%{public}d]\n", userId_); std::lock_guard lock(mtx); if (!inputMethodSetting) { return ErrorCode::ERROR_NULL_POINTER; } std::u16string currentValue = inputMethodSetting->GetValue(key); - IMSA_HILOGD("PerUserSession::OnSettingChanged key = %{public}s", Utils::ToStr8(key).c_str()); - IMSA_HILOGD("PerUserSession::OnSettingChanged value = %{public}s", Utils::ToStr8(value).c_str()); - IMSA_HILOGD("PerUserSession::OnSettingChanged currentValue = %{public}s", Utils::ToStr8(currentValue).c_str()); + IMSA_HILOGD("key = %{public}s, value = %{public}s, currentValue = %{public}s", Utils::ToStr8(key).c_str(), + Utils::ToStr8(value).c_str(), Utils::ToStr8(currentValue).c_str()); if (currentValue == value) { IMSA_HILOGI("End...[%{public}d]\n", userId_); @@ -612,7 +603,7 @@ namespace MiscServices { inputMethodSetting->SetCurrentKeyboardType(-1); } } - IMSA_HILOGI("End...[%{public}d]\n", userId_); + IMSA_HILOGD("End...[%{public}d]\n", userId_); return ErrorCode::NO_ERROR; } @@ -682,7 +673,7 @@ namespace MiscServices { */ int PerUserSession::OnHideKeyboardSelf(int flags) { - IMSA_HILOGW("PerUserSession::OnHideKeyboardSelf"); + IMSA_HILOGD("PerUserSession::OnHideKeyboardSelf"); (void)flags; sptr client = GetCurrentClient(); if (client == nullptr) { @@ -694,7 +685,7 @@ namespace MiscServices { int PerUserSession::OnShowKeyboardSelf() { - IMSA_HILOGI("PerUserSession::OnShowKeyboardSelf"); + IMSA_HILOGD("PerUserSession::OnShowKeyboardSelf"); sptr client = GetCurrentClient(); if (client == nullptr) { IMSA_HILOGE("current client is nullptr"); @@ -758,7 +749,6 @@ namespace MiscServices { */ void PerUserSession::OnSetDisplayMode(int mode) { - currentDisplayMode = mode; sptr client = GetCurrentClient(); if (client == nullptr) { IMSA_HILOGE("current client is nullptr"); @@ -784,7 +774,7 @@ namespace MiscServices { if (index < 0 || index >= MAX_IME) { return; } - IMSA_HILOGI("Start...[%{public}d]\n", userId_); + IMSA_HILOGD("Start...[%{public}d]\n", userId_); if (currentIme[index] && currentIme[index]->mImeId == imeId) { int ret = StartInputMethod(index); if (needReshowClient && GetImeIndex(needReshowClient) == index) { @@ -794,14 +784,14 @@ namespace MiscServices { needReshowClient = nullptr; } } - IMSA_HILOGI("End...[%{public}d]\n", userId_); + IMSA_HILOGD("End...[%{public}d]\n", userId_); } /*! It's called when this user is locked */ void PerUserSession::OnUserLocked() { - IMSA_HILOGI("PerUserSession::OnUserLocked"); + IMSA_HILOGD("PerUserSession::OnUserLocked"); std::lock_guard lock(mtx); if (userState == UserState::USER_STATE_STARTED) { IMSA_HILOGI("End...[%{public}d]\n", userId_); @@ -1052,7 +1042,7 @@ namespace MiscServices { */ int32_t PerUserSession::OnPrepareInput(const ClientInfo &clientInfo) { - IMSA_HILOGI("PerUserSession::OnPrepareInput Start\n"); + IMSA_HILOGD("PerUserSession::OnPrepareInput Start\n"); int ret = AddClient(clientInfo.client->AsObject(), clientInfo); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("PerUserSession::OnPrepareInput %{public}s", ErrorCode::ToString(ret)); @@ -1064,7 +1054,7 @@ namespace MiscServices { void PerUserSession::SendAgentToSingleClient(const ClientInfo &clientInfo) { - IMSA_HILOGI("PerUserSession::SendAgentToSingleClient"); + IMSA_HILOGD("PerUserSession::SendAgentToSingleClient"); if (imsAgent == nullptr) { IMSA_HILOGI("PerUserSession::SendAgentToSingleClient imsAgent is nullptr"); CreateComponentFailed(userId_, ErrorCode::ERROR_NULL_POINTER); @@ -1080,14 +1070,14 @@ namespace MiscServices { */ int32_t PerUserSession::OnReleaseInput(sptr client) { - IMSA_HILOGI("PerUserSession::OnReleaseInput Start\n"); + IMSA_HILOGD("PerUserSession::OnReleaseInput Start\n"); if (imsCore[0] == nullptr) { return ErrorCode::ERROR_IME_NOT_AVAILABLE; } imsCore[0]->SetClientState(false); HideKeyboard(client); RemoveClient(client->AsObject()); - IMSA_HILOGI("PerUserSession::OnReleaseInput End...[%{public}d]\n", userId_); + IMSA_HILOGD("PerUserSession::OnReleaseInput End...[%{public}d]\n", userId_); return ErrorCode::NO_ERROR; } @@ -1098,7 +1088,7 @@ namespace MiscServices { */ int32_t PerUserSession::OnStartInput(sptr client, bool isShowKeyboard) { - IMSA_HILOGI("PerUserSession::OnStartInput"); + IMSA_HILOGD("PerUserSession::OnStartInput"); if (imsCore[0] == nullptr) { return ErrorCode::ERROR_IME_NOT_AVAILABLE; } @@ -1108,7 +1098,7 @@ namespace MiscServices { int32_t PerUserSession::OnSetCoreAndAgent(sptr core, sptr agent) { - IMSA_HILOGI("PerUserSession::SetCoreAndAgent Start\n"); + IMSA_HILOGD("PerUserSession::SetCoreAndAgent Start\n"); if (core == nullptr || agent == nullptr) { IMSA_HILOGE("PerUserSession::SetCoreAndAgent core or agent nullptr"); return ErrorCode::ERROR_EX_NULL_POINTER; @@ -1127,7 +1117,7 @@ namespace MiscServices { void PerUserSession::SendAgentToAllClients() { - IMSA_HILOGI("PerUserSession::SendAgentToAllClients"); + IMSA_HILOGD("PerUserSession::SendAgentToAllClients"); std::lock_guard lock(mtx); if (imsAgent == nullptr) { IMSA_HILOGE("PerUserSession::SendAgentToAllClients imsAgent is nullptr"); @@ -1144,7 +1134,7 @@ namespace MiscServices { void PerUserSession::InitInputControlChannel() { - IMSA_HILOGI("PerUserSession::InitInputControlChannel"); + IMSA_HILOGD("PerUserSession::InitInputControlChannel"); sptr inputControlChannel = new InputControlChannelStub(userId_); int ret = imsCore[0]->InitInputControlChannel(inputControlChannel); if (ret != ErrorCode::NO_ERROR) { @@ -1159,13 +1149,13 @@ namespace MiscServices { */ int32_t PerUserSession::OnStopInput(sptr client) { - IMSA_HILOGI("PerUserSession::OnStopInput"); + IMSA_HILOGD("PerUserSession::OnStopInput"); return HideKeyboard(client); } void PerUserSession::StopInputService(std::string imeId) { - IMSA_HILOGI("PerUserSession::StopInputService"); + IMSA_HILOGD("PerUserSession::StopInputService"); if (imsCore[0] == nullptr) { IMSA_HILOGE("imsCore[0] is nullptr"); return; @@ -1177,7 +1167,7 @@ namespace MiscServices { bool PerUserSession::IsRestartIme(uint32_t index) { - IMSA_HILOGI("PerUserSession::IsRestartIme"); + IMSA_HILOGD("PerUserSession::IsRestartIme"); std::lock_guard lock(resetLock); auto now = time(nullptr); if (difftime(now, manager[index].last) > IME_RESET_TIME_OUT) { @@ -1221,7 +1211,7 @@ namespace MiscServices { int32_t PerUserSession::OnInputMethodSwitched(const Property &property, const SubProperty &subProperty) { - IMSA_HILOGI("PerUserSession::OnInputMethodSwitched"); + IMSA_HILOGD("PerUserSession::OnInputMethodSwitched"); std::lock_guard lock(mtx); for (const auto &client : mapClients) { auto clientInfo = client.second; @@ -1254,14 +1244,14 @@ namespace MiscServices { SubProperty PerUserSession::GetCurrentSubProperty() { - IMSA_HILOGI("PerUserSession::GetCurrentSubProperty"); + IMSA_HILOGD("PerUserSession::GetCurrentSubProperty"); std::lock_guard lock(propertyLock_); return currentSubProperty; } void PerUserSession::SetCurrentSubProperty(const SubProperty &subProperty) { - IMSA_HILOGI("PerUserSession::SetCurrentSubProperty"); + IMSA_HILOGD("PerUserSession::SetCurrentSubProperty"); std::lock_guard lock(propertyLock_); currentSubProperty = subProperty; } From 74141b65157d6dec2f066874112f8e89b31d1c9d Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Wed, 23 Nov 2022 19:23:21 +0800 Subject: [PATCH 085/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/include/peruser_session.h | 5 +++-- services/src/peruser_session.cpp | 14 +++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index 0142d21c..bfcf62c6 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -183,9 +183,10 @@ private: bool IsRestartIme(uint32_t index); void ClearImeData(uint32_t index); void SetCurrentClient(sptr client); - sptr GetImsCore(int32_t index); - void SetImsCore(int32_t index, sptr &core); sptr GetCurrentClient(); + void SetImsCore(int32_t index, sptr &core); + sptr GetImsCore(int32_t index); + bool CompareCore(int32_t index); std::mutex propertyLock_; SubProperty currentSubProperty; diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index f0453c72..b8ad0269 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -665,15 +665,13 @@ namespace MiscServices { KeyboardType *type = GetKeyboardType(index, currentKbdIndex[index]); if (type) { sptr client = GetCurrentClient(); - sptr core = GetImsCore(index); - sptr core_ = GetImsCore((1 - index)); if (client != nullptr) { int ret = core->setKeyboardType(*type); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("setKeyboardType ret: %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); } } - if (core == core_) { + if (CompareCore(index)) { inputMethodSetting->SetCurrentKeyboardType(type->getHashCode()); inputMethodSetting->SetCurrentSysKeyboardType(type->getHashCode()); currentKbdIndex[1 - index] = currentKbdIndex[index]; @@ -1304,5 +1302,15 @@ namespace MiscServices { std::lock_guard lock(imsCoreLock_); imsCore[index] = core; } + + bool PerUserSession::CompareCore(int32_t index) + { + sptr core = GetImsCore(index); + sptr core_ = GetImsCore((1 - index)); + if (core == core_) { + return true; + } + return false; + } } // namespace MiscServices } // namespace OHOS From eadfd783bcefa0206d9b44db1c1ea115fdc5f1dd Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Wed, 23 Nov 2022 19:41:33 +0800 Subject: [PATCH 086/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/src/peruser_session.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index b8ad0269..3c843435 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -352,10 +352,8 @@ namespace MiscServices { IMSA_HILOGE("Aborted! %{public}s", ErrorCode::ToString(ErrorCode::ERROR_IME_NOT_STARTED)); return ErrorCode::ERROR_IME_NOT_STARTED; } - sptr core_ = GetImsCore((1 - index)); - sptr nullCore = nullptr; - if (currentIme[index] == currentIme[1 - index] && core_ != nullptr) { - SetImsCore(index, nullCore); + if (currentIme[index] == currentIme[1 - index] && GetImsCore((1 - index)) != nullptr) { + SetImsCore(index, nullptr); inputControlChannel[index] = nullptr; localControlChannel[index] = nullptr; IMSA_HILOGI("End...[%{public}d]\n", userId_); @@ -377,7 +375,7 @@ namespace MiscServices { if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("RemoveDeathRecipient return : %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); } - SetImsCore(index, nullCore); + SetImsCore(index, nullptr); inputControlChannel[index] = nullptr; localControlChannel[index] = nullptr; IMSA_HILOGI("End...[%{public}d]\n", userId_); @@ -1222,8 +1220,7 @@ namespace MiscServices { sptr core = GetImsCore(index); if (core != nullptr) { core->AsObject()->RemoveDeathRecipient(imsDeathRecipient); - sptr nullCore = nullptr; - SetImsCore(index, nullCore); + SetImsCore(index, nullptr); } inputControlChannel[index] = nullptr; localControlChannel[index] = nullptr; From 7c3c5fbe1f7cf35007e55aed7d4062cd88dd0e6b Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Wed, 23 Nov 2022 19:56:29 +0800 Subject: [PATCH 087/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/include/peruser_session.h | 2 +- services/src/peruser_session.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index bfcf62c6..ef667839 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -184,7 +184,7 @@ private: void ClearImeData(uint32_t index); void SetCurrentClient(sptr client); sptr GetCurrentClient(); - void SetImsCore(int32_t index, sptr &core); + void SetImsCore(int32_t index, sptr core); sptr GetImsCore(int32_t index); bool CompareCore(int32_t index); diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 3c843435..f20b8b44 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -664,7 +664,7 @@ namespace MiscServices { if (type) { sptr client = GetCurrentClient(); if (client != nullptr) { - int ret = core->setKeyboardType(*type); + int ret = GetImsCore(index)->setKeyboardType(*type); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("setKeyboardType ret: %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); } @@ -1294,7 +1294,7 @@ namespace MiscServices { return imsCore[index]; } - void PerUserSession::SetImsCore(int32_t index, sptr &core) + void PerUserSession::SetImsCore(int32_t index, sptr core) { std::lock_guard lock(imsCoreLock_); imsCore[index] = core; From c964ea8c50554211355ea4fd181dc112dd043b47 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Wed, 23 Nov 2022 19:58:40 +0800 Subject: [PATCH 088/112] modify code Signed-off-by: zhaolinglan --- services/adapter/keyboard/BUILD.gn | 5 +- .../keyboard/include/input_event_callback.h | 44 +++++++ .../keyboard/{ => include}/keyboard_event.h | 18 +-- .../adapter/keyboard/input_event_callback.h | 120 ------------------ .../keyboard/src/input_event_callback.cpp | 95 ++++++++++++++ .../keyboard/{ => src}/keyboard_event.cpp | 6 +- services/include/im_common_event_manager.h | 2 +- .../include/input_method_system_ability.h | 4 +- services/src/input_method_system_ability.cpp | 21 ++- 9 files changed, 165 insertions(+), 150 deletions(-) create mode 100644 services/adapter/keyboard/include/input_event_callback.h rename services/adapter/keyboard/{ => include}/keyboard_event.h (80%) delete mode 100644 services/adapter/keyboard/input_event_callback.h create mode 100644 services/adapter/keyboard/src/input_event_callback.cpp rename services/adapter/keyboard/{ => src}/keyboard_event.cpp (91%) diff --git a/services/adapter/keyboard/BUILD.gn b/services/adapter/keyboard/BUILD.gn index d07b86ae..cac9aca9 100644 --- a/services/adapter/keyboard/BUILD.gn +++ b/services/adapter/keyboard/BUILD.gn @@ -23,7 +23,10 @@ config("inputmethod_adapter_native_config") { } ohos_static_library("keboard_event_static") { - sources = [ "keyboard_event.cpp" ] + sources = [ + "src/input_event_callback.cpp", + "src/keyboard_event.cpp", + ] configs = [ ":inputmethod_adapter_native_config" ] diff --git a/services/adapter/keyboard/include/input_event_callback.h b/services/adapter/keyboard/include/input_event_callback.h new file mode 100644 index 00000000..6b01f70e --- /dev/null +++ b/services/adapter/keyboard/include/input_event_callback.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 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 INPUTMETHOD_IMF_INPUT_EVENT_CALLBACK_H +#define INPUTMETHOD_IMF_INPUT_EVENT_CALLBACK_H + +#include +#include +#include + +#include "keyboard_event.h" +#include "input_manager.h" +#include "key_event.h" + +namespace OHOS { +namespace MiscServices { +class InputEventCallback : public MMI::IInputEventConsumer { +public: + virtual void OnInputEvent(std::shared_ptr keyEvent) const; + virtual void OnInputEvent(std::shared_ptr pointerEvent) const; + virtual void OnInputEvent(std::shared_ptr axisEvent) const; + void SetKeyHandle(KeyHandle handle); + +private: + KeyHandle keyHandler_ = nullptr; + static uint32_t keyState; + static CombinationKey FindCombinationKey(uint32_t state) ; +}; +} // namespace MiscServices +} // namespace OHOS + +#endif // INPUTMETHOD_IMF_INPUT_EVENT_CALLBACK_H diff --git a/services/adapter/keyboard/keyboard_event.h b/services/adapter/keyboard/include/keyboard_event.h similarity index 80% rename from services/adapter/keyboard/keyboard_event.h rename to services/adapter/keyboard/include/keyboard_event.h index 002ba8b6..46430c9c 100644 --- a/services/adapter/keyboard/keyboard_event.h +++ b/services/adapter/keyboard/include/keyboard_event.h @@ -26,14 +26,14 @@ namespace OHOS { namespace MiscServices { -struct CombineKey { - std::set preKeys; - int32_t finalKey; +enum CombinationKey : uint32_t { + UNKNOWN = 0, + CAPS, + SHIFT, + CTRL_SHIFT }; -enum CombineKeyCode : uint32_t { COMBINE_KEYCODE_CAPS = 0, COMBINE_KEYCODE_SHIFT, COMBINE_KEYCODE_CTRL_SHIFT }; - -using KeyHandle = std::function; +using KeyHandle = std::function; class KeyboardEvent { public: @@ -48,12 +48,6 @@ private: KeyboardEvent &operator=(const KeyboardEvent &) = delete; KeyboardEvent &operator=(KeyboardEvent &&) = delete; }; - -struct KeyboardEventHandler { - CombineKey combine; - KeyHandle handle; -}; - } // namespace MiscServices } // namespace OHOS #endif // IMF_KEYBOARD_EVENT_H diff --git a/services/adapter/keyboard/input_event_callback.h b/services/adapter/keyboard/input_event_callback.h deleted file mode 100644 index fb7daf20..00000000 --- a/services/adapter/keyboard/input_event_callback.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2022 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 INPUTMETHOD_IMF_INPUT_EVENT_CALLBACK_H -#define INPUTMETHOD_IMF_INPUT_EVENT_CALLBACK_H - -#include -#include - -#include -#include -#include - -#include "global.h" -#include "keyboard_event.h" - -namespace OHOS { -namespace MiscServices { -class InputEventCallback : public MMI::IInputEventConsumer { -public: - virtual void OnInputEvent(std::shared_ptr keyEvent) const; - virtual void OnInputEvent(std::shared_ptr pointerEvent) const; - virtual void OnInputEvent(std::shared_ptr axisEvent) const; - void SetKeyHandle(KeyHandle handle); - -private: - KeyHandle keyHandler_ = nullptr; - static std::mutex statusMapLock_; - static std::map statusMap_; - std::map, CombineKeyCode> combinedKeyMap_ = { - { { MMI::KeyEvent::KEYCODE_CAPS_LOCK }, CombineKeyCode::COMBINE_KEYCODE_CAPS }, - { { MMI::KeyEvent::KEYCODE_SHIFT_LEFT }, CombineKeyCode::COMBINE_KEYCODE_SHIFT }, - { { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT }, CombineKeyCode::COMBINE_KEYCODE_SHIFT }, - { { MMI::KeyEvent::KEYCODE_SHIFT_LEFT, MMI::KeyEvent::KEYCODE_CTRL_LEFT }, - CombineKeyCode::COMBINE_KEYCODE_CTRL_SHIFT }, - { { MMI::KeyEvent::KEYCODE_SHIFT_LEFT, MMI::KeyEvent::KEYCODE_CTRL_RIGHT }, - CombineKeyCode::COMBINE_KEYCODE_CTRL_SHIFT }, - { { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, MMI::KeyEvent::KEYCODE_CTRL_LEFT }, - CombineKeyCode::COMBINE_KEYCODE_CTRL_SHIFT }, - { { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, MMI::KeyEvent::KEYCODE_CTRL_RIGHT }, - CombineKeyCode::COMBINE_KEYCODE_CTRL_SHIFT }, - }; -}; - -std::mutex InputEventCallback::statusMapLock_; -std::map InputEventCallback::statusMap_ = { - { MMI::KeyEvent::KEYCODE_SHIFT_LEFT, false }, - { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, false }, - { MMI::KeyEvent::KEYCODE_CTRL_LEFT, false }, - { MMI::KeyEvent::KEYCODE_CTRL_RIGHT, false }, - { MMI::KeyEvent::KEYCODE_CAPS_LOCK, false }, -}; - -void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) const -{ - auto keyCode = keyEvent->GetKeyCode(); - auto keyAction = keyEvent->GetKeyAction(); - IMSA_HILOGD("keyCode: %{public}d, keyAction: %{public}d", keyCode, keyAction); - - std::lock_guard lock(statusMapLock_); - if (statusMap_.find(keyCode) == statusMap_.end() || keyAction == MMI::KeyEvent::KEY_ACTION_UNKNOWN) { - IMSA_HILOGD("keyevent undefined"); - return; - } - if (keyAction == MMI::KeyEvent::KEY_ACTION_DOWN) { - IMSA_HILOGD("key %{public}d pressed down", keyCode); - statusMap_[keyCode] = true; - return; - } - - IMSA_HILOGD("key %{public}d pressed up", keyCode); - std::vector downKeys; - for (auto &key : statusMap_) { - if (key.second) { - downKeys.push_back(key.first); - key.second = false; - } - } - auto combinedKey = combinedKeyMap_.find(downKeys); - if (combinedKey == combinedKeyMap_.end()) { - IMSA_HILOGD("undefined combinedkey"); - return; - } - if (keyHandler_ == nullptr) { - IMSA_HILOGE("keyHandler_ is nullptr"); - return; - } - int32_t ret = keyHandler_(combinedKey->second); - IMSA_HILOGI("handle keyevent ret: %{public}d", ret); -} - -void InputEventCallback::OnInputEvent(std::shared_ptr pointerEvent) const -{ -} - -void InputEventCallback::OnInputEvent(std::shared_ptr axisEvent) const -{ -} - -void InputEventCallback::SetKeyHandle(KeyHandle handle) -{ - IMSA_HILOGD("set key handle"); - keyHandler_ = std::move(handle); -} -} // namespace MiscServices -} // namespace OHOS - -#endif // INPUTMETHOD_IMF_INPUT_EVENT_CALLBACK_H diff --git a/services/adapter/keyboard/src/input_event_callback.cpp b/services/adapter/keyboard/src/input_event_callback.cpp new file mode 100644 index 00000000..723bab66 --- /dev/null +++ b/services/adapter/keyboard/src/input_event_callback.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2022 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 "../include/input_event_callback.h" + +#include "global.h" + +namespace OHOS { +namespace MiscServices { +constexpr uint32_t SHIFT_LEFT_POS = 0X1; +constexpr uint32_t SHIFT_RIGHT_POS = 0X1 << 1; +constexpr uint32_t CTRL_LEFT_POS = 0X1 << 2; +constexpr uint32_t CTRL_RIGHT_POS = 0X1 << 3; +constexpr uint32_t CAPS_POS = 0X1 << 4; + +uint32_t InputEventCallback::keyState = 0; + +std::map POS_MAP{ + { MMI::KeyEvent::KEYCODE_SHIFT_LEFT, SHIFT_LEFT_POS }, + { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, SHIFT_RIGHT_POS }, + { MMI::KeyEvent::KEYCODE_CTRL_LEFT, CTRL_LEFT_POS }, + { MMI::KeyEvent::KEYCODE_CTRL_RIGHT, CTRL_RIGHT_POS }, + { MMI::KeyEvent::KEYCODE_CAPS_LOCK, CAPS_POS }, +}; + +void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) const +{ + auto keyCode = keyEvent->GetKeyCode(); + auto keyAction = keyEvent->GetKeyAction(); + if (POS_MAP.find(keyCode) == POS_MAP.end() || keyAction == MMI::KeyEvent::KEY_ACTION_UNKNOWN) { + IMSA_HILOGD("key event unknown"); + return; + } + IMSA_HILOGD("keyCode: %{public}d, keyAction: %{public}d", keyCode, keyAction); + if (keyAction == MMI::KeyEvent::KEY_ACTION_DOWN) { + IMSA_HILOGD("key %{public}d pressed down", keyCode); + keyState = keyState | POS_MAP[keyCode]; + return; + } + + CombinationKey key = FindCombinationKey(keyState); + keyState = keyState & ~POS_MAP[keyCode]; + if (key == CombinationKey::UNKNOWN) { + IMSA_HILOGE("combination key unknown"); + return; + } + if (keyHandler_ == nullptr) { + IMSA_HILOGE("keyHandler_ is nullptr"); + return; + } + int32_t ret = keyHandler_(key); + IMSA_HILOGI("handle key event ret: %{public}d", ret); +} + +void InputEventCallback::OnInputEvent(std::shared_ptr pointerEvent) const +{ +} + +void InputEventCallback::OnInputEvent(std::shared_ptr axisEvent) const +{ +} + +void InputEventCallback::SetKeyHandle(KeyHandle handle) +{ + keyHandler_ = std::move(handle); +} + +CombinationKey InputEventCallback::FindCombinationKey(uint32_t state) +{ + if (state == CAPS_POS) { + return CombinationKey::CAPS; + } + if (state == SHIFT_LEFT_POS || state == SHIFT_RIGHT_POS) { + return CombinationKey::SHIFT; + } + if ((state == (CTRL_LEFT_POS | SHIFT_LEFT_POS)) || (state == (CTRL_LEFT_POS | SHIFT_RIGHT_POS)) + || (state == (CTRL_RIGHT_POS | SHIFT_LEFT_POS)) || (state == (CTRL_RIGHT_POS | SHIFT_RIGHT_POS))) { + return CombinationKey::CTRL_SHIFT; + } + return CombinationKey::UNKNOWN; +} +} // namespace MiscServices +} // namespace OHOS \ No newline at end of file diff --git a/services/adapter/keyboard/keyboard_event.cpp b/services/adapter/keyboard/src/keyboard_event.cpp similarity index 91% rename from services/adapter/keyboard/keyboard_event.cpp rename to services/adapter/keyboard/src/keyboard_event.cpp index 4b29adda..6cefad8b 100644 --- a/services/adapter/keyboard/keyboard_event.cpp +++ b/services/adapter/keyboard/src/keyboard_event.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "keyboard_event.h" +#include "../include/keyboard_event.h" #include #include @@ -21,7 +21,7 @@ #include #include "global.h" -#include "input_event_callback.h" +#include "../include/input_event_callback.h" namespace OHOS { namespace MiscServices { @@ -42,7 +42,7 @@ int32_t KeyboardEvent::AddKeyEventMonitor(KeyHandle handle) InputManager::GetInstance()->AddMonitor(std::static_pointer_cast(callback)); if (monitorId < 0) { IMSA_HILOGE("add monitor failed, id: %{public}d", monitorId); - return ErrorCode::ERROR_STATUS_UNKNOWN_ERROR; + return ErrorCode::ERROR_SUBSCRIBE_KEYBOARD_EVENT; } IMSA_HILOGD("add monitor success, id: %{public}d", monitorId); return ErrorCode::NO_ERROR; diff --git a/services/include/im_common_event_manager.h b/services/include/im_common_event_manager.h index af0360c8..9c5ad5cd 100644 --- a/services/include/im_common_event_manager.h +++ b/services/include/im_common_event_manager.h @@ -20,7 +20,7 @@ #include #include -#include "../adapter/keyboard/keyboard_event.h" +#include "../adapter/keyboard/include/keyboard_event.h" #include "common_event_data.h" #include "common_event_manager.h" #include "common_event_subscribe_info.h" diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index d58fc830..1ff4e439 100644 --- a/services/include/input_method_system_ability.h +++ b/services/include/input_method_system_ability.h @@ -20,7 +20,7 @@ #include #include -#include "../adapter/keyboard/keyboard_event.h" +#include "../adapter/keyboard/include/keyboard_event.h" #include "ability_manager_interface.h" #include "application_info.h" #include "bundle_mgr_proxy.h" @@ -140,7 +140,7 @@ private: using CompareHandler = std::function; SubProperty FindSubPropertyByCompare(const std::string &bundleName, CompareHandler compare); SubProperty GetExtends(const std::vector &metaData); - int32_t SwitchByCombinedKey(const CombineKeyCode &property); + int32_t SwitchByCombinationKey(const CombinationKey &key); int32_t QueryImeInfos(int32_t userId, std::vector &infos); }; diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index a1fe1460..6d5d0ef5 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -19,7 +19,6 @@ #include #include -#include "../adapter/keyboard/keyboard_event.h" #include "ability_connect_callback_proxy.h" #include "ability_manager_interface.h" #include "application_info.h" @@ -31,6 +30,7 @@ #include "input_method_status.h" #include "ipc_skeleton.h" #include "iservice_registry.h" +#include "itypes_util.h" #include "message_handler.h" #include "os_account_manager.h" #include "para_handle.h" @@ -38,7 +38,6 @@ #include "system_ability.h" #include "system_ability_definition.h" #include "ui_service_mgr_client.h" -#include "itypes_util.h" namespace OHOS { namespace MiscServices { @@ -1401,16 +1400,16 @@ namespace MiscServices { return {}; } - int32_t InputMethodSystemAbility::SwitchByCombinedKey(const CombineKeyCode &keyCode) + int32_t InputMethodSystemAbility::SwitchByCombinationKey(const CombinationKey &key) { - IMSA_HILOGI("InputMethodSystemAbility::SwitchByCombinedKey"); + IMSA_HILOGI("InputMethodSystemAbility::SwitchByCombinationKey"); auto current = GetCurrentInputMethodSubtype(); if (current == nullptr) { IMSA_HILOGE("GetCurrentInputMethodSubtype failed"); return ErrorCode::ERROR_EX_NULL_POINTER; } - if (keyCode == CombineKeyCode::COMBINE_KEYCODE_CAPS) { - IMSA_HILOGI("COMBINE_KEYCODE_CAPS press"); + if (key == CombinationKey::CAPS) { + IMSA_HILOGI("CAPS press"); auto target = current->mode == "upper" ? FindSubPropertyByCompare(current->id, [¤t](const SubProperty &property) { return property.mode == "lower"; }) @@ -1418,8 +1417,8 @@ namespace MiscServices { [¤t](const SubProperty &property) { return property.mode == "upper"; }); return SwitchInputMethod(target.id, target.label); } - if (keyCode == CombineKeyCode::COMBINE_KEYCODE_SHIFT) { - IMSA_HILOGI("COMBINE_KEYCODE_SHIFT press"); + if (key == CombinationKey::SHIFT) { + IMSA_HILOGI("SHIFT press"); auto target = current->language == "chinese" ? FindSubPropertyByCompare(current->id, [¤t](const SubProperty &property) { return property.language == "english"; }) @@ -1427,8 +1426,8 @@ namespace MiscServices { [¤t](const SubProperty &property) { return property.language == "chinese"; }); return SwitchInputMethod(target.id, target.label); } - if (keyCode == CombineKeyCode::COMBINE_KEYCODE_CTRL_SHIFT) { - IMSA_HILOGI("COMBINE_KEYCODE_CTRL_SHIFT press"); + if (key == CombinationKey::CTRL_SHIFT) { + IMSA_HILOGI("CTRL_SHIFT press"); std::vector props = {}; auto ret = ListProperty(MAIN_USER_ID, props); if (ret != ErrorCode::NO_ERROR) { @@ -1449,7 +1448,7 @@ namespace MiscServices { { IMSA_HILOGI("InputMethodSystemAbility::InitKeyEventMonitor"); bool ret = ImCommonEventManager::GetInstance()->SubscribeKeyboardEvent( - [this](const CombineKeyCode &keyCode) { return SwitchByCombinedKey(keyCode); }); + [this](const CombinationKey &keyCode) { return SwitchByCombinationKey(keyCode); }); return ret ? ErrorCode::NO_ERROR : ErrorCode::ERROR_SERVICE_START_FAILED; } } // namespace MiscServices From 314be8dbd04bbc46b0978fc9f57775d5aa50b77e Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Wed, 23 Nov 2022 20:02:01 +0800 Subject: [PATCH 089/112] modify code Signed-off-by: zhaolinglan --- services/adapter/keyboard/include/keyboard_event.h | 3 +-- services/adapter/keyboard/src/keyboard_event.cpp | 4 ++-- services/src/input_method_system_ability.cpp | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/services/adapter/keyboard/include/keyboard_event.h b/services/adapter/keyboard/include/keyboard_event.h index 46430c9c..4c542fbb 100644 --- a/services/adapter/keyboard/include/keyboard_event.h +++ b/services/adapter/keyboard/include/keyboard_event.h @@ -16,13 +16,12 @@ #ifndef IMF_KEYBOARD_EVENT_H #define IMF_KEYBOARD_EVENT_H -#include - #include #include #include #include "global.h" +#include "key_event.h" namespace OHOS { namespace MiscServices { diff --git a/services/adapter/keyboard/src/keyboard_event.cpp b/services/adapter/keyboard/src/keyboard_event.cpp index 6cefad8b..5cbda6c4 100644 --- a/services/adapter/keyboard/src/keyboard_event.cpp +++ b/services/adapter/keyboard/src/keyboard_event.cpp @@ -16,12 +16,12 @@ #include "../include/keyboard_event.h" #include -#include #include -#include "global.h" #include "../include/input_event_callback.h" +#include "global.h" +#include "key_event.h" namespace OHOS { namespace MiscServices { diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 6d5d0ef5..a979ce73 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -16,7 +16,6 @@ #include "input_method_system_ability.h" #include -#include #include #include "ability_connect_callback_proxy.h" @@ -31,6 +30,7 @@ #include "ipc_skeleton.h" #include "iservice_registry.h" #include "itypes_util.h" +#include "key_event.h" #include "message_handler.h" #include "os_account_manager.h" #include "para_handle.h" From 4fdaaa0f87d702702faf6f42cf59ee0f0bef9076 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Wed, 23 Nov 2022 20:13:52 +0800 Subject: [PATCH 090/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/src/peruser_session.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index f20b8b44..24be9532 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -1291,17 +1291,29 @@ namespace MiscServices { sptr PerUserSession::GetImsCore(int32_t index) { std::lock_guard lock(imsCoreLock_); + if (index < DEFAULT_IME || index > SECURITY_IME) { + IMSA_HILOGE("PerUserSession::SetImsCore out of index. index = %{public}d", index); + return nullptr; + } return imsCore[index]; } void PerUserSession::SetImsCore(int32_t index, sptr core) { std::lock_guard lock(imsCoreLock_); + if (index < DEFAULT_IME || index > SECURITY_IME) { + IMSA_HILOGE("PerUserSession::SetImsCore out of index. index = %{public}d", index); + return; + } imsCore[index] = core; } bool PerUserSession::CompareCore(int32_t index) { + if (index < DEFAULT_IME || index > SECURITY_IME) { + IMSA_HILOGE("PerUserSession::SetImsCore out of index. index = %{public}d", index); + return false; + } sptr core = GetImsCore(index); sptr core_ = GetImsCore((1 - index)); if (core == core_) { From 4df035eb3051ca031c4ab710b8eac9a4cb210c20 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Wed, 23 Nov 2022 20:54:41 +0800 Subject: [PATCH 091/112] modify code Signed-off-by: zhaolinglan --- test/fuzztest/inputmethod_fuzzer/BUILD.gn | 69 +++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 test/fuzztest/inputmethod_fuzzer/BUILD.gn diff --git a/test/fuzztest/inputmethod_fuzzer/BUILD.gn b/test/fuzztest/inputmethod_fuzzer/BUILD.gn new file mode 100644 index 00000000..e3f713b2 --- /dev/null +++ b/test/fuzztest/inputmethod_fuzzer/BUILD.gn @@ -0,0 +1,69 @@ +# Copyright (c) 2022 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. + +import("//base/inputmethod/imf/inputmethod.gni") + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("InputMethodFuzzTest") { + module_out_path = "inputmethod/inputmethod" + + fuzz_config_file = "//base/inputmethod/imf/test/fuzztest/inputmethod_fuzzer" + + include_dirs = [ + "//base/inputmethod/imf/services/include", + "//base/inputmethod/imf/services/adapter/keyboard/include", + "//base/inputmethod/imf/etc/para/include", + "//foundation/ability/ability_runtime/interfaces/inner_api/app_manager/include/appmgr", + "//foundation/ability/ability_runtime/services/abilitymgr/include", + "//foundation/ability/ability_runtime/interfaces/inner_api/ability_manager/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "inputmethod_fuzzer.cpp" ] + + deps = [ + "//base/inputmethod/imf/etc/para:inputmethod_para", + "//base/inputmethod/imf/frameworks/inputmethod_controller:inputmethod_client", + "//base/inputmethod/imf/services:inputmethod_service", + "//foundation/ability/ability_base:want", + "//foundation/ability/ability_runtime/services/abilitymgr:abilityms", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + ] + + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":InputMethodFuzzTest", + ] +} +############################################################################### From 0674b2c7a61e6b11e3aa5f306a027ac7fa59ef84 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Wed, 23 Nov 2022 21:06:14 +0800 Subject: [PATCH 092/112] modify code Signed-off-by: zhaolinglan --- .../keyboard/src/input_event_callback.cpp | 30 +++++++++---------- .../adapter/keyboard/src/keyboard_event.cpp | 4 +-- services/include/im_common_event_manager.h | 2 +- .../include/input_method_system_ability.h | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/services/adapter/keyboard/src/input_event_callback.cpp b/services/adapter/keyboard/src/input_event_callback.cpp index 723bab66..06b86340 100644 --- a/services/adapter/keyboard/src/input_event_callback.cpp +++ b/services/adapter/keyboard/src/input_event_callback.cpp @@ -13,26 +13,26 @@ * limitations under the License. */ -#include "../include/input_event_callback.h" +#include "input_event_callback.h" #include "global.h" namespace OHOS { namespace MiscServices { -constexpr uint32_t SHIFT_LEFT_POS = 0X1; -constexpr uint32_t SHIFT_RIGHT_POS = 0X1 << 1; -constexpr uint32_t CTRL_LEFT_POS = 0X1 << 2; -constexpr uint32_t CTRL_RIGHT_POS = 0X1 << 3; -constexpr uint32_t CAPS_POS = 0X1 << 4; +constexpr uint32_t SHIFT_LEFT_MASK = 0X1; +constexpr uint32_t SHIFT_RIGHT_MASK = 0X1 << 1; +constexpr uint32_t CTRL_LEFT_MASK = 0X1 << 2; +constexpr uint32_t CTRL_RIGHT_MASK = 0X1 << 3; +constexpr uint32_t CAPS_MASK = 0X1 << 4; uint32_t InputEventCallback::keyState = 0; std::map POS_MAP{ - { MMI::KeyEvent::KEYCODE_SHIFT_LEFT, SHIFT_LEFT_POS }, - { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, SHIFT_RIGHT_POS }, - { MMI::KeyEvent::KEYCODE_CTRL_LEFT, CTRL_LEFT_POS }, - { MMI::KeyEvent::KEYCODE_CTRL_RIGHT, CTRL_RIGHT_POS }, - { MMI::KeyEvent::KEYCODE_CAPS_LOCK, CAPS_POS }, + { MMI::KeyEvent::KEYCODE_SHIFT_LEFT, SHIFT_LEFT_MASK }, + { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, SHIFT_RIGHT_MASK }, + { MMI::KeyEvent::KEYCODE_CTRL_LEFT, CTRL_LEFT_MASK }, + { MMI::KeyEvent::KEYCODE_CTRL_RIGHT, CTRL_RIGHT_MASK }, + { MMI::KeyEvent::KEYCODE_CAPS_LOCK, CAPS_MASK }, }; void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) const @@ -79,14 +79,14 @@ void InputEventCallback::SetKeyHandle(KeyHandle handle) CombinationKey InputEventCallback::FindCombinationKey(uint32_t state) { - if (state == CAPS_POS) { + if (state == CAPS_MASK) { return CombinationKey::CAPS; } - if (state == SHIFT_LEFT_POS || state == SHIFT_RIGHT_POS) { + if (state == SHIFT_LEFT_MASK || state == SHIFT_RIGHT_MASK) { return CombinationKey::SHIFT; } - if ((state == (CTRL_LEFT_POS | SHIFT_LEFT_POS)) || (state == (CTRL_LEFT_POS | SHIFT_RIGHT_POS)) - || (state == (CTRL_RIGHT_POS | SHIFT_LEFT_POS)) || (state == (CTRL_RIGHT_POS | SHIFT_RIGHT_POS))) { + if ((state == (CTRL_LEFT_MASK | SHIFT_LEFT_MASK)) || (state == (CTRL_LEFT_MASK | SHIFT_RIGHT_MASK)) + || (state == (CTRL_RIGHT_MASK | SHIFT_LEFT_MASK)) || (state == (CTRL_RIGHT_MASK | SHIFT_RIGHT_MASK))) { return CombinationKey::CTRL_SHIFT; } return CombinationKey::UNKNOWN; diff --git a/services/adapter/keyboard/src/keyboard_event.cpp b/services/adapter/keyboard/src/keyboard_event.cpp index 5cbda6c4..b843ae15 100644 --- a/services/adapter/keyboard/src/keyboard_event.cpp +++ b/services/adapter/keyboard/src/keyboard_event.cpp @@ -13,14 +13,14 @@ * limitations under the License. */ -#include "../include/keyboard_event.h" +#include "keyboard_event.h" #include #include -#include "../include/input_event_callback.h" #include "global.h" +#include "input_event_callback.h" #include "key_event.h" namespace OHOS { diff --git a/services/include/im_common_event_manager.h b/services/include/im_common_event_manager.h index 9c5ad5cd..9e70d693 100644 --- a/services/include/im_common_event_manager.h +++ b/services/include/im_common_event_manager.h @@ -20,12 +20,12 @@ #include #include -#include "../adapter/keyboard/include/keyboard_event.h" #include "common_event_data.h" #include "common_event_manager.h" #include "common_event_subscribe_info.h" #include "common_event_subscriber.h" #include "common_event_support.h" +#include "keyboard_event.h" #include "matching_skills.h" #include "system_ability_status_change_stub.h" diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index 1ff4e439..49f73cdf 100644 --- a/services/include/input_method_system_ability.h +++ b/services/include/input_method_system_ability.h @@ -20,7 +20,6 @@ #include #include -#include "../adapter/keyboard/include/keyboard_event.h" #include "ability_manager_interface.h" #include "application_info.h" #include "bundle_mgr_proxy.h" @@ -29,6 +28,7 @@ #include "input_method_system_ability_stub.h" #include "inputmethod_dump.h" #include "inputmethod_trace.h" +#include "keyboard_event.h" #include "peruser_session.h" #include "peruser_setting.h" #include "system_ability.h" From 71bee2ef11e61386145f60314dc1f7f5c8ee07bd Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Wed, 23 Nov 2022 21:16:37 +0800 Subject: [PATCH 093/112] modify code Signed-off-by: zhaolinglan --- .../keyboard/src/input_event_callback.cpp | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/services/adapter/keyboard/src/input_event_callback.cpp b/services/adapter/keyboard/src/input_event_callback.cpp index 06b86340..7fec2f03 100644 --- a/services/adapter/keyboard/src/input_event_callback.cpp +++ b/services/adapter/keyboard/src/input_event_callback.cpp @@ -19,15 +19,13 @@ namespace OHOS { namespace MiscServices { -constexpr uint32_t SHIFT_LEFT_MASK = 0X1; -constexpr uint32_t SHIFT_RIGHT_MASK = 0X1 << 1; -constexpr uint32_t CTRL_LEFT_MASK = 0X1 << 2; -constexpr uint32_t CTRL_RIGHT_MASK = 0X1 << 3; -constexpr uint32_t CAPS_MASK = 0X1 << 4; +constexpr uint8_t SHIFT_LEFT_MASK = 0X1; +constexpr uint8_t SHIFT_RIGHT_MASK = 0X1 << 1; +constexpr uint8_t CTRL_LEFT_MASK = 0X1 << 2; +constexpr uint8_t CTRL_RIGHT_MASK = 0X1 << 3; +constexpr uint8_t CAPS_MASK = 0X1 << 4; -uint32_t InputEventCallback::keyState = 0; - -std::map POS_MAP{ +const std::map MASK_MAP{ { MMI::KeyEvent::KEYCODE_SHIFT_LEFT, SHIFT_LEFT_MASK }, { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, SHIFT_RIGHT_MASK }, { MMI::KeyEvent::KEYCODE_CTRL_LEFT, CTRL_LEFT_MASK }, @@ -35,23 +33,25 @@ std::map POS_MAP{ { MMI::KeyEvent::KEYCODE_CAPS_LOCK, CAPS_MASK }, }; +uint32_t InputEventCallback::keyState = 0; + void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) const { auto keyCode = keyEvent->GetKeyCode(); auto keyAction = keyEvent->GetKeyAction(); - if (POS_MAP.find(keyCode) == POS_MAP.end() || keyAction == MMI::KeyEvent::KEY_ACTION_UNKNOWN) { + if (MASK_MAP.find(keyCode) == MASK_MAP.end() || keyAction == MMI::KeyEvent::KEY_ACTION_UNKNOWN) { IMSA_HILOGD("key event unknown"); return; } IMSA_HILOGD("keyCode: %{public}d, keyAction: %{public}d", keyCode, keyAction); if (keyAction == MMI::KeyEvent::KEY_ACTION_DOWN) { IMSA_HILOGD("key %{public}d pressed down", keyCode); - keyState = keyState | POS_MAP[keyCode]; + keyState = keyState | MASK_MAP[keyCode]; return; } CombinationKey key = FindCombinationKey(keyState); - keyState = keyState & ~POS_MAP[keyCode]; + keyState = keyState & ~MASK_MAP[keyCode]; if (key == CombinationKey::UNKNOWN) { IMSA_HILOGE("combination key unknown"); return; From 80ca01aaf44198114589a4444484f337a21ce9ad Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Wed, 23 Nov 2022 21:39:56 +0800 Subject: [PATCH 094/112] modify code Signed-off-by: zhaolinglan --- services/BUILD.gn | 1 + services/adapter/keyboard/src/input_event_callback.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/services/BUILD.gn b/services/BUILD.gn index 9097a23e..abdcb50a 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -23,6 +23,7 @@ config("inputmethod_services_native_config") { "//base/notification/common_event_service/frameworks/core/include", "//base/notification/common_event_service/interfaces/innerkits/native/include", "//foundation/multimodalinput/input/interfaces/native/innerkits/event/include", + "${inputmethod_path}/services/adapter/keyboard/include", "${inputmethod_path}/services/dfx/include", ] diff --git a/services/adapter/keyboard/src/input_event_callback.cpp b/services/adapter/keyboard/src/input_event_callback.cpp index 7fec2f03..6f6d1246 100644 --- a/services/adapter/keyboard/src/input_event_callback.cpp +++ b/services/adapter/keyboard/src/input_event_callback.cpp @@ -39,19 +39,20 @@ void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) c { auto keyCode = keyEvent->GetKeyCode(); auto keyAction = keyEvent->GetKeyAction(); - if (MASK_MAP.find(keyCode) == MASK_MAP.end() || keyAction == MMI::KeyEvent::KEY_ACTION_UNKNOWN) { + auto currKey = MASK_MAP.find(keyCode); + if (currKey == MASK_MAP.end() || keyAction == MMI::KeyEvent::KEY_ACTION_UNKNOWN) { IMSA_HILOGD("key event unknown"); return; } IMSA_HILOGD("keyCode: %{public}d, keyAction: %{public}d", keyCode, keyAction); if (keyAction == MMI::KeyEvent::KEY_ACTION_DOWN) { IMSA_HILOGD("key %{public}d pressed down", keyCode); - keyState = keyState | MASK_MAP[keyCode]; + keyState = keyState | currKey->second; return; } CombinationKey key = FindCombinationKey(keyState); - keyState = keyState & ~MASK_MAP[keyCode]; + keyState = keyState & ~currKey->second; if (key == CombinationKey::UNKNOWN) { IMSA_HILOGE("combination key unknown"); return; From 5c445ca35a99df65c78e7766cd488a9f325407bd Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Wed, 23 Nov 2022 22:59:17 +0800 Subject: [PATCH 095/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/include/peruser_session.h | 9 ++++++++- services/src/peruser_session.cpp | 28 ++++++++-------------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index e8677f08..dbb44fb3 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -180,7 +180,14 @@ private: sptr GetCurrentClient(); void SetImsCore(int32_t index, sptr core); sptr GetImsCore(int32_t index); - bool CompareCore(int32_t index); + bool CompareCore(); + inline bool CheckCoreIndex(int32_t index) + { + if (index < DEFAULT_IME || index > SECURITY_IME) { + return false; + } + return true; + } std::mutex propertyLock_; SubProperty currentSubProperty; diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index f7c0256b..c8847a93 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -736,9 +736,7 @@ namespace MiscServices { return; } InputMethodSetting tmpSetting; - sptr core = GetImsCore(index); - sptr core_ = GetImsCore((1- index)); - if (core == core_) { + if (CompareCore()) { tmpSetting.SetCurrentKeyboardType(type->getHashCode()); tmpSetting.SetCurrentSysKeyboardType(type->getHashCode()); } @@ -907,20 +905,16 @@ namespace MiscServices { } } } - sptr core = GetImsCore(imeIndex); - sptr core_ = GetImsCore((1 - imeIndex)); if (!flag) { IMSA_HILOGW("The current keyboard type is not found in the current IME. Reset it!"); type = GetKeyboardType(imeIndex, currentKbdIndex[imeIndex]); - } else if (core == core_) { + } else if (CompareCore()) { currentKbdIndex[1 - imeIndex] = currentKbdIndex[imeIndex]; } } if (type) { InputMethodSetting tmpSetting; - sptr core = GetImsCore(imeIndex); - sptr core_ = GetImsCore((1 - imeIndex)); - if (core == core_) { + if (CompareCore()) { inputMethodSetting->SetCurrentKeyboardType(type->getHashCode()); inputMethodSetting->SetCurrentSysKeyboardType(type->getHashCode()); currentKbdIndex[1 - imeIndex] = currentKbdIndex[imeIndex]; @@ -1281,8 +1275,7 @@ namespace MiscServices { sptr PerUserSession::GetImsCore(int32_t index) { std::lock_guard lock(imsCoreLock_); - if (index < DEFAULT_IME || index > SECURITY_IME) { - IMSA_HILOGE("PerUserSession::SetImsCore out of index. index = %{public}d", index); + if (CheckCoreIndex(index)) { return nullptr; } return imsCore[index]; @@ -1291,21 +1284,16 @@ namespace MiscServices { void PerUserSession::SetImsCore(int32_t index, sptr core) { std::lock_guard lock(imsCoreLock_); - if (index < DEFAULT_IME || index > SECURITY_IME) { - IMSA_HILOGE("PerUserSession::SetImsCore out of index. index = %{public}d", index); + if (CheckCoreIndex(index)) { return; } imsCore[index] = core; } - bool PerUserSession::CompareCore(int32_t index) + bool PerUserSession::CompareCore() { - if (index < DEFAULT_IME || index > SECURITY_IME) { - IMSA_HILOGE("PerUserSession::SetImsCore out of index. index = %{public}d", index); - return false; - } - sptr core = GetImsCore(index); - sptr core_ = GetImsCore((1 - index)); + sptr core = GetImsCore(DEFAULT_IME); + sptr core_ = GetImsCore(SECURITY_IME); if (core == core_) { return true; } From 56cb619129e0a9397812fc0ccf91f54d824f69c2 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Wed, 23 Nov 2022 23:12:07 +0800 Subject: [PATCH 096/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/src/peruser_session.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index c8847a93..25b84b68 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -660,7 +660,7 @@ namespace MiscServices { IMSA_HILOGE("setKeyboardType ret: %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); } } - if (CompareCore(index)) { + if (CompareCore()) { inputMethodSetting->SetCurrentKeyboardType(type->getHashCode()); inputMethodSetting->SetCurrentSysKeyboardType(type->getHashCode()); currentKbdIndex[1 - index] = currentKbdIndex[index]; From eb568f3758c68e0d393be9c4d40c94a6e4bd39db Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Thu, 24 Nov 2022 09:27:56 +0800 Subject: [PATCH 097/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/include/peruser_session.h | 7 ++----- services/src/peruser_session.cpp | 18 +++++++++--------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index dbb44fb3..cc446df5 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -181,12 +181,9 @@ private: void SetImsCore(int32_t index, sptr core); sptr GetImsCore(int32_t index); bool CompareCore(); - inline bool CheckCoreIndex(int32_t index) + static inline bool IsValid(int32_t index) { - if (index < DEFAULT_IME || index > SECURITY_IME) { - return false; - } - return true; + return index >= DEFAULT_IME && index <= SECURITY_IME; } std::mutex propertyLock_; diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 25b84b68..d83efe16 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -393,7 +393,7 @@ namespace MiscServices { IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! index = -1 or clientInfo is nullptr"); return ErrorCode::ERROR_CLIENT_NOT_FOUND; } - sptr core = GetImsCore(0); + sptr core = GetImsCore(DEFAULT_IME); if (core == nullptr) { IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! imsCore[%{public}d] is nullptr", index); return ErrorCode::ERROR_NULL_POINTER; @@ -431,7 +431,7 @@ namespace MiscServices { if (clientInfo == nullptr) { IMSA_HILOGE("PerUserSession::HideKeyboard GetClientInfo pointer nullptr"); } - sptr core = GetImsCore(0); + sptr core = GetImsCore(DEFAULT_IME); if (core == nullptr) { IMSA_HILOGE("PerUserSession::HideKeyboard imsCore[index] is nullptr"); return ErrorCode::ERROR_IME_NOT_STARTED; @@ -1077,7 +1077,7 @@ namespace MiscServices { int32_t PerUserSession::OnReleaseInput(sptr client) { IMSA_HILOGI("PerUserSession::OnReleaseInput Start\n"); - sptr core = GetImsCore(0); + sptr core = GetImsCore(DEFAULT_IME); if (core == nullptr) { return ErrorCode::ERROR_IME_NOT_AVAILABLE; } @@ -1096,7 +1096,7 @@ namespace MiscServices { int32_t PerUserSession::OnStartInput(sptr client, bool isShowKeyboard) { IMSA_HILOGI("PerUserSession::OnStartInput"); - sptr core = GetImsCore(0); + sptr core = GetImsCore(DEFAULT_IME); if (core == nullptr) { return ErrorCode::ERROR_IME_NOT_AVAILABLE; } @@ -1144,7 +1144,7 @@ namespace MiscServices { { IMSA_HILOGD("PerUserSession::InitInputControlChannel"); sptr inputControlChannel = new InputControlChannelStub(userId_); - sptr core = GetImsCore(0); + sptr core = GetImsCore(DEFAULT_IME); if (core == nullptr) { IMSA_HILOGE("PerUserSession::InitInputControlChannel core is nullptr"); return; @@ -1169,7 +1169,7 @@ namespace MiscServices { void PerUserSession::StopInputService(std::string imeId) { IMSA_HILOGI("PerUserSession::StopInputService"); - sptr core = GetImsCore(0); + sptr core = GetImsCore(DEFAULT_IME); if (core == nullptr) { IMSA_HILOGE("imsCore[0] is nullptr"); return; @@ -1245,7 +1245,7 @@ namespace MiscServices { return ErrorCode::NO_ERROR; } SetCurrentSubProperty(subProperty); - sptr core = GetImsCore(0); + sptr core = GetImsCore(DEFAULT_IME); if (core == nullptr) { IMSA_HILOGE("imsCore is nullptr"); return ErrorCode::ERROR_EX_NULL_POINTER; @@ -1275,7 +1275,7 @@ namespace MiscServices { sptr PerUserSession::GetImsCore(int32_t index) { std::lock_guard lock(imsCoreLock_); - if (CheckCoreIndex(index)) { + if (!IsValid(index)) { return nullptr; } return imsCore[index]; @@ -1284,7 +1284,7 @@ namespace MiscServices { void PerUserSession::SetImsCore(int32_t index, sptr core) { std::lock_guard lock(imsCoreLock_); - if (CheckCoreIndex(index)) { + if (!IsValid(index)) { return; } imsCore[index] = core; From 7b3f62a93da929bb08ee718c134c0bf55ab671f7 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Thu, 24 Nov 2022 10:10:14 +0800 Subject: [PATCH 098/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/include/peruser_session.h | 4 ++++ services/src/peruser_session.cpp | 23 ++++++----------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index cc446df5..0d2f7c4e 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -185,6 +185,10 @@ private: { return index >= DEFAULT_IME && index <= SECURITY_IME; } + inline bool IsIMEEqual() + { + return GetImsCore(DEFAULT_IME) == GetImsCore(SECURITY_IME); + } std::mutex propertyLock_; SubProperty currentSubProperty; diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index d83efe16..98f16722 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -660,7 +660,7 @@ namespace MiscServices { IMSA_HILOGE("setKeyboardType ret: %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); } } - if (CompareCore()) { + if (IsIMEEqual()) { inputMethodSetting->SetCurrentKeyboardType(type->getHashCode()); inputMethodSetting->SetCurrentSysKeyboardType(type->getHashCode()); currentKbdIndex[1 - index] = currentKbdIndex[index]; @@ -736,7 +736,7 @@ namespace MiscServices { return; } InputMethodSetting tmpSetting; - if (CompareCore()) { + if (IsIMEEqual()) { tmpSetting.SetCurrentKeyboardType(type->getHashCode()); tmpSetting.SetCurrentSysKeyboardType(type->getHashCode()); } @@ -908,13 +908,13 @@ namespace MiscServices { if (!flag) { IMSA_HILOGW("The current keyboard type is not found in the current IME. Reset it!"); type = GetKeyboardType(imeIndex, currentKbdIndex[imeIndex]); - } else if (CompareCore()) { + } else if (IsIMEEqual()) { currentKbdIndex[1 - imeIndex] = currentKbdIndex[imeIndex]; } } if (type) { InputMethodSetting tmpSetting; - if (CompareCore()) { + if (IsIMEEqual()) { inputMethodSetting->SetCurrentKeyboardType(type->getHashCode()); inputMethodSetting->SetCurrentSysKeyboardType(type->getHashCode()); currentKbdIndex[1 - imeIndex] = currentKbdIndex[imeIndex]; @@ -962,8 +962,7 @@ namespace MiscServices { */ void PerUserSession::CopyInputMethodService(int imeIndex) { - sptr core = GetImsCore((1 - imeIndex)); - SetImsCore(imeIndex, core); + SetImsCore(imeIndex, GetImsCore((1 - imeIndex))); localControlChannel[imeIndex] = localControlChannel[1 - imeIndex]; inputControlChannel[imeIndex] = inputControlChannel[1 - imeIndex]; inputMethodToken[imeIndex] = inputMethodToken[1 - imeIndex]; @@ -1111,7 +1110,7 @@ namespace MiscServices { IMSA_HILOGE("PerUserSession::SetCoreAndAgent core or agent nullptr"); return ErrorCode::ERROR_EX_NULL_POINTER; } - SetImsCore(0, core); + SetImsCore(DEFAULT_IME, core); if (imsDeathRecipient != nullptr) { imsDeathRecipient->SetDeathRecipient([this, core](const wptr &) { this->OnImsDied(core); }); bool ret = core->AsObject()->AddDeathRecipient(imsDeathRecipient); @@ -1289,15 +1288,5 @@ namespace MiscServices { } imsCore[index] = core; } - - bool PerUserSession::CompareCore() - { - sptr core = GetImsCore(DEFAULT_IME); - sptr core_ = GetImsCore(SECURITY_IME); - if (core == core_) { - return true; - } - return false; - } } // namespace MiscServices } // namespace OHOS From f799fe92eb6ac4ae87d6ba00d79d0e155e00511b Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Thu, 24 Nov 2022 10:16:26 +0800 Subject: [PATCH 099/112] Signed-off-by: ma-shaoyin Changes to be committed: --- 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 0d2f7c4e..66e80a1e 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -129,7 +129,7 @@ private: sptr imsCore[MAX_IME]; // the remote handlers of input method service sptr inputMethodToken[MAX_IME]; // the window token of keyboard int currentKbdIndex[MAX_IME]; // current keyboard index - int lastImeIndex = 0; // The last ime which showed keyboard + int lastImeIndex = DEFAULT_IME; // The last ime which showed keyboard InputMethodSetting *inputMethodSetting; // The pointer referred to the object in PerUserSetting sptr imsAgent; From eed3640e08b16582d16055ee04c03a87c51c545a Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Thu, 24 Nov 2022 10:49:20 +0800 Subject: [PATCH 100/112] Signed-off-by: ma-shaoyin Changes to be committed: --- services/include/peruser_session.h | 1 - 1 file changed, 1 deletion(-) diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index 66e80a1e..60dc4770 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -180,7 +180,6 @@ private: sptr GetCurrentClient(); void SetImsCore(int32_t index, sptr core); sptr GetImsCore(int32_t index); - bool CompareCore(); static inline bool IsValid(int32_t index) { return index >= DEFAULT_IME && index <= SECURITY_IME; From 1878347b8a7dbd447c1b13f2b0107db62b04a1b8 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Thu, 24 Nov 2022 11:31:46 +0800 Subject: [PATCH 101/112] modify code Signed-off-by: zhaolinglan --- .../keyboard/include/input_event_callback.h | 17 ++++++-- .../adapter/keyboard/include/keyboard_event.h | 9 +--- .../keyboard/src/input_event_callback.cpp | 43 +++---------------- .../include/input_method_system_ability.h | 2 +- services/src/input_method_system_ability.cpp | 11 ++--- 5 files changed, 27 insertions(+), 55 deletions(-) diff --git a/services/adapter/keyboard/include/input_event_callback.h b/services/adapter/keyboard/include/input_event_callback.h index 6b01f70e..2c101125 100644 --- a/services/adapter/keyboard/include/input_event_callback.h +++ b/services/adapter/keyboard/include/input_event_callback.h @@ -20,12 +20,23 @@ #include #include -#include "keyboard_event.h" #include "input_manager.h" #include "key_event.h" +#include "keyboard_event.h" namespace OHOS { namespace MiscServices { +constexpr uint8_t SHIFT_LEFT_MASK = 0X1; +constexpr uint8_t SHIFT_RIGHT_MASK = 0X1 << 1; +constexpr uint8_t CTRL_LEFT_MASK = 0X1 << 2; +constexpr uint8_t CTRL_RIGHT_MASK = 0X1 << 3; +constexpr uint8_t CAPS_MASK = 0X1 << 4; + +constexpr bool IS_KEYS_DOWN(uint32_t state, uint8_t mask) +{ + return (state & mask) == state; +} + class InputEventCallback : public MMI::IInputEventConsumer { public: virtual void OnInputEvent(std::shared_ptr keyEvent) const; @@ -35,8 +46,8 @@ public: private: KeyHandle keyHandler_ = nullptr; - static uint32_t keyState; - static CombinationKey FindCombinationKey(uint32_t state) ; + static uint32_t keyState_; + static uint32_t FindCombinationKey(uint32_t state); }; } // namespace MiscServices } // namespace OHOS diff --git a/services/adapter/keyboard/include/keyboard_event.h b/services/adapter/keyboard/include/keyboard_event.h index 4c542fbb..134a2f6e 100644 --- a/services/adapter/keyboard/include/keyboard_event.h +++ b/services/adapter/keyboard/include/keyboard_event.h @@ -25,14 +25,7 @@ namespace OHOS { namespace MiscServices { -enum CombinationKey : uint32_t { - UNKNOWN = 0, - CAPS, - SHIFT, - CTRL_SHIFT -}; - -using KeyHandle = std::function; +using KeyHandle = std::function; class KeyboardEvent { public: diff --git a/services/adapter/keyboard/src/input_event_callback.cpp b/services/adapter/keyboard/src/input_event_callback.cpp index 6f6d1246..c04bb573 100644 --- a/services/adapter/keyboard/src/input_event_callback.cpp +++ b/services/adapter/keyboard/src/input_event_callback.cpp @@ -19,21 +19,7 @@ namespace OHOS { namespace MiscServices { -constexpr uint8_t SHIFT_LEFT_MASK = 0X1; -constexpr uint8_t SHIFT_RIGHT_MASK = 0X1 << 1; -constexpr uint8_t CTRL_LEFT_MASK = 0X1 << 2; -constexpr uint8_t CTRL_RIGHT_MASK = 0X1 << 3; -constexpr uint8_t CAPS_MASK = 0X1 << 4; - -const std::map MASK_MAP{ - { MMI::KeyEvent::KEYCODE_SHIFT_LEFT, SHIFT_LEFT_MASK }, - { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, SHIFT_RIGHT_MASK }, - { MMI::KeyEvent::KEYCODE_CTRL_LEFT, CTRL_LEFT_MASK }, - { MMI::KeyEvent::KEYCODE_CTRL_RIGHT, CTRL_RIGHT_MASK }, - { MMI::KeyEvent::KEYCODE_CAPS_LOCK, CAPS_MASK }, -}; - -uint32_t InputEventCallback::keyState = 0; +uint32_t InputEventCallback::keyState_ = static_cast(0); void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) const { @@ -47,21 +33,17 @@ void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) c IMSA_HILOGD("keyCode: %{public}d, keyAction: %{public}d", keyCode, keyAction); if (keyAction == MMI::KeyEvent::KEY_ACTION_DOWN) { IMSA_HILOGD("key %{public}d pressed down", keyCode); - keyState = keyState | currKey->second; + keyState_ = static_cast(keyState_ | currKey->second); return; } - CombinationKey key = FindCombinationKey(keyState); - keyState = keyState & ~currKey->second; - if (key == CombinationKey::UNKNOWN) { - IMSA_HILOGE("combination key unknown"); - return; - } if (keyHandler_ == nullptr) { IMSA_HILOGE("keyHandler_ is nullptr"); + keyState_ = static_cast(keyState_ & ~currKey->second); return; } - int32_t ret = keyHandler_(key); + int32_t ret = keyHandler_(keyState_); + keyState_ = static_cast(keyState_ & ~currKey->second); IMSA_HILOGI("handle key event ret: %{public}d", ret); } @@ -77,20 +59,5 @@ void InputEventCallback::SetKeyHandle(KeyHandle handle) { keyHandler_ = std::move(handle); } - -CombinationKey InputEventCallback::FindCombinationKey(uint32_t state) -{ - if (state == CAPS_MASK) { - return CombinationKey::CAPS; - } - if (state == SHIFT_LEFT_MASK || state == SHIFT_RIGHT_MASK) { - return CombinationKey::SHIFT; - } - if ((state == (CTRL_LEFT_MASK | SHIFT_LEFT_MASK)) || (state == (CTRL_LEFT_MASK | SHIFT_RIGHT_MASK)) - || (state == (CTRL_RIGHT_MASK | SHIFT_LEFT_MASK)) || (state == (CTRL_RIGHT_MASK | SHIFT_RIGHT_MASK))) { - return CombinationKey::CTRL_SHIFT; - } - return CombinationKey::UNKNOWN; -} } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index 49f73cdf..65e48558 100644 --- a/services/include/input_method_system_ability.h +++ b/services/include/input_method_system_ability.h @@ -140,7 +140,7 @@ private: using CompareHandler = std::function; SubProperty FindSubPropertyByCompare(const std::string &bundleName, CompareHandler compare); SubProperty GetExtends(const std::vector &metaData); - int32_t SwitchByCombinationKey(const CombinationKey &key); + int32_t SwitchByCombinationKey(const uint32_t &state); int32_t QueryImeInfos(int32_t userId, std::vector &infos); }; diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index d5e7651f..69bc8e00 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -26,6 +26,7 @@ #include "errors.h" #include "global.h" #include "im_common_event_manager.h" +#include "input_event_callback.h" #include "input_method_status.h" #include "ipc_skeleton.h" #include "iservice_registry.h" @@ -1401,7 +1402,7 @@ namespace MiscServices { return {}; } - int32_t InputMethodSystemAbility::SwitchByCombinationKey(const CombinationKey &key) + int32_t InputMethodSystemAbility::SwitchByCombinationKey(const uint32_t &state) { IMSA_HILOGI("InputMethodSystemAbility::SwitchByCombinationKey"); auto current = GetCurrentInputMethodSubtype(); @@ -1409,7 +1410,7 @@ namespace MiscServices { IMSA_HILOGE("GetCurrentInputMethodSubtype failed"); return ErrorCode::ERROR_EX_NULL_POINTER; } - if (key == CombinationKey::CAPS) { + if (IS_KEYS_DOWN(state, CAPS_MASK)) { IMSA_HILOGI("CAPS press"); auto target = current->mode == "upper" ? FindSubPropertyByCompare(current->id, @@ -1418,7 +1419,7 @@ namespace MiscServices { [¤t](const SubProperty &property) { return property.mode == "upper"; }); return SwitchInputMethod(target.id, target.label); } - if (key == CombinationKey::SHIFT) { + if (IS_KEYS_DOWN(state, SHIFT_LEFT_MASK) || IS_KEYS_DOWN(state, SHIFT_RIGHT_MASK)) { IMSA_HILOGI("SHIFT press"); auto target = current->language == "chinese" ? FindSubPropertyByCompare(current->id, @@ -1427,7 +1428,7 @@ namespace MiscServices { [¤t](const SubProperty &property) { return property.language == "chinese"; }); return SwitchInputMethod(target.id, target.label); } - if (key == CombinationKey::CTRL_SHIFT) { + if (IS_KEYS_DOWN(state, CTRL_LEFT_MASK)) { IMSA_HILOGI("CTRL_SHIFT press"); std::vector props = {}; auto ret = ListProperty(MAIN_USER_ID, props); @@ -1449,7 +1450,7 @@ namespace MiscServices { { IMSA_HILOGI("InputMethodSystemAbility::InitKeyEventMonitor"); bool ret = ImCommonEventManager::GetInstance()->SubscribeKeyboardEvent( - [this](const CombinationKey &keyCode) { return SwitchByCombinationKey(keyCode); }); + [this](const uint32_t &keyCode) { return SwitchByCombinationKey(keyCode); }); return ret ? ErrorCode::NO_ERROR : ErrorCode::ERROR_SERVICE_START_FAILED; } } // namespace MiscServices From a629e6f4c08c81e5d384f65e8affba44f233bc6b Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Thu, 24 Nov 2022 11:43:42 +0800 Subject: [PATCH 102/112] modify code Signed-off-by: zhaolinglan --- services/src/input_method_system_ability.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 69bc8e00..29aab385 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -1428,7 +1428,10 @@ namespace MiscServices { [¤t](const SubProperty &property) { return property.language == "chinese"; }); return SwitchInputMethod(target.id, target.label); } - if (IS_KEYS_DOWN(state, CTRL_LEFT_MASK)) { + if (IS_KEYS_DOWN(state, CTRL_LEFT_MASK | SHIFT_LEFT_MASK) || + IS_KEYS_DOWN(state, CTRL_LEFT_MASK | SHIFT_RIGHT_MASK)|| + IS_KEYS_DOWN(state, CTRL_RIGHT_MASK | SHIFT_LEFT_MASK) || + IS_KEYS_DOWN(state, CTRL_RIGHT_MASK | SHIFT_RIGHT_MASK)) { IMSA_HILOGI("CTRL_SHIFT press"); std::vector props = {}; auto ret = ListProperty(MAIN_USER_ID, props); From ac09ff350e2c795dadae59e3cc906263e77d1690 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Thu, 24 Nov 2022 14:12:47 +0800 Subject: [PATCH 103/112] modify code Signed-off-by: zhaolinglan --- .../adapter/keyboard/include/input_event_callback.h | 11 ----------- services/adapter/keyboard/include/keyboard_event.h | 10 ++++++++++ services/src/input_method_system_ability.cpp | 1 - 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/services/adapter/keyboard/include/input_event_callback.h b/services/adapter/keyboard/include/input_event_callback.h index 2c101125..5edf6c10 100644 --- a/services/adapter/keyboard/include/input_event_callback.h +++ b/services/adapter/keyboard/include/input_event_callback.h @@ -26,17 +26,6 @@ namespace OHOS { namespace MiscServices { -constexpr uint8_t SHIFT_LEFT_MASK = 0X1; -constexpr uint8_t SHIFT_RIGHT_MASK = 0X1 << 1; -constexpr uint8_t CTRL_LEFT_MASK = 0X1 << 2; -constexpr uint8_t CTRL_RIGHT_MASK = 0X1 << 3; -constexpr uint8_t CAPS_MASK = 0X1 << 4; - -constexpr bool IS_KEYS_DOWN(uint32_t state, uint8_t mask) -{ - return (state & mask) == state; -} - class InputEventCallback : public MMI::IInputEventConsumer { public: virtual void OnInputEvent(std::shared_ptr keyEvent) const; diff --git a/services/adapter/keyboard/include/keyboard_event.h b/services/adapter/keyboard/include/keyboard_event.h index 134a2f6e..5b9ccbe5 100644 --- a/services/adapter/keyboard/include/keyboard_event.h +++ b/services/adapter/keyboard/include/keyboard_event.h @@ -25,6 +25,16 @@ namespace OHOS { namespace MiscServices { +constexpr uint8_t SHIFT_LEFT_MASK = 0X1; +constexpr uint8_t SHIFT_RIGHT_MASK = 0X1 << 1; +constexpr uint8_t CTRL_LEFT_MASK = 0X1 << 2; +constexpr uint8_t CTRL_RIGHT_MASK = 0X1 << 3; +constexpr uint8_t CAPS_MASK = 0X1 << 4; +constexpr bool IS_KEYS_DOWN(uint32_t state, uint8_t mask) +{ + return (state & mask) == state; +} + using KeyHandle = std::function; class KeyboardEvent { diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 29aab385..42755b39 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -26,7 +26,6 @@ #include "errors.h" #include "global.h" #include "im_common_event_manager.h" -#include "input_event_callback.h" #include "input_method_status.h" #include "ipc_skeleton.h" #include "iservice_registry.h" From a6ae5283a1040da24403e22f358395a3ce0c5d45 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Thu, 24 Nov 2022 14:54:02 +0800 Subject: [PATCH 104/112] modify code Signed-off-by: zhaolinglan --- services/adapter/keyboard/include/input_event_callback.h | 1 - services/adapter/keyboard/src/input_event_callback.cpp | 7 +++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/services/adapter/keyboard/include/input_event_callback.h b/services/adapter/keyboard/include/input_event_callback.h index 5edf6c10..1612fbe3 100644 --- a/services/adapter/keyboard/include/input_event_callback.h +++ b/services/adapter/keyboard/include/input_event_callback.h @@ -36,7 +36,6 @@ public: private: KeyHandle keyHandler_ = nullptr; static uint32_t keyState_; - static uint32_t FindCombinationKey(uint32_t state); }; } // namespace MiscServices } // namespace OHOS diff --git a/services/adapter/keyboard/src/input_event_callback.cpp b/services/adapter/keyboard/src/input_event_callback.cpp index c04bb573..d99acbd1 100644 --- a/services/adapter/keyboard/src/input_event_callback.cpp +++ b/services/adapter/keyboard/src/input_event_callback.cpp @@ -20,6 +20,13 @@ namespace OHOS { namespace MiscServices { uint32_t InputEventCallback::keyState_ = static_cast(0); +const std::map MASK_MAP{ + { MMI::KeyEvent::KEYCODE_SHIFT_LEFT, SHIFT_LEFT_MASK }, + { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, SHIFT_RIGHT_MASK }, + { MMI::KeyEvent::KEYCODE_CTRL_LEFT, CTRL_LEFT_MASK }, + { MMI::KeyEvent::KEYCODE_CTRL_RIGHT, CTRL_RIGHT_MASK }, + { MMI::KeyEvent::KEYCODE_CAPS_LOCK, CAPS_MASK }, +}; void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) const { From 9dff707ec4131067461f3ba765259c2b93463557 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Thu, 24 Nov 2022 15:02:06 +0800 Subject: [PATCH 105/112] modify code Signed-off-by: zhaolinglan --- services/include/peruser_session.h | 2 +- services/src/peruser_session.cpp | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index 047117bc..f49e9266 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -180,7 +180,7 @@ private: sptr GetCurrentClient(); void SetImsCore(int32_t index, sptr core); sptr GetImsCore(int32_t index); - int32_t SetClientState(bool state); + int32_t SetClientState(bool isAlive); static inline bool IsValid(int32_t index) { return index >= DEFAULT_IME && index <= SECURITY_IME; diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 58ab4af4..dbb9e72f 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -1076,7 +1076,7 @@ namespace MiscServices { */ int32_t PerUserSession::OnReleaseInput(sptr client) { - IMSA_HILOGI("PerUserSession::OnReleaseInput Start\n"); + IMSA_HILOGI("PerUserSession::OnReleaseInput Start"); int ret = SetClientState(false); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("failed to set client state, ret %{public}d", ret); @@ -1275,18 +1275,6 @@ namespace MiscServices { currentSubProperty = subProperty; } - int32_t PerUserSession::SetClientState(bool state) - { - IMSA_HILOGI("set client state: %{public}s", state ? "true" : "false"); - auto core = GetImsCore(DEFAULT_IME); - if (core == nullptr) { - IMSA_HILOGE("imsCore is nullptr"); - return ErrorCode::ERROR_EX_NULL_POINTER; - } - core->SetClientState(state); - return ErrorCode::NO_ERROR; - } - sptr PerUserSession::GetImsCore(int32_t index) { std::lock_guard lock(imsCoreLock_); @@ -1304,5 +1292,17 @@ namespace MiscServices { } imsCore[index] = core; } + + int32_t PerUserSession::SetClientState(bool isAlive) + { + IMSA_HILOGD("set client state %{public}s", isAlive ? "alive" : "dead"); + auto core = GetImsCore(DEFAULT_IME); + if (core == nullptr) { + IMSA_HILOGE("imsCore is nullptr"); + return ErrorCode::ERROR_EX_NULL_POINTER; + } + core->SetClientState(isAlive); + return ErrorCode::NO_ERROR; + } } // namespace MiscServices } // namespace OHOS From 5a11ac3d7054a4d1e992fecacb24c59556510c7e Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Thu, 24 Nov 2022 15:06:49 +0800 Subject: [PATCH 106/112] modify code Signed-off-by: zhaolinglan --- services/src/peruser_session.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index dbb9e72f..c50ec899 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -1087,6 +1087,7 @@ namespace MiscServices { IMSA_HILOGE("failed to hide keyboard ret %{public}d", ret); return ret; } + RemoveClient(client->AsObject()); IMSA_HILOGD("PerUserSession::OnReleaseInput End...[%{public}d]\n", userId_); return ErrorCode::NO_ERROR; } From acae45512053d1ec0f8feb677bf7d6023b463ab4 Mon Sep 17 00:00:00 2001 From: Hollokin Date: Thu, 24 Nov 2022 16:43:22 +0800 Subject: [PATCH 107/112] =?UTF-8?q?=E3=80=90=E8=BE=93=E5=85=A5=E6=B3=95?= =?UTF-8?q?=E6=A1=86=E6=9E=B6=E3=80=91ListInputMethodInfo=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=A4=B1=E8=AF=AF=E4=BF=AE=E6=94=B9=E8=BF=98=E5=8E=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hollokin --- services/src/input_method_system_ability.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 0700af0b..26920e7b 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -739,6 +739,7 @@ namespace MiscServices { property.descriptionId = applicationInfo.descriptionId; property.label = Str8ToStr16(labelString); property.description = Str8ToStr16(descriptionString); + properties.emplace_back(property); } return properties; } From aa776bc419cd02cd4cbc0b2a2f7d858eb5f62f21 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Thu, 24 Nov 2022 19:48:56 +0800 Subject: [PATCH 108/112] modify code Signed-off-by: zhaolinglan --- .../adapter/keyboard/include/keyboard_event.h | 19 ++++++------ .../keyboard/src/input_event_callback.cpp | 29 ++++++++++--------- .../include/input_method_system_ability.h | 2 +- services/src/input_method_system_ability.cpp | 15 +++++----- 4 files changed, 34 insertions(+), 31 deletions(-) diff --git a/services/adapter/keyboard/include/keyboard_event.h b/services/adapter/keyboard/include/keyboard_event.h index 5b9ccbe5..852a570c 100644 --- a/services/adapter/keyboard/include/keyboard_event.h +++ b/services/adapter/keyboard/include/keyboard_event.h @@ -25,22 +25,21 @@ namespace OHOS { namespace MiscServices { -constexpr uint8_t SHIFT_LEFT_MASK = 0X1; -constexpr uint8_t SHIFT_RIGHT_MASK = 0X1 << 1; -constexpr uint8_t CTRL_LEFT_MASK = 0X1 << 2; -constexpr uint8_t CTRL_RIGHT_MASK = 0X1 << 3; -constexpr uint8_t CAPS_MASK = 0X1 << 4; -constexpr bool IS_KEYS_DOWN(uint32_t state, uint8_t mask) -{ - return (state & mask) == state; -} - using KeyHandle = std::function; class KeyboardEvent { public: static KeyboardEvent &GetInstance(); static int32_t AddKeyEventMonitor(KeyHandle handle); + static constexpr uint8_t SHIFT_LEFT_MASK = 0X1; + static constexpr uint8_t SHIFT_RIGHT_MASK = 0X1 << 1; + static constexpr uint8_t CTRL_LEFT_MASK = 0X1 << 2; + static constexpr uint8_t CTRL_RIGHT_MASK = 0X1 << 3; + static constexpr uint8_t CAPS_MASK = 0X1 << 4; + static constexpr bool IS_KEYS_DOWN(uint32_t state, uint8_t mask) + { + return (state & mask) == state; + } private: static constexpr int32_t PRESS_KEY_DELAY_MS = 200; diff --git a/services/adapter/keyboard/src/input_event_callback.cpp b/services/adapter/keyboard/src/input_event_callback.cpp index d99acbd1..f5c25dca 100644 --- a/services/adapter/keyboard/src/input_event_callback.cpp +++ b/services/adapter/keyboard/src/input_event_callback.cpp @@ -21,11 +21,11 @@ namespace OHOS { namespace MiscServices { uint32_t InputEventCallback::keyState_ = static_cast(0); const std::map MASK_MAP{ - { MMI::KeyEvent::KEYCODE_SHIFT_LEFT, SHIFT_LEFT_MASK }, - { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, SHIFT_RIGHT_MASK }, - { MMI::KeyEvent::KEYCODE_CTRL_LEFT, CTRL_LEFT_MASK }, - { MMI::KeyEvent::KEYCODE_CTRL_RIGHT, CTRL_RIGHT_MASK }, - { MMI::KeyEvent::KEYCODE_CAPS_LOCK, CAPS_MASK }, + { MMI::KeyEvent::KEYCODE_SHIFT_LEFT, KeyboardEvent::SHIFT_LEFT_MASK }, + { MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, KeyboardEvent::SHIFT_RIGHT_MASK }, + { MMI::KeyEvent::KEYCODE_CTRL_LEFT, KeyboardEvent::CTRL_LEFT_MASK }, + { MMI::KeyEvent::KEYCODE_CTRL_RIGHT, KeyboardEvent::CTRL_RIGHT_MASK }, + { MMI::KeyEvent::KEYCODE_CAPS_LOCK, KeyboardEvent::CAPS_MASK }, }; void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) const @@ -33,25 +33,28 @@ void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) c auto keyCode = keyEvent->GetKeyCode(); auto keyAction = keyEvent->GetKeyAction(); auto currKey = MASK_MAP.find(keyCode); - if (currKey == MASK_MAP.end() || keyAction == MMI::KeyEvent::KEY_ACTION_UNKNOWN) { - IMSA_HILOGD("key event unknown"); + if (currKey == MASK_MAP.end()) { + IMSA_HILOGD("key code unknown"); return; } IMSA_HILOGD("keyCode: %{public}d, keyAction: %{public}d", keyCode, keyAction); + if (keyAction == MMI::KeyEvent::KEY_ACTION_DOWN) { IMSA_HILOGD("key %{public}d pressed down", keyCode); keyState_ = static_cast(keyState_ | currKey->second); return; } - if (keyHandler_ == nullptr) { - IMSA_HILOGE("keyHandler_ is nullptr"); + if (keyAction == MMI::KeyEvent::KEY_ACTION_UP) { + if (keyHandler_ == nullptr) { + IMSA_HILOGE("keyHandler_ is nullptr"); + keyState_ = static_cast(keyState_ & ~currKey->second); + return; + } + int32_t ret = keyHandler_(keyState_); keyState_ = static_cast(keyState_ & ~currKey->second); - return; + IMSA_HILOGI("handle key event ret: %{public}d", ret); } - int32_t ret = keyHandler_(keyState_); - keyState_ = static_cast(keyState_ & ~currKey->second); - IMSA_HILOGI("handle key event ret: %{public}d", ret); } void InputEventCallback::OnInputEvent(std::shared_ptr pointerEvent) const diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index 65e48558..efc2c0d7 100644 --- a/services/include/input_method_system_ability.h +++ b/services/include/input_method_system_ability.h @@ -140,7 +140,7 @@ private: using CompareHandler = std::function; SubProperty FindSubPropertyByCompare(const std::string &bundleName, CompareHandler compare); SubProperty GetExtends(const std::vector &metaData); - int32_t SwitchByCombinationKey(const uint32_t &state); + int32_t SwitchByCombinationKey(uint32_t state); int32_t QueryImeInfos(int32_t userId, std::vector &infos); }; diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 42755b39..84808bbb 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -1401,7 +1401,7 @@ namespace MiscServices { return {}; } - int32_t InputMethodSystemAbility::SwitchByCombinationKey(const uint32_t &state) + int32_t InputMethodSystemAbility::SwitchByCombinationKey(uint32_t state) { IMSA_HILOGI("InputMethodSystemAbility::SwitchByCombinationKey"); auto current = GetCurrentInputMethodSubtype(); @@ -1409,7 +1409,7 @@ namespace MiscServices { IMSA_HILOGE("GetCurrentInputMethodSubtype failed"); return ErrorCode::ERROR_EX_NULL_POINTER; } - if (IS_KEYS_DOWN(state, CAPS_MASK)) { + if (KeyboardEvent::IS_KEYS_DOWN(state, KeyboardEvent::CAPS_MASK)) { IMSA_HILOGI("CAPS press"); auto target = current->mode == "upper" ? FindSubPropertyByCompare(current->id, @@ -1418,7 +1418,8 @@ namespace MiscServices { [¤t](const SubProperty &property) { return property.mode == "upper"; }); return SwitchInputMethod(target.id, target.label); } - if (IS_KEYS_DOWN(state, SHIFT_LEFT_MASK) || IS_KEYS_DOWN(state, SHIFT_RIGHT_MASK)) { + if (KeyboardEvent::IS_KEYS_DOWN(state, KeyboardEvent::SHIFT_LEFT_MASK) + || KeyboardEvent::IS_KEYS_DOWN(state, KeyboardEvent::SHIFT_RIGHT_MASK)) { IMSA_HILOGI("SHIFT press"); auto target = current->language == "chinese" ? FindSubPropertyByCompare(current->id, @@ -1427,10 +1428,10 @@ namespace MiscServices { [¤t](const SubProperty &property) { return property.language == "chinese"; }); return SwitchInputMethod(target.id, target.label); } - if (IS_KEYS_DOWN(state, CTRL_LEFT_MASK | SHIFT_LEFT_MASK) || - IS_KEYS_DOWN(state, CTRL_LEFT_MASK | SHIFT_RIGHT_MASK)|| - IS_KEYS_DOWN(state, CTRL_RIGHT_MASK | SHIFT_LEFT_MASK) || - IS_KEYS_DOWN(state, CTRL_RIGHT_MASK | SHIFT_RIGHT_MASK)) { + if (KeyboardEvent::IS_KEYS_DOWN(state, KeyboardEvent::CTRL_LEFT_MASK | KeyboardEvent::SHIFT_LEFT_MASK) + || KeyboardEvent::IS_KEYS_DOWN(state, KeyboardEvent::CTRL_LEFT_MASK | KeyboardEvent::SHIFT_RIGHT_MASK) + || KeyboardEvent::IS_KEYS_DOWN(state, KeyboardEvent::CTRL_RIGHT_MASK | KeyboardEvent::SHIFT_LEFT_MASK) + || KeyboardEvent::IS_KEYS_DOWN(state, KeyboardEvent::CTRL_RIGHT_MASK | KeyboardEvent::SHIFT_RIGHT_MASK)) { IMSA_HILOGI("CTRL_SHIFT press"); std::vector props = {}; auto ret = ListProperty(MAIN_USER_ID, props); From 671f91f305a3f9512a37aa41cac756640b27933c Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Thu, 24 Nov 2022 21:49:12 +0800 Subject: [PATCH 109/112] Signed-off-by: ma-shaoyin Changes to be committed: --- frameworks/inputmethod_ability/src/input_method_ability.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/frameworks/inputmethod_ability/src/input_method_ability.cpp b/frameworks/inputmethod_ability/src/input_method_ability.cpp index 93956630..5dec26bd 100644 --- a/frameworks/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/inputmethod_ability/src/input_method_ability.cpp @@ -51,7 +51,6 @@ InputMethodAbility::~InputMethodAbility() delete msgHandler; msgHandler = nullptr; } - instance_ = nullptr; } sptr InputMethodAbility::GetInstance() From 7320f3d6b1fb6914fd79498e19f8d3c1c2400650 Mon Sep 17 00:00:00 2001 From: LingLan Zhao Date: Fri, 25 Nov 2022 14:44:22 +0800 Subject: [PATCH 110/112] modify code Signed-off-by: LingLan Zhao --- services/adapter/keyboard/include/keyboard_event.h | 4 ++-- services/adapter/keyboard/src/input_event_callback.cpp | 9 +++------ services/src/input_method_system_ability.cpp | 4 ++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/services/adapter/keyboard/include/keyboard_event.h b/services/adapter/keyboard/include/keyboard_event.h index 852a570c..2ad7df15 100644 --- a/services/adapter/keyboard/include/keyboard_event.h +++ b/services/adapter/keyboard/include/keyboard_event.h @@ -25,7 +25,7 @@ namespace OHOS { namespace MiscServices { -using KeyHandle = std::function; +using KeyHandle = std::function; class KeyboardEvent { public: @@ -38,7 +38,7 @@ public: static constexpr uint8_t CAPS_MASK = 0X1 << 4; static constexpr bool IS_KEYS_DOWN(uint32_t state, uint8_t mask) { - return (state & mask) == state; + return state == mask; } private: diff --git a/services/adapter/keyboard/src/input_event_callback.cpp b/services/adapter/keyboard/src/input_event_callback.cpp index f5c25dca..3d213405 100644 --- a/services/adapter/keyboard/src/input_event_callback.cpp +++ b/services/adapter/keyboard/src/input_event_callback.cpp @@ -46,14 +46,11 @@ void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) c } if (keyAction == MMI::KeyEvent::KEY_ACTION_UP) { - if (keyHandler_ == nullptr) { - IMSA_HILOGE("keyHandler_ is nullptr"); - keyState_ = static_cast(keyState_ & ~currKey->second); - return; + if (keyHandler_ != nullptr) { + int32_t ret = keyHandler_(keyState_); + IMSA_HILOGI("handle key event ret: %{public}d", ret); } - int32_t ret = keyHandler_(keyState_); keyState_ = static_cast(keyState_ & ~currKey->second); - IMSA_HILOGI("handle key event ret: %{public}d", ret); } } diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 84808bbb..dc2e2f18 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -1,4 +1,4 @@ -/* +-/* * Copyright (C) 2021 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. @@ -1453,7 +1453,7 @@ namespace MiscServices { { IMSA_HILOGI("InputMethodSystemAbility::InitKeyEventMonitor"); bool ret = ImCommonEventManager::GetInstance()->SubscribeKeyboardEvent( - [this](const uint32_t &keyCode) { return SwitchByCombinationKey(keyCode); }); + [this](uint32_t keyCode) { return SwitchByCombinationKey(keyCode); }); return ret ? ErrorCode::NO_ERROR : ErrorCode::ERROR_SERVICE_START_FAILED; } } // namespace MiscServices From 944540dc6c0ac687bb5d999965fc4c4f678279a4 Mon Sep 17 00:00:00 2001 From: LingLan Zhao Date: Fri, 25 Nov 2022 14:56:40 +0800 Subject: [PATCH 111/112] modify code Signed-off-by: LingLan Zhao --- services/src/input_method_system_ability.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index dc2e2f18..9261503a 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -1,4 +1,4 @@ --/* +/* * Copyright (C) 2021 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. From cbc0924486a1929795ee24bc97c0166c2b196764 Mon Sep 17 00:00:00 2001 From: Hollokin Date: Fri, 25 Nov 2022 20:26:12 +0800 Subject: [PATCH 112/112] =?UTF-8?q?=E3=80=90TDD=E3=80=91ability=E7=9B=B8?= =?UTF-8?q?=E5=85=B3TDD=E7=94=A8=E4=BE=8B=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hollokin --- .../include/input_method_ability.h | 1 - .../include/input_method_setting_listener.h | 6 +- .../src/input_method_controller.cpp | 2 +- .../js/napi/inputmethodclient/js_utils.cpp | 165 +++--- services/include/global.h | 93 ++-- services/src/global.cpp | 22 +- unitest/BUILD.gn | 3 + unitest/src/input_method_ability_test.cpp | 511 +++++++++++++----- 8 files changed, 504 insertions(+), 299 deletions(-) diff --git a/frameworks/inputmethod_ability/include/input_method_ability.h b/frameworks/inputmethod_ability/include/input_method_ability.h index 76dcbb02..8afb464e 100644 --- a/frameworks/inputmethod_ability/include/input_method_ability.h +++ b/frameworks/inputmethod_ability/include/input_method_ability.h @@ -43,7 +43,6 @@ public: InputMethodAbility(); ~InputMethodAbility(); static sptr GetInstance(); - sptr OnConnect(); int32_t InsertText(const std::string text); void setImeListener(std::shared_ptr imeListener); void setKdListener(std::shared_ptr kdListener); diff --git a/frameworks/inputmethod_controller/include/input_method_setting_listener.h b/frameworks/inputmethod_controller/include/input_method_setting_listener.h index 308d5a11..1203fca7 100644 --- a/frameworks/inputmethod_controller/include/input_method_setting_listener.h +++ b/frameworks/inputmethod_controller/include/input_method_setting_listener.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef INPUTMETHOD_IMF_INPUT_METHOD_ENGINE_LISTENER_H -#define INPUTMETHOD_IMF_INPUT_METHOD_ENGINE_LISTENER_H +#ifndef INPUTMETHOD_IMF_INPUT_METHOD_SETTING_LISTENER_H +#define INPUTMETHOD_IMF_INPUT_METHOD_SETTING_LISTENER_H #include "input_method_property.h" @@ -28,4 +28,4 @@ public: } // namespace MiscServices } // namespace OHOS -#endif // INPUTMETHOD_IMF_INPUT_METHOD_ENGINE_LISTENER_H +#endif // INPUTMETHOD_IMF_INPUT_METHOD_SETTING_LISTENER_H diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index 57f216a9..39b6f359 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -502,7 +502,7 @@ using namespace MessageID; int32_t InputMethodController::GetTextAfterCursor(int32_t number, std::u16string &text) { - IMSA_HILOGI("InputMethodController::GetTextBeforeCursor"); + IMSA_HILOGI("InputMethodController::GetTextAfterCursor"); if (!mTextString.empty() && mTextString.size() <= INT_MAX) { int32_t endPos = (mSelectNewEnd + number < static_cast(mTextString.size())) ? (mSelectNewEnd + number) diff --git a/interfaces/kits/js/napi/inputmethodclient/js_utils.cpp b/interfaces/kits/js/napi/inputmethodclient/js_utils.cpp index 2a3b644e..d9388adb 100644 --- a/interfaces/kits/js/napi/inputmethodclient/js_utils.cpp +++ b/interfaces/kits/js/napi/inputmethodclient/js_utils.cpp @@ -20,9 +20,7 @@ namespace MiscServices { const std::map JsUtils::ERROR_CODE_MAP = { { ErrorCode::ERROR_STATUS_PERMISSION_DENIED, EXCEPTION_PERMISSION }, { ErrorCode::ERROR_REMOTE_IME_DIED, EXCEPTION_IMENGINE }, - { ErrorCode::ERROR_RESTART_IME_FAILED, EXCEPTION_IMENGINE }, { ErrorCode::ERROR_REMOTE_CLIENT_DIED, EXCEPTION_IMCLIENT }, - { ErrorCode::ERROR_CLIENT_DUPLICATED, EXCEPTION_IMCLIENT }, { ErrorCode::ERROR_CLIENT_NOT_FOUND, EXCEPTION_IMCLIENT }, { ErrorCode::ERROR_CLIENT_NULL_POINTER, EXCEPTION_IMCLIENT }, { ErrorCode::ERROR_NOT_IME_PACKAGE, EXCEPTION_SETTINGS }, @@ -42,19 +40,11 @@ const std::map JsUtils::ERROR_CODE_MAP = { { ErrorCode::ERROR_IME_BIND_FAILED, EXCEPTION_IMMS }, { ErrorCode::ERROR_IME_UNBIND_FAILED, EXCEPTION_IMMS }, { ErrorCode::ERROR_IME_START_FAILED, EXCEPTION_IMMS }, - { ErrorCode::ERROR_IME_STOP_FAILED, EXCEPTION_IMMS }, { ErrorCode::ERROR_KBD_SHOW_FAILED, EXCEPTION_IMMS }, { ErrorCode::ERROR_KBD_HIDE_FAILED, EXCEPTION_IMMS }, { ErrorCode::ERROR_IME_NOT_STARTED, EXCEPTION_IMMS }, { ErrorCode::ERROR_KBD_IS_OCCUPIED, EXCEPTION_IMMS }, { ErrorCode::ERROR_KBD_IS_NOT_SHOWING, EXCEPTION_IMMS }, - { ErrorCode::ERROR_IME_ALREADY_STARTED, EXCEPTION_IMMS }, - { ErrorCode::ERROR_NO_NEXT_IME, EXCEPTION_IMMS }, - { ErrorCode::ERROR_CLIENTWINDOW_NOT_FOCUSED, EXCEPTION_IMMS }, - { ErrorCode::ERROR_CLIENT_NOT_WINDOW, EXCEPTION_IMMS }, - { ErrorCode::ERROR_IME_PROPERTY_MARSHALL, EXCEPTION_IMMS }, - { ErrorCode::ERROR_GETTING_CURRENT_IME, EXCEPTION_IMMS }, - { ErrorCode::ERROR_LIST_IME, EXCEPTION_IMMS }, { ErrorCode::ERROR_EX_NULL_POINTER, EXCEPTION_IMMS }, { ErrorCode::ERROR_PERSIST_CONFIG, EXCEPTION_CONFPERSIST }, { ErrorCode::ERROR_PACKAGE_MANAGER, EXCEPTION_PACKAGEMANAGER }, @@ -83,86 +73,85 @@ const std::map JsUtils::ERROR_CODE_MAP = { }; const std::map JsUtils::ERROR_CODE_CONVERT_MESSAGE_MAP = { - { EXCEPTION_PERMISSION, "the permissions check fails." }, - { EXCEPTION_PARAMCHECK, "the parameters check fails." }, - { EXCEPTION_UNSUPPORTED, "call unsupported api." }, - { EXCEPTION_PACKAGEMANAGER, "package manager error." }, - { EXCEPTION_IMENGINE, "input method engine error." }, - { EXCEPTION_IMCLIENT, "input method client error." }, - { EXCEPTION_KEYEVENT, "key event processing error." }, - { EXCEPTION_CONFPERSIST, "configuration persisting error." }, - { EXCEPTION_CONTROLLER, "input method controller error." }, - { EXCEPTION_SETTINGS, "input method settings extension error." }, - { EXCEPTION_IMMS, "input method manager service error." }, - { EXCEPTION_OTHERS, "others error." }, - }; + { EXCEPTION_PERMISSION, "the permissions check fails." }, + { EXCEPTION_PARAMCHECK, "the parameters check fails." }, + { EXCEPTION_UNSUPPORTED, "call unsupported api." }, + { EXCEPTION_PACKAGEMANAGER, "package manager error." }, + { EXCEPTION_IMENGINE, "input method engine error." }, + { EXCEPTION_IMCLIENT, "input method client error." }, + { EXCEPTION_KEYEVENT, "key event processing error." }, + { EXCEPTION_CONFPERSIST, "configuration persisting error." }, + { EXCEPTION_CONTROLLER, "input method controller error." }, + { EXCEPTION_SETTINGS, "input method settings extension error." }, + { EXCEPTION_IMMS, "input method manager service error." }, + { EXCEPTION_OTHERS, "others error." }, +}; - const std::map JsUtils::PARAMETER_TYPE = { - { TYPE_UNDEFINED, "napi_undefine." }, - { TYPE_NULL, "napi_null." }, - { TYPE_BOOLEAN, "napi_boolean." }, - { TYPE_NUMBER, "napi_number." }, - { TYPE_STRING, "napi_string." }, - { TYPE_SYMBOL, "napi_symbol." }, - { TYPE_OBJECT, "napi_object." }, - { TYPE_FUNCTION, "napi_function." }, - { TYPE_EXTERNAL, "napi_external." }, - { TYPE_BIGINT, "napi_bigint." }, - }; +const std::map JsUtils::PARAMETER_TYPE = { + { TYPE_UNDEFINED, "napi_undefine." }, + { TYPE_NULL, "napi_null." }, + { TYPE_BOOLEAN, "napi_boolean." }, + { TYPE_NUMBER, "napi_number." }, + { TYPE_STRING, "napi_string." }, + { TYPE_SYMBOL, "napi_symbol." }, + { TYPE_OBJECT, "napi_object." }, + { TYPE_FUNCTION, "napi_function." }, + { TYPE_EXTERNAL, "napi_external." }, + { TYPE_BIGINT, "napi_bigint." }, +}; - void JsUtils::ThrowException(napi_env env, int32_t err, const std::string &msg, TypeCode type) - { - std::string errMsg = ToMessage(err); - if (type == TypeCode::TYPE_NONE) { - errMsg = errMsg + msg; - IMSA_HILOGE("THROW_PARAMTER_ERROR message: %{public}s", errMsg.c_str()); - } else { - auto iter = PARAMETER_TYPE.find(type); - if (iter != PARAMETER_TYPE.end()) { - errMsg = errMsg + "The type of " + msg + " must be " + iter->second; - IMSA_HILOGE("THROW_PARAMTER_TYPE_ERROR message: %{public}s", errMsg.c_str()); - } +void JsUtils::ThrowException(napi_env env, int32_t err, const std::string &msg, TypeCode type) +{ + std::string errMsg = ToMessage(err); + if (type == TypeCode::TYPE_NONE) { + errMsg = errMsg + msg; + IMSA_HILOGE("THROW_PARAMTER_ERROR message: %{public}s", errMsg.c_str()); + } else { + auto iter = PARAMETER_TYPE.find(type); + if (iter != PARAMETER_TYPE.end()) { + errMsg = errMsg + "The type of " + msg + " must be " + iter->second; + IMSA_HILOGE("THROW_PARAMTER_TYPE_ERROR message: %{public}s", errMsg.c_str()); } - napi_throw_error(env, std::to_string(err).c_str(), errMsg.c_str()); - } - - napi_value JsUtils::ToError(napi_env env, int32_t code) - { - IMSA_HILOGE("ToError start"); - napi_value errorObj; - NAPI_CALL(env, napi_create_object(env, &errorObj)); - napi_value errorCode = nullptr; - NAPI_CALL( - env, napi_create_string_utf8(env, std::to_string(Convert(code)).c_str(), NAPI_AUTO_LENGTH, &errorCode)); - napi_value errorMessage = nullptr; - NAPI_CALL(env, napi_create_string_utf8(env, ToMessage(Convert(code)).c_str(), NAPI_AUTO_LENGTH, &errorMessage)); - NAPI_CALL(env, napi_set_named_property(env, errorObj, "code", errorCode)); - NAPI_CALL(env, napi_set_named_property(env, errorObj, "message", errorMessage)); - IMSA_HILOGE("ToError end"); - return errorObj; - } - - int32_t JsUtils::Convert(int32_t code) - { - IMSA_HILOGI("Convert start"); - auto iter = ERROR_CODE_MAP.find(code); - if (iter != ERROR_CODE_MAP.end()) { - IMSA_HILOGE("ErrorCode: %{public}d", iter->second); - return iter->second; - } - IMSA_HILOGI("Convert end"); - return ERROR_CODE_QUERY_FAILED; - } - - const std::string JsUtils::ToMessage(int32_t code) - { - IMSA_HILOGI("ToMessage start"); - auto iter = ERROR_CODE_CONVERT_MESSAGE_MAP.find(code); - if (iter != ERROR_CODE_CONVERT_MESSAGE_MAP.end()) { - IMSA_HILOGI("ErrorMessage: %{public}s", (iter->second).c_str()); - return iter->second; - } - return "error is out of definition."; } + napi_throw_error(env, std::to_string(err).c_str(), errMsg.c_str()); } -} \ No newline at end of file + +napi_value JsUtils::ToError(napi_env env, int32_t code) +{ + IMSA_HILOGE("ToError start"); + napi_value errorObj; + NAPI_CALL(env, napi_create_object(env, &errorObj)); + napi_value errorCode = nullptr; + NAPI_CALL(env, napi_create_string_utf8(env, std::to_string(Convert(code)).c_str(), NAPI_AUTO_LENGTH, &errorCode)); + napi_value errorMessage = nullptr; + NAPI_CALL(env, napi_create_string_utf8(env, ToMessage(Convert(code)).c_str(), NAPI_AUTO_LENGTH, &errorMessage)); + NAPI_CALL(env, napi_set_named_property(env, errorObj, "code", errorCode)); + NAPI_CALL(env, napi_set_named_property(env, errorObj, "message", errorMessage)); + IMSA_HILOGE("ToError end"); + return errorObj; +} + +int32_t JsUtils::Convert(int32_t code) +{ + IMSA_HILOGI("Convert start"); + auto iter = ERROR_CODE_MAP.find(code); + if (iter != ERROR_CODE_MAP.end()) { + IMSA_HILOGE("ErrorCode: %{public}d", iter->second); + return iter->second; + } + IMSA_HILOGI("Convert end"); + return ERROR_CODE_QUERY_FAILED; +} + +const std::string JsUtils::ToMessage(int32_t code) +{ + IMSA_HILOGI("ToMessage start"); + auto iter = ERROR_CODE_CONVERT_MESSAGE_MAP.find(code); + if (iter != ERROR_CODE_CONVERT_MESSAGE_MAP.end()) { + IMSA_HILOGI("ErrorMessage: %{public}s", (iter->second).c_str()); + return iter->second; + } + return "error is out of definition."; +} +} // namespace MiscServices +} // namespace OHOS \ No newline at end of file diff --git a/services/include/global.h b/services/include/global.h index 18a9445d..3be7aaa1 100644 --- a/services/include/global.h +++ b/services/include/global.h @@ -101,64 +101,53 @@ enum { ERROR_STATUS_UNEXPECTED_NULL = ERROR_STATUS_UNKNOWN_ERROR + 8, // unexpected null, // binder exception error code from Status.h - ERROR_EX_ILLEGAL_ARGUMENT = -3, // illegal argument exception - ERROR_EX_NULL_POINTER = -4, // null pointer exception - ERROR_EX_ILLEGAL_STATE = -5, // illegal state exception - ERROR_EX_NETWORK_MAIN_THREAD = -6, // network main thread exception - ERROR_EX_UNSUPPORTED_OPERATION = -7, // unsupported operation exception - ERROR_EX_SERVICE_SPECIFIC = -8, // service specific exception - ERROR_EX_PARCELABLE = -9, // parcelable exception + ERROR_EX_ILLEGAL_ARGUMENT = -3, // illegal argument exception + ERROR_EX_NULL_POINTER = -4, // null pointer exception + ERROR_EX_ILLEGAL_STATE = -5, // illegal state exception + ERROR_EX_NETWORK_MAIN_THREAD = -6, // network main thread exception + ERROR_EX_UNSUPPORTED_OPERATION = -7, // unsupported operation exception + ERROR_EX_SERVICE_SPECIFIC = -8, // service specific exception + ERROR_EX_PARCELABLE = -9, // parcelable exception // no error - NO_ERROR = 0, // no error + NO_ERROR = 0, // no error // system service error - ERROR_NULL_POINTER, // null pointer - ERROR_BAD_PARAMETERS, // bad parameters - ERROR_SERVICE_START_FAILED, // failed to start service - ERROR_USER_NOT_STARTED, // user is not started - ERROR_USER_ALREADY_STARTED, // user has already started - ERROR_USER_NOT_UNLOCKED, // user is not unlocked - ERROR_USER_ALREADY_UNLOCKED, // user has already unlocked - ERROR_USER_NOT_LOCKED, // user is not locked + ERROR_NULL_POINTER = 1, // null pointer + ERROR_BAD_PARAMETERS = 2, // bad parameters + ERROR_USER_NOT_STARTED = 3, // user is not started + ERROR_USER_ALREADY_STARTED = 4, // user has already started + ERROR_USER_NOT_UNLOCKED = 5, // user is not unlocked + ERROR_USER_ALREADY_UNLOCKED = 6, // user has already unlocked + ERROR_USER_NOT_LOCKED = 7, // user is not locked - ERROR_IME_NOT_AVAILABLE, // input method engine is not available - ERROR_SECURITY_IME_NOT_AVAILABLE, // security input method engine is not available - ERROR_TOKEN_CREATE_FAILED, // failed to create window token - ERROR_TOKEN_DESTROY_FAILED, // failed to destroy window token - ERROR_IME_BIND_FAILED, // failed to bind IME service - ERROR_IME_UNBIND_FAILED, // failed to unbind IME service - ERROR_IME_START_FAILED, // failed to start IME service - ERROR_IME_STOP_FAILED, // failed to stop IME service - ERROR_KBD_SHOW_FAILED, // failed to show keyboard - ERROR_KBD_HIDE_FAILED, // failed to hide keyboard - ERROR_IME_NOT_STARTED, // input method service is not started - ERROR_KBD_IS_OCCUPIED, // keyboard is showing by other client - ERROR_KBD_IS_NOT_SHOWING, // keyboard is not showing - ERROR_IME_ALREADY_STARTED, // input method service has already started - ERROR_NOT_IME_PACKAGE, // not an IME package - ERROR_IME_PACKAGE_DUPLICATED, // duplicated IME package - ERROR_SETTING_SAME_VALUE, // same setting value - ERROR_NO_NEXT_IME, // no next ime is available - ERROR_CLIENTWINDOW_NOT_FOCUSED, // the input client window is not focused - ERROR_CLIENT_NOT_WINDOW, // the input client is not from a valid window - ERROR_ADD_CLIENT_FAILED, - ERROR_IME_PROPERTY_MARSHALL, // failed to marshall the ime property - ERROR_GETTING_CURRENT_IME, - ERROR_LIST_IME, - ERROR_SWITCH_IME, + ERROR_IME_NOT_AVAILABLE = 8, // input method engine is not available + ERROR_SECURITY_IME_NOT_AVAILABLE = 9, // security input method engine is not available + ERROR_TOKEN_CREATE_FAILED = 10, // failed to create window token + ERROR_TOKEN_DESTROY_FAILED = 11, // failed to destroy window token + ERROR_IME_BIND_FAILED = 12, // failed to bind IME service + ERROR_IME_UNBIND_FAILED = 13, // failed to unbind IME service + ERROR_IME_START_FAILED = 14, // failed to start IME service + ERROR_KBD_SHOW_FAILED = 15, // failed to show keyboard + ERROR_KBD_HIDE_FAILED = 16, // failed to hide keyboard + ERROR_IME_NOT_STARTED = 17, // input method service is not started + ERROR_KBD_IS_OCCUPIED = 18, // keyboard is showing by other client + ERROR_KBD_IS_NOT_SHOWING = 19, // keyboard is not showing + ERROR_NOT_IME_PACKAGE = 20, // not an IME package + ERROR_IME_PACKAGE_DUPLICATED = 21, // duplicated IME package + ERROR_SETTING_SAME_VALUE = 22, // same setting value + ERROR_ADD_CLIENT_FAILED = 23, // add client failed + ERROR_SWITCH_IME = 24, // error from ime - ERROR_REMOTE_IME_DIED, // remote input method service died abnormally - ERROR_RESTART_IME_FAILED, // failed to restart input method service - ERROR_IME_NULL_POINTER, // null pointer + ERROR_REMOTE_IME_DIED = 25, // remote input method service died abnormally // error from client - ERROR_REMOTE_CLIENT_DIED, // remote client died abnormally - ERROR_CLIENT_DUPLICATED, // duplicated client - ERROR_CLIENT_NOT_FOUND, // client is not found - ERROR_CLIENT_NULL_POINTER, // null pointer - ERROR_SUBSCRIBE_KEYBOARD_EVENT, - ERROR_CONTROLLER_INVOKING_FAILED, - ERROR_PERSIST_CONFIG, - ERROR_PACKAGE_MANAGER, + ERROR_REMOTE_CLIENT_DIED = 26, // remote client died abnormally + ERROR_CLIENT_NOT_FOUND = 27, // client is not found + ERROR_CLIENT_NULL_POINTER = 28, // null pointer + ERROR_SUBSCRIBE_KEYBOARD_EVENT = 29, + ERROR_CONTROLLER_INVOKING_FAILED = 30, + ERROR_PERSIST_CONFIG = 31, + ERROR_PACKAGE_MANAGER = 32, + ERROR_SERVICE_START_FAILED = 33, }; const char *ToString(int errorCode); }; // namespace ErrorCode diff --git a/services/src/global.cpp b/services/src/global.cpp index 2d123132..7cbe8ec2 100644 --- a/services/src/global.cpp +++ b/services/src/global.cpp @@ -82,8 +82,8 @@ const char *ToString(int errorCode) case ERROR_IME_START_FAILED: { return "failed to start input"; } - case ERROR_IME_STOP_FAILED: { - return "failed to stop input"; + case ERROR_ADD_CLIENT_FAILED: { + return "failed fo add client"; } case ERROR_KBD_SHOW_FAILED: { return "failed to show keyboard"; @@ -100,9 +100,6 @@ const char *ToString(int errorCode) case ERROR_KBD_IS_NOT_SHOWING: { return "keyboard is not showing"; } - case ERROR_IME_ALREADY_STARTED: { - return "input method service has already started"; - } case ERROR_NOT_IME_PACKAGE: { return "not an input method engine package"; } @@ -112,27 +109,12 @@ const char *ToString(int errorCode) case ERROR_SETTING_SAME_VALUE: { return "same setting value"; } - case ERROR_NO_NEXT_IME: { - return "next input method engine is not available"; - } - case ERROR_CLIENTWINDOW_NOT_FOCUSED: { - return "input client window is not focused"; - } - case ERROR_CLIENT_NOT_WINDOW: { - return "input client is not from a valid window"; - } case ERROR_REMOTE_IME_DIED: { return "input method service died"; } - case ERROR_RESTART_IME_FAILED: { - return "failed to restart input method service"; - } case ERROR_REMOTE_CLIENT_DIED: { return "input client died"; } - case ERROR_CLIENT_DUPLICATED: { - return "duplicated client"; - } case ERROR_CLIENT_NOT_FOUND: { return "client is not found"; } diff --git a/unitest/BUILD.gn b/unitest/BUILD.gn index 0b2b0ed3..1f6c9110 100644 --- a/unitest/BUILD.gn +++ b/unitest/BUILD.gn @@ -76,6 +76,9 @@ ohos_unittest("InputMethodAbilityTest") { external_deps = [ "ability_base:want", + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", "c_utils:utils", "hiviewdfx_hilog_native:libhilog", ] diff --git a/unitest/src/input_method_ability_test.cpp b/unitest/src/input_method_ability_test.cpp index df4e49ca..24b60791 100644 --- a/unitest/src/input_method_ability_test.cpp +++ b/unitest/src/input_method_ability_test.cpp @@ -13,15 +13,17 @@ * limitations under the License. */ -#include -#include +#include "input_method_ability.h" #include #include +#include #include #include +#include #include +#include "accesstoken_kit.h" #include "global.h" #include "i_input_data_channel.h" #include "input_attribute.h" @@ -29,164 +31,405 @@ #include "input_data_channel_proxy.h" #include "input_data_channel_stub.h" #include "input_method_agent_stub.h" +#include "input_method_controller.h" #include "input_method_core_proxy.h" #include "input_method_core_stub.h" #include "message_handler.h" +#include "nativetoken_kit.h" +#include "token_setproc.h" using namespace testing::ext; +using namespace OHOS::Security::AccessToken; namespace OHOS { namespace MiscServices { - class InputMethodAbilityTest : public testing::Test { - public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); +class InputMethodAbilityTest : public testing::Test { +public: + static std::string imeIdStopped_; + static bool showKeyboard_; + static int direction_; + static int deleteForwardLength_; + static int deleteBackwardLength_; + static std::u16string insertText_; + static int key_; + static int keyboardStatus_; + static bool status_; + static sptr imc_; + static sptr inputMethodAbility_; + + class KeyboardListenerTestImpl : public KeyboardListener { + bool OnKeyEvent(int32_t keyCode, int32_t keyStatus) + { + return true; + } + void OnCursorUpdate(int32_t positionX, int32_t positionY, int32_t height) + { + } + void OnSelectionChange(int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd) + { + } + void OnTextChange(std::string text) + { + } }; + class InputMethodEngineListenerImpl : public InputMethodEngineListener { + public: + InputMethodEngineListenerImpl() = default; + ~InputMethodEngineListenerImpl() = default; - void InputMethodAbilityTest::SetUpTestCase(void) + void OnKeyboardStatus(bool isShow) + { + showKeyboard_ = isShow; + IMSA_HILOGI("InputMethodEngineListenerImpl OnKeyboardStatus"); + } + + void OnInputStart() + { + IMSA_HILOGI("InputMethodEngineListenerImpl OnInputStart"); + } + + void OnInputStop(std::string imeId) + { + imeIdStopped_ = imeId; + IMSA_HILOGI("InputMethodEngineListenerImpl OnInputStop"); + } + + void OnSetCallingWindow(uint32_t windowId) + { + IMSA_HILOGI("InputMethodEngineListenerImpl OnSetCallingWindow"); + } + + void OnSetSubtype(const SubProperty &property) + { + IMSA_HILOGI("InputMethodEngineListenerImpl OnSetSubtype"); + } + }; + class TextChangeListener : public OnTextChangedListener { + public: + void InsertText(const std::u16string &text) override + { + insertText_ = text; + } + + void DeleteForward(int32_t length) override + { + deleteForwardLength_ = length; + IMSA_HILOGI("TextChangeListener: DeleteForward, length is: %{public}d", length); + } + + void DeleteBackward(int32_t length) override + { + deleteBackwardLength_ = length; + IMSA_HILOGI("TextChangeListener: DeleteBackward, direction is: %{public}d", length); + } + + void SendKeyEventFromInputMethod(const KeyEvent &event) override + { + } + + void SendKeyboardInfo(const KeyboardInfo &info) override + { + FunctionKey functionKey = info.GetFunctionKey(); + KeyboardStatus keyboardStatus = info.GetKeyboardStatus(); + key_ = (int)functionKey; + keyboardStatus_ = (int)keyboardStatus; + } + + void SetKeyboardStatus(bool status) override + { + status_ = status; + } + + void MoveCursor(const Direction direction) override + { + direction_ = (int)direction; + IMSA_HILOGI("TextChangeListener: MoveCursor, direction is: %{public}d", direction); + } + }; + void GrantPermission() { - IMSA_HILOGI("InputMethodAbilityTest::SetUpTestCase"); + const char **perms = new const char *[1]; + perms[0] = "ohos.permission.CONNECT_IME_ABILITY"; + TokenInfoParams infoInstance = { + .dcapsNum = 0, + .permsNum = 1, + .aclsNum = 0, + .dcaps = nullptr, + .perms = perms, + .acls = nullptr, + .processName = "inputmethod_imf", + .aplStr = "system_core", + }; + uint64_t tokenId = GetAccessTokenId(&infoInstance); + int res = SetSelfTokenID(tokenId); + if (res == 0) { + IMSA_HILOGI("SetSelfTokenID success!"); + } else { + IMSA_HILOGE("SetSelfTokenID fail!"); + } + AccessTokenKit::ReloadNativeTokenInfo(); + delete[] perms; } - - void InputMethodAbilityTest::TearDownTestCase(void) + static void SetUpTestCase(void) { - IMSA_HILOGI("InputMethodAbilityTest::TearDownTestCase"); + imc_ = InputMethodController::GetInstance(); + ASSERT_TRUE(imc_ != nullptr); } - - void InputMethodAbilityTest::SetUp(void) + static void TearDownTestCase(void) { + } + void SetUp() + { + inputMethodAbility_ = InputMethodAbility::GetInstance(); + GrantPermission(); IMSA_HILOGI("InputMethodAbilityTest::SetUp"); + sptr textListener = new TextChangeListener(); + imc_->Attach(textListener); } - - void InputMethodAbilityTest::TearDown(void) + void TearDown() { - IMSA_HILOGI("InputMethodAbilityTest::TearDown"); } +}; - /** - * @tc.name: testReadWriteIInputMethodAgent - * @tc.desc: Checkout IInputMethodAgent. - * @tc.type: FUNC - * @tc.require: issueI5JBR6 - */ - HWTEST_F(InputMethodAbilityTest, testReadWriteIInputMethodAgent, TestSize.Level0) - { - sptr mInputMethodAgentStub = new InputMethodAgentStub(); - MessageParcel data; - auto ret = data.WriteRemoteObject(mInputMethodAgentStub->AsObject()); - EXPECT_TRUE(ret); - auto remoteObject = data.ReadRemoteObject(); - sptr iface = iface_cast(remoteObject); - EXPECT_TRUE(iface != nullptr); - } +std::string InputMethodAbilityTest::imeIdStopped_; +bool InputMethodAbilityTest::showKeyboard_; +int InputMethodAbilityTest::direction_; +int InputMethodAbilityTest::deleteForwardLength_; +int InputMethodAbilityTest::deleteBackwardLength_; +std::u16string InputMethodAbilityTest::insertText_; +int InputMethodAbilityTest::key_; +int InputMethodAbilityTest::keyboardStatus_; +bool InputMethodAbilityTest::status_; +sptr InputMethodAbilityTest::imc_; +sptr InputMethodAbilityTest::inputMethodAbility_; - /** - * @tc.name: testReadWriteIInputMethodCore - * @tc.desc: Checkout IInputMethodCore. - * @tc.type: FUNC - */ - HWTEST_F(InputMethodAbilityTest, testReadWriteIInputMethodCore, TestSize.Level0) - { - sptr mInputMethodCoreStub = new InputMethodCoreStub(0); - MessageParcel data; - auto ret = data.WriteRemoteObject(mInputMethodCoreStub->AsObject()); - EXPECT_TRUE(ret); - auto remoteObject = data.ReadRemoteObject(); - sptr iface = iface_cast(remoteObject); - EXPECT_TRUE(iface != nullptr); - } +/** +* @tc.name: testShowKeyboardInputMethodCoreProxy +* @tc.desc: Test InputMethodCoreProxy ShowKeyboard +* @tc.type: FUNC +* @tc.require: issueI5NXHK +*/ +HWTEST_F(InputMethodAbilityTest, testShowKeyboardInputMethodCoreProxy, TestSize.Level0) +{ + sptr coreStub = new InputMethodCoreStub(0); + sptr core = coreStub; + auto msgHandler = new (std::nothrow) MessageHandler(); + coreStub->SetMessageHandler(msgHandler); + sptr channelStub = new InputDataChannelStub(); - /** - * @tc.name: testShowKeyboardInputMethodCoreProxy - * @tc.desc: Test InputMethodCoreProxy ShowKeyboard - * @tc.type: FUNC - * @tc.require: issueI5NXHK - */ - HWTEST_F(InputMethodAbilityTest, testShowKeyboardInputMethodCoreProxy, TestSize.Level0) - { - sptr coreStub = new InputMethodCoreStub(0); - sptr core = coreStub; - auto msgHandler = new (std::nothrow) MessageHandler(); - coreStub->SetMessageHandler(msgHandler); - sptr channelStub = new InputDataChannelStub(); + MessageParcel data; + data.WriteRemoteObject(core->AsObject()); + data.WriteRemoteObject(channelStub->AsObject()); + sptr coreObject = data.ReadRemoteObject(); + sptr channelObject = data.ReadRemoteObject(); - MessageParcel data; - data.WriteRemoteObject(core->AsObject()); - data.WriteRemoteObject(channelStub->AsObject()); - sptr coreObject = data.ReadRemoteObject(); - sptr channelObject = data.ReadRemoteObject(); + sptr coreProxy = new InputMethodCoreProxy(coreObject); + sptr channelProxy = new InputDataChannelProxy(channelObject); + SubProperty subProperty; + auto ret = coreProxy->showKeyboard(channelProxy, true, subProperty); + delete msgHandler; + EXPECT_EQ(ret, ErrorCode::NO_ERROR); +} - sptr coreProxy = new InputMethodCoreProxy(coreObject); - sptr channelProxy = new InputDataChannelProxy(channelObject); - SubProperty subProperty; - auto ret = coreProxy->showKeyboard(channelProxy, true, subProperty); - delete msgHandler; - EXPECT_EQ(ret, 0); - } +/** +* @tc.name: testShowKeyboardInputMethodCoreStub +* @tc.desc: Test InputMethodCoreStub ShowKeyboard +* @tc.type: FUNC +* @tc.require: issueI5NXHK +*/ +HWTEST_F(InputMethodAbilityTest, testShowKeyboardInputMethodCoreStub, TestSize.Level0) +{ + sptr coreStub = new InputMethodCoreStub(0); + SubProperty subProperty; + auto ret = coreStub->showKeyboard(nullptr, true, subProperty); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); +} - /** - * @tc.name: testShowKeyboardInputMethodCoreStub - * @tc.desc: Test InputMethodCoreStub ShowKeyboard - * @tc.type: FUNC - * @tc.require: issueI5NXHK - */ - HWTEST_F(InputMethodAbilityTest, testShowKeyboardInputMethodCoreStub, TestSize.Level0) - { - sptr coreStub = new InputMethodCoreStub(0); - SubProperty subProperty; - auto ret = coreStub->showKeyboard(nullptr, true, subProperty); - EXPECT_EQ(ret, 0); - } +/** +* @tc.name: testSerializedInputAttribute +* @tc.desc: Checkout the serialization of InputAttribute. +* @tc.type: FUNC +*/ +HWTEST_F(InputMethodAbilityTest, testSerializedInputAttribute, TestSize.Level0) +{ + InputAttribute inAttribute; + inAttribute.inputPattern = InputAttribute::PATTERN_PASSWORD; + MessageParcel data; + EXPECT_TRUE(InputAttribute::Marshalling(inAttribute, data)); + InputAttribute outAttribute; + EXPECT_TRUE(InputAttribute::Unmarshalling(outAttribute, data)); + EXPECT_TRUE(outAttribute.GetSecurityFlag()); +} - /** - * @tc.name: testReadWriteIInputControlChannel - * @tc.desc: Checkout IInputControlChannel. - * @tc.type: FUNC - */ - HWTEST_F(InputMethodAbilityTest, testReadWriteIInputControlChannel, TestSize.Level0) - { - sptr mInputControlChannelStub = new InputControlChannelStub(0); - MessageParcel data; - auto ret = data.WriteRemoteObject(mInputControlChannelStub->AsObject()); - EXPECT_TRUE(ret); - auto remoteObject = data.ReadRemoteObject(); - sptr iface = iface_cast(remoteObject); - EXPECT_TRUE(iface != nullptr); - } +/** +* @tc.name: testSerializedKeyboardType +* @tc.desc: Checkout the serialization of KeyboardType. +* @tc.type: FUNC +*/ +HWTEST_F(InputMethodAbilityTest, testSerializedKeyboardType, TestSize.Level0) +{ + int32_t def_value = 2021; + sptr mKeyboardType = new KeyboardType(); + mKeyboardType->setId(def_value); + MessageParcel data; + auto ret = data.WriteParcelable(mKeyboardType); + EXPECT_TRUE(ret); + sptr deserialization = data.ReadParcelable(); + ASSERT_TRUE(deserialization != nullptr); + EXPECT_TRUE(deserialization->getId() == def_value); +} - /** - * @tc.name: testSerializedInputAttribute - * @tc.desc: Checkout the serialization of InputAttribute. - * @tc.type: FUNC - */ - HWTEST_F(InputMethodAbilityTest, testSerializedInputAttribute, TestSize.Level0) - { - InputAttribute inAttribute; - inAttribute.inputPattern = InputAttribute::PATTERN_PASSWORD; - MessageParcel data; - EXPECT_TRUE(InputAttribute::Marshalling(inAttribute, data)); - InputAttribute outAttribute; - EXPECT_TRUE(InputAttribute::Unmarshalling(outAttribute, data)); - EXPECT_TRUE(outAttribute.GetSecurityFlag()); - } +/** +* @tc.name: testMoveCursor +* @tc.desc: InputMethodAbility MoveCursor +* @tc.type: FUNC +* @tc.require: +* @tc.author: Hollokin +*/ +HWTEST_F(InputMethodAbilityTest, testMoveCursor, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodAbility MoveCursor Test START"); + auto ret = inputMethodAbility_->MoveCursor(4); // move cursor right + usleep(500); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_EQ(direction_, 4); +} - /** - * @tc.name: testSerializedKeyboardType - * @tc.desc: Checkout the serialization of KeyboardType. - * @tc.type: FUNC - */ - HWTEST_F(InputMethodAbilityTest, testSerializedKeyboardType, TestSize.Level0) - { - int32_t def_value = 2021; - sptr mKeyboardType = new KeyboardType(); - mKeyboardType->setId(def_value); - MessageParcel data; - auto ret = data.WriteParcelable(mKeyboardType); - EXPECT_TRUE(ret); - sptr deserialization = data.ReadParcelable(); - EXPECT_TRUE(deserialization != nullptr); - EXPECT_TRUE(deserialization->getId() == def_value); - } +/** +* @tc.name: testInsertText +* @tc.desc: InputMethodAbility InsertText +* @tc.type: FUNC +* @tc.require: +* @tc.author: Hollokin +*/ +HWTEST_F(InputMethodAbilityTest, testInsertText, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodAbility InsertText Test START"); + auto ret = inputMethodAbility_->InsertText("text"); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + usleep(500); + EXPECT_EQ(insertText_, u"text"); +} + +/** +* @tc.name: testSetImeListener +* @tc.desc: InputMethodAbility SetImeListener +* @tc.type: FUNC +* @tc.require: +* @tc.author: Hollokin +*/ +HWTEST_F(InputMethodAbilityTest, testSetImeListener, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodAbility SetImeListener Test START"); + auto listener = std::make_shared(); + inputMethodAbility_->setImeListener(listener); + auto ret = imc_->StopInputSession(); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_EQ(imeIdStopped_, ""); + + ret = imc_->ShowSoftKeyboard(); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + usleep(500); + EXPECT_EQ(showKeyboard_, true); + + ret = imc_->HideSoftKeyboard(); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_EQ(showKeyboard_, false); +} + +/** +* @tc.name: testSetKdListener +* @tc.desc: InputMethodAbility SetKdListener +* @tc.type: FUNC +* @tc.require: +* @tc.author: Hollokin +*/ +HWTEST_F(InputMethodAbilityTest, testSetKdListener, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodAbility SetKdListener Test START"); + auto keyBoardListener = std::make_shared(); + inputMethodAbility_->setKdListener(keyBoardListener); +} + +/** +* @tc.name: testSendFunctionKey +* @tc.desc: InputMethodAbility SendFunctionKey +* @tc.type: FUNC +* @tc.require: +* @tc.author: Hollokin +*/ +HWTEST_F(InputMethodAbilityTest, testSendFunctionKey, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodAbility SendFunctionKey Test START"); + auto ret = inputMethodAbility_->SendFunctionKey(0); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); +} + +/** +* @tc.name: testDeleteText +* @tc.desc: InputMethodAbility DeleteForward & DeleteBackward +* @tc.type: FUNC +* @tc.require: +* @tc.author: Hollokin +*/ +HWTEST_F(InputMethodAbilityTest, testDeleteText, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodAbility testDelete Test START"); + int32_t deleteForwardLenth = 1; + auto ret = inputMethodAbility_->DeleteForward(deleteForwardLenth); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + usleep(500); + EXPECT_EQ(deleteForwardLength_, deleteForwardLenth); + int32_t deleteBackwardLenth = 2; + ret = inputMethodAbility_->DeleteBackward(deleteBackwardLenth); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + usleep(500); + EXPECT_EQ(deleteBackwardLength_, deleteBackwardLenth); +} + +/** +* @tc.name: testGetText001 +* @tc.desc: InputMethodAbility GetTextBeforeCursor & GetTextAfterCursor +* @tc.type: FUNC +* @tc.require: +* @tc.author: Hollokin +*/ +HWTEST_F(InputMethodAbilityTest, testGetText001, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodAbility testGetText001 START"); + imc_->OnSelectionChange(u"onselectionchange", 0, 3); + std::u16string text; + auto ret = inputMethodAbility_->GetTextAfterCursor(8, text); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_EQ(text, u"electioncha"); + ret = inputMethodAbility_->GetTextBeforeCursor(3, text); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_EQ(text, u""); +} + +/** +* @tc.name: testGetEnterKeyType +* @tc.desc: InputMethodAbility GetEnterKeyType & GetInputPattern +* @tc.type: FUNC +* @tc.require: +* @tc.author: Hollokin +*/ +HWTEST_F(InputMethodAbilityTest, testGetEnterKeyType, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodAbility testGetEnterKeyType START"); + Configuration config; + EnterKeyType keyType = EnterKeyType::NEXT; + config.SetEnterKeyType(keyType); + TextInputType textInputType = TextInputType::DATETIME; + config.SetTextInputType(textInputType); + imc_->OnConfigurationChange(config); + int32_t keyType2; + auto ret = inputMethodAbility_->GetEnterKeyType(keyType2); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_EQ(keyType2, (int)keyType); + int32_t inputPattern; + ret = inputMethodAbility_->GetInputPattern(inputPattern); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_EQ(inputPattern, (int)textInputType); +} } // namespace MiscServices } // namespace OHOS