From f6218b6cadf39c496e8a1d32e52011a0e06b9e3a Mon Sep 17 00:00:00 2001 From: heguokai <275503077@qq.com> Date: Fri, 5 Sep 2025 17:55:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0NotificationButton?= =?UTF-8?q?=E4=B8=AD=E6=8C=89=E9=92=AE=E6=95=B0=E9=87=8F=E7=9A=84=E9=99=90?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: heguokai <275503077@qq.com> --- frameworks/ets/ani/include/sts_common.h | 2 +- .../ets/ani/include/sts_convert_other.h | 9 +++++---- frameworks/ets/ani/src/sts_common.cpp | 6 +++++- frameworks/ets/ani/src/sts_convert_other.cpp | 20 ++++++++++++------- .../ets/ani/src/sts_notification_content.cpp | 11 ++++------ frameworks/ets/ani/src/sts_request.cpp | 10 +++------- frameworks/ets/ani/src/sts_subscribe_info.cpp | 4 +--- 7 files changed, 32 insertions(+), 30 deletions(-) diff --git a/frameworks/ets/ani/include/sts_common.h b/frameworks/ets/ani/include/sts_common.h index 680c3c93c..910401b66 100644 --- a/frameworks/ets/ani/include/sts_common.h +++ b/frameworks/ets/ani/include/sts_common.h @@ -53,7 +53,7 @@ ani_status GetPropertyDouble(ani_env *env, ani_object obj, const char *name, ani_status GetPropertyRef(ani_env *env, ani_object obj, const char *name, ani_boolean &isUndefined, ani_ref &outRef); ani_status GetPropertyStringArray(ani_env *env, ani_object param, const char *name, - ani_boolean &isUndefined, std::vector &res); + std::vector &res, const uint32_t maxLen = 0); ani_status GetPropertyNumberArray(ani_env *env, ani_object param, const char *name, ani_boolean &isUndefined, std::vector &res); diff --git a/frameworks/ets/ani/include/sts_convert_other.h b/frameworks/ets/ani/include/sts_convert_other.h index 39e909f83..45e871186 100644 --- a/frameworks/ets/ani/include/sts_convert_other.h +++ b/frameworks/ets/ani/include/sts_convert_other.h @@ -26,6 +26,7 @@ namespace OHOS { namespace NotificationSts { using namespace OHOS::Media; using namespace OHOS::AbilityRuntime::WantAgent; +const uint32_t BUTTON_RESOURCE_SIZE = 3; std::shared_ptr UnwrapWantAgent(ani_env *env, ani_object agent); ani_object WarpWantAgent(ani_env *env, std::shared_ptr wantAgent); @@ -36,8 +37,8 @@ std::shared_ptr GetPixelMapFromAni(ani_env* env, ani_object obj); // ani_object to vector ani_status GetPixelMapArrayByRef(ani_env *env, ani_ref param, std::vector> &pixelMaps); // ani_object to vector -ani_status GetPixelMapArray(ani_env *env, - ani_object param, const char *name, std::vector> &pixelMaps); +ani_status GetPixelMapArray(ani_env *env, ani_object param, const char *name, + std::vector> &pixelMaps, const uint32_t maxLen); // map ro AniRecord bool GetAniPictrueInfo(ani_env *env, std::map>> pictureMap, ani_object &pictureInfoObj); @@ -48,8 +49,8 @@ ani_status GetMapOfPictureInfo(ani_env *env, ani_object obj, ani_object GetAniArrayPixelMap(ani_env *env, const std::vector> pixelMaps); ani_status UnwrapResource(ani_env *env, ani_object obj, ResourceManager::Resource &resource); -ani_status GetResourceArray(ani_env *env, - ani_object param, const char *name, std::vector &res); +ani_status GetResourceArray(ani_env *env, ani_object param, const char *name, + std::vector &res, const uint32_t maxLen); ani_object GetAniResource(ani_env *env, const std::shared_ptr resource); ani_object GetAniArrayResource(ani_env *env, const std::vector> resources); diff --git a/frameworks/ets/ani/src/sts_common.cpp b/frameworks/ets/ani/src/sts_common.cpp index b07fbe225..8606bd93e 100644 --- a/frameworks/ets/ani/src/sts_common.cpp +++ b/frameworks/ets/ani/src/sts_common.cpp @@ -238,7 +238,7 @@ ani_status GetPropertyRef(ani_env *env, ani_object obj, const char *name, ani_bo } ani_status GetPropertyStringArray(ani_env *env, ani_object param, const char *name, - ani_boolean &isUndefined, std::vector &res) + std::vector &res, const uint32_t maxLen) { if (env == nullptr || param == nullptr || name == nullptr) { ANS_LOGE("GetPropertyStringArray fail, has nullptr"); @@ -248,6 +248,7 @@ ani_status GetPropertyStringArray(ani_env *env, ani_object param, const char *na ani_ref arrayObj = nullptr; ani_status status; ani_double length; + ani_boolean isUndefined = ANI_FALSE; if ((status = GetPropertyRef(env, param, name, isUndefined, arrayObj)) != ANI_OK || isUndefined == ANI_TRUE) { ANS_LOGE("GetPropertyRef fail, status = %{public}d, isUndefind = %{public}d", status, isUndefined); return ANI_INVALID_ARGS; @@ -257,6 +258,9 @@ ani_status GetPropertyStringArray(ani_env *env, ani_object param, const char *na ANS_LOGE("status : %{public}d", status); return status; } + if (maxLen > 0 && length > maxLen) { + length = static_cast(maxLen); + } std::string str = ""; for (int i = 0; i < static_cast(length); i++) { ani_ref stringEntryRef; diff --git a/frameworks/ets/ani/src/sts_convert_other.cpp b/frameworks/ets/ani/src/sts_convert_other.cpp index 29c205265..999796612 100644 --- a/frameworks/ets/ani/src/sts_convert_other.cpp +++ b/frameworks/ets/ani/src/sts_convert_other.cpp @@ -97,7 +97,8 @@ std::shared_ptr GetPixelMapFromAni(ani_env* env, ani_object obj) return PixelMapTaiheAni::GetNativePixelMap(env, obj); } -ani_status GetPixelMapArrayByRef(ani_env *env, ani_ref param, std::vector> &pixelMaps) +ani_status GetPixelMapArrayByRef(ani_env *env, ani_ref param, + std::vector> &pixelMaps, const uint32_t maxLen) { ANS_LOGD("GetPixelMapArrayByRef call"); if (env == nullptr || param == nullptr) { @@ -111,7 +112,9 @@ ani_status GetPixelMapArrayByRef(ani_env *env, ani_ref param, std::vector 0 && length > maxLen) { + length = static_cast(maxLen); + } for (int i = 0; i < static_cast(length); i++) { ani_ref pixelMapRef; status = env->Object_CallMethodByName_Ref(static_cast(param), @@ -133,8 +136,8 @@ ani_status GetPixelMapArrayByRef(ani_env *env, ani_ref param, std::vector> &pixelMaps) +ani_status GetPixelMapArray(ani_env *env, ani_object param, const char *name, + std::vector> &pixelMaps, const uint32_t maxLen) { ANS_LOGD("GetPixelMapArray call"); if (env == nullptr || param == nullptr || name == nullptr) { @@ -148,7 +151,7 @@ ani_status GetPixelMapArray(ani_env *env, return ANI_INVALID_ARGS; } - if ((status = GetPixelMapArrayByRef(env, arrayObj, pixelMaps)) != ANI_OK) { + if ((status = GetPixelMapArrayByRef(env, arrayObj, pixelMaps, maxLen)) != ANI_OK) { pixelMaps.clear(); return status; } @@ -156,8 +159,8 @@ ani_status GetPixelMapArray(ani_env *env, return status; } -ani_status GetResourceArray(ani_env *env, - ani_object param, const char *name, std::vector &res) +ani_status GetResourceArray(ani_env *env, ani_object param, const char *name, + std::vector &res, const uint32_t maxLen) { ANS_LOGD("GetResourceArray call"); if (env == nullptr || param == nullptr || name == nullptr) { @@ -177,6 +180,9 @@ ani_status GetResourceArray(ani_env *env, ANS_LOGE("GetResourceArray : status : %{public}d", status); return status; } + if (length > maxLen) { + length = static_cast(maxLen); + } for (int i = 0; i < static_cast(length); i++) { ani_ref iconRef; status = env->Object_CallMethodByName_Ref(static_cast(arrayObj), diff --git a/frameworks/ets/ani/src/sts_notification_content.cpp b/frameworks/ets/ani/src/sts_notification_content.cpp index 52abe95ed..b4093bc9b 100644 --- a/frameworks/ets/ani/src/sts_notification_content.cpp +++ b/frameworks/ets/ani/src/sts_notification_content.cpp @@ -359,9 +359,8 @@ void UnWarpNotificationLocalLiveViewButton(ani_env *env, ani_object obj, return; } std::vector names = {}; - ani_boolean isUndefined = ANI_TRUE; // names?: Array - if (GetPropertyStringArray(env, obj, "names", isUndefined, names) == ANI_OK && isUndefined == ANI_FALSE) { + if (GetPropertyStringArray(env, obj, "names", names, BUTTON_RESOURCE_SIZE) == ANI_OK) { for (auto name: names) { button.addSingleButtonName(GetResizeStr(name, STR_MAX_SIZE)); } @@ -370,7 +369,7 @@ void UnWarpNotificationLocalLiveViewButton(ani_env *env, ani_object obj, } // icons?: Array std::vector> icons = {}; - if (ANI_OK == GetPixelMapArray(env, obj, "icons", icons)) { + if (ANI_OK == GetPixelMapArray(env, obj, "icons", icons, BUTTON_RESOURCE_SIZE)) { for (auto icon : icons) { button.addSingleButtonIcon(icon); } @@ -379,7 +378,7 @@ void UnWarpNotificationLocalLiveViewButton(ani_env *env, ani_object obj, } // iconsResource?: Array std::vector resources = {}; - if (ANI_OK == GetResourceArray(env, obj, "iconsResource", resources)) { + if (ANI_OK == GetResourceArray(env, obj, "iconsResource", resources, BUTTON_RESOURCE_SIZE)) { for (auto res : resources) { std::shared_ptr pRes = std::make_shared(res); button.addSingleButtonIconResource(pRes); @@ -825,9 +824,7 @@ ani_status UnWarpNotificationMultiLineContent(ani_env *env, ani_object obj, multiLineContent->SetBriefText(GetResizeStr(briefText, SHORT_TEXT_SIZE)); std::vector lines = {}; - isUndefined = ANI_TRUE; - if ((status = GetPropertyStringArray(env, obj, "lines", isUndefined, lines)) != ANI_OK - || isUndefined == ANI_TRUE) { + if ((status = GetPropertyStringArray(env, obj, "lines", lines)) != ANI_OK) { ANS_LOGE("UnWarpNotificationMultiLineContent: get lines failed"); return ANI_INVALID_ARGS; } diff --git a/frameworks/ets/ani/src/sts_request.cpp b/frameworks/ets/ani/src/sts_request.cpp index a02288d3b..5f8de29c8 100644 --- a/frameworks/ets/ani/src/sts_request.cpp +++ b/frameworks/ets/ani/src/sts_request.cpp @@ -51,9 +51,7 @@ void UnWarpDistributedOptions(ani_env *env, ani_object obj, StsDistributedOption } // supportDisplayDevices?: Array; std::vector tempStrings = {}; - isUndefined = ANI_TRUE; - if (GetPropertyStringArray(env, obj, "supportDisplayDevices", isUndefined, tempStrings) == ANI_OK - && isUndefined == ANI_FALSE) { + if (GetPropertyStringArray(env, obj, "supportDisplayDevices", tempStrings) == ANI_OK) { std::vector supportDisplayDevices = {}; for (auto device: tempStrings) { supportDisplayDevices.emplace_back(GetResizeStr(device, STR_MAX_SIZE)); @@ -64,9 +62,7 @@ void UnWarpDistributedOptions(ani_env *env, ani_object obj, StsDistributedOption } // supportOperateDevices?: Array; tempStrings.clear(); - isUndefined = ANI_TRUE; - if (GetPropertyStringArray(env, obj, "supportOperateDevices", isUndefined, tempStrings) == ANI_OK - && isUndefined == ANI_FALSE) { + if (GetPropertyStringArray(env, obj, "supportOperateDevices", tempStrings) == ANI_OK) { std::vector supportOperateDevices = {}; for (auto device: tempStrings) { supportOperateDevices.emplace_back(GetResizeStr(device, STR_MAX_SIZE)); @@ -1346,7 +1342,7 @@ bool UnWarpNotificationFilter(ani_env *env, ani_object obj, LiveViewFilter& filt ANS_LOGD("UnWarpNotificationFilter:UnWarpNotificationKey label is undefined"); } - if (ANI_OK != (status = GetPropertyStringArray(env, obj, "extraInfoKeys", isUndefined, filter.extraInfoKeys))) { + if (ANI_OK != (status = GetPropertyStringArray(env, obj, "extraInfoKeys", filter.extraInfoKeys))) { ANS_LOGD("UnWarpNotificationFilter:get extraInfoKeysObj failed. status %{public}d", status); } return true; diff --git a/frameworks/ets/ani/src/sts_subscribe_info.cpp b/frameworks/ets/ani/src/sts_subscribe_info.cpp index 9b1dd67a2..269b6f6b2 100644 --- a/frameworks/ets/ani/src/sts_subscribe_info.cpp +++ b/frameworks/ets/ani/src/sts_subscribe_info.cpp @@ -31,9 +31,7 @@ bool UnwarpNotificationSubscribeInfo(ani_env *env, ani_object value, Notificatio ani_double filterLimit = 0.0; std::string deviceType; ani_boolean isUndefined = ANI_TRUE; - if (ANI_OK != GetPropertyStringArray(env, value, "bundleNames", isUndefined, res) - || isUndefined == ANI_TRUE - || res.empty()) { + if (ANI_OK != GetPropertyStringArray(env, value, "bundleNames", res) || res.empty()) { ANS_LOGE("UnWarpStringArrayOrUndefinedByProperty faild"); } std::vector bundleNames = {}; -- Gitee From 5cf544ccf6c1966758be91191b9bf8cc9c6e506b Mon Sep 17 00:00:00 2001 From: heguokai Date: Fri, 5 Sep 2025 12:59:12 +0000 Subject: [PATCH 2/2] update frameworks/ets/ani/include/sts_convert_other.h. Signed-off-by: heguokai --- frameworks/ets/ani/include/sts_convert_other.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frameworks/ets/ani/include/sts_convert_other.h b/frameworks/ets/ani/include/sts_convert_other.h index 45e871186..13bfe6c56 100644 --- a/frameworks/ets/ani/include/sts_convert_other.h +++ b/frameworks/ets/ani/include/sts_convert_other.h @@ -35,7 +35,8 @@ ani_object GetAniWantAgentArray(ani_env *env, std::vector pixelMap); std::shared_ptr GetPixelMapFromAni(ani_env* env, ani_object obj); // ani_object to vector -ani_status GetPixelMapArrayByRef(ani_env *env, ani_ref param, std::vector> &pixelMaps); +ani_status GetPixelMapArrayByRef(ani_env *env, ani_ref param, + std::vector> &pixelMaps, const uint32_t maxLen = 0); // ani_object to vector ani_status GetPixelMapArray(ani_env *env, ani_object param, const char *name, std::vector> &pixelMaps, const uint32_t maxLen); -- Gitee