From b8841230ef8013f04700c452633f94ce815b5c93 Mon Sep 17 00:00:00 2001 From: KangPeng Date: Mon, 25 Aug 2025 15:27:07 +0800 Subject: [PATCH 01/10] extra config Signed-off-by: KangPeng --- bundle.json | 9 ++ .../js_text_input_client_engine.cpp | 20 +++ .../js_text_input_client_engine.h | 5 + frameworks/js/napi/inputmethodclient/BUILD.gn | 1 + .../js/napi/inputmethodclient/js_utils.cpp | 117 ++++++++++++++++++ .../js/napi/inputmethodclient/js_utils.h | 6 + .../kits/extra_config/extra_config_napi.cpp | 35 ++++++ .../include/extra_config.h | 44 +++++++ .../include/input_attribute.h | 107 +++++++++++++++- .../include/input_method_tools.h | 2 + .../src/input_method_tools.cpp | 16 +++ interfaces/kits/js/BUILD.gn | 60 +++++++++ interfaces/kits/js/extra_config_napi.h | 35 ++++++ 13 files changed, 454 insertions(+), 3 deletions(-) create mode 100644 frameworks/kits/extra_config/extra_config_napi.cpp create mode 100644 frameworks/native/inputmethod_controller/include/extra_config.h create mode 100644 interfaces/kits/js/BUILD.gn create mode 100644 interfaces/kits/js/extra_config_napi.h diff --git a/bundle.json b/bundle.json index f01a865e7..ede373559 100644 --- a/bundle.json +++ b/bundle.json @@ -125,6 +125,15 @@ }, { "name": "//base/inputmethod/imf/frameworks/kits/extension_cj:cj_inputmethod_extension_ffi" + }, + { + "name": "//base/inputmethod/imf/interfaces/kits/js:extra_config_napi", + "header": { + "header_files": [ + "extra_config_napi.h" + ], + "header_base": "//base/inputmethod/imf/interfaces/kits/js/" + } } ], "test": [ diff --git a/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp b/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp index 0bac05f5a..e3ae2f2e5 100644 --- a/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp +++ b/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp @@ -1164,6 +1164,24 @@ bool JsRange::Read(napi_env env, napi_value jsObject, Range &nativeObject) return ret; } +bool JsExtraConfigInfo::Write(napi_env env, napi_value &jsObject, const ExtraConfig &nativeObject) +{ + auto value = JsUtils::GetJsExtraConfig(env, nativeObject); + std::string name = "extraConfig"; + return napi_set_named_property(env, jsObject, name.c_str(), value) == napi_ok; +} + +bool JsExtraConfigInfo::Read(napi_env env, napi_value jsObject, ExtraConfig &nativeObject) +{ + napi_value value = nullptr; + std::string name = "extraConfig"; + napi_get_named_property(env, jsObject, name.c_str(), &value); + auto status = JsUtils::GetValue(env, value, nativeObject); + CHECK_RETURN(status == napi_ok, "ExtraConfig covert failed, type must be Record", + false); + return true; +} + napi_value JsInputAttribute::Write(napi_env env, const InputAttribute &nativeObject) { napi_value jsObject = nullptr; @@ -1186,6 +1204,7 @@ napi_value JsInputAttribute::Write(napi_env env, const InputAttribute &nativeObj if (InputMethodAbility::GetInstance().IsSystemApp()) { ret = ret && JsUtil::Object::WriteProperty(env, jsObject, "fluidLightMode", nativeObject.fluidLightMode); } + ret = ret && JsExtraConfigInfo::Write(env, jsObject, nativeObject.extraConfig); return ret ? jsObject : JsUtil::Const::Null(env); } @@ -1212,6 +1231,7 @@ bool JsInputAttribute::Read(napi_env env, napi_value jsObject, InputAttribute &n if (InputMethodAbility::GetInstance().IsSystemApp()) { ret = ret && JsUtil::Object::ReadProperty(env, jsObject, "fluidLightMode", nativeObject.fluidLightMode); } + ret = ret && JsExtraConfigInfo::Read(env, jsObject, nativeObject.extraConfig); return ret; } diff --git a/frameworks/js/napi/inputmethodability/js_text_input_client_engine.h b/frameworks/js/napi/inputmethodability/js_text_input_client_engine.h index 2cbefdba6..2f6ab8b9b 100644 --- a/frameworks/js/napi/inputmethodability/js_text_input_client_engine.h +++ b/frameworks/js/napi/inputmethodability/js_text_input_client_engine.h @@ -58,6 +58,11 @@ struct JsRange { static bool Read(napi_env env, napi_value jsObject, Range &nativeObject); }; +struct JsExtraConfigInfo { + static bool Write(napi_env env, napi_value &jsObject, const ExtraConfig &nativeObject); + static bool Read(napi_env env, napi_value jsObject, ExtraConfig &nativeObject); +}; + struct JsInputAttribute { static napi_value Write(napi_env env, const InputAttribute &nativeObject); static bool Read(napi_env env, napi_value jsObject, InputAttribute &nativeObject); diff --git a/frameworks/js/napi/inputmethodclient/BUILD.gn b/frameworks/js/napi/inputmethodclient/BUILD.gn index 5f25fba09..ab2cc1525 100644 --- a/frameworks/js/napi/inputmethodclient/BUILD.gn +++ b/frameworks/js/napi/inputmethodclient/BUILD.gn @@ -19,6 +19,7 @@ config("imf_config") { include_dirs = [ "include", "${inputmethod_path}/frameworks/js/napi/inputmethodability", + "${inputmethod_path}/interfaces/kits/js", ] } diff --git a/frameworks/js/napi/inputmethodclient/js_utils.cpp b/frameworks/js/napi/inputmethodclient/js_utils.cpp index 08c72d745..a14314ac9 100644 --- a/frameworks/js/napi/inputmethodclient/js_utils.cpp +++ b/frameworks/js/napi/inputmethodclient/js_utils.cpp @@ -581,5 +581,122 @@ napi_status JsUtils::GetMessageHandlerCallbackParam(napi_value *argv, } return napi_ok; } + +napi_status JsUtils::GetValue(napi_env env, napi_value in, ExtraConfig &out, uint32_t maxLen) +{ + if (maxLen > MAX_EXTRA_CONFIG_SIZE) { + return napi_generic_failure; + } + napi_value propType = nullptr; + napi_status status = napi_get_named_property(env, in, "customSettings", &propType); + CHECK_RETURN((status == napi_ok), "no property customSettings ", status); + return GetValue(env, propType, out.customSettings, maxLen); +} + +napi_status JsUtils::GetValue(napi_env env, napi_value in, CustomSettings &out, uint32_t maxLen) +{ + napi_valuetype type = napi_undefined; + napi_status status = napi_typeof(env, in, &type); + PARAM_CHECK_RETURN(env, type != napi_undefined, "param is undefined.", TYPE_NONE, napi_generic_failure); + + napi_value keys = nullptr; + napi_get_property_names(env, in, &keys); + uint32_t arrLen = 0; + status = napi_get_array_length(env, keys, &arrLen); + if (status != napi_ok) { + IMSA_HILOGE("napi_get_array_length error"); + return status; + } + IMSA_HILOGD("length : %{public}u", arrLen); + uint32_t totalSize = 0; + for (size_t iter = 0; iter < arrLen; ++iter) { + napi_value key = nullptr; + status = napi_get_element(env, keys, iter, &key); + CHECK_RETURN(status == napi_ok, "napi_get_element error", status); + + napi_value value = nullptr; + status = napi_get_property(env, in, key, &value); + CHECK_RETURN(status == napi_ok, "napi_get_property error", status); + + std::string keyStr; + status = GetValue(env, key, keyStr); + CHECK_RETURN(status == napi_ok, "GetValue keyStr error", status); + uint32_t keySize = keyStr.size(); + + CustomValueType customSettingData; + uint32_t valueSize = 0; + status = GetValue(env, value, customSettingData, valueSize); + CHECK_RETURN(status == napi_ok, "GetValue customSettingData error", status); + totalSize = totalSize + keySize + valueSize; + out.emplace(keyStr, customSettingData); + } + if (totalSize > maxLen) { + out.clear(); + IMSA_HILOGE("totalSize : %{public}d", totalSize); + return napi_generic_failure; + } + return status; +} + +napi_status JsUtils::GetValue(napi_env env, napi_value in, CustomValueType &out, uint32_t &valueSize) +{ + napi_valuetype valueType = napi_undefined; + napi_status status = napi_typeof(env, in, &valueType); + CHECK_RETURN(status == napi_ok, "napi_typeof error", napi_generic_failure); + if (valueType == napi_string) { + std::string customSettingStr; + status = GetValue(env, in, customSettingStr); + CHECK_RETURN(status == napi_ok, "GetValue napi_string error", napi_generic_failure); + valueSize = customSettingStr.size(); + out.emplace(customSettingStr); + } else if (valueType == napi_boolean) { + bool customSettingBool = false; + status = GetValue(env, in, customSettingBool); + CHECK_RETURN(status == napi_ok, "GetValue napi_boolean error", napi_generic_failure); + valueSize = sizeof(bool); + out.emplace(customSettingBool); + } else if (valueType == napi_number) { + int32_t customSettingInt = 0; + status = GetValue(env, in, customSettingInt); + CHECK_RETURN(status == napi_ok, "GetValue napi_number error", napi_generic_failure); + valueSize = sizeof(int32_t); + out.emplace(customSettingInt); + } else { + PARAM_CHECK_RETURN(env, false, "value type must be string | boolean | number", TYPE_NONE, napi_generic_failure); + } + return status; +} + +napi_value JsUtils::GetJsExtraConfig(napi_env env, const ExtraConfig &in) +{ + napi_value jsExtraConfig = nullptr; + napi_value jsObject = nullptr; + NAPI_CALL(env, napi_create_object(env, &jsExtraConfig)); + NAPI_CALL(env, napi_create_object(env, &jsObject)); + for (const auto &iter : in.customSettings) { + size_t idx = iter.second.index(); + napi_value value = nullptr; + if (idx == static_cast(CustomValueTypeValue::CUSTOM_VALUE_TYPE_STRING)) { + auto stringValue = std::get_if(&iter.second); + if (stringValue != nullptr) { + NAPI_CALL(env, napi_create_string_utf8(env, (*stringValue).c_str(), (*stringValue).size(), &value)); + } + } else if (idx == static_cast(CustomValueTypeValue::CUSTOM_VALUE_TYPE_BOOL)) { + auto boolValue = std::get_if(&iter.second); + if (boolValue != nullptr) { + NAPI_CALL(env, napi_get_boolean(env, *boolValue, &value)); + } + } else if (idx == static_cast(CustomValueTypeValue::CUSTOM_VALUE_TYPE_NUMBER)) { + auto numberValue = std::get_if(&iter.second); + if (numberValue != nullptr) { + NAPI_CALL(env, napi_create_int32(env, *numberValue, &value)); + } + } + NAPI_CALL(env, napi_set_named_property(env, jsObject, iter.first.c_str(), value)); + } + std::string name = "customSettings"; + napi_set_named_property(env, jsExtraConfig, name.c_str(), jsObject); + return jsExtraConfig; +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/napi/inputmethodclient/js_utils.h b/frameworks/js/napi/inputmethodclient/js_utils.h index 71797468f..8fe5f8c9a 100644 --- a/frameworks/js/napi/inputmethodclient/js_utils.h +++ b/frameworks/js/napi/inputmethodclient/js_utils.h @@ -28,6 +28,7 @@ #include "napi/native_common.h" #include "napi/native_node_api.h" #include "string_ex.h" +#include "extra_config.h" using Ability = OHOS::AppExecFwk::Ability; namespace OHOS { @@ -133,6 +134,7 @@ struct JsPropertyInfo { std::string propertyName; }; +constexpr uint32_t MAX_EXTRA_CONFIG_SIZE = 1024 * 1024; // 1M class JsUtils { public: static void ThrowException(napi_env env, int32_t err, const std::string &msg, TypeCode type); @@ -182,6 +184,10 @@ public: static napi_status GetMessageHandlerCallbackParam(napi_value *argv, const std::shared_ptr &jsMessageHandler, const ArrayBuffer &arrayBuffer, size_t size); + static napi_status GetValue(napi_env env, napi_value in, ExtraConfig &out, uint32_t maxLen = MAX_EXTRA_CONFIG_SIZE); + static napi_status GetValue(napi_env env, napi_value in, CustomSettings &out, uint32_t maxLen = MAX_EXTRA_CONFIG_SIZE); + static napi_status GetValue(napi_env env, napi_value in, CustomValueType &out, uint32_t &valueSize); + static napi_value GetJsExtraConfig(napi_env env, const ExtraConfig &in); private: static const std::map ERROR_CODE_MAP; diff --git a/frameworks/kits/extra_config/extra_config_napi.cpp b/frameworks/kits/extra_config/extra_config_napi.cpp new file mode 100644 index 000000000..ff67f9dd9 --- /dev/null +++ b/frameworks/kits/extra_config/extra_config_napi.cpp @@ -0,0 +1,35 @@ +/* + * 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 "extra_config_napi.h" +#include "js_utils.h" + +namespace OHOS { +namespace MiscServices { + +napi_status JsExtraConfig::CreateExtraConfig(napi_env env, const ExtraConfig &in, napi_value &out) +{ + out = JsUtils::GetJsExtraConfig(env, in); + return napi_ok; +} + +napi_status JsExtraConfig::GetExtraConfig(napi_env env, napi_value in, ExtraConfig &out, uint32_t maxLen) +{ + auto status = JsUtils::GetValue(env, in, out, maxLen); + CHECK_RETURN(status == napi_ok, "ExtraConfig convert failed", napi_generic_failure); + return napi_ok; +} +} // namespace MiscServices +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/inputmethod_controller/include/extra_config.h b/frameworks/native/inputmethod_controller/include/extra_config.h new file mode 100644 index 000000000..e9bee33b0 --- /dev/null +++ b/frameworks/native/inputmethod_controller/include/extra_config.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2022-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. + */ + +#ifndef INPUTMETHOD_EXTRA_CONFIG_H +#define INPUTMETHOD_EXTRA_CONFIG_H + +#include +#include +#include +#include + +namespace OHOS { +namespace MiscServices { + +enum CustomValueTypeValue : int32_t { + CUSTOM_VALUE_TYPE_STRING = 0, + CUSTOM_VALUE_TYPE_NUMBER, + CUSTOM_VALUE_TYPE_BOOL +}; +using CustomValueType = std::variant; +using CustomSettings = std::unordered_map; +struct ExtraConfig { + CustomSettings customSettings = {}; + bool operator==(const ExtraConfig &info) const + { + return customSettings == info.customSettings; + } +}; +} // namespace MiscServices +} // namespace OHOS + +#endif // INPUTMETHOD_EXTRA_CONFIG_H \ No newline at end of file diff --git a/frameworks/native/inputmethod_controller/include/input_attribute.h b/frameworks/native/inputmethod_controller/include/input_attribute.h index 8b1e6151b..c4388355d 100644 --- a/frameworks/native/inputmethod_controller/include/input_attribute.h +++ b/frameworks/native/inputmethod_controller/include/input_attribute.h @@ -20,6 +20,7 @@ #include #include "parcel.h" +#include "extra_config.h" namespace OHOS { namespace MiscServices { @@ -30,6 +31,93 @@ enum class CapitalizeMode : int32_t { CHARACTERS }; +struct ExtraConfigInner : public Parcelable { + CustomSettings customSettings = {}; + bool ReadFromParcel(Parcel &in) + { + uint32_t size = 0; + size = in.ReadUint32(); + + customSettings.clear(); + if (size == 0) { + return true; + } + for (uint32_t index = 0; index < size; index++) { + std::string key = in.ReadString(); + int32_t valueType = in.ReadInt32(); + if (valueType == static_cast(CustomValueTypeValue::CUSTOM_VALUE_TYPE_STRING)) { + std::string strValue = in.ReadString(); + customSettings.insert(std::make_pair(key, strValue)); + } else if (valueType == static_cast(CustomValueTypeValue::CUSTOM_VALUE_TYPE_BOOL)) { + bool boolValue = false; + boolValue = in.ReadBool(); + customSettings.insert(std::make_pair(key, boolValue)); + } else if (valueType == static_cast(CustomValueTypeValue::CUSTOM_VALUE_TYPE_NUMBER)) { + int32_t intValue = 0; + intValue = in.ReadInt32(); + customSettings.insert(std::make_pair(key, intValue)); + } + } + return true; + } + + bool Marshalling(Parcel &out) const + { + if (!out.WriteUint32(customSettings.size())) { + return false; + } + if (customSettings.size() == 0) { + return true; + } + for (auto& it : customSettings) { + std::string key = it.first; + if (!out.WriteString(key)) { + return false; + } + auto value = it.second; + bool ret = false; + int32_t valueType = static_cast(value.index()); + if (!out.WriteInt32(valueType)) { + return false; + } + if (valueType == static_cast(CustomValueTypeValue::CUSTOM_VALUE_TYPE_STRING)) { + auto stringValue = std::get_if(&value); + if (stringValue != nullptr) { + ret = out.WriteString(*stringValue); + } + } else if (valueType == static_cast(CustomValueTypeValue::CUSTOM_VALUE_TYPE_BOOL)) { + auto boolValue = std::get_if(&value); + if (boolValue != nullptr) { + ret = out.WriteBool(*boolValue); + } + } else if (valueType == static_cast(CustomValueTypeValue::CUSTOM_VALUE_TYPE_NUMBER)) { + auto numberValue = std::get_if(&value); + if (numberValue != nullptr) { + ret = out.WriteInt32(*numberValue); + } + } + if (ret == false) { + return ret; + } + } + return true; + } + static ExtraConfigInner *Unmarshalling(Parcel &in) + { + ExtraConfigInner *data = new (std::nothrow) ExtraConfigInner(); + if (data && !data->ReadFromParcel(in)) { + delete data; + data = nullptr; + } + return data; + } + bool operator==(const ExtraConfigInner &info) const + { + return customSettings == info.customSettings; + } +}; + + struct InputAttribute { static const int32_t PATTERN_TEXT = 0x00000001; static const int32_t PATTERN_PASSWORD = 0x00000007; @@ -51,6 +139,7 @@ struct InputAttribute { std::u16string abilityName { u"" }; CapitalizeMode capitalizeMode = CapitalizeMode::NONE; bool needAutoInputNumkey { false }; // number keys need to be automatically handled by imf + ExtraConfig extraConfig = {}; bool GetSecurityFlag() const { @@ -71,7 +160,8 @@ struct InputAttribute { bool operator==(const InputAttribute &info) const { return inputPattern == info.inputPattern && enterKeyType == info.enterKeyType && - inputOption == info.inputOption && isTextPreviewSupported == info.isTextPreviewSupported; + inputOption == info.inputOption && isTextPreviewSupported == info.isTextPreviewSupported && + extraConfig == info.extraConfig; } inline std::string ToString() const @@ -83,6 +173,7 @@ struct InputAttribute { << "immersiveMode:" << immersiveMode << "windowId:" << windowId << "callingDisplayId:" << callingDisplayId << "needNumInput: " << needAutoInputNumkey + << "extraConfig.customSettings.size: " << extraConfig.customSettings.size() << "]"; return ss.str(); } @@ -108,6 +199,7 @@ struct InputAttributeInner : public Parcelable { std::u16string abilityName { u"" }; CapitalizeMode capitalizeMode = CapitalizeMode::NONE; bool needAutoInputNumkey { false }; // number keys need to be automatically handled by imf + ExtraConfigInner extraConfig; bool ReadFromParcel(Parcel &in) { @@ -130,6 +222,11 @@ struct InputAttributeInner : public Parcelable { needAutoInputNumkey = in.ReadBool(); gradientMode = in.ReadInt32(); fluidLightMode = in.ReadInt32(); + std::unique_ptr extraConfigInfo(in.ReadParcelable()); + if (extraConfigInfo == nullptr) { + return false; + } + extraConfig = *extraConfigInfo; return true; } @@ -164,6 +261,9 @@ struct InputAttributeInner : public Parcelable { ret = ret && out.WriteBool(needAutoInputNumkey); ret = ret && out.WriteInt32(gradientMode); ret = ret && out.WriteInt32(fluidLightMode); + if (!out.WriteParcelable(&extraConfig)) { + return false; + } return ret; } @@ -177,10 +277,11 @@ struct InputAttributeInner : public Parcelable { return data; } - bool operator==(const InputAttribute &info) const + bool operator==(const InputAttributeInner &info) const { return inputPattern == info.inputPattern && enterKeyType == info.enterKeyType && - inputOption == info.inputOption && isTextPreviewSupported == info.isTextPreviewSupported; + inputOption == info.inputOption && isTextPreviewSupported == info.isTextPreviewSupported && + extraConfig == info.extraConfig; } bool GetSecurityFlag() const diff --git a/frameworks/native/inputmethod_controller/include/input_method_tools.h b/frameworks/native/inputmethod_controller/include/input_method_tools.h index 43efedecc..33d02f1c8 100644 --- a/frameworks/native/inputmethod_controller/include/input_method_tools.h +++ b/frameworks/native/inputmethod_controller/include/input_method_tools.h @@ -27,6 +27,8 @@ class InputMethodTools { public: static InputMethodTools &GetInstance(); ~InputMethodTools() = default; + ExtraConfigInner ExtraConfigToInner(const ExtraConfig &extraConfig); + ExtraConfig InnerToExtraConfig(const ExtraConfigInner &inner); InputAttributeInner AttributeToInner(const InputAttribute &attribute); InputAttribute InnerToAttribute(const InputAttributeInner &inner); CursorInfoInner CursorInfoToInner(const CursorInfo &cursorInfo); diff --git a/frameworks/native/inputmethod_controller/src/input_method_tools.cpp b/frameworks/native/inputmethod_controller/src/input_method_tools.cpp index 814e638ba..b5277e64e 100644 --- a/frameworks/native/inputmethod_controller/src/input_method_tools.cpp +++ b/frameworks/native/inputmethod_controller/src/input_method_tools.cpp @@ -24,6 +24,20 @@ InputMethodTools &InputMethodTools::GetInstance() return instance; } +ExtraConfigInner InputMethodTools::ExtraConfigToInner(const ExtraConfig &extraConfig) +{ + ExtraConfigInner inner; + inner.customSettings = extraConfig.customSettings; + return inner; +} + +ExtraConfig InputMethodTools::InnerToExtraConfig(const ExtraConfigInner &inner) +{ + ExtraConfig extraConfig; + extraConfig.customSettings = inner.customSettings; + return extraConfig; +} + InputAttributeInner InputMethodTools::AttributeToInner(const InputAttribute &attribute) { InputAttributeInner inner; @@ -41,6 +55,7 @@ InputAttributeInner InputMethodTools::AttributeToInner(const InputAttribute &att inner.abilityName = attribute.abilityName; inner.capitalizeMode = attribute.capitalizeMode; inner.needAutoInputNumkey = attribute.needAutoInputNumkey; + inner.extraConfig = ExtraConfigToInner(attribute.extraConfig); return inner; } @@ -61,6 +76,7 @@ InputAttribute InputMethodTools::InnerToAttribute(const InputAttributeInner &inn inputAttribute.abilityName = inner.abilityName; inputAttribute.capitalizeMode = inner.capitalizeMode; inputAttribute.needAutoInputNumkey = inner.needAutoInputNumkey; + inputAttribute.extraConfig = InnerToExtraConfig(inner.extraConfig); return inputAttribute; } diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn new file mode 100644 index 000000000..3531f5acd --- /dev/null +++ b/interfaces/kits/js/BUILD.gn @@ -0,0 +1,60 @@ +# 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") + +config("extra_config") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "${inputmethod_path}/frameworks/native/inputmethod_controller/include", + "${inputmethod_path}/frameworks/js/napi/inputmethodclient", + "${inputmethod_path}/interfaces/kits/js", + ] +} + +ohos_shared_library("extra_config_napi") { + branch_protector_ret = "pac_ret" + sanitize = { + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + integer_overflow = true + ubsan = true + } + sources = [ + "${inputmethod_path}/frameworks/js/napi/inputmethodclient/js_utils.cpp", + "${inputmethod_path}/frameworks/kits/extra_config/extra_config_napi.cpp", + ] + + configs = [ ":extra_config" ] + + deps = [ + "${inputmethod_path}/common:inputmethod_common", + "${inputmethod_path}/frameworks/js/napi/common:inputmethod_js_common", + ] + + external_deps = [ + "ability_runtime:abilitykit_native", + "c_utils:utils", + "hilog:libhilog", + ] + + public_configs = [ ":extra_config" ] + + innerapi_tags = [ "platformsdk" ] + subsystem_name = "inputmethod" + part_name = "imf" +} diff --git a/interfaces/kits/js/extra_config_napi.h b/interfaces/kits/js/extra_config_napi.h new file mode 100644 index 000000000..70bcc6ad7 --- /dev/null +++ b/interfaces/kits/js/extra_config_napi.h @@ -0,0 +1,35 @@ +/* + * 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. + */ + +#ifndef INTERFACE_JS_EXTRA_CONFIG +#define INTERFACE_JS_EXTRA_CONFIG + +#include "napi/native_api.h" +#include "extra_config.h" + +namespace OHOS { +namespace MiscServices { +constexpr uint32_t DEFAULT_MAX_EXTRA_CONFIG_SIZE = 128 * 1024; // 128K +class JsExtraConfig { +public: + JsExtraConfig() = default; + ~JsExtraConfig() = default; + static napi_status CreateExtraConfig(napi_env env, const ExtraConfig &in, napi_value &out); + static napi_status GetExtraConfig(napi_env env, napi_value in, ExtraConfig &out, + uint32_t maxLen = DEFAULT_MAX_EXTRA_CONFIG_SIZE); +}; +} // namespace MiscServices +} // namespace OHOS +#endif // INTERFACE_JS_EXTRA_CONFIG \ No newline at end of file -- Gitee From 9e6ef75d14229abb84818846339f38a87d91d088 Mon Sep 17 00:00:00 2001 From: KangPeng Date: Tue, 26 Aug 2025 17:18:05 +0800 Subject: [PATCH 02/10] extra config Signed-off-by: KangPeng --- frameworks/js/napi/inputmethodclient/BUILD.gn | 1 - frameworks/js/napi/inputmethodclient/js_utils.h | 3 ++- .../include/input_attribute.h | 1 - .../cpp_test/src/input_method_ability_test.cpp | 16 ++++++++++++++++ .../src/input_method_controller_test.cpp | 3 +++ 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/frameworks/js/napi/inputmethodclient/BUILD.gn b/frameworks/js/napi/inputmethodclient/BUILD.gn index ab2cc1525..5f25fba09 100644 --- a/frameworks/js/napi/inputmethodclient/BUILD.gn +++ b/frameworks/js/napi/inputmethodclient/BUILD.gn @@ -19,7 +19,6 @@ config("imf_config") { include_dirs = [ "include", "${inputmethod_path}/frameworks/js/napi/inputmethodability", - "${inputmethod_path}/interfaces/kits/js", ] } diff --git a/frameworks/js/napi/inputmethodclient/js_utils.h b/frameworks/js/napi/inputmethodclient/js_utils.h index 8fe5f8c9a..494f368d3 100644 --- a/frameworks/js/napi/inputmethodclient/js_utils.h +++ b/frameworks/js/napi/inputmethodclient/js_utils.h @@ -185,7 +185,8 @@ public: const std::shared_ptr &jsMessageHandler, const ArrayBuffer &arrayBuffer, size_t size); static napi_status GetValue(napi_env env, napi_value in, ExtraConfig &out, uint32_t maxLen = MAX_EXTRA_CONFIG_SIZE); - static napi_status GetValue(napi_env env, napi_value in, CustomSettings &out, uint32_t maxLen = MAX_EXTRA_CONFIG_SIZE); + static napi_status GetValue(napi_env env, napi_value in, CustomSettings &out, + uint32_t maxLen = MAX_EXTRA_CONFIG_SIZE); static napi_status GetValue(napi_env env, napi_value in, CustomValueType &out, uint32_t &valueSize); static napi_value GetJsExtraConfig(napi_env env, const ExtraConfig &in); diff --git a/frameworks/native/inputmethod_controller/include/input_attribute.h b/frameworks/native/inputmethod_controller/include/input_attribute.h index c4388355d..5f3f5342e 100644 --- a/frameworks/native/inputmethod_controller/include/input_attribute.h +++ b/frameworks/native/inputmethod_controller/include/input_attribute.h @@ -117,7 +117,6 @@ struct ExtraConfigInner : public Parcelable { } }; - struct InputAttribute { static const int32_t PATTERN_TEXT = 0x00000001; static const int32_t PATTERN_PASSWORD = 0x00000007; diff --git a/test/unittest/cpp_test/src/input_method_ability_test.cpp b/test/unittest/cpp_test/src/input_method_ability_test.cpp index 6e8086070..dc2d0f82f 100644 --- a/test/unittest/cpp_test/src/input_method_ability_test.cpp +++ b/test/unittest/cpp_test/src/input_method_ability_test.cpp @@ -364,6 +364,22 @@ HWTEST_F(InputMethodAbilityTest, testSerializedInputAttribute_WithSpecificBundle EXPECT_EQ(inAttribute.bundleName, ret->bundleName); } +/** + * @tc.name: testSerializedInputAttribute + * @tc.desc: Checkout the serialization of InputAttribute. + * @tc.type: FUNC + */ +HWTEST_F(InputMethodAbilityTest, testSerializedExtraConfig, TestSize.Level0) +{ + ExtraConfigInner extraConfig; + extraConfig.customSettings.empace("key", true); + MessageParcel data; + EXPECT_TRUE(extraConfig.Marshalling(data)); + auto ret = ExtraConfigInner::Unmarshalling(data); + EXPECT_NE(ret, nullptr); + EXPECT_EQ(extraConfig.customSettings["key"],ret->extraConfig.customSettings["key"]); +} + /** * @tc.name: testShowKeyboardInputMethodCoreProxy * @tc.desc: Test InputMethodCoreProxy ShowKeyboard diff --git a/test/unittest/cpp_test/src/input_method_controller_test.cpp b/test/unittest/cpp_test/src/input_method_controller_test.cpp index 5df383aab..bb733df1c 100644 --- a/test/unittest/cpp_test/src/input_method_controller_test.cpp +++ b/test/unittest/cpp_test/src/input_method_controller_test.cpp @@ -1126,6 +1126,7 @@ HWTEST_F(InputMethodControllerTest, testOnEditorAttributeChanged02, TestSize.Lev InputAttribute attribute = { .inputPattern = static_cast(TextInputType::DATETIME), .enterKeyType = static_cast(EnterKeyType::GO), .isTextPreviewSupported = true }; + attribute.extraConfig.customSettings.emplace("key", "test"); auto ret = inputMethodController_->Attach(textListener_, false, attribute); EXPECT_EQ(ret, ErrorCode::NO_ERROR); Configuration info; @@ -1136,6 +1137,7 @@ HWTEST_F(InputMethodControllerTest, testOnEditorAttributeChanged02, TestSize.Lev EXPECT_EQ(InputMethodControllerTest::inputAttribute_.inputPattern, static_cast(info.GetTextInputType())); EXPECT_EQ(InputMethodControllerTest::inputAttribute_.enterKeyType, static_cast(info.GetEnterKeyType())); EXPECT_EQ(InputMethodControllerTest::inputAttribute_.isTextPreviewSupported, attribute.isTextPreviewSupported); + EXPECT_EQ(InputMethodControllerTest::inputAttribute_.extraConfig, attribute.extraConfig); } /** @@ -2020,6 +2022,7 @@ HWTEST_F(InputMethodControllerTest, testUpdateTextPreviewState, TestSize.Level0) IMSA_HILOGI("IMC testUpdateTextPreviewState Test START"); ASSERT_NE(inputMethodController_, nullptr); inputMethodController_->textConfig_.inputAttribute.isTextPreviewSupported = false; + inputMethodController_->textConfig_.inputAttribute.extraConfig.customSettings.emplace("key", "test"); inputMethodController_->UpdateTextPreviewState(true); EXPECT_TRUE(inputMethodController_->textConfig_.inputAttribute.isTextPreviewSupported); inputMethodController_->UpdateTextPreviewState(true); -- Gitee From 485fd2c492198ef1f9998a97612e31ad2b6929ee Mon Sep 17 00:00:00 2001 From: KangPeng Date: Wed, 27 Aug 2025 10:47:14 +0800 Subject: [PATCH 03/10] extra config Signed-off-by: KangPeng --- test/unittest/cpp_test/src/input_method_ability_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unittest/cpp_test/src/input_method_ability_test.cpp b/test/unittest/cpp_test/src/input_method_ability_test.cpp index dc2d0f82f..306bc41b8 100644 --- a/test/unittest/cpp_test/src/input_method_ability_test.cpp +++ b/test/unittest/cpp_test/src/input_method_ability_test.cpp @@ -372,12 +372,12 @@ HWTEST_F(InputMethodAbilityTest, testSerializedInputAttribute_WithSpecificBundle HWTEST_F(InputMethodAbilityTest, testSerializedExtraConfig, TestSize.Level0) { ExtraConfigInner extraConfig; - extraConfig.customSettings.empace("key", true); + extraConfig.customSettings.emplace("key", true); MessageParcel data; EXPECT_TRUE(extraConfig.Marshalling(data)); auto ret = ExtraConfigInner::Unmarshalling(data); EXPECT_NE(ret, nullptr); - EXPECT_EQ(extraConfig.customSettings["key"],ret->extraConfig.customSettings["key"]); + EXPECT_EQ(extraConfig.customSettings["key"],ret->customSettings["key"]); } /** -- Gitee From 491e8aaef870b5eb811cca99e1f3446330711ef0 Mon Sep 17 00:00:00 2001 From: KangPeng Date: Fri, 29 Aug 2025 11:35:14 +0800 Subject: [PATCH 04/10] extra config Signed-off-by: KangPeng --- .../js_text_input_client_engine.cpp | 12 +++++++-- .../js/napi/inputmethodclient/js_utils.cpp | 26 ++++++++++++------- .../js/napi/inputmethodclient/js_utils.h | 2 +- .../kits/extra_config/extra_config_napi.cpp | 3 +-- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp b/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp index e3ae2f2e5..c97f11e22 100644 --- a/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp +++ b/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp @@ -1166,9 +1166,17 @@ bool JsRange::Read(napi_env env, napi_value jsObject, Range &nativeObject) bool JsExtraConfigInfo::Write(napi_env env, napi_value &jsObject, const ExtraConfig &nativeObject) { - auto value = JsUtils::GetJsExtraConfig(env, nativeObject); + napi_value jsExtraConfig = nullptr; + auto status = napi_create_object(env, &jsExtraConfig); + if (status != napi_ok) { + return false; + } + status = JsUtils::GetJsExtraConfig(env, nativeObject, jsExtraConfig); + if (status != napi_ok) { + return false; + } std::string name = "extraConfig"; - return napi_set_named_property(env, jsObject, name.c_str(), value) == napi_ok; + return napi_set_named_property(env, jsObject, name.c_str(), jsExtraConfig) == napi_ok; } bool JsExtraConfigInfo::Read(napi_env env, napi_value jsObject, ExtraConfig &nativeObject) diff --git a/frameworks/js/napi/inputmethodclient/js_utils.cpp b/frameworks/js/napi/inputmethodclient/js_utils.cpp index a14314ac9..b5e8ef80e 100644 --- a/frameworks/js/napi/inputmethodclient/js_utils.cpp +++ b/frameworks/js/napi/inputmethodclient/js_utils.cpp @@ -667,36 +667,42 @@ napi_status JsUtils::GetValue(napi_env env, napi_value in, CustomValueType &out, return status; } -napi_value JsUtils::GetJsExtraConfig(napi_env env, const ExtraConfig &in) +napi_status JsUtils::GetJsExtraConfig(napi_env env, const ExtraConfig &in, napi_value &out) { - napi_value jsExtraConfig = nullptr; napi_value jsObject = nullptr; - NAPI_CALL(env, napi_create_object(env, &jsExtraConfig)); - NAPI_CALL(env, napi_create_object(env, &jsObject)); + CHECK_RETURN(napi_create_object(env, &jsObject) == napi_ok, "create_object error", + napi_generic_failure); for (const auto &iter : in.customSettings) { size_t idx = iter.second.index(); napi_value value = nullptr; if (idx == static_cast(CustomValueTypeValue::CUSTOM_VALUE_TYPE_STRING)) { auto stringValue = std::get_if(&iter.second); if (stringValue != nullptr) { - NAPI_CALL(env, napi_create_string_utf8(env, (*stringValue).c_str(), (*stringValue).size(), &value)); + status = ; + CHECK_RETURN(napi_create_string_utf8(env, (*stringValue).c_str(), (*stringValue).size(), &value) + == napi_ok, "create_string_utf8 error", napi_generic_failure); } } else if (idx == static_cast(CustomValueTypeValue::CUSTOM_VALUE_TYPE_BOOL)) { auto boolValue = std::get_if(&iter.second); if (boolValue != nullptr) { - NAPI_CALL(env, napi_get_boolean(env, *boolValue, &value)); + CHECK_RETURN(napi_get_boolean(env, *boolValue, &value) == napi_ok, + "get_boolean error", napi_generic_failure); } } else if (idx == static_cast(CustomValueTypeValue::CUSTOM_VALUE_TYPE_NUMBER)) { auto numberValue = std::get_if(&iter.second); if (numberValue != nullptr) { - NAPI_CALL(env, napi_create_int32(env, *numberValue, &value)); + status = ; + CHECK_RETURN(napi_create_int32(env, *numberValue, &value) == napi_ok, + "create_int32 error", napi_generic_failure); } } - NAPI_CALL(env, napi_set_named_property(env, jsObject, iter.first.c_str(), value)); + CHECK_RETURN(napi_set_named_property(env, jsObject, iter.first.c_str(), value) == napi_ok, + "set_named_property error", napi_generic_failure); } std::string name = "customSettings"; - napi_set_named_property(env, jsExtraConfig, name.c_str(), jsObject); - return jsExtraConfig; + CHECK_RETURN(napi_set_named_property(env, jsExtraConfig, name.c_str(), jsObject) == napi_ok, + "set_named_property error", napi_generic_failure); + return napi_ok; } } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/napi/inputmethodclient/js_utils.h b/frameworks/js/napi/inputmethodclient/js_utils.h index 494f368d3..e93785de5 100644 --- a/frameworks/js/napi/inputmethodclient/js_utils.h +++ b/frameworks/js/napi/inputmethodclient/js_utils.h @@ -188,7 +188,7 @@ public: static napi_status GetValue(napi_env env, napi_value in, CustomSettings &out, uint32_t maxLen = MAX_EXTRA_CONFIG_SIZE); static napi_status GetValue(napi_env env, napi_value in, CustomValueType &out, uint32_t &valueSize); - static napi_value GetJsExtraConfig(napi_env env, const ExtraConfig &in); + static napi_status GetJsExtraConfig(napi_env env, const ExtraConfig &in, napi_value &out); private: static const std::map ERROR_CODE_MAP; diff --git a/frameworks/kits/extra_config/extra_config_napi.cpp b/frameworks/kits/extra_config/extra_config_napi.cpp index ff67f9dd9..e4eb701de 100644 --- a/frameworks/kits/extra_config/extra_config_napi.cpp +++ b/frameworks/kits/extra_config/extra_config_napi.cpp @@ -21,8 +21,7 @@ namespace MiscServices { napi_status JsExtraConfig::CreateExtraConfig(napi_env env, const ExtraConfig &in, napi_value &out) { - out = JsUtils::GetJsExtraConfig(env, in); - return napi_ok; + return JsUtils::GetJsExtraConfig(env, in, out); } napi_status JsExtraConfig::GetExtraConfig(napi_env env, napi_value in, ExtraConfig &out, uint32_t maxLen) -- Gitee From 81bb2639e7dd7721d441d9b805d0ec562753642d Mon Sep 17 00:00:00 2001 From: KangPeng Date: Fri, 29 Aug 2025 14:51:30 +0800 Subject: [PATCH 05/10] extra config Signed-off-by: KangPeng --- frameworks/js/napi/inputmethodclient/js_utils.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/frameworks/js/napi/inputmethodclient/js_utils.cpp b/frameworks/js/napi/inputmethodclient/js_utils.cpp index b5e8ef80e..942defec1 100644 --- a/frameworks/js/napi/inputmethodclient/js_utils.cpp +++ b/frameworks/js/napi/inputmethodclient/js_utils.cpp @@ -678,7 +678,6 @@ napi_status JsUtils::GetJsExtraConfig(napi_env env, const ExtraConfig &in, napi_ if (idx == static_cast(CustomValueTypeValue::CUSTOM_VALUE_TYPE_STRING)) { auto stringValue = std::get_if(&iter.second); if (stringValue != nullptr) { - status = ; CHECK_RETURN(napi_create_string_utf8(env, (*stringValue).c_str(), (*stringValue).size(), &value) == napi_ok, "create_string_utf8 error", napi_generic_failure); } @@ -691,7 +690,6 @@ napi_status JsUtils::GetJsExtraConfig(napi_env env, const ExtraConfig &in, napi_ } else if (idx == static_cast(CustomValueTypeValue::CUSTOM_VALUE_TYPE_NUMBER)) { auto numberValue = std::get_if(&iter.second); if (numberValue != nullptr) { - status = ; CHECK_RETURN(napi_create_int32(env, *numberValue, &value) == napi_ok, "create_int32 error", napi_generic_failure); } @@ -700,7 +698,7 @@ napi_status JsUtils::GetJsExtraConfig(napi_env env, const ExtraConfig &in, napi_ "set_named_property error", napi_generic_failure); } std::string name = "customSettings"; - CHECK_RETURN(napi_set_named_property(env, jsExtraConfig, name.c_str(), jsObject) == napi_ok, + CHECK_RETURN(napi_set_named_property(env, out, name.c_str(), jsObject) == napi_ok, "set_named_property error", napi_generic_failure); return napi_ok; } -- Gitee From b28474cd5cbb6f047c66fc0ee9e80f1a161fc5c9 Mon Sep 17 00:00:00 2001 From: KangPeng Date: Mon, 1 Sep 2025 19:36:51 +0800 Subject: [PATCH 06/10] extra config Signed-off-by: KangPeng --- .../js_text_input_client_engine.cpp | 8 ++++---- frameworks/js/napi/inputmethodclient/js_utils.cpp | 15 +++++++-------- frameworks/js/napi/inputmethodclient/js_utils.h | 2 +- .../inputmethod_controller/include/extra_config.h | 4 ++-- .../include/input_attribute.h | 4 ++-- interfaces/kits/js/extra_config_napi.h | 2 +- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp b/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp index c97f11e22..81f34e893 100644 --- a/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp +++ b/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp @@ -1183,10 +1183,10 @@ bool JsExtraConfigInfo::Read(napi_env env, napi_value jsObject, ExtraConfig &nat { napi_value value = nullptr; std::string name = "extraConfig"; - napi_get_named_property(env, jsObject, name.c_str(), &value); - auto status = JsUtils::GetValue(env, value, nativeObject); - CHECK_RETURN(status == napi_ok, "ExtraConfig covert failed, type must be Record", - false); + auto status = napi_get_named_property(env, jsObject, name.c_str(), &value); + CHECK_RETURN(status == napi_ok, "ExtraConfig get_named_property", false); + status = JsUtils::GetValue(env, value, nativeObject); + CHECK_RETURN(status == napi_ok, "ExtraConfig covert failed", false); return true; } diff --git a/frameworks/js/napi/inputmethodclient/js_utils.cpp b/frameworks/js/napi/inputmethodclient/js_utils.cpp index 942defec1..a27815d14 100644 --- a/frameworks/js/napi/inputmethodclient/js_utils.cpp +++ b/frameworks/js/napi/inputmethodclient/js_utils.cpp @@ -670,8 +670,7 @@ napi_status JsUtils::GetValue(napi_env env, napi_value in, CustomValueType &out, napi_status JsUtils::GetJsExtraConfig(napi_env env, const ExtraConfig &in, napi_value &out) { napi_value jsObject = nullptr; - CHECK_RETURN(napi_create_object(env, &jsObject) == napi_ok, "create_object error", - napi_generic_failure); + CHECK_RETURN(napi_create_object(env, &jsObject) == napi_ok, "create_object error", napi_generic_failure); for (const auto &iter : in.customSettings) { size_t idx = iter.second.index(); napi_value value = nullptr; @@ -684,22 +683,22 @@ napi_status JsUtils::GetJsExtraConfig(napi_env env, const ExtraConfig &in, napi_ } else if (idx == static_cast(CustomValueTypeValue::CUSTOM_VALUE_TYPE_BOOL)) { auto boolValue = std::get_if(&iter.second); if (boolValue != nullptr) { - CHECK_RETURN(napi_get_boolean(env, *boolValue, &value) == napi_ok, - "get_boolean error", napi_generic_failure); + CHECK_RETURN(napi_get_boolean(env, *boolValue, &value) == napi_ok, "get_boolean error", + napi_generic_failure); } } else if (idx == static_cast(CustomValueTypeValue::CUSTOM_VALUE_TYPE_NUMBER)) { auto numberValue = std::get_if(&iter.second); if (numberValue != nullptr) { - CHECK_RETURN(napi_create_int32(env, *numberValue, &value) == napi_ok, - "create_int32 error", napi_generic_failure); + CHECK_RETURN(napi_create_int32(env, *numberValue, &value) == napi_ok, "create_int32 error", + napi_generic_failure); } } CHECK_RETURN(napi_set_named_property(env, jsObject, iter.first.c_str(), value) == napi_ok, "set_named_property error", napi_generic_failure); } std::string name = "customSettings"; - CHECK_RETURN(napi_set_named_property(env, out, name.c_str(), jsObject) == napi_ok, - "set_named_property error", napi_generic_failure); + CHECK_RETURN(napi_set_named_property(env, out, name.c_str(), jsObject) == napi_ok, "set_named_property error", + napi_generic_failure); return napi_ok; } } // namespace MiscServices diff --git a/frameworks/js/napi/inputmethodclient/js_utils.h b/frameworks/js/napi/inputmethodclient/js_utils.h index e93785de5..adcf21079 100644 --- a/frameworks/js/napi/inputmethodclient/js_utils.h +++ b/frameworks/js/napi/inputmethodclient/js_utils.h @@ -19,6 +19,7 @@ #include #include "ability.h" +#include "extra_config.h" #include "global.h" #include "input_method_panel.h" #include "input_method_utils.h" @@ -28,7 +29,6 @@ #include "napi/native_common.h" #include "napi/native_node_api.h" #include "string_ex.h" -#include "extra_config.h" using Ability = OHOS::AppExecFwk::Ability; namespace OHOS { diff --git a/frameworks/native/inputmethod_controller/include/extra_config.h b/frameworks/native/inputmethod_controller/include/extra_config.h index e9bee33b0..d665ea859 100644 --- a/frameworks/native/inputmethod_controller/include/extra_config.h +++ b/frameworks/native/inputmethod_controller/include/extra_config.h @@ -17,9 +17,9 @@ #define INPUTMETHOD_EXTRA_CONFIG_H #include -#include -#include #include +#include +#include namespace OHOS { namespace MiscServices { diff --git a/frameworks/native/inputmethod_controller/include/input_attribute.h b/frameworks/native/inputmethod_controller/include/input_attribute.h index 5f3f5342e..dfc9e8bac 100644 --- a/frameworks/native/inputmethod_controller/include/input_attribute.h +++ b/frameworks/native/inputmethod_controller/include/input_attribute.h @@ -19,8 +19,8 @@ #include #include -#include "parcel.h" #include "extra_config.h" +#include "parcel.h" namespace OHOS { namespace MiscServices { @@ -69,7 +69,7 @@ struct ExtraConfigInner : public Parcelable { if (customSettings.size() == 0) { return true; } - for (auto& it : customSettings) { + for (auto &it : customSettings) { std::string key = it.first; if (!out.WriteString(key)) { return false; diff --git a/interfaces/kits/js/extra_config_napi.h b/interfaces/kits/js/extra_config_napi.h index 70bcc6ad7..bc8a398d9 100644 --- a/interfaces/kits/js/extra_config_napi.h +++ b/interfaces/kits/js/extra_config_napi.h @@ -16,8 +16,8 @@ #ifndef INTERFACE_JS_EXTRA_CONFIG #define INTERFACE_JS_EXTRA_CONFIG -#include "napi/native_api.h" #include "extra_config.h" +#include "napi/native_api.h" namespace OHOS { namespace MiscServices { -- Gitee From ecb1b0edc9241598c1d356d4c833a7c715d6c30a Mon Sep 17 00:00:00 2001 From: KangPeng Date: Tue, 2 Sep 2025 09:52:04 +0800 Subject: [PATCH 07/10] extra config Signed-off-by: KangPeng --- test/unittest/cpp_test/src/input_method_ability_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/cpp_test/src/input_method_ability_test.cpp b/test/unittest/cpp_test/src/input_method_ability_test.cpp index 306bc41b8..8267a15d5 100644 --- a/test/unittest/cpp_test/src/input_method_ability_test.cpp +++ b/test/unittest/cpp_test/src/input_method_ability_test.cpp @@ -377,7 +377,7 @@ HWTEST_F(InputMethodAbilityTest, testSerializedExtraConfig, TestSize.Level0) EXPECT_TRUE(extraConfig.Marshalling(data)); auto ret = ExtraConfigInner::Unmarshalling(data); EXPECT_NE(ret, nullptr); - EXPECT_EQ(extraConfig.customSettings["key"],ret->customSettings["key"]); + EXPECT_EQ(extraConfig.customSettings["key"], ret->customSettings["key"]); } /** -- Gitee From 2001d4c4e8049e3da528cf375a5745498e02ab38 Mon Sep 17 00:00:00 2001 From: KangPeng Date: Thu, 4 Sep 2025 19:00:12 +0800 Subject: [PATCH 08/10] extra config Signed-off-by: KangPeng --- .../js/napi/inputmethodability/BUILD.gn | 2 + .../js_text_input_client_engine.cpp | 11 +- .../js/napi/inputmethodclient/js_utils.cpp | 120 ----------------- .../js/napi/inputmethodclient/js_utils.h | 6 - .../kits/extra_config/extra_config_napi.cpp | 126 +++++++++++++++++- .../include/extra_config.h | 2 +- .../include/input_attribute.h | 6 +- interfaces/kits/js/extra_config_napi.h | 7 + 8 files changed, 143 insertions(+), 137 deletions(-) diff --git a/frameworks/js/napi/inputmethodability/BUILD.gn b/frameworks/js/napi/inputmethodability/BUILD.gn index 31622c658..afac97554 100644 --- a/frameworks/js/napi/inputmethodability/BUILD.gn +++ b/frameworks/js/napi/inputmethodability/BUILD.gn @@ -23,6 +23,7 @@ config("inputmethodengine_native_config") { "${inputmethod_path}/frameworks/native/inputmethod_ability/include", "${inputmethod_path}/frameworks/native/inputmethod_controller/include", "${inputmethod_path}/interfaces/inner_api/inputmethod_controller/include", + "${inputmethod_path}/interfaces/kits/js", ] ldflags = [ "-Wl,--exclude-libs=ALL" ] cflags_cc = [ @@ -76,6 +77,7 @@ ohos_shared_library("inputmethodengine") { "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:input_control_channel_proxy", "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:inputmethod_ability", "${inputmethod_path}/services/json:imf_json_static", + "${inputmethod_path}/interfaces/kits/js:extra_config_napi", ] external_deps = [ diff --git a/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp b/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp index 81f34e893..b87f6e4ca 100644 --- a/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp +++ b/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp @@ -16,6 +16,7 @@ #include "js_text_input_client_engine.h" #include "event_checker.h" +#include "extra_config_napi.h" #include "input_method_ability.h" #include "inputmethod_trace.h" #include "js_callback_handler.h" @@ -1171,7 +1172,7 @@ bool JsExtraConfigInfo::Write(napi_env env, napi_value &jsObject, const ExtraCon if (status != napi_ok) { return false; } - status = JsUtils::GetJsExtraConfig(env, nativeObject, jsExtraConfig); + status = JsExtraConfig::GetJsExtraConfig(env, nativeObject, jsExtraConfig); if (status != napi_ok) { return false; } @@ -1181,11 +1182,15 @@ bool JsExtraConfigInfo::Write(napi_env env, napi_value &jsObject, const ExtraCon bool JsExtraConfigInfo::Read(napi_env env, napi_value jsObject, ExtraConfig &nativeObject) { + napi_valuetype valueType = napi_undefined; + napi_status status = napi_typeof(env, jsObject, &valueType); + CHECK_RETURN(status != napi_undefined, "napi_typeof error", false); + napi_value value = nullptr; std::string name = "extraConfig"; - auto status = napi_get_named_property(env, jsObject, name.c_str(), &value); + status = napi_get_named_property(env, jsObject, name.c_str(), &value); CHECK_RETURN(status == napi_ok, "ExtraConfig get_named_property", false); - status = JsUtils::GetValue(env, value, nativeObject); + status = JsExtraConfig::GetValue(env, value, nativeObject); CHECK_RETURN(status == napi_ok, "ExtraConfig covert failed", false); return true; } diff --git a/frameworks/js/napi/inputmethodclient/js_utils.cpp b/frameworks/js/napi/inputmethodclient/js_utils.cpp index a27815d14..08c72d745 100644 --- a/frameworks/js/napi/inputmethodclient/js_utils.cpp +++ b/frameworks/js/napi/inputmethodclient/js_utils.cpp @@ -581,125 +581,5 @@ napi_status JsUtils::GetMessageHandlerCallbackParam(napi_value *argv, } return napi_ok; } - -napi_status JsUtils::GetValue(napi_env env, napi_value in, ExtraConfig &out, uint32_t maxLen) -{ - if (maxLen > MAX_EXTRA_CONFIG_SIZE) { - return napi_generic_failure; - } - napi_value propType = nullptr; - napi_status status = napi_get_named_property(env, in, "customSettings", &propType); - CHECK_RETURN((status == napi_ok), "no property customSettings ", status); - return GetValue(env, propType, out.customSettings, maxLen); -} - -napi_status JsUtils::GetValue(napi_env env, napi_value in, CustomSettings &out, uint32_t maxLen) -{ - napi_valuetype type = napi_undefined; - napi_status status = napi_typeof(env, in, &type); - PARAM_CHECK_RETURN(env, type != napi_undefined, "param is undefined.", TYPE_NONE, napi_generic_failure); - - napi_value keys = nullptr; - napi_get_property_names(env, in, &keys); - uint32_t arrLen = 0; - status = napi_get_array_length(env, keys, &arrLen); - if (status != napi_ok) { - IMSA_HILOGE("napi_get_array_length error"); - return status; - } - IMSA_HILOGD("length : %{public}u", arrLen); - uint32_t totalSize = 0; - for (size_t iter = 0; iter < arrLen; ++iter) { - napi_value key = nullptr; - status = napi_get_element(env, keys, iter, &key); - CHECK_RETURN(status == napi_ok, "napi_get_element error", status); - - napi_value value = nullptr; - status = napi_get_property(env, in, key, &value); - CHECK_RETURN(status == napi_ok, "napi_get_property error", status); - - std::string keyStr; - status = GetValue(env, key, keyStr); - CHECK_RETURN(status == napi_ok, "GetValue keyStr error", status); - uint32_t keySize = keyStr.size(); - - CustomValueType customSettingData; - uint32_t valueSize = 0; - status = GetValue(env, value, customSettingData, valueSize); - CHECK_RETURN(status == napi_ok, "GetValue customSettingData error", status); - totalSize = totalSize + keySize + valueSize; - out.emplace(keyStr, customSettingData); - } - if (totalSize > maxLen) { - out.clear(); - IMSA_HILOGE("totalSize : %{public}d", totalSize); - return napi_generic_failure; - } - return status; -} - -napi_status JsUtils::GetValue(napi_env env, napi_value in, CustomValueType &out, uint32_t &valueSize) -{ - napi_valuetype valueType = napi_undefined; - napi_status status = napi_typeof(env, in, &valueType); - CHECK_RETURN(status == napi_ok, "napi_typeof error", napi_generic_failure); - if (valueType == napi_string) { - std::string customSettingStr; - status = GetValue(env, in, customSettingStr); - CHECK_RETURN(status == napi_ok, "GetValue napi_string error", napi_generic_failure); - valueSize = customSettingStr.size(); - out.emplace(customSettingStr); - } else if (valueType == napi_boolean) { - bool customSettingBool = false; - status = GetValue(env, in, customSettingBool); - CHECK_RETURN(status == napi_ok, "GetValue napi_boolean error", napi_generic_failure); - valueSize = sizeof(bool); - out.emplace(customSettingBool); - } else if (valueType == napi_number) { - int32_t customSettingInt = 0; - status = GetValue(env, in, customSettingInt); - CHECK_RETURN(status == napi_ok, "GetValue napi_number error", napi_generic_failure); - valueSize = sizeof(int32_t); - out.emplace(customSettingInt); - } else { - PARAM_CHECK_RETURN(env, false, "value type must be string | boolean | number", TYPE_NONE, napi_generic_failure); - } - return status; -} - -napi_status JsUtils::GetJsExtraConfig(napi_env env, const ExtraConfig &in, napi_value &out) -{ - napi_value jsObject = nullptr; - CHECK_RETURN(napi_create_object(env, &jsObject) == napi_ok, "create_object error", napi_generic_failure); - for (const auto &iter : in.customSettings) { - size_t idx = iter.second.index(); - napi_value value = nullptr; - if (idx == static_cast(CustomValueTypeValue::CUSTOM_VALUE_TYPE_STRING)) { - auto stringValue = std::get_if(&iter.second); - if (stringValue != nullptr) { - CHECK_RETURN(napi_create_string_utf8(env, (*stringValue).c_str(), (*stringValue).size(), &value) - == napi_ok, "create_string_utf8 error", napi_generic_failure); - } - } else if (idx == static_cast(CustomValueTypeValue::CUSTOM_VALUE_TYPE_BOOL)) { - auto boolValue = std::get_if(&iter.second); - if (boolValue != nullptr) { - CHECK_RETURN(napi_get_boolean(env, *boolValue, &value) == napi_ok, "get_boolean error", - napi_generic_failure); - } - } else if (idx == static_cast(CustomValueTypeValue::CUSTOM_VALUE_TYPE_NUMBER)) { - auto numberValue = std::get_if(&iter.second); - if (numberValue != nullptr) { - CHECK_RETURN(napi_create_int32(env, *numberValue, &value) == napi_ok, "create_int32 error", - napi_generic_failure); - } - } - CHECK_RETURN(napi_set_named_property(env, jsObject, iter.first.c_str(), value) == napi_ok, - "set_named_property error", napi_generic_failure); - } - std::string name = "customSettings"; - CHECK_RETURN(napi_set_named_property(env, out, name.c_str(), jsObject) == napi_ok, "set_named_property error", - napi_generic_failure); - return napi_ok; -} } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/napi/inputmethodclient/js_utils.h b/frameworks/js/napi/inputmethodclient/js_utils.h index adcf21079..4de5a3b10 100644 --- a/frameworks/js/napi/inputmethodclient/js_utils.h +++ b/frameworks/js/napi/inputmethodclient/js_utils.h @@ -134,7 +134,6 @@ struct JsPropertyInfo { std::string propertyName; }; -constexpr uint32_t MAX_EXTRA_CONFIG_SIZE = 1024 * 1024; // 1M class JsUtils { public: static void ThrowException(napi_env env, int32_t err, const std::string &msg, TypeCode type); @@ -184,11 +183,6 @@ public: static napi_status GetMessageHandlerCallbackParam(napi_value *argv, const std::shared_ptr &jsMessageHandler, const ArrayBuffer &arrayBuffer, size_t size); - static napi_status GetValue(napi_env env, napi_value in, ExtraConfig &out, uint32_t maxLen = MAX_EXTRA_CONFIG_SIZE); - static napi_status GetValue(napi_env env, napi_value in, CustomSettings &out, - uint32_t maxLen = MAX_EXTRA_CONFIG_SIZE); - static napi_status GetValue(napi_env env, napi_value in, CustomValueType &out, uint32_t &valueSize); - static napi_status GetJsExtraConfig(napi_env env, const ExtraConfig &in, napi_value &out); private: static const std::map ERROR_CODE_MAP; diff --git a/frameworks/kits/extra_config/extra_config_napi.cpp b/frameworks/kits/extra_config/extra_config_napi.cpp index e4eb701de..e5d10f7e8 100644 --- a/frameworks/kits/extra_config/extra_config_napi.cpp +++ b/frameworks/kits/extra_config/extra_config_napi.cpp @@ -18,16 +18,136 @@ namespace OHOS { namespace MiscServices { +napi_status JsExtraConfig::GetValue(napi_env env, napi_value in, ExtraConfig &out, uint32_t maxLen) +{ + if (maxLen > MAX_EXTRA_CONFIG_SIZE) { + return napi_generic_failure; + } + napi_valuetype type = napi_undefined; + napi_status status = napi_typeof(env, in, &type); + CHECK_RETURN(type != napi_undefined, "param is undefined.", napi_generic_failure); + + napi_value propType = nullptr; + status = napi_get_named_property(env, in, "customSettings", &propType); + CHECK_RETURN((status == napi_ok), "no property customSettings ", status); + return GetValue(env, propType, out.customSettings, maxLen); +} + +napi_status JsExtraConfig::GetValue(napi_env env, napi_value in, CustomSettings &out, uint32_t maxLen) +{ + napi_valuetype type = napi_undefined; + napi_status status = napi_typeof(env, in, &type); + CHECK_RETURN(type != napi_undefined, "param is undefined.", napi_generic_failure); + + napi_value keys = nullptr; + napi_get_property_names(env, in, &keys); + uint32_t arrLen = 0; + status = napi_get_array_length(env, keys, &arrLen); + if (status != napi_ok) { + IMSA_HILOGE("napi_get_array_length error"); + return status; + } + IMSA_HILOGD("length : %{public}u", arrLen); + uint32_t totalSize = 0; + for (size_t iter = 0; iter < arrLen; ++iter) { + napi_value key = nullptr; + status = napi_get_element(env, keys, iter, &key); + CHECK_RETURN(status == napi_ok, "napi_get_element error", status); + + napi_value value = nullptr; + status = napi_get_property(env, in, key, &value); + CHECK_RETURN(status == napi_ok, "napi_get_property error", status); + + std::string keyStr; + status = JsUtils::GetValue(env, key, keyStr); + CHECK_RETURN(status == napi_ok, "GetValue keyStr error", status); + uint32_t keySize = keyStr.size(); + + CustomValueType customSettingData; + uint32_t valueSize = 0; + status = GetValue(env, value, customSettingData, valueSize); + CHECK_RETURN(status == napi_ok, "GetValue customSettingData error", status); + totalSize = totalSize + keySize + valueSize; + out.emplace(keyStr, customSettingData); + } + if (totalSize > maxLen) { + out.clear(); + IMSA_HILOGE("totalSize : %{public}d", totalSize); + return napi_generic_failure; + } + return status; +} + +napi_status JsExtraConfig::GetValue(napi_env env, napi_value in, CustomValueType &out, uint32_t &valueSize) +{ + napi_valuetype valueType = napi_undefined; + napi_status status = napi_typeof(env, in, &valueType); + CHECK_RETURN(status == napi_ok, "napi_typeof error", napi_generic_failure); + if (valueType == napi_string) { + std::string customSettingStr; + status = JsUtils::GetValue(env, in, customSettingStr); + CHECK_RETURN(status == napi_ok, "GetValue napi_string error", napi_generic_failure); + valueSize = customSettingStr.size(); + out.emplace(customSettingStr); + } else if (valueType == napi_boolean) { + bool customSettingBool = false; + status = JsUtils::GetValue(env, in, customSettingBool); + CHECK_RETURN(status == napi_ok, "GetValue napi_boolean error", napi_generic_failure); + valueSize = sizeof(bool); + out.emplace(customSettingBool); + } else if (valueType == napi_number) { + int32_t customSettingInt = 0; + status = JsUtils::GetValue(env, in, customSettingInt); + CHECK_RETURN(status == napi_ok, "GetValue napi_number error", napi_generic_failure); + valueSize = sizeof(int32_t); + out.emplace(customSettingInt); + } else { + CHECK_RETURN(false, "value type must be string | boolean | number", napi_generic_failure); + } + return status; +} + +napi_status JsExtraConfig::GetJsExtraConfig(napi_env env, const ExtraConfig &in, napi_value &out) +{ + napi_value jsObject = nullptr; + CHECK_RETURN(napi_create_object(env, &jsObject) == napi_ok, "create_object error", napi_generic_failure); + for (const auto &iter : in.customSettings) { + size_t idx = iter.second.index(); + napi_value value = nullptr; + if (idx == static_cast(CustomValueTypeValue::CUSTOM_VALUE_TYPE_STRING)) { + auto stringValue = std::get_if(&iter.second); + CHECK_RETURN(stringValue != nullptr, "stringValue is nullptr", napi_generic_failure); + CHECK_RETURN(napi_create_string_utf8(env, (*stringValue).c_str(), (*stringValue).size(), &value) + == napi_ok, "create_string_utf8 error", napi_generic_failure); + } else if (idx == static_cast(CustomValueTypeValue::CUSTOM_VALUE_TYPE_BOOL)) { + auto boolValue = std::get_if(&iter.second); + CHECK_RETURN(boolValue != nullptr, "boolValue is nullptr", napi_generic_failure); + CHECK_RETURN(napi_get_boolean(env, *boolValue, &value) == napi_ok, "get_boolean error", + napi_generic_failure); + } else if (idx == static_cast(CustomValueTypeValue::CUSTOM_VALUE_TYPE_NUMBER)) { + auto numberValue = std::get_if(&iter.second); + CHECK_RETURN(numberValue != nullptr, "numberValue is nullptr", napi_generic_failure); + CHECK_RETURN(napi_create_int32(env, *numberValue, &value) == napi_ok, "create_int32 error", + napi_generic_failure); + } + CHECK_RETURN(napi_set_named_property(env, jsObject, iter.first.c_str(), value) == napi_ok, + "set_named_property error", napi_generic_failure); + } + std::string name = "customSettings"; + CHECK_RETURN(napi_set_named_property(env, out, name.c_str(), jsObject) == napi_ok, "set_named_property error", + napi_generic_failure); + return napi_ok; +} napi_status JsExtraConfig::CreateExtraConfig(napi_env env, const ExtraConfig &in, napi_value &out) { - return JsUtils::GetJsExtraConfig(env, in, out); + return GetJsExtraConfig(env, in, out); } napi_status JsExtraConfig::GetExtraConfig(napi_env env, napi_value in, ExtraConfig &out, uint32_t maxLen) { - auto status = JsUtils::GetValue(env, in, out, maxLen); - CHECK_RETURN(status == napi_ok, "ExtraConfig convert failed", napi_generic_failure); + auto status = GetValue(env, in, out, maxLen); + CHECK_RETURN(status == napi_ok, "ExtraConfig convert failed", status); return napi_ok; } } // namespace MiscServices diff --git a/frameworks/native/inputmethod_controller/include/extra_config.h b/frameworks/native/inputmethod_controller/include/extra_config.h index d665ea859..3d47f0f01 100644 --- a/frameworks/native/inputmethod_controller/include/extra_config.h +++ b/frameworks/native/inputmethod_controller/include/extra_config.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-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/frameworks/native/inputmethod_controller/include/input_attribute.h b/frameworks/native/inputmethod_controller/include/input_attribute.h index dfc9e8bac..45f3b59d5 100644 --- a/frameworks/native/inputmethod_controller/include/input_attribute.h +++ b/frameworks/native/inputmethod_controller/include/input_attribute.h @@ -159,8 +159,7 @@ struct InputAttribute { bool operator==(const InputAttribute &info) const { return inputPattern == info.inputPattern && enterKeyType == info.enterKeyType && - inputOption == info.inputOption && isTextPreviewSupported == info.isTextPreviewSupported && - extraConfig == info.extraConfig; + inputOption == info.inputOption && isTextPreviewSupported == info.isTextPreviewSupported; } inline std::string ToString() const @@ -279,8 +278,7 @@ struct InputAttributeInner : public Parcelable { bool operator==(const InputAttributeInner &info) const { return inputPattern == info.inputPattern && enterKeyType == info.enterKeyType && - inputOption == info.inputOption && isTextPreviewSupported == info.isTextPreviewSupported && - extraConfig == info.extraConfig; + inputOption == info.inputOption && isTextPreviewSupported == info.isTextPreviewSupported; } bool GetSecurityFlag() const diff --git a/interfaces/kits/js/extra_config_napi.h b/interfaces/kits/js/extra_config_napi.h index bc8a398d9..cd6064802 100644 --- a/interfaces/kits/js/extra_config_napi.h +++ b/interfaces/kits/js/extra_config_napi.h @@ -22,10 +22,17 @@ namespace OHOS { namespace MiscServices { constexpr uint32_t DEFAULT_MAX_EXTRA_CONFIG_SIZE = 128 * 1024; // 128K +constexpr uint32_t MAX_EXTRA_CONFIG_SIZE = 1024 * 1024; // 1M + class JsExtraConfig { public: JsExtraConfig() = default; ~JsExtraConfig() = default; + static napi_status GetValue(napi_env env, napi_value in, ExtraConfig &out, uint32_t maxLen = MAX_EXTRA_CONFIG_SIZE); + static napi_status GetValue(napi_env env, napi_value in, CustomSettings &out, + uint32_t maxLen = MAX_EXTRA_CONFIG_SIZE); + static napi_status GetValue(napi_env env, napi_value in, CustomValueType &out, uint32_t &valueSize); + static napi_status GetJsExtraConfig(napi_env env, const ExtraConfig &in, napi_value &out); static napi_status CreateExtraConfig(napi_env env, const ExtraConfig &in, napi_value &out); static napi_status GetExtraConfig(napi_env env, napi_value in, ExtraConfig &out, uint32_t maxLen = DEFAULT_MAX_EXTRA_CONFIG_SIZE); -- Gitee From f83b4d815b1eb1784ad40078b94d31455c2e2a95 Mon Sep 17 00:00:00 2001 From: KangPeng Date: Thu, 4 Sep 2025 19:04:24 +0800 Subject: [PATCH 09/10] extra config Signed-off-by: KangPeng --- .../inputmethod_controller/include/input_attribute.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/frameworks/native/inputmethod_controller/include/input_attribute.h b/frameworks/native/inputmethod_controller/include/input_attribute.h index 45f3b59d5..653ef16c6 100644 --- a/frameworks/native/inputmethod_controller/include/input_attribute.h +++ b/frameworks/native/inputmethod_controller/include/input_attribute.h @@ -35,13 +35,12 @@ struct ExtraConfigInner : public Parcelable { CustomSettings customSettings = {}; bool ReadFromParcel(Parcel &in) { - uint32_t size = 0; - size = in.ReadUint32(); - - customSettings.clear(); + uint32_t size = in.ReadUint32(); if (size == 0) { return true; } + customSettings.clear(); + for (uint32_t index = 0; index < size; index++) { std::string key = in.ReadString(); int32_t valueType = in.ReadInt32(); -- Gitee From 5a3fa30321842f08908c31840e6e2e74c29674d6 Mon Sep 17 00:00:00 2001 From: KangPeng Date: Thu, 4 Sep 2025 19:37:15 +0800 Subject: [PATCH 10/10] extra config Signed-off-by: KangPeng --- .../js/napi/inputmethodability/js_text_input_client_engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp b/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp index b87f6e4ca..5d193c444 100644 --- a/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp +++ b/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp @@ -1184,7 +1184,7 @@ bool JsExtraConfigInfo::Read(napi_env env, napi_value jsObject, ExtraConfig &nat { napi_valuetype valueType = napi_undefined; napi_status status = napi_typeof(env, jsObject, &valueType); - CHECK_RETURN(status != napi_undefined, "napi_typeof error", false); + CHECK_RETURN(valueType != napi_undefined, "napi_typeof error", false); napi_value value = nullptr; std::string name = "extraConfig"; -- Gitee