From fcff8f4f756d63363b77cf4e9fbcaf089d182d95 Mon Sep 17 00:00:00 2001 From: zzl12383 Date: Tue, 12 May 2026 12:29:33 +0800 Subject: [PATCH] fix auto fill Co-Authored-By: manual Signed-off-by: zzl12383 --- .../src/ets_auto_fill_manager.cpp | 30 +++++----- .../src/ets_auto_fill_manager_util.cpp | 57 +++++++++---------- .../js_auto_fill_manager_util.cpp | 33 +++++------ frameworks/native/ability/BUILD.gn | 1 + 4 files changed, 62 insertions(+), 59 deletions(-) diff --git a/frameworks/ets/ani/auto_fill_manager/src/ets_auto_fill_manager.cpp b/frameworks/ets/ani/auto_fill_manager/src/ets_auto_fill_manager.cpp index 23bd12e938..a5c7749845 100644 --- a/frameworks/ets/ani/auto_fill_manager/src/ets_auto_fill_manager.cpp +++ b/frameworks/ets/ani/auto_fill_manager/src/ets_auto_fill_manager.cpp @@ -106,23 +106,25 @@ void EtsAutoFillManager::OnRequestAutoSaveInner(ani_env *env, int32_t instanceId AbilityRuntime::EtsErrorUtil::ThrowError(env, AbilityRuntime::AbilityErrorCode::ERROR_CODE_INNER); return; } - if (uiContent->CheckNeedAutoSave()) { - if (!hasRequest) { - uiContent->DumpViewData(request.viewData, request.autoFillType); - } - request.autoFillCommand = AbilityRuntime::AutoFill::AutoFillCommand::SAVE; - AbilityRuntime::AutoFill::AutoFillResult result; - auto ret = AbilityRuntime::AutoFillManager::GetInstance().RequestAutoSave(uiContent, request, - saveRequestCallback, result); - if (ret != ERR_OK) { - TAG_LOGE(AAFwkTag::AUTOFILLMGR, "RequestAutoSave error[%{public}d]", ret); - AbilityRuntime::EtsErrorUtil::ThrowError(env, AbilityRuntime::EtsErrorUtil::CreateErrorByNativeErr(env, - static_cast(ret))); + if (!hasRequest) { + if (!uiContent->CheckNeedAutoSave()) { + TAG_LOGE(AAFwkTag::AUTOFILLMGR, "no need auto save"); return; } - std::lock_guard lock(saveMutex_); - saveRequestObject_.emplace(instanceId, saveRequestCallback); + uiContent->DumpViewData(request.viewData, request.autoFillType); } + request.autoFillCommand = AbilityRuntime::AutoFill::AutoFillCommand::SAVE; + AbilityRuntime::AutoFill::AutoFillResult result; + auto ret = AbilityRuntime::AutoFillManager::GetInstance().RequestAutoSave(uiContent, request, + saveRequestCallback, result); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::AUTOFILLMGR, "RequestAutoSave error[%{public}d]", ret); + AbilityRuntime::EtsErrorUtil::ThrowError(env, AbilityRuntime::EtsErrorUtil::CreateErrorByNativeErr(env, + static_cast(ret))); + return; + } + std::lock_guard lock(saveMutex_); + saveRequestObject_.emplace(instanceId, saveRequestCallback); #endif // SUPPORT_GRAPHICS } diff --git a/frameworks/ets/ani/auto_fill_manager/src/ets_auto_fill_manager_util.cpp b/frameworks/ets/ani/auto_fill_manager/src/ets_auto_fill_manager_util.cpp index c7ac6c56f4..24603b5b38 100644 --- a/frameworks/ets/ani/auto_fill_manager/src/ets_auto_fill_manager_util.cpp +++ b/frameworks/ets/ani/auto_fill_manager/src/ets_auto_fill_manager_util.cpp @@ -155,16 +155,15 @@ ani_object WrapViewData(ani_env *env, const AbilityBase::ViewData &viewData) return nullptr; } - ani_object aniPageNodeInfos = nullptr; - if (!CreateArrayObject(env, aniPageNodeInfos, viewData.nodes.size())) { + ani_object aniNodes = nullptr; + if (!CreateArrayObject(env, aniNodes, viewData.nodes.size())) { TAG_LOGE(AAFwkTag::AUTOFILLMGR, "fail to create array object"); return nullptr; } ani_size index = 0; ani_status status = ANI_ERROR; - for (const auto& item : viewData.nodes) { - status = env->Object_CallMethodByName_Void( - aniPageNodeInfos, "$_set", "iY:", index, WrapPageNodeInfo(env, item)); + for (const auto &item : viewData.nodes) { + status = env->Object_CallMethodByName_Void(aniNodes, "$_set", "iY:", index, WrapPageNodeInfo(env, item)); if (status != ANI_OK) { TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Object_CallMethodByName_Void failed: %{public}d", status); return nullptr; @@ -172,7 +171,7 @@ ani_object WrapViewData(ani_env *env, const AbilityBase::ViewData &viewData) ++index; } - if (!SetRefProperty(env, object, PAGE_NODE_INFOS, aniPageNodeInfos)) { + if (!SetRefProperty(env, object, PAGE_NODE_INFOS, aniNodes)) { TAG_LOGE(AAFwkTag::AUTOFILLMGR, "set pageNodeInfos failed"); return nullptr; } @@ -315,32 +314,32 @@ bool UnwrapViewData(ani_env *env, ani_object object, AbilityBase::ViewData &view return false; } - ani_ref aniPageNodeInfos = nullptr; - if (GetRefProperty(env, object, PAGE_NODE_INFOS, aniPageNodeInfos) && aniPageNodeInfos != nullptr) { - ani_int length = 0; - ani_status status = ANI_ERROR; - status = env->Object_GetPropertyByName_Int(reinterpret_cast(aniPageNodeInfos), "length", &length); - if (status != ANI_OK) { - TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Object_GetPropertyByName_Int failed: status: %{public}d", status); + ani_ref aniNodes = nullptr; + if (!GetRefProperty(env, object, PAGE_NODE_INFOS, aniNodes) || aniNodes == nullptr) { + TAG_LOGE(AAFwkTag::AUTOFILLMGR, "parameter error"); + errorMsg = "Parameter error. The type of viewData.pageNodeInfos must be array"; + return false; + } + ani_int length = 0; + ani_status status = env->Object_GetPropertyByName_Int(reinterpret_cast(aniNodes), "length", &length); + if (status != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Object_GetPropertyByName_Int failed: status: %{public}d", status); + return false; + } + viewData.nodes.clear(); + for (int i = 0; i < length; ++i) { + ani_ref aniPageNodeInfo = nullptr; + if ((status = env->Object_CallMethodByName_Ref(reinterpret_cast(aniNodes), + "$_get", "i:Y", &aniPageNodeInfo, (ani_int)i)) != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Object_CallMethodByName_Ref failed: status: %{public}d", status); return false; } - viewData.nodes.clear(); - for (int i = 0; i < length; ++i) { - ani_ref aniPageNodeInfo; - status = env->Object_CallMethodByName_Ref(reinterpret_cast(aniPageNodeInfos), - "$_get", "i:Y", &aniPageNodeInfo, (ani_int)i); - if (status != ANI_OK) { - TAG_LOGE(AAFwkTag::AUTOFILLMGR, - "Object_CallMethodByName_Ref failed: status: %{public}d, index: %{public}d", status, i); - return false; - } - AbilityBase::PageNodeInfo pageNodeInfo; - if (!UnwrapPageNodeInfo(env, reinterpret_cast(aniPageNodeInfo), pageNodeInfo, errorMsg)) { - TAG_LOGE(AAFwkTag::AUTOFILLMGR, "UnwrapPageNodeInfo failed"); - return false; - } - viewData.nodes.emplace_back(pageNodeInfo); + AbilityBase::PageNodeInfo pageNodeInfo; + if (!UnwrapPageNodeInfo(env, reinterpret_cast(aniPageNodeInfo), pageNodeInfo, errorMsg)) { + TAG_LOGE(AAFwkTag::AUTOFILLMGR, "UnwrapPageNodeInfo failed"); + return false; } + viewData.nodes.emplace_back(pageNodeInfo); } ani_ref aniPageRect = nullptr; diff --git a/frameworks/js/napi/auto_fill_manager/js_auto_fill_manager_util.cpp b/frameworks/js/napi/auto_fill_manager/js_auto_fill_manager_util.cpp index dddc5b0569..41334e3641 100644 --- a/frameworks/js/napi/auto_fill_manager/js_auto_fill_manager_util.cpp +++ b/frameworks/js/napi/auto_fill_manager/js_auto_fill_manager_util.cpp @@ -130,7 +130,7 @@ napi_value WrapViewData(const napi_env env, const AbilityBase::ViewData &viewDat napi_value jsArray = nullptr; NAPI_CALL(env, napi_create_array(env, &jsArray)); uint32_t index = 0; - for (auto element : viewData.nodes) { + for (const auto &element : viewData.nodes) { napi_value jsSubValue = WrapPageNodeInfo(env, element); if (jsSubValue != nullptr && napi_set_element(env, jsArray, index, jsSubValue) == napi_ok) { ++index; @@ -273,24 +273,25 @@ bool UnwrapViewData(napi_env env, napi_value jsValue, AbilityBase::ViewData &vie } napi_value jsPageNodeInfos = GetPropertyValueByPropertyName(env, jsValue, PAGE_NODE_INFOS, napi_object); - if (jsPageNodeInfos != nullptr) { - uint32_t arraySize = 0; - if (!IsArrayForNapiValue(env, jsPageNodeInfos, arraySize)) { + uint32_t arraySize = 0; + if (jsPageNodeInfos == nullptr || !IsArrayForNapiValue(env, jsPageNodeInfos, arraySize)) { + TAG_LOGE(AAFwkTag::AUTOFILLMGR, "parameter error"); + errorMsg = "Parameter error. The type of viewData.pageNodeInfos must be array"; + return false; + } + viewData.nodes.clear(); + for (uint32_t i = 0; i < arraySize; ++i) { + napi_value jsPageNodeInfo = nullptr; + if (napi_get_element(env, jsPageNodeInfos, i, &jsPageNodeInfo) != napi_ok) { + TAG_LOGE(AAFwkTag::AUTOFILLMGR, "napi_get_element failed"); return false; } - viewData.nodes.clear(); - for (uint32_t i = 0; i < arraySize; ++i) { - napi_value jsPageNodeInfo = nullptr; - if (napi_get_element(env, jsPageNodeInfos, i, &jsPageNodeInfo) != napi_ok) { - return false; - } - AbilityBase::PageNodeInfo pageNodeInfo; - if (!UnwrapPageNodeInfo(env, jsPageNodeInfo, pageNodeInfo, errorMsg)) { - TAG_LOGE(AAFwkTag::AUTOFILLMGR, "UnwrapPageNodeInfo failed"); - return false; - } - viewData.nodes.emplace_back(pageNodeInfo); + AbilityBase::PageNodeInfo pageNodeInfo; + if (!UnwrapPageNodeInfo(env, jsPageNodeInfo, pageNodeInfo, errorMsg)) { + TAG_LOGE(AAFwkTag::AUTOFILLMGR, "UnwrapPageNodeInfo failed"); + return false; } + viewData.nodes.emplace_back(pageNodeInfo); } napi_value jsPageRect = GetPropertyValueByPropertyName(env, jsValue, PAGE_RECT, napi_object); diff --git a/frameworks/native/ability/BUILD.gn b/frameworks/native/ability/BUILD.gn index 77a438d22b..dba36b0df4 100644 --- a/frameworks/native/ability/BUILD.gn +++ b/frameworks/native/ability/BUILD.gn @@ -166,6 +166,7 @@ ohos_shared_library("cj_ability_context_native") { "faultloggerd:libdfx_dumpcatcher", "hilog:libhilog", "hitrace:hitrace_meter", + "icu:shared_icuuc", "image_framework:image_native", "ipc:ipc_single", "napi:cj_bind_ffi",