diff --git a/BUILD.gn b/BUILD.gn index 8b35a409ee96262293a21ad19190b5c18efc7f40..d5fc2ef0e496d43468b3a8a06d74580eb9d19105 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", ] } } diff --git a/bundle.json b/bundle.json index c4fe00354ffeb185c2fd3524e54fdaabdf216849..9b7591e12280b026e11ee2a119f9ac00ef8e6546 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" ] }, "inner_api": [ diff --git a/frameworks/native/inputmethod_controller/IInputMethodSystemAbility.idl b/frameworks/native/inputmethod_controller/IInputMethodSystemAbility.idl index a9b854cf8ea00a914ddc4695daa92c28df396e12..3271d982a57378e7e94a2fbbe6169ca770597162 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 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 51ec411880474f14ada576c5afbe2d1c23b0fb24..f2d0666ebf7d1999123164d74cacf1ac3212f3f5 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 isFull) +{ + IMSA_HILOGI("enter."); + auto proxy = GetSystemAbilityProxy(); + if (proxy == nullptr) { + IMSA_HILOGE("proxy is nullptr!"); + return false; + } + bool ret = false; + proxy->SetImeMode(bundleName, isFull, ret); return ret; } diff --git a/interfaces/inner_api/inputmethod_ability/BUILD.gn b/interfaces/inner_api/inputmethod_ability/BUILD.gn index 5c4e7262ad78292ed8367b780b80abf0ca821442..d1641b4129f9b087f00fb501e7faed226931608f 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 d63bff863d47c10fe06509f442b05c118f265f14..2326c2cd8ad4a7870bfcc4020c6f6906de789d04 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/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h index b14b45adbb56fb8007fd19f4959e99de9cb84c62..00ccbdf7c5a6b2cca4a3de8cfa4d424ba7904afa 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 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 602cae5ba1f9f12f3917e70d6ab2b6149afb4252..69c66959ad25d01df247f980a6d0829e175f5708 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 isFull = 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 26a9308e3df02620cbf4180096f20d1ad08588c1..cb8384f41dd34a43d7dcc59ad35b7ad59c92eef1 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" @@ -220,25 +221,51 @@ 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) { - IMSA_HILOGE("user is not main."); + const char *settingKey = "settings.inputmethod.enable_ime"; + 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 = "{\"enableImeList\" : {\"" + std::to_string(userId) + "\" : [\"" + bundleName + "\"]}}"; + } else { + value = SetSettingValues(settingValue, bundleName, isEnable); + } + IMSA_HILOGI("value: %{public}s", value.c_str()); + 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; } - const char *settingKey = "settings.inputmethod.enable_ime"; + ret = SetStringValue(std::string(SETTING_URI_PROXY), settingKey, value); + return ret; +} + +bool SettingsDataUtils::SetImeMode(int32_t userId, const std::string &bundleName, bool isFull) +{ + 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 == "") { - value = "{\"enableImeList\" : {\"100\" : [\"" + bundleName + "\"]}}"; + if (!isFull) { + return true; + } + value = "{\"fullExperienceList\" : {\"100\" : [\"" + bundleName + "\"]}}"; } else { - value = SetSettingValues(settingValue, bundleName); + value = SetSettingValues(settingValue, bundleName, isFull); } 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 +281,39 @@ 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 d7c0894f9473931aaa517e49d7b7f795376d808e..f97fc5d8a368d2aac257924fdce26266f1b24fe9 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 9b4161112bf4245667805ef436b70bd2abdc1fee..83392cf6264efd6024f82954e3a67878d58fe55d 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 59c634ee2dc7527961d2f0b6b7cc65f62ec90363..8017cd8393e471c9a176ce290cb6216db7995e25 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 b50213cb386670d9488ed896966e13e5165d95c9..560585c9333f22beff45eb9f2b7d372c9094fc8d 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 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 cf8188bc3aa8d2e97fbc11c6919fcea45c25a543..d6a283d97ee83e974f83ff0f05a827d26fd856da 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::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()->SetImeMode(userId, bundleName, isFull); 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 0000000000000000000000000000000000000000..b826f91013dd8c5c26d0425f1b327a7dee3896a7 --- /dev/null +++ b/tools/ime/BUILD.gn @@ -0,0 +1,47 @@ +# 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 +# +# 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") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + + sources = [ + "src/input_method_manager_command.cpp", + "src/main.cpp", + ] + include_dirs = [ + "include", + "${inputmethod_path}/interfaces/inner_api/inputmethod_controller/include", + ] + + deps = [ "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "input:libmmi-client", + ] + + configs = [] + + 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 0000000000000000000000000000000000000000..703ce4b13da2b94d0028d26da94d97c06692b525 --- /dev/null +++ b/tools/ime/include/input_method_manager_command.h @@ -0,0 +1,27 @@ +/* + * 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 + * + * 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 0000000000000000000000000000000000000000..db1a54932de457ce2b97a392fcf33bec5236e4ee --- /dev/null +++ b/tools/ime/src/input_method_manager_command.cpp @@ -0,0 +1,166 @@ +/* + * 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 + * + * 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 isFull = true; + if (optarg == nullptr) { + std::cout << "Invalid argument" << std::endl; + ShowUsage(); + return 0; + } + retValue = MiscServices::InputMethodController::GetInstance()->SetImeMode(optarg, isFull); + 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 isFull = false; + if (optarg == nullptr) { + std::cout << "Invalid argument" << std::endl; + ShowUsage(); + return 0; + } + retValue = MiscServices::InputMethodController::GetInstance()->SetImeMode(optarg, isFull); + 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::NATIVE_SA; + 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 ..." << 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 diff --git a/tools/ime/src/main.cpp b/tools/ime/src/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0033473ad3808bd61b74914c8fc7c53649b54baf --- /dev/null +++ b/tools/ime/src/main.cpp @@ -0,0 +1,22 @@ +/* + * 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 + * + * 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