From d23687fe6eae05b8034d2adf9245742a7aa12c2e Mon Sep 17 00:00:00 2001 From: heguokai <275503077@qq.com> Date: Fri, 12 Sep 2025 12:05:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dsubscribe=E4=B8=ADinfo?= =?UTF-8?q?=E4=B8=BA=E5=BF=85=E5=A1=AB=E5=8F=82=E6=95=B0=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98&=E4=BF=AE=E5=A4=8Dbutton=E4=B8=ADid=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= 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 | 1 + frameworks/ets/ani/src/sts_common.cpp | 21 +++++++++++++++++++ frameworks/ets/ani/src/sts_convert_other.cpp | 4 ++-- .../ets/ets/@ohos.notificationSubscribe.ets | 5 +---- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/frameworks/ets/ani/include/sts_common.h b/frameworks/ets/ani/include/sts_common.h index 21de78298..ff18fecf5 100644 --- a/frameworks/ets/ani/include/sts_common.h +++ b/frameworks/ets/ani/include/sts_common.h @@ -76,6 +76,7 @@ void GetPropertyRefValue(ani_env *env, ani_object obj, const char *name, ani_boo bool SetFieldString(ani_env *env, ani_class cls, ani_object &object, const std::string fieldName, const std::string value); bool SetFieldInt(ani_env *env, ani_class cls, ani_object &object, const std::string fieldName, const int32_t value); +bool SetFieldLong(ani_env *env, ani_class cls, ani_object &object, const std::string fieldName, const int64_t value); bool SetOptionalFieldBoolean(ani_env *env, ani_class cls, ani_object &object, const std::string fieldName, bool value); bool SetOptionalFieldDouble(ani_env *env, ani_class cls, ani_object &object, diff --git a/frameworks/ets/ani/src/sts_common.cpp b/frameworks/ets/ani/src/sts_common.cpp index f53f8a254..6c828f89b 100644 --- a/frameworks/ets/ani/src/sts_common.cpp +++ b/frameworks/ets/ani/src/sts_common.cpp @@ -565,6 +565,27 @@ bool SetFieldInt(ani_env *env, ani_class cls, ani_object &object, return true; } +bool SetFieldLong(ani_env *env, ani_class cls, ani_object &object, + const std::string fieldName, const int64_t value) +{ + if (env == nullptr || cls == nullptr || object == nullptr || fieldName.empty()) { + ANS_LOGE("SetFieldLong fail. has nullptr or fieldName is empty"); + return false; + } + ani_field field = nullptr; + ani_status status = env->Class_FindField(cls, fieldName.c_str(), &field); + ANS_LOGD("SetFieldLong fieldName : %{public}s", fieldName.c_str()); + if (status != ANI_OK || field == nullptr) { + ANS_LOGE("Class_FindField fail. status : %{public}d", status); + return false; + } + if ((status = env->Object_SetField_Long(object, field, static_cast(value))) != ANI_OK) { + ANS_LOGE("Object_SetField_Long fail. status : %{public}d", status); + return false; + } + return true; +} + bool SetOptionalFieldBoolean(ani_env *env, ani_class cls, ani_object &object, const std::string fieldName, bool value) { diff --git a/frameworks/ets/ani/src/sts_convert_other.cpp b/frameworks/ets/ani/src/sts_convert_other.cpp index 50dbaa6bf..5dc444819 100644 --- a/frameworks/ets/ani/src/sts_convert_other.cpp +++ b/frameworks/ets/ani/src/sts_convert_other.cpp @@ -395,8 +395,8 @@ ani_object GetAniResource(ani_env *env, const std::shared_ptrid)) { - ANS_LOGE("GetAniResource : set moduleName failed, status = %{public}d", status); + if (!SetFieldLong(env, resourceCls, resourceObject, "id", static_cast(resource->id))) { + ANS_LOGE("GetAniResource : set id failed"); } ANS_LOGD("GetAniResource end"); return resourceObject; diff --git a/frameworks/ets/ets/@ohos.notificationSubscribe.ets b/frameworks/ets/ets/@ohos.notificationSubscribe.ets index b848fd736..51c887177 100644 --- a/frameworks/ets/ets/@ohos.notificationSubscribe.ets +++ b/frameworks/ets/ets/@ohos.notificationSubscribe.ets @@ -54,10 +54,7 @@ function isInvalidParameter(bundle: BundleOption): BusinessError function isInvalidParameter(info?: NotificationSubscribeInfo): boolean { - if (info == null) { - return false; - } - if (info?.deviceType != undefined && info.deviceType?.length === 0) { + if (info != undefined && info?.deviceType != undefined && info?.deviceType?.length === 0) { return false; } return true; -- Gitee