fix auto fill

Co-Authored-By: manual
Signed-off-by: zzl12383 <zhengzhuolan@huawei-partners.com>
This commit is contained in:
zzl12383
2026-05-12 12:29:33 +08:00
parent 5994d4789f
commit fcff8f4f75
4 changed files with 62 additions and 59 deletions
@@ -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<int32_t>(ret)));
if (!hasRequest) {
if (!uiContent->CheckNeedAutoSave()) {
TAG_LOGE(AAFwkTag::AUTOFILLMGR, "no need auto save");
return;
}
std::lock_guard<std::mutex> 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<int32_t>(ret)));
return;
}
std::lock_guard<std::mutex> lock(saveMutex_);
saveRequestObject_.emplace(instanceId, saveRequestCallback);
#endif // SUPPORT_GRAPHICS
}
@@ -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<ani_object>(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<ani_object>(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<ani_object>(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<ani_object>(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<ani_object>(aniPageNodeInfo), pageNodeInfo, errorMsg)) {
TAG_LOGE(AAFwkTag::AUTOFILLMGR, "UnwrapPageNodeInfo failed");
return false;
}
viewData.nodes.emplace_back(pageNodeInfo);
AbilityBase::PageNodeInfo pageNodeInfo;
if (!UnwrapPageNodeInfo(env, reinterpret_cast<ani_object>(aniPageNodeInfo), pageNodeInfo, errorMsg)) {
TAG_LOGE(AAFwkTag::AUTOFILLMGR, "UnwrapPageNodeInfo failed");
return false;
}
viewData.nodes.emplace_back(pageNodeInfo);
}
ani_ref aniPageRect = nullptr;
@@ -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);
+1
View File
@@ -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",