From 572c8aa785da849ccf7ebf29ef6d9f0c581d425a Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Tue, 22 Apr 2025 20:49:12 +0800 Subject: [PATCH 01/10] hdc tool Signed-off-by: qianyong325 --- BUILD.gn | 1 + bundle.json | 3 +- .../IInputMethodSystemAbility.idl | 3 +- .../src/input_method_controller.cpp | 17 +- .../include/input_method_controller.h | 12 +- .../common/include/settings_data_utils.h | 5 +- .../common/src/settings_data_utils.cpp | 73 ++++++-- .../include/identity_checker.h | 1 + .../include/identity_checker_impl.h | 1 + .../src/identity_checker_impl.cpp | 5 + .../include/input_method_system_ability.h | 3 +- services/src/input_method_system_ability.cpp | 24 ++- tools/ime/BUILD.gn | 88 ++++++++++ .../include/input_method_manager_command.h | 27 +++ .../ime/src/input_method_manager_command.cpp | 165 ++++++++++++++++++ tools/ime/src/main.cpp | 22 +++ 16 files changed, 426 insertions(+), 24 deletions(-) create mode 100644 tools/ime/BUILD.gn create mode 100644 tools/ime/include/input_method_manager_command.h create mode 100644 tools/ime/src/input_method_manager_command.cpp create mode 100644 tools/ime/src/main.cpp diff --git a/BUILD.gn b/BUILD.gn index 8b35a409e..69e257247 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -31,6 +31,7 @@ group("imf_packages") { "profile:inputmethod_inputmethod_sa_profiles", "services:inputmethod_service", "test/unitest/src:unittest", + "tools/ime:ime_command", ] } } diff --git a/bundle.json b/bundle.json index c4fe00354..93cd48323 100644 --- a/bundle.json +++ b/bundle.json @@ -87,7 +87,8 @@ "//base/inputmethod/imf/frameworks/js/napi/keyboardpanelmanager:keyboardpanelmanager", "//base/inputmethod/imf/frameworks/cj:cj_inputmethod_ffi", "//base/inputmethod/imf/seccomp_policy:imf_ext_secure_filter", - "//base/inputmethod/imf/services/dialog:input_method_choose_dialog" + "//base/inputmethod/imf/services/dialog:input_method_choose_dialog", + "//base/inputmethod/imf/tools/ime:ime_command" ] }, "inner_api": [ diff --git a/frameworks/native/inputmethod_controller/IInputMethodSystemAbility.idl b/frameworks/native/inputmethod_controller/IInputMethodSystemAbility.idl index a9b854cf8..5769d53c3 100644 --- a/frameworks/native/inputmethod_controller/IInputMethodSystemAbility.idl +++ b/frameworks/native/inputmethod_controller/IInputMethodSystemAbility.idl @@ -57,7 +57,8 @@ interface OHOS.MiscServices.IInputMethodSystemAbility { void GetSecurityMode([out] int security); void IsDefaultIme(); void IsDefaultImeSet([out] boolean resultValue); - void EnableIme([in] String bundleName, [out] boolean resultValue); + void EnableIme([in] String bundleName, [in] boolean isEnable, [out] boolean resultValue); + void SetImeMode([in] String bundleName, [in] boolean isEnable, [out] boolean resultValue); void ConnectSystemCmd([in] IRemoteObject channel, [out] IRemoteObject agent); void GetInputMethodState([out] int state); void IsSystemApp([out] boolean resultValue); diff --git a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp index 51ec41188..f5c00eedc 100644 --- a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp @@ -569,7 +569,7 @@ bool InputMethodController::IsDefaultImeSet() return ret; } -bool InputMethodController::EnableIme(const std::string &bundleName) +bool InputMethodController::EnableIme(const std::string &bundleName, bool isEnable) { IMSA_HILOGI("enter."); auto proxy = GetSystemAbilityProxy(); @@ -578,7 +578,20 @@ bool InputMethodController::EnableIme(const std::string &bundleName) return false; } bool ret = false; - proxy->EnableIme(bundleName, ret); + proxy->EnableIme(bundleName, isEnable, ret); + return ret; +} + +bool InputMethodController::SetImeMode(const std::string &bundleName, bool isEnable) +{ + IMSA_HILOGI("enter."); + auto proxy = GetSystemAbilityProxy(); + if (proxy == nullptr) { + IMSA_HILOGE("proxy is nullptr!"); + return false; + } + bool ret = false; + proxy->SetImeMode(bundleName, isEnable, ret); return ret; } diff --git a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h index b14b45adb..bc037969a 100644 --- a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h +++ b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h @@ -867,7 +867,17 @@ public: * * @since 13 */ - IMF_API bool EnableIme(const std::string &bundleName); + IMF_API bool EnableIme(const std::string &bundleName, bool isEnable = true); + + /** + * @brief Set the ime mode called bundleName. + * + * This function is used to set the ime mode called bundleName. + * Do not call this interface unless you know what you are doing + * + * @since 13 + */ + IMF_API bool SetImeMode(const std::string &bundleName, bool isEnable = true); /** * @brief Send ArrayBuffer message to ime. diff --git a/services/adapter/settings_data_provider/common/include/settings_data_utils.h b/services/adapter/settings_data_provider/common/include/settings_data_utils.h index 602cae5ba..57b442d5e 100644 --- a/services/adapter/settings_data_provider/common/include/settings_data_utils.h +++ b/services/adapter/settings_data_provider/common/include/settings_data_utils.h @@ -54,7 +54,8 @@ public: bool SetStringValue(const std::string &uriProxy, const std::string &key, const std::string &value); bool ReleaseDataShareHelper(std::shared_ptr &helper); Uri GenerateTargetUri(const std::string &uriProxy, const std::string &key); - bool EnableIme(int32_t userId, const std::string &bundleName); + bool EnableIme(int32_t userId, const std::string &bundleName, bool isEnable = true); + bool SetImeMode(int32_t userId, const std::string &bundleName, bool isEnable = true); private: SettingsDataUtils() = default; @@ -63,7 +64,7 @@ private: int32_t UnregisterObserver(const sptr &observer); sptr GetToken(); std::vector Split(const std::string &text, char separator); - std::string SetSettingValues(const std::string &settingValue, const std::string &bundleName); + std::string SetSettingValues(const std::string &settingValue, const std::string &bundleName, bool isEnable); private: static std::mutex instanceMutex_; diff --git a/services/adapter/settings_data_provider/common/src/settings_data_utils.cpp b/services/adapter/settings_data_provider/common/src/settings_data_utils.cpp index 26a9308e3..34021ac0e 100644 --- a/services/adapter/settings_data_provider/common/src/settings_data_utils.cpp +++ b/services/adapter/settings_data_provider/common/src/settings_data_utils.cpp @@ -220,7 +220,7 @@ sptr SettingsDataUtils::GetToken() return remoteObj_; } -bool SettingsDataUtils::EnableIme(int32_t userId, const std::string &bundleName) +bool SettingsDataUtils::EnableIme(int32_t userId, const std::string &bundleName, bool isEnable) { const int32_t mainUserId = 100; if (userId != mainUserId) { @@ -233,12 +233,43 @@ bool SettingsDataUtils::EnableIme(int32_t userId, const std::string &bundleName) IMSA_HILOGI("settingValue: %{public}s", settingValue.c_str()); std::string value = ""; if (settingValue == "") { + if (!isEnable) { + return true; + } value = "{\"enableImeList\" : {\"100\" : [\"" + bundleName + "\"]}}"; } else { - value = SetSettingValues(settingValue, bundleName); + value = SetSettingValues(settingValue, bundleName, isEnable); + } + IMSA_HILOGI("value: %{public}s", value.c_str()); + auto ret = SetStringValue(std::string(SETTING_URI_PROXY), settingKey, value); + ret = SetStringValue(SETTINGS_USER_DATA_URI + std::to_string(userId) + "?Proxy=true", settingKey, value); + return ret; +} + +bool SettingsDataUtils::SetImeMode(int32_t userId, const std::string &bundleName, bool isEnable) +{ + const int32_t mainUserId = 100; + if (userId != mainUserId) { + IMSA_HILOGE("user is not main."); + return false; + } + const char *settingKey = "settings.inputmethod.full_experience"; + std::string settingValue = ""; + GetStringValue(std::string(SETTING_URI_PROXY), settingKey, settingValue); + IMSA_HILOGI("settingValue: %{public}s", settingValue.c_str()); + std::string value = ""; + if (settingValue == "") { + if (!isEnable) { + return true; + } + value = "{\"fullExperienceList\" : {\"100\" : [\"" + bundleName + "\"]}}"; + } else { + value = SetSettingValues(settingValue, bundleName, isEnable); } IMSA_HILOGI("value: %{public}s", value.c_str()); - return SetStringValue(std::string(SETTING_URI_PROXY), settingKey, value); + auto ret = SetStringValue(std::string(SETTING_URI_PROXY), settingKey, value); + ret = SetStringValue(SETTINGS_USER_DATA_URI + std::to_string(userId) + "?Proxy=true", settingKey, value); + return ret; } std::vector SettingsDataUtils::Split(const std::string &text, char delim) @@ -254,20 +285,38 @@ std::vector SettingsDataUtils::Split(const std::string &text, char return tokens; } -std::string SettingsDataUtils::SetSettingValues(const std::string &settingValue, const std::string &bundleName) +std::string SettingsDataUtils::SetSettingValues(const std::string &settingValue, const std::string &bundleName, bool isEnable) { std::string value = ""; - std::vector settingValues = Split(settingValue, ']'); - for (uint32_t i = 0; i < settingValues.size(); ++i) { - if (i == 0) { - if (settingValues[0].back() == '[') { - value += settingValues[i] + "\"" + bundleName + "\"" + "]"; + size_t startPos = 0; + if (isEnable) { + if (settingValue.find(bundleName, startPos) != std::string::npos) { + return settingValue; + } + std::vector settingValues = Split(settingValue, ']'); + for (uint32_t i = 0; i < settingValues.size(); ++i) { + if (i == 0) { + if (settingValues[0].back() == '[') { + value += settingValues[i] + "\"" + bundleName + "\"" + "]"; + } else { + value += settingValues[i] + ",\"" + bundleName + "\"" + "]"; + } } else { - value += settingValues[i] + ",\"" + bundleName + "\"" + "]"; + value += settingValues[i]; + } + } + } else { + std::string originalStr = settingValue; + std::string subString = "\"" + bundleName + "\""; + while ((startPos = originalStr.find(subString, startPos)) != std::string::npos) { + if (startPos > 0 && originalStr[startPos-1] != ',') { + startPos -= 1; } - } else { - value += settingValues[i]; + value += originalStr.substr(0, startPos); + startPos += (subString.length() + 1); + originalStr.erase(0, startPos); } + value += originalStr; } return value; } diff --git a/services/identity_checker/include/identity_checker.h b/services/identity_checker/include/identity_checker.h index d7c0894f9..f97fc5d8a 100644 --- a/services/identity_checker/include/identity_checker.h +++ b/services/identity_checker/include/identity_checker.h @@ -30,6 +30,7 @@ public: virtual bool HasPermission(uint32_t tokenId, const std::string &permission) = 0; virtual bool IsBroker(Security::AccessToken::AccessTokenID tokenId) = 0; virtual bool IsNativeSa(Security::AccessToken::AccessTokenID tokenId) = 0; + virtual bool IsFormShell(Security::AccessToken::AccessTokenID tokenId) = 0; virtual std::string GetBundleNameByToken(uint32_t tokenId); virtual bool IsFocusedUIExtension(uint32_t callingTokenId, uint64_t displayId = DEFAULT_DISPLAY_ID) { diff --git a/services/identity_checker/include/identity_checker_impl.h b/services/identity_checker/include/identity_checker_impl.h index 9b4161112..83392cf62 100644 --- a/services/identity_checker/include/identity_checker_impl.h +++ b/services/identity_checker/include/identity_checker_impl.h @@ -28,6 +28,7 @@ public: bool HasPermission(uint32_t tokenId, const std::string &permission) override; bool IsBroker(Security::AccessToken::AccessTokenID tokenId) override; bool IsNativeSa(Security::AccessToken::AccessTokenID tokenId) override; + bool IsFormShell(Security::AccessToken::AccessTokenID tokenId) override; std::string GetBundleNameByToken(uint32_t tokenId) override; bool IsFocusedUIExtension(uint32_t callingTokenId, uint64_t displayId = DEFAULT_DISPLAY_ID) override; uint64_t GetDisplayIdByWindowId(int32_t callingWindowId) override; diff --git a/services/identity_checker/src/identity_checker_impl.cpp b/services/identity_checker/src/identity_checker_impl.cpp index 59c634ee2..8017cd839 100644 --- a/services/identity_checker/src/identity_checker_impl.cpp +++ b/services/identity_checker/src/identity_checker_impl.cpp @@ -99,6 +99,11 @@ bool IdentityCheckerImpl::IsNativeSa(AccessTokenID tokenId) return AccessTokenKit::GetTokenTypeFlag(tokenId) == TypeATokenTypeEnum::TOKEN_NATIVE; } +bool IdentityCheckerImpl::IsFormShell(AccessTokenID tokenId) +{ + return AccessTokenKit::GetTokenTypeFlag(tokenId) == TypeATokenTypeEnum::TOKEN_SHELL; +} + bool IdentityCheckerImpl::IsFocusedUIExtension(uint32_t callingTokenId, uint64_t displayId) { bool isFocused = false; diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index b50213cb3..2d1acacec 100644 --- a/services/include/input_method_system_ability.h +++ b/services/include/input_method_system_ability.h @@ -85,7 +85,8 @@ public: void DumpAllMethod(int fd); ErrCode IsDefaultIme() override; ErrCode IsDefaultImeSet(bool& resultValue) override; - ErrCode EnableIme(const std::string &bundleName, bool& resultValue) override; + ErrCode EnableIme(const std::string &bundleName, bool isEnable, bool& resultValue) override; + ErrCode SetImeMode(const std::string &bundleName, bool isEnable, bool& resultValue) override; ErrCode GetInputMethodState(int32_t &status) override; ErrCode IsSystemApp(bool& resultValue) override; int32_t RegisterProxyIme( diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index cf8188bc3..3f39a5b9f 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -1163,14 +1163,25 @@ ErrCode InputMethodSystemAbility::SwitchInputMethod(const std::string &bundleNam : OnSwitchInputMethod(userId, switchInfo, static_cast(trigger)); } -ErrCode InputMethodSystemAbility::EnableIme(const std::string &bundleName, bool& resultValue) +ErrCode InputMethodSystemAbility::EnableIme(const std::string &bundleName, bool isEnable, bool& resultValue) { if (CheckEnableAndSwitchPermission() != ErrorCode::NO_ERROR) { IMSA_HILOGE("Check enable ime value failed!"); return false; } int32_t userId = GetCallingUserId(); - resultValue = SettingsDataUtils::GetInstance()->EnableIme(userId, bundleName); + resultValue = SettingsDataUtils::GetInstance()->EnableIme(userId, bundleName, isEnable); + return ERR_OK; +} + +ErrCode InputMethodSystemAbility::EnableIme(const std::string &bundleName, bool isEnable, bool& resultValue) +{ + if (CheckEnableAndSwitchPermission() != ErrorCode::NO_ERROR) { + IMSA_HILOGE("Check enable ime value failed!"); + return false; + } + int32_t userId = GetCallingUserId(); + resultValue = SettingsDataUtils::GetInstance()->EnableIme(userId, bundleName, isEnable); return ERR_OK; } @@ -2048,7 +2059,12 @@ ErrCode InputMethodSystemAbility::UnRegisteredProxyIme(int32_t type, const sptr< int32_t InputMethodSystemAbility::CheckEnableAndSwitchPermission() { - if (!identityChecker_->IsNativeSa(IPCSkeleton::GetCallingFullTokenID())) { + auto fullToken = IPCSkeleton::GetCallingFullTokenID(); + if (identityChecker_->IsFormShell(fullToken)) { + IMSA_HILOGD("is form shell!"); + return ErrorCode::NO_ERROR; + } + if (!identityChecker_->IsNativeSa(fullToken)) { IMSA_HILOGE("not native sa!"); return ErrorCode::ERROR_STATUS_SYSTEM_PERMISSION; } @@ -2585,7 +2601,7 @@ int32_t InputMethodSystemAbility::GetAlternativeIme(std::string &ime) return ErrorCode::ERROR_NOT_IME; } bool resultValue = false; - EnableIme(props[0].name, resultValue); + EnableIme(props[0].name, true, resultValue); if (resultValue == true) { ime = props[0].name + "/" + props[0].id; return ErrorCode::NO_ERROR; diff --git a/tools/ime/BUILD.gn b/tools/ime/BUILD.gn new file mode 100644 index 000000000..5639befcc --- /dev/null +++ b/tools/ime/BUILD.gn @@ -0,0 +1,88 @@ +# Copyright (c) 2021-2025 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") +import("//build/ohos.gni") + +ohos_executable("ime_command") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + + sources = [ + "${inputmethod_path}/frameworks/native/inputmethod_ability/src/input_method_ability.cpp", + "${inputmethod_path}/frameworks/native/inputmethod_ability/src/input_method_agent_service_impl.cpp", + "${inputmethod_path}/frameworks/native/inputmethod_ability/src/input_method_core_service_impl.cpp", + "${inputmethod_path}/frameworks/native/inputmethod_controller/src/ime_event_monitor_manager_impl.cpp", + "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_client_info.cpp", + "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_client_service_impl.cpp", + "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_data_channel_service_impl.cpp", + "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_method_controller.cpp", + "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_method_tools.cpp", + "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_method_utils.cpp", + "${inputmethod_path}/frameworks/native/inputmethod_controller/src/keyevent_consumer_service_impl.cpp", + "src/input_method_manager_command.cpp", + "src/main.cpp", + ] + include_dirs = [ + "include", + "${inputmethod_path}/interfaces/inner_api/inputmethod_controller/include", + ] + + deps = [ + "${inputmethod_path}/common:inputmethod_common", + "${inputmethod_path}/common/imf_hisysevent:imf_hisysevent", + "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:input_control_channel_proxy", + "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:input_data_channel_stub", + "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:input_method_core_stub", + "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:input_method_system_ability_proxy", + "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:inputmethod_ability", + "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:keyevent_consumer_stub", + "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:input_method_agent_proxy", + "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:input_method_agent_stub", + "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client", + "${inputmethod_path}/services:inputmethod_service", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:ability_context_native", + "ability_runtime:ability_manager", + "cJSON:cjson", + "c_utils:utils", + "eventhandler:libeventhandler", + "hilog:libhilog", + "input:libmmi-client", + "ipc:ipc_single", + "napi:ace_napi", + "window_manager:libdm", + ] + + if (window_manager_use_sceneboard) { + external_deps += [ "window_manager:libwm_lite" ] + } else { + external_deps += [ "window_manager:libwm" ] + } + + configs = [ + "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client_native_public_config", + "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:inputmethod_ability_native_public_config", + ] + + install_enable = true + subsystem_name = "inputmethod" + part_name = "imf" +} diff --git a/tools/ime/include/input_method_manager_command.h b/tools/ime/include/input_method_manager_command.h new file mode 100644 index 000000000..2960e3318 --- /dev/null +++ b/tools/ime/include/input_method_manager_command.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2021-2025 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 + +namespace OHOS { +namespace MMI { +class InputMethodManagerCommand { +public: + InputMethodManagerCommand() = default; + int32_t ParseCommand(int32_t argc, char *argv[]); + void ShowUsage(); +}; +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/tools/ime/src/input_method_manager_command.cpp b/tools/ime/src/input_method_manager_command.cpp new file mode 100644 index 000000000..3f2884011 --- /dev/null +++ b/tools/ime/src/input_method_manager_command.cpp @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2021-2025 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 "input_method_manager_command.h" +#include +#include + +#include "input_method_controller.h" + +class InputMethodManagerCommand { +public: + int32_t ParseCommand(int32_t argc, char *argv[]); + void ShowUsage(); +}; +namespace OHOS { +namespace MMI { +int32_t InputMethodManagerCommand::ParseCommand(int32_t argc, char *argv[]) +{ + int32_t optCode = 0; + if ((optCode = getopt(argc, argv, "b:d:e:f:ghls:")) != -1) { + switch (optCode) { + case 'e': { + bool retValue = false; + bool isEnable = true; + if (optarg == nullptr) { + std::cout << "Invalid argument" << std::endl; + ShowUsage(); + return 0; + } + retValue = MiscServices::InputMethodController::GetInstance()->EnableIme(optarg, isEnable); + if (retValue) { + std::cout << "enable ime success " << optarg << std::endl; + } else { + std::cout << "Could not enable the InputMethod" << std::endl; + } + break; + } + case 'd': { + bool retValue = false; + bool isEnable = false; + if (optarg == nullptr) { + std::cout << "Invalid argument" << std::endl; + ShowUsage(); + return 0; + } + retValue = MiscServices::InputMethodController::GetInstance()->EnableIme(optarg, isEnable); + if (retValue) { + std::cout << "disenable ime success " << optarg << std::endl; + } else { + std::cout << "Could not enable the InputMethod" << std::endl; + } + break; + } + case 'f': { + bool retValue = false; + bool isEnable = true; + if (optarg == nullptr) { + std::cout << "Invalid argument" << std::endl; + ShowUsage(); + return 0; + } + retValue = MiscServices::InputMethodController::GetInstance()->SetImeMode(optarg, isEnable); + if (retValue) { + std::cout << "set ime full mode success " << optarg << std::endl; + } else { + std::cout << "Could not set ime full mode" << std::endl; + } + break; + } + case 'b': { + bool retValue = false; + bool isEnable = false; + if (optarg == nullptr) { + std::cout << "Invalid argument" << std::endl; + ShowUsage(); + return 0; + } + retValue = MiscServices::InputMethodController::GetInstance()->SetImeMode(optarg, isEnable); + if (retValue) { + std::cout << "set ime basic mode success " << optarg << std::endl; + } else { + std::cout << "Could not set ime basic mode" << std::endl; + } + break; + } + case 'g': { + std::shared_ptr propertyData; + propertyData = MiscServices::InputMethodController::GetInstance()->GetCurrentInputMethod(); + if (!propertyData) { + std::cerr << "error:can not get current inputmethod" << std::endl; + return 0; + } + std::cout << "the current inputmethod is: " << propertyData->name << std::endl; + break; + } + case 'l': { + std::vector enabledMethods; + bool filterEnabled = true; + MiscServices::InputMethodController::GetInstance()->ListInputMethod(filterEnabled, enabledMethods); + for (auto property : enabledMethods) { + std::cout << "BundleName: " << property.name << ", id: " << property.id << std::endl; + } + break; + } + case 's': { + int32_t retValue = 0; + MiscServices::SwitchTrigger trigger = MiscServices::SwitchTrigger::IMSA; + std::string subName = ""; + if (optarg == nullptr) { + std::cout << "Invalid argument" << std::endl; + ShowUsage(); + return 0; + } + retValue = MiscServices::InputMethodController::GetInstance()->SwitchInputMethod(trigger, optarg, subName); + if (retValue != 0) { + std::cout << "Could not switch the InputMethod" << std::endl; + } else { + std::cout << "the inputmethod has been switched successfully" << optarg << std::endl; + } + break; + } + case 'h': { + ShowUsage(); + return 0; + } + default: { + std::cout << "invalid command" << std::endl; + ShowUsage(); + return 0; + } + } + } else { + std::cout << "too few arguments to function" << std::endl; + ShowUsage(); + return 0; + } + return 0; +} + +void InputMethodManagerCommand::ShowUsage() +{ + std::cout << "Usage: ime_command ..." << std::endl; + std::cout << "Enable inputmethod is: ime_command -e bundleName " << std::endl; + std::cout << "Disenable inputmethod is: ime_command -d bundleName " << std::endl; + std::cout << "Enable full inputmethod is: ime_command -f bundleName " << std::endl; + std::cout << "Enable basic inputmethod is: ime_command -b bundleName " << std::endl; + std::cout << "Switch inputmethod is: ime_command -s bundleName " << std::endl; + std::cout << "Get current inputmethod is: ime_command -g " << std::endl; + std::cout << "List inputmethods is: ime_command -l " << std::endl; + std::cout << "List of inputmethod Commands: ime_command -h " << std::endl; +} +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/tools/ime/src/main.cpp b/tools/ime/src/main.cpp new file mode 100644 index 000000000..d371cfaf2 --- /dev/null +++ b/tools/ime/src/main.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2021-2025 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 "input_method_manager_command.h" + +int32_t main(int32_t argc, char** argv) +{ + OHOS::MMI::InputMethodManagerCommand command; + return command.ParseCommand(argc, argv); +} \ No newline at end of file -- Gitee From 49f016ba98cefd5b8c24a60f3ccc711e70e2acbb Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Wed, 23 Apr 2025 01:56:09 +0000 Subject: [PATCH 02/10] =?UTF-8?q?=E6=B7=BB=E5=8A=A0config=E5=AF=B9?= =?UTF-8?q?=E5=BA=94visibility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- interfaces/inner_api/inputmethod_ability/BUILD.gn | 1 + interfaces/inner_api/inputmethod_controller/BUILD.gn | 1 + services/src/input_method_system_ability.cpp | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/interfaces/inner_api/inputmethod_ability/BUILD.gn b/interfaces/inner_api/inputmethod_ability/BUILD.gn index 5c4e7262a..d1641b412 100644 --- a/interfaces/inner_api/inputmethod_ability/BUILD.gn +++ b/interfaces/inner_api/inputmethod_ability/BUILD.gn @@ -69,6 +69,7 @@ config("inputmethod_ability_native_public_config") { "${inputmethod_path}/frameworks/ndk/*", "${inputmethod_path}/test/fuzztest/*", "${inputmethod_path}/test/unittest/*", + "${inputmethod_path}/tools/ime/*", "../inputmethod_controller/*", "./*", ] diff --git a/interfaces/inner_api/inputmethod_controller/BUILD.gn b/interfaces/inner_api/inputmethod_controller/BUILD.gn index d63bff863..2326c2cd8 100644 --- a/interfaces/inner_api/inputmethod_controller/BUILD.gn +++ b/interfaces/inner_api/inputmethod_controller/BUILD.gn @@ -44,6 +44,7 @@ config("inputmethod_client_native_public_config") { "${inputmethod_path}/interfaces/inner_api/inputmethod_ability/*", "${inputmethod_path}/test/fuzztest/*", "${inputmethod_path}/test/unittest/*", + "${inputmethod_path}/tools/ime/*", "./*", ] include_dirs = [ diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 3f39a5b9f..5336a035e 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -1174,7 +1174,7 @@ ErrCode InputMethodSystemAbility::EnableIme(const std::string &bundleName, bool return ERR_OK; } -ErrCode InputMethodSystemAbility::EnableIme(const std::string &bundleName, bool isEnable, bool& resultValue) +ErrCode InputMethodSystemAbility::SetImeMode(const std::string &bundleName, bool isEnable, bool& resultValue) { if (CheckEnableAndSwitchPermission() != ErrorCode::NO_ERROR) { IMSA_HILOGE("Check enable ime value failed!"); -- Gitee From dba6ce5cbe31d43566bbd6026691ee9a44be6b4b Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Wed, 23 Apr 2025 11:19:26 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- .vscode/settings.json | 72 +++++++++++++++++++ .../IInputMethodSystemAbility.idl | 2 +- .../src/input_method_controller.cpp | 4 +- .../include/input_method_controller.h | 2 +- .../common/include/settings_data_utils.h | 2 +- .../common/src/settings_data_utils.cpp | 9 +-- .../include/input_method_system_ability.h | 2 +- services/src/input_method_system_ability.cpp | 4 +- .../ime/src/input_method_manager_command.cpp | 11 +-- 9 files changed, 91 insertions(+), 17 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..03c3f4fd1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,72 @@ +{ + "files.associations": { + "chrono": "cpp", + "array": "cpp", + "deque": "cpp", + "list": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "string_view": "cpp", + "initializer_list": "cpp", + "ranges": "cpp", + "regex": "cpp", + "*.tcc": "cpp", + "optional": "cpp", + "ratio": "cpp", + "system_error": "cpp", + "functional": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "variant": "cpp", + "istream": "cpp", + "ostream": "cpp", + "bitset": "cpp", + "algorithm": "cpp", + "atomic": "cpp", + "bit": "cpp", + "cctype": "cpp", + "cinttypes": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "codecvt": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "csignal": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "map": "cpp", + "set": "cpp", + "exception": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "random": "cpp", + "fstream": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "numbers": "cpp", + "semaphore": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "typeinfo": "cpp", + "iostream": "cpp" + } +} \ No newline at end of file diff --git a/frameworks/native/inputmethod_controller/IInputMethodSystemAbility.idl b/frameworks/native/inputmethod_controller/IInputMethodSystemAbility.idl index 5769d53c3..3271d982a 100644 --- a/frameworks/native/inputmethod_controller/IInputMethodSystemAbility.idl +++ b/frameworks/native/inputmethod_controller/IInputMethodSystemAbility.idl @@ -58,7 +58,7 @@ interface OHOS.MiscServices.IInputMethodSystemAbility { void IsDefaultIme(); void IsDefaultImeSet([out] boolean resultValue); void EnableIme([in] String bundleName, [in] boolean isEnable, [out] boolean resultValue); - void SetImeMode([in] String bundleName, [in] boolean isEnable, [out] boolean resultValue); + void SetImeMode([in] String bundleName, [in] boolean isFull, [out] boolean resultValue); void ConnectSystemCmd([in] IRemoteObject channel, [out] IRemoteObject agent); void GetInputMethodState([out] int state); void IsSystemApp([out] boolean resultValue); diff --git a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp index f5c00eedc..f2d0666eb 100644 --- a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp @@ -582,7 +582,7 @@ bool InputMethodController::EnableIme(const std::string &bundleName, bool isEnab return ret; } -bool InputMethodController::SetImeMode(const std::string &bundleName, bool isEnable) +bool InputMethodController::SetImeMode(const std::string &bundleName, bool isFull) { IMSA_HILOGI("enter."); auto proxy = GetSystemAbilityProxy(); @@ -591,7 +591,7 @@ bool InputMethodController::SetImeMode(const std::string &bundleName, bool isEna return false; } bool ret = false; - proxy->SetImeMode(bundleName, isEnable, ret); + proxy->SetImeMode(bundleName, isFull, ret); return ret; } diff --git a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h index bc037969a..00ccbdf7c 100644 --- a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h +++ b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h @@ -877,7 +877,7 @@ public: * * @since 13 */ - IMF_API bool SetImeMode(const std::string &bundleName, bool isEnable = true); + IMF_API bool SetImeMode(const std::string &bundleName, bool isFull = true); /** * @brief Send ArrayBuffer message to ime. diff --git a/services/adapter/settings_data_provider/common/include/settings_data_utils.h b/services/adapter/settings_data_provider/common/include/settings_data_utils.h index 57b442d5e..69c66959a 100644 --- a/services/adapter/settings_data_provider/common/include/settings_data_utils.h +++ b/services/adapter/settings_data_provider/common/include/settings_data_utils.h @@ -55,7 +55,7 @@ public: bool ReleaseDataShareHelper(std::shared_ptr &helper); Uri GenerateTargetUri(const std::string &uriProxy, const std::string &key); bool EnableIme(int32_t userId, const std::string &bundleName, bool isEnable = true); - bool SetImeMode(int32_t userId, const std::string &bundleName, bool isEnable = true); + bool SetImeMode(int32_t userId, const std::string &bundleName, bool isFull = true); private: SettingsDataUtils() = default; diff --git a/services/adapter/settings_data_provider/common/src/settings_data_utils.cpp b/services/adapter/settings_data_provider/common/src/settings_data_utils.cpp index 34021ac0e..0a73c6810 100644 --- a/services/adapter/settings_data_provider/common/src/settings_data_utils.cpp +++ b/services/adapter/settings_data_provider/common/src/settings_data_utils.cpp @@ -246,7 +246,7 @@ bool SettingsDataUtils::EnableIme(int32_t userId, const std::string &bundleName, return ret; } -bool SettingsDataUtils::SetImeMode(int32_t userId, const std::string &bundleName, bool isEnable) +bool SettingsDataUtils::SetImeMode(int32_t userId, const std::string &bundleName, bool isFull) { const int32_t mainUserId = 100; if (userId != mainUserId) { @@ -259,12 +259,12 @@ bool SettingsDataUtils::SetImeMode(int32_t userId, const std::string &bundleName IMSA_HILOGI("settingValue: %{public}s", settingValue.c_str()); std::string value = ""; if (settingValue == "") { - if (!isEnable) { + if (!isFull) { return true; } value = "{\"fullExperienceList\" : {\"100\" : [\"" + bundleName + "\"]}}"; } else { - value = SetSettingValues(settingValue, bundleName, isEnable); + value = SetSettingValues(settingValue, bundleName, isFull); } IMSA_HILOGI("value: %{public}s", value.c_str()); auto ret = SetStringValue(std::string(SETTING_URI_PROXY), settingKey, value); @@ -285,7 +285,8 @@ std::vector SettingsDataUtils::Split(const std::string &text, char return tokens; } -std::string SettingsDataUtils::SetSettingValues(const std::string &settingValue, const std::string &bundleName, bool isEnable) +std::string SettingsDataUtils::SetSettingValues(const std::string &settingValue, const std::string &bundleName, + bool isEnable) { std::string value = ""; size_t startPos = 0; diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index 2d1acacec..560585c93 100644 --- a/services/include/input_method_system_ability.h +++ b/services/include/input_method_system_ability.h @@ -86,7 +86,7 @@ public: ErrCode IsDefaultIme() override; ErrCode IsDefaultImeSet(bool& resultValue) override; ErrCode EnableIme(const std::string &bundleName, bool isEnable, bool& resultValue) override; - ErrCode SetImeMode(const std::string &bundleName, bool isEnable, bool& resultValue) override; + ErrCode SetImeMode(const std::string &bundleName, bool isFull, bool& resultValue) override; ErrCode GetInputMethodState(int32_t &status) override; ErrCode IsSystemApp(bool& resultValue) override; int32_t RegisterProxyIme( diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 5336a035e..d6a283d97 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -1174,14 +1174,14 @@ ErrCode InputMethodSystemAbility::EnableIme(const std::string &bundleName, bool return ERR_OK; } -ErrCode InputMethodSystemAbility::SetImeMode(const std::string &bundleName, bool isEnable, bool& resultValue) +ErrCode InputMethodSystemAbility::SetImeMode(const std::string &bundleName, bool isFull, bool& resultValue) { if (CheckEnableAndSwitchPermission() != ErrorCode::NO_ERROR) { IMSA_HILOGE("Check enable ime value failed!"); return false; } int32_t userId = GetCallingUserId(); - resultValue = SettingsDataUtils::GetInstance()->EnableIme(userId, bundleName, isEnable); + resultValue = SettingsDataUtils::GetInstance()->SetImeMode(userId, bundleName, isFull); return ERR_OK; } diff --git a/tools/ime/src/input_method_manager_command.cpp b/tools/ime/src/input_method_manager_command.cpp index 3f2884011..10b3240d7 100644 --- a/tools/ime/src/input_method_manager_command.cpp +++ b/tools/ime/src/input_method_manager_command.cpp @@ -65,13 +65,13 @@ int32_t InputMethodManagerCommand::ParseCommand(int32_t argc, char *argv[]) } case 'f': { bool retValue = false; - bool isEnable = true; + bool isFull = true; if (optarg == nullptr) { std::cout << "Invalid argument" << std::endl; ShowUsage(); return 0; } - retValue = MiscServices::InputMethodController::GetInstance()->SetImeMode(optarg, isEnable); + retValue = MiscServices::InputMethodController::GetInstance()->SetImeMode(optarg, isFull); if (retValue) { std::cout << "set ime full mode success " << optarg << std::endl; } else { @@ -81,13 +81,13 @@ int32_t InputMethodManagerCommand::ParseCommand(int32_t argc, char *argv[]) } case 'b': { bool retValue = false; - bool isEnable = false; + bool isFull = false; if (optarg == nullptr) { std::cout << "Invalid argument" << std::endl; ShowUsage(); return 0; } - retValue = MiscServices::InputMethodController::GetInstance()->SetImeMode(optarg, isEnable); + retValue = MiscServices::InputMethodController::GetInstance()->SetImeMode(optarg, isFull); if (retValue) { std::cout << "set ime basic mode success " << optarg << std::endl; } else { @@ -123,7 +123,8 @@ int32_t InputMethodManagerCommand::ParseCommand(int32_t argc, char *argv[]) ShowUsage(); return 0; } - retValue = MiscServices::InputMethodController::GetInstance()->SwitchInputMethod(trigger, optarg, subName); + retValue = MiscServices::InputMethodController::GetInstance()->SwitchInputMethod( + trigger, optarg, subName); if (retValue != 0) { std::cout << "Could not switch the InputMethod" << std::endl; } else { -- Gitee From e39bf6a3c86e59ab72f1099a105b7deeb906234b Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Wed, 23 Apr 2025 03:20:14 +0000 Subject: [PATCH 04/10] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20.v?= =?UTF-8?q?scode/settings.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 72 ------------------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 03c3f4fd1..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,72 +0,0 @@ -{ - "files.associations": { - "chrono": "cpp", - "array": "cpp", - "deque": "cpp", - "list": "cpp", - "string": "cpp", - "unordered_map": "cpp", - "unordered_set": "cpp", - "vector": "cpp", - "string_view": "cpp", - "initializer_list": "cpp", - "ranges": "cpp", - "regex": "cpp", - "*.tcc": "cpp", - "optional": "cpp", - "ratio": "cpp", - "system_error": "cpp", - "functional": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "variant": "cpp", - "istream": "cpp", - "ostream": "cpp", - "bitset": "cpp", - "algorithm": "cpp", - "atomic": "cpp", - "bit": "cpp", - "cctype": "cpp", - "cinttypes": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "codecvt": "cpp", - "compare": "cpp", - "concepts": "cpp", - "condition_variable": "cpp", - "csignal": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "map": "cpp", - "set": "cpp", - "exception": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "random": "cpp", - "fstream": "cpp", - "iomanip": "cpp", - "iosfwd": "cpp", - "limits": "cpp", - "mutex": "cpp", - "new": "cpp", - "numbers": "cpp", - "semaphore": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "stop_token": "cpp", - "streambuf": "cpp", - "thread": "cpp", - "typeinfo": "cpp", - "iostream": "cpp" - } -} \ No newline at end of file -- Gitee From 98906833530ee36d43f1e2c9f8bca5d532724d79 Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Wed, 23 Apr 2025 06:58:55 +0000 Subject: [PATCH 05/10] =?UTF-8?q?=E5=88=87=E6=8D=A2=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E6=B3=95=E6=9D=83=E9=99=90=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- tools/ime/src/input_method_manager_command.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ime/src/input_method_manager_command.cpp b/tools/ime/src/input_method_manager_command.cpp index 10b3240d7..3b0d62713 100644 --- a/tools/ime/src/input_method_manager_command.cpp +++ b/tools/ime/src/input_method_manager_command.cpp @@ -116,7 +116,7 @@ int32_t InputMethodManagerCommand::ParseCommand(int32_t argc, char *argv[]) } case 's': { int32_t retValue = 0; - MiscServices::SwitchTrigger trigger = MiscServices::SwitchTrigger::IMSA; + MiscServices::SwitchTrigger trigger = MiscServices::SwitchTrigger::NATIVE_SA; std::string subName = ""; if (optarg == nullptr) { std::cout << "Invalid argument" << std::endl; -- Gitee From c83adb9c0a94b4e743bf2cb909dbf665b5efc862 Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Thu, 24 Apr 2025 09:38:33 +0000 Subject: [PATCH 06/10] =?UTF-8?q?=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- .../common/src/settings_data_utils.cpp | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/services/adapter/settings_data_provider/common/src/settings_data_utils.cpp b/services/adapter/settings_data_provider/common/src/settings_data_utils.cpp index 0a73c6810..5be367f87 100644 --- a/services/adapter/settings_data_provider/common/src/settings_data_utils.cpp +++ b/services/adapter/settings_data_provider/common/src/settings_data_utils.cpp @@ -16,6 +16,7 @@ #include "settings_data_utils.h" #include "ime_info_inquirer.h" +#include "ipc_skeleton.h" #include "iservice_registry.h" #include "system_ability_definition.h" @@ -222,11 +223,6 @@ sptr SettingsDataUtils::GetToken() bool SettingsDataUtils::EnableIme(int32_t userId, const std::string &bundleName, bool isEnable) { - const int32_t mainUserId = 100; - if (userId != mainUserId) { - IMSA_HILOGE("user is not main."); - return false; - } const char *settingKey = "settings.inputmethod.enable_ime"; std::string settingValue = ""; GetStringValue(std::string(SETTING_URI_PROXY), settingKey, settingValue); @@ -241,18 +237,18 @@ bool SettingsDataUtils::EnableIme(int32_t userId, const std::string &bundleName, value = SetSettingValues(settingValue, bundleName, isEnable); } IMSA_HILOGI("value: %{public}s", value.c_str()); - auto ret = SetStringValue(std::string(SETTING_URI_PROXY), settingKey, value); - ret = SetStringValue(SETTINGS_USER_DATA_URI + std::to_string(userId) + "?Proxy=true", settingKey, value); + auto ret = SetStringValue(SETTINGS_USER_DATA_URI + std::to_string(userId) + "?Proxy=true", settingKey, value); + auto uid = IPCSkeleton::GetCallingUid(); + if (userId != uid) { + IMSA_HILOGE("user is not current user."); + return false; + } + ret = SetStringValue(std::string(SETTING_URI_PROXY), settingKey, value); return ret; } bool SettingsDataUtils::SetImeMode(int32_t userId, const std::string &bundleName, bool isFull) { - const int32_t mainUserId = 100; - if (userId != mainUserId) { - IMSA_HILOGE("user is not main."); - return false; - } const char *settingKey = "settings.inputmethod.full_experience"; std::string settingValue = ""; GetStringValue(std::string(SETTING_URI_PROXY), settingKey, settingValue); -- Gitee From ce18757b2ba3072662c3e8d69e5d69050e2509b4 Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Thu, 24 Apr 2025 09:39:57 +0000 Subject: [PATCH 07/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- .../settings_data_provider/common/src/settings_data_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/adapter/settings_data_provider/common/src/settings_data_utils.cpp b/services/adapter/settings_data_provider/common/src/settings_data_utils.cpp index 5be367f87..cb8384f41 100644 --- a/services/adapter/settings_data_provider/common/src/settings_data_utils.cpp +++ b/services/adapter/settings_data_provider/common/src/settings_data_utils.cpp @@ -232,7 +232,7 @@ bool SettingsDataUtils::EnableIme(int32_t userId, const std::string &bundleName, if (!isEnable) { return true; } - value = "{\"enableImeList\" : {\"100\" : [\"" + bundleName + "\"]}}"; + value = "{\"enableImeList\" : {\"" + std::to_string(userId) + "\" : [\"" + bundleName + "\"]}}"; } else { value = SetSettingValues(settingValue, bundleName, isEnable); } -- Gitee From 67626a66b5fa819316f5451867d2b11edb024c48 Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Fri, 25 Apr 2025 03:16:34 +0000 Subject: [PATCH 08/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9gn=E5=92=8Cime=5Fcomman?= =?UTF-8?q?d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- BUILD.gn | 2 +- bundle.json | 2 +- tools/ime/BUILD.gn | 40 ++----------------- .../ime/src/input_method_manager_command.cpp | 18 ++++----- 4 files changed, 14 insertions(+), 48 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 69e257247..d5fc2ef0e 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -31,7 +31,7 @@ group("imf_packages") { "profile:inputmethod_inputmethod_sa_profiles", "services:inputmethod_service", "test/unitest/src:unittest", - "tools/ime:ime_command", + "tools/ime:ime", ] } } diff --git a/bundle.json b/bundle.json index 93cd48323..9b7591e12 100644 --- a/bundle.json +++ b/bundle.json @@ -88,7 +88,7 @@ "//base/inputmethod/imf/frameworks/cj:cj_inputmethod_ffi", "//base/inputmethod/imf/seccomp_policy:imf_ext_secure_filter", "//base/inputmethod/imf/services/dialog:input_method_choose_dialog", - "//base/inputmethod/imf/tools/ime:ime_command" + "//base/inputmethod/imf/tools/ime:ime" ] }, "inner_api": [ diff --git a/tools/ime/BUILD.gn b/tools/ime/BUILD.gn index 5639befcc..652847255 100644 --- a/tools/ime/BUILD.gn +++ b/tools/ime/BUILD.gn @@ -14,7 +14,7 @@ import("//base/inputmethod/imf/inputmethod.gni") import("//build/ohos.gni") -ohos_executable("ime_command") { +ohos_executable("ime") { branch_protector_ret = "pac_ret" sanitize = { cfi = true @@ -23,17 +23,6 @@ ohos_executable("ime_command") { } sources = [ - "${inputmethod_path}/frameworks/native/inputmethod_ability/src/input_method_ability.cpp", - "${inputmethod_path}/frameworks/native/inputmethod_ability/src/input_method_agent_service_impl.cpp", - "${inputmethod_path}/frameworks/native/inputmethod_ability/src/input_method_core_service_impl.cpp", - "${inputmethod_path}/frameworks/native/inputmethod_controller/src/ime_event_monitor_manager_impl.cpp", - "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_client_info.cpp", - "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_client_service_impl.cpp", - "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_data_channel_service_impl.cpp", - "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_method_controller.cpp", - "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_method_tools.cpp", - "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_method_utils.cpp", - "${inputmethod_path}/frameworks/native/inputmethod_controller/src/keyevent_consumer_service_impl.cpp", "src/input_method_manager_command.cpp", "src/main.cpp", ] @@ -42,33 +31,13 @@ ohos_executable("ime_command") { "${inputmethod_path}/interfaces/inner_api/inputmethod_controller/include", ] - deps = [ - "${inputmethod_path}/common:inputmethod_common", - "${inputmethod_path}/common/imf_hisysevent:imf_hisysevent", - "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:input_control_channel_proxy", - "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:input_data_channel_stub", - "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:input_method_core_stub", - "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:input_method_system_ability_proxy", - "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:inputmethod_ability", - "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:keyevent_consumer_stub", - "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:input_method_agent_proxy", - "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:input_method_agent_stub", - "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client", - "${inputmethod_path}/services:inputmethod_service", - ] + deps = [ "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client" ] external_deps = [ - "ability_base:want", - "ability_runtime:ability_context_native", - "ability_runtime:ability_manager", - "cJSON:cjson", "c_utils:utils", - "eventhandler:libeventhandler", "hilog:libhilog", "input:libmmi-client", "ipc:ipc_single", - "napi:ace_napi", - "window_manager:libdm", ] if (window_manager_use_sceneboard) { @@ -77,10 +46,7 @@ ohos_executable("ime_command") { external_deps += [ "window_manager:libwm" ] } - configs = [ - "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client_native_public_config", - "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:inputmethod_ability_native_public_config", - ] + configs = [] install_enable = true subsystem_name = "inputmethod" diff --git a/tools/ime/src/input_method_manager_command.cpp b/tools/ime/src/input_method_manager_command.cpp index 3b0d62713..0d458d38e 100644 --- a/tools/ime/src/input_method_manager_command.cpp +++ b/tools/ime/src/input_method_manager_command.cpp @@ -152,15 +152,15 @@ int32_t InputMethodManagerCommand::ParseCommand(int32_t argc, char *argv[]) void InputMethodManagerCommand::ShowUsage() { - std::cout << "Usage: ime_command ..." << std::endl; - std::cout << "Enable inputmethod is: ime_command -e bundleName " << std::endl; - std::cout << "Disenable inputmethod is: ime_command -d bundleName " << std::endl; - std::cout << "Enable full inputmethod is: ime_command -f bundleName " << std::endl; - std::cout << "Enable basic inputmethod is: ime_command -b bundleName " << std::endl; - std::cout << "Switch inputmethod is: ime_command -s bundleName " << std::endl; - std::cout << "Get current inputmethod is: ime_command -g " << std::endl; - std::cout << "List inputmethods is: ime_command -l " << std::endl; - std::cout << "List of inputmethod Commands: ime_command -h " << std::endl; + std::cout << "Usage: ime ..." << std::endl; + std::cout << "Enable inputmethod is: ime -e bundleName " << std::endl; + std::cout << "Disenable inputmethod is: ime -d bundleName " << std::endl; + std::cout << "Enable full inputmethod is: ime -f bundleName " << std::endl; + std::cout << "Enable basic inputmethod is: ime -b bundleName " << std::endl; + std::cout << "Switch inputmethod is: ime -s bundleName " << std::endl; + std::cout << "Get current inputmethod is: ime -g " << std::endl; + std::cout << "List inputmethods is: ime -l " << std::endl; + std::cout << "List of inputmethod Commands: ime -h " << std::endl; } } // namespace MMI } // namespace OHOS \ No newline at end of file -- Gitee From 067315ca8b61e073e8a89da14acd0689b26ad9d1 Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Fri, 25 Apr 2025 03:18:45 +0000 Subject: [PATCH 09/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=89=88=E6=9D=83?= =?UTF-8?q?=E5=A3=B0=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- tools/ime/BUILD.gn | 2 +- tools/ime/include/input_method_manager_command.h | 2 +- tools/ime/src/input_method_manager_command.cpp | 2 +- tools/ime/src/main.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/ime/BUILD.gn b/tools/ime/BUILD.gn index 652847255..93f3c67e6 100644 --- a/tools/ime/BUILD.gn +++ b/tools/ime/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2025 Huawei Device Co., Ltd. +# Copyright (c) 2025 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/tools/ime/include/input_method_manager_command.h b/tools/ime/include/input_method_manager_command.h index 2960e3318..703ce4b13 100644 --- a/tools/ime/include/input_method_manager_command.h +++ b/tools/ime/include/input_method_manager_command.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2025 Huawei Device Co., Ltd. + * Copyright (c) 2025 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/tools/ime/src/input_method_manager_command.cpp b/tools/ime/src/input_method_manager_command.cpp index 0d458d38e..db1a54932 100644 --- a/tools/ime/src/input_method_manager_command.cpp +++ b/tools/ime/src/input_method_manager_command.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2025 Huawei Device Co., Ltd. + * Copyright (c) 2025 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/tools/ime/src/main.cpp b/tools/ime/src/main.cpp index d371cfaf2..0033473ad 100644 --- a/tools/ime/src/main.cpp +++ b/tools/ime/src/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2025 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 -- Gitee From d3c86661c6f0649a0a491ac337cd56e1519280e1 Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Fri, 25 Apr 2025 06:46:16 +0000 Subject: [PATCH 10/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9gn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- tools/ime/BUILD.gn | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tools/ime/BUILD.gn b/tools/ime/BUILD.gn index 93f3c67e6..b826f9101 100644 --- a/tools/ime/BUILD.gn +++ b/tools/ime/BUILD.gn @@ -37,15 +37,8 @@ ohos_executable("ime") { "c_utils:utils", "hilog:libhilog", "input:libmmi-client", - "ipc:ipc_single", ] - if (window_manager_use_sceneboard) { - external_deps += [ "window_manager:libwm_lite" ] - } else { - external_deps += [ "window_manager:libwm" ] - } - configs = [] install_enable = true -- Gitee