From 4816593bd350327ec5ec873a91d0e9289cf019ce Mon Sep 17 00:00:00 2001 From: xuxinjie4 Date: Mon, 10 Mar 2025 22:14:20 +0800 Subject: [PATCH] Fix enum error Signed-off-by: xuxinjie4 --- interfaces/ani/ets/hisysevent_ani.cpp | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/interfaces/ani/ets/hisysevent_ani.cpp b/interfaces/ani/ets/hisysevent_ani.cpp index c007eaf..db78074 100644 --- a/interfaces/ani/ets/hisysevent_ani.cpp +++ b/interfaces/ani/ets/hisysevent_ani.cpp @@ -247,20 +247,10 @@ static void AddParamToEventInfo(ani_env *env, ani_ref element, std::string key, return; } -static ani_status EnumEventTypeGetInt32(ani_env *env, ani_int enumIndex, int32_t &value) +static ani_status EnumEventTypeGetInt32(ani_env *env, ani_enum_item enumTypeRef, int32_t &value) { - ani_enum aniEnum {}; - if (ANI_OK != env->FindEnum(ENUM_NAME_EVENTTYPE.c_str(), &aniEnum)) { - HILOG_ERROR(LOG_CORE, "FindEnum %{public}s Failed", ENUM_NAME_EVENTTYPE.c_str()); - return ANI_ERROR; - } - ani_enum_item enumItem {}; - if (ANI_OK != env->Enum_GetEnumItemByIndex(aniEnum, static_cast(enumIndex), &enumItem)) { - HILOG_ERROR(LOG_CORE, "Enum_GetEnumItemByIndex %{public}d Failed", static_cast(enumIndex)); - return ANI_ERROR; - } ani_int aniInt {}; - if (ANI_OK != env->EnumItem_GetValue_Int(enumItem, &aniInt)) { + if (ANI_OK != env->EnumItem_GetValue_Int(enumTypeRef, &aniInt)) { HILOG_ERROR(LOG_CORE, "EnumItem_GetValue_Int Failed"); return ANI_ERROR; } @@ -415,13 +405,13 @@ static bool ParseSysEventInfo(ani_env *env, ani_object info, HiSysEventInfo& eve return false; } eventInfo.name = ParseStringValue(env, static_cast(nameRef)); - ani_int eventTypeIndex; - if (ANI_OK != env->Object_GetPropertyByName_Int(info, "eventType", &eventTypeIndex)) { - HILOG_ERROR(LOG_CORE, "Object_GetPropertyByName_Int eventType Failed"); + ani_enum_item eventTypeRef; + if (ANI_OK != env->Object_GetPropertyByName_Ref(info, "eventType", &eventTypeRef)) { + HILOG_ERROR(LOG_CORE, "Object_GetPropertyByName_Ref eventType Failed"); return false; } int32_t eventTypeValue; - if (ANI_OK != EnumEventTypeGetInt32(env, eventTypeIndex, eventTypeValue)) { + if (ANI_OK != EnumEventTypeGetInt32(env, eventTypeRef, eventTypeValue)) { HILOG_ERROR(LOG_CORE, "EnumEventTypeGetInt32 Failed"); return false; } -- Gitee