From a86b17da4ee7d6e9a4a29a308e17444daf4d70f4 Mon Sep 17 00:00:00 2001 From: mmorozov Date: Thu, 24 Apr 2025 11:04:32 +0300 Subject: [PATCH] Add new array API Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/IBX9UI?from=project-issue Signed-off-by: mmorozov --- .../src/ani_common_start_options.cpp | 10 +++++----- .../ani/ani_common/src/ani_common_util.cpp | 2 +- .../app_manager/src/ets_app_manager_utils.cpp | 2 +- .../ets/ani/wantagent/src/ani_want_agent.cpp | 19 +++++++------------ 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/frameworks/ets/ani/ani_common/src/ani_common_start_options.cpp b/frameworks/ets/ani/ani_common/src/ani_common_start_options.cpp index f7138f6996c..d97d0e919fa 100644 --- a/frameworks/ets/ani/ani_common/src/ani_common_start_options.cpp +++ b/frameworks/ets/ani/ani_common/src/ani_common_start_options.cpp @@ -111,7 +111,7 @@ bool SetSupportWindowModes(ani_env *env, ani_object param, AAFwk::StartOptions & ani_ref supportWindowModesRef = nullptr; ani_boolean hasValue = true; if (GetPropertyRef(env, param, "supportWindowModes", supportWindowModesRef, hasValue) && !hasValue) { - ani_array_ref supportWindowModesArr = reinterpret_cast(supportWindowModesRef); + ani_array supportWindowModesArr = reinterpret_cast(supportWindowModesRef); ani_size supportWindowModesLen = 0; if (env->Array_GetLength(supportWindowModesArr, &supportWindowModesLen) != ANI_OK) { TAG_LOGE(AAFwkTag::ANI, "Array_GetLength failed"); @@ -120,8 +120,8 @@ bool SetSupportWindowModes(ani_env *env, ani_object param, AAFwk::StartOptions & for (size_t i = 0; i < supportWindowModesLen; ++i) { ani_ref supportWindowModeRef = nullptr; int32_t supportWindowMode = 0; - if (env->Array_Get_Ref(supportWindowModesArr, i, &supportWindowModeRef) != ANI_OK) { - TAG_LOGE(AAFwkTag::ANI, "Array_Get_Ref failed"); + if (env->Array_Get(supportWindowModesArr, i, &supportWindowModeRef) != ANI_OK) { + TAG_LOGE(AAFwkTag::JSNAPI, "Array_Get failed"); return false; } AAFwk::AniEnumConvertUtil::EnumConvert_EtsToNative( @@ -291,5 +291,5 @@ bool UnwrapStartWindowOption(ani_env *env, ani_object param, startWindowOption = option; return true; } -} // namespace AppExecFwk -} // namespace OHOS \ No newline at end of file +} // namespace AppExecFwk +} // namespace OHOS diff --git a/frameworks/ets/ani/ani_common/src/ani_common_util.cpp b/frameworks/ets/ani/ani_common/src/ani_common_util.cpp index b199cdbe31e..a6512fc3b62 100644 --- a/frameworks/ets/ani/ani_common/src/ani_common_util.cpp +++ b/frameworks/ets/ani/ani_common/src/ani_common_util.cpp @@ -733,7 +733,7 @@ bool UnwrapArrayString(ani_env *env, const ani_object &arrayObj, std::vectorArray_Get_Ref(reinterpret_cast(arrayObj), idx, &ref)) != ANI_OK) { + if ((status = env->Array_Get(reinterpret_cast(arrayObj), idx, &ref)) != ANI_OK) { TAG_LOGE(AAFwkTag::ANI, "status: %{public}d, index: %{public}zu", status, idx); return false; } diff --git a/frameworks/ets/ani/app_manager/src/ets_app_manager_utils.cpp b/frameworks/ets/ani/app_manager/src/ets_app_manager_utils.cpp index 500fa37d7d7..002cbb337ae 100644 --- a/frameworks/ets/ani/app_manager/src/ets_app_manager_utils.cpp +++ b/frameworks/ets/ani/app_manager/src/ets_app_manager_utils.cpp @@ -662,7 +662,7 @@ bool UnWrapArrayString(ani_env *env, ani_object arrayObj, std::vectorArray_Get_Ref(reinterpret_cast(arrayObj), idx, &ref)) != ANI_OK) { + if ((status = env->Array_Get(reinterpret_cast(arrayObj), idx, &ref)) != ANI_OK) { TAG_LOGE(AAFwkTag::APPMGR, "status : %{public}d, index: %{public}zu", status, idx); return false; } diff --git a/frameworks/ets/ani/wantagent/src/ani_want_agent.cpp b/frameworks/ets/ani/wantagent/src/ani_want_agent.cpp index 2a106a584d4..eb5de1e7469 100644 --- a/frameworks/ets/ani/wantagent/src/ani_want_agent.cpp +++ b/frameworks/ets/ani/wantagent/src/ani_want_agent.cpp @@ -373,7 +373,7 @@ int32_t EtsWantAgent::GetWantAgentParam(ani_env *env, ani_object info, WantAgent TAG_LOGE(AAFwkTag::WANTAGENT, "wants GetProperty status: %{public}d, or null wantsRef", status); return PARAMETER_ERROR; } - ani_array_ref wantsArr = reinterpret_cast(wantsRef); + ani_array wantsArr = reinterpret_cast(wantsRef); ani_size length = 0; if ((status = env->Array_GetLength(wantsArr, &length)) != ANI_OK) { TAG_LOGE(AAFwkTag::WANTAGENT, "wants Array_GetLength failed status: %{public}d", status); @@ -381,13 +381,9 @@ int32_t EtsWantAgent::GetWantAgentParam(ani_env *env, ani_object info, WantAgent } for (size_t i = 0; i < length; i++) { ani_ref wantRef = nullptr; - if ((status = env->Array_Get_Ref(wantsArr, i, &wantRef)) != ANI_OK || wantRef == nullptr) { - TAG_LOGE(AAFwkTag::WANTAGENT, "Array_Get_Ref failed status: %{public}d, or null wantRef", status); - return PARAMETER_ERROR; - } std::shared_ptr want = std::make_shared(); - if (!UnwrapWant(env, reinterpret_cast(wantRef), *want)) { - TAG_LOGE(AAFwkTag::WANTAGENT, "UnwrapWant failed"); + if ((status = env->Array_Get(wantsArr, i, &wantRef)) != ANI_OK) { + TAG_LOGE(AAFwkTag::WANTAGENT, "Array_Get failed status : %{public}d", status); return PARAMETER_ERROR; } params.wants.emplace_back(want); @@ -416,8 +412,8 @@ int32_t EtsWantAgent::GetWantAgentParam(ani_env *env, ani_object info, WantAgent TAG_LOGE(AAFwkTag::WANTAGENT, "actionFlags GetPropertyRef failed"); return PARAMETER_ERROR; } + ani_array actionFlagsArr = reinterpret_cast(actionFlagsRef); if (!isUndefined) { - ani_array_ref actionFlagsArr = reinterpret_cast(actionFlagsRef); ani_size actionFlagsLen = 0; if ((status = env->Array_GetLength(actionFlagsArr, &actionFlagsLen)) != ANI_OK) { TAG_LOGE(AAFwkTag::WANTAGENT, "Array_GetLength failed status: %{public}d", status); @@ -425,12 +421,11 @@ int32_t EtsWantAgent::GetWantAgentParam(ani_env *env, ani_object info, WantAgent } for (size_t i = 0; i < actionFlagsLen; i++) { ani_ref actionFlagRef = nullptr; - if ((status = env->Array_Get_Ref(actionFlagsArr, i, &actionFlagRef)) != ANI_OK || - actionFlagRef == nullptr) { - TAG_LOGE(AAFwkTag::WANTAGENT, "Array_Get_Ref failed status: %{public}d, or null actionFlagRef", status); + int32_t actionFlag = 0; + if ((status = env->Array_Get(actionFlagsArr, i, &actionFlagRef)) != ANI_OK) { + TAG_LOGE(AAFwkTag::WANTAGENT, "Array_Get failed status: %{public}d", status); return PARAMETER_ERROR; } - int32_t actionFlag = 0; AAFwk::AniEnumConvertUtil::EnumConvert_EtsToNative( env, reinterpret_cast(actionFlagRef), actionFlag); params.wantAgentFlags.emplace_back(static_cast(actionFlag)); -- Gitee