diff --git a/frameworks/ets/ani/include/sts_common.h b/frameworks/ets/ani/include/sts_common.h index 21de782989811b85247c5b8d01a257a3952d814f..ff18fecf5a85584b33ff44f99d8fcc4f5dad8782 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 f53f8a254465921971de8b159c6235e6f5b86ced..6c828f89b5bc31e9995d0b05154088e87a8d706d 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 50dbaa6bf80a4b6a399381cc01f3f98d7d01f836..5dc444819863632cda372235fef1791a92d69f91 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 b848fd7364c3c2934e86e33c441a963d1182a545..51c8871779db198cad801b99be0dd2fcdad62fea 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;