diff --git a/frameworks/ets/ani/include/sts_common.h b/frameworks/ets/ani/include/sts_common.h index 99091c7c082add58035069f5f0496391b3009c53..f6ae24018929866367e52e34a15c5800c36581d2 100644 --- a/frameworks/ets/ani/include/sts_common.h +++ b/frameworks/ets/ani/include/sts_common.h @@ -72,6 +72,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 5e54098a898bcf420b02991c526acbfb319aa286..51b795cd924ebab104271e12048821f89149c4ac 100644 --- a/frameworks/ets/ani/src/sts_common.cpp +++ b/frameworks/ets/ani/src/sts_common.cpp @@ -559,6 +559,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 9452b606d09796a76a587ec03b936435aba5b44c..18ded976d2643406a8b75b0dbe18005c71e4b3f8 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;