From bd3331cd273d231d033380e9981c45a7e412842b Mon Sep 17 00:00:00 2001 From: Otto Eotvos Date: Mon, 26 May 2025 14:20:17 +0200 Subject: [PATCH] Update hardcoded names affected by name mangling Issue: https://gitee.com/openharmony/notification_common_event_service/issues/ICR1Q9 Description: Swap hard-coded names to API calls when interacting with ANI. Change-Id: I19d9c83e2f4b8f28c1e876d10c7b44713fe01b66 Signed-off-by: Otto Eotvos --- .../src/ani/ani_common_event_utils.cpp | 17 ++++++----- .../src/ani_common_event_utils.cpp | 28 ++++++++++--------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/frameworks/extension/src/ani/ani_common_event_utils.cpp b/frameworks/extension/src/ani/ani_common_event_utils.cpp index 17f6dea9..6738dc64 100644 --- a/frameworks/extension/src/ani/ani_common_event_utils.cpp +++ b/frameworks/extension/src/ani/ani_common_event_utils.cpp @@ -17,12 +17,14 @@ #include "ani_common_want.h" #include "event_log_wrapper.h" +#include + namespace OHOS { namespace EventManagerFwkAni { using namespace OHOS::EventFwk; using namespace OHOS::AppExecFwk; -#define SETTER_METHOD_NAME(property) "" #property +using namespace arkts::ani_signature; void AniCommonEventUtils::CreateNewObjectByClass( ani_env* env, const char* className, ani_class& cls, ani_object& ani_data) @@ -94,6 +96,7 @@ void AniCommonEventUtils::ConvertCommonEventDataToEts( ani_env* env, ani_object& ani_data, const CommonEventData& commonEventData) { EVENT_LOGD("called"); + ani_class cls = nullptr; CreateNewObjectByClass(env, "commonEvent.commonEventData.CommonEventDataImpl", cls, ani_data); if ((ani_data == nullptr) || (cls == nullptr)) { @@ -105,26 +108,26 @@ void AniCommonEventUtils::ConvertCommonEventDataToEts( // set event [string] env->String_NewUTF8( commonEventData.GetWant().GetAction().c_str(), commonEventData.GetWant().GetAction().size(), &string); - CallSetter(env, cls, ani_data, SETTER_METHOD_NAME(event), string); + CallSetter(env, cls, ani_data, Builder::BuildSetterName("event").c_str(), string); // set bundleName [string] env->String_NewUTF8( commonEventData.GetWant().GetBundle().c_str(), commonEventData.GetWant().GetBundle().size(), &string); - CallSetter(env, cls, ani_data, SETTER_METHOD_NAME(bundleName), string); + CallSetter(env, cls, ani_data, Builder::BuildSetterName("bundleName").c_str(), string); // set data [string] env->String_NewUTF8(commonEventData.GetData().c_str(), commonEventData.GetData().size(), &string); - CallSetter(env, cls, ani_data, SETTER_METHOD_NAME(data), string); + CallSetter(env, cls, ani_data, Builder::BuildSetterName("data").c_str(), string); // set code [number] ani_object codeObject; CreateAniIntObject(env, codeObject, commonEventData.GetCode()); - CallSetter(env, cls, ani_data, SETTER_METHOD_NAME(code), codeObject); + CallSetter(env, cls, ani_data, Builder::BuildSetterName("code").c_str(), codeObject); // set parameters [Record] ani_ref wantParamRef = WrapWantParams(env, commonEventData.GetWant().GetParams()); - CallSetter(env, cls, ani_data, SETTER_METHOD_NAME(parameters), wantParamRef); + CallSetter(env, cls, ani_data, Builder::BuildSetterName("parameters").c_str(), wantParamRef); } } // namespace EventManagerFwkAni -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/kits/ani/common_event/src/ani_common_event_utils.cpp b/interfaces/kits/ani/common_event/src/ani_common_event_utils.cpp index 2d7a1665..c046ece9 100644 --- a/interfaces/kits/ani/common_event/src/ani_common_event_utils.cpp +++ b/interfaces/kits/ani/common_event/src/ani_common_event_utils.cpp @@ -17,12 +17,14 @@ #include "ani_common_want.h" #include "event_log_wrapper.h" +#include + namespace OHOS { namespace EventManagerFwkAni { using namespace OHOS::EventFwk; using namespace OHOS::AppExecFwk; -#define SETTER_METHOD_NAME(property) "" #property +using namespace arkts::ani_signature; void AniCommonEventUtils::GetStdString(ani_env* env, ani_string str, std::string& result) { @@ -358,36 +360,36 @@ void AniCommonEventUtils::GetCommonEventSubscribeInfoToEts( // set events [Array] ani_object eventsParamRef = GetAniStringArray(env, subscriber->GetSubscribeInfo().GetMatchingSkills().GetEvents()); - CallSetter(env, cls, infoObject, SETTER_METHOD_NAME(events), eventsParamRef); + CallSetter(env, cls, infoObject, Builder::BuildSetterName("events").c_str(), eventsParamRef); ani_string string = nullptr; // set publisherPermission [string] status = env->String_NewUTF8( subscriber->GetSubscribeInfo().GetPermission().c_str(), subscriber->GetSubscribeInfo().GetPermission().size(), &string); - CallSetter(env, cls, infoObject, SETTER_METHOD_NAME(publisherPermission), string); + CallSetter(env, cls, infoObject, Builder::BuildSetterName("publisherPermission").c_str(), string); // set publisherDeviceId [string] status = env->String_NewUTF8( subscriber->GetSubscribeInfo().GetDeviceId().c_str(), subscriber->GetSubscribeInfo().GetDeviceId().size(), &string); - CallSetter(env, cls, infoObject, SETTER_METHOD_NAME(publisherDeviceId), string); + CallSetter(env, cls, infoObject, Builder::BuildSetterName("publisherDeviceId").c_str(), string); // set publisherBundleName [string] status = env->String_NewUTF8( subscriber->GetSubscribeInfo().GetPublisherBundleName().c_str(), subscriber->GetSubscribeInfo().GetPublisherBundleName().size(), &string); - CallSetter(env, cls, infoObject, SETTER_METHOD_NAME(publisherBundleName), string); + CallSetter(env, cls, infoObject, Builder::BuildSetterName("publisherBundleName").c_str(), string); // set userId [int] ani_object userIdObject; CreateAniIntObject(env, userIdObject, subscriber->GetSubscribeInfo().GetUserId()); - CallSetter(env, cls, infoObject, SETTER_METHOD_NAME(userId), userIdObject); + CallSetter(env, cls, infoObject, Builder::BuildSetterName("userId").c_str(), userIdObject); // set priority [int] ani_object priorityObject; CreateAniIntObject(env, priorityObject, subscriber->GetSubscribeInfo().GetPriority()); - CallSetter(env, cls, infoObject, SETTER_METHOD_NAME(priority), priorityObject); + CallSetter(env, cls, infoObject, Builder::BuildSetterName("priority").c_str(), priorityObject); } ani_object AniCommonEventUtils::GetAniStringArray(ani_env *env, std::vector strs) @@ -560,26 +562,26 @@ void AniCommonEventUtils::ConvertCommonEventDataToEts( // set event [string] env->String_NewUTF8( commonEventData.GetWant().GetAction().c_str(), commonEventData.GetWant().GetAction().size(), &string); - CallSetter(env, cls, ani_data, SETTER_METHOD_NAME(event), string); + CallSetter(env, cls, ani_data, Builder::BuildSetterName("event").c_str(), string); // set bundleName [string] env->String_NewUTF8( commonEventData.GetWant().GetBundle().c_str(), commonEventData.GetWant().GetBundle().size(), &string); - CallSetter(env, cls, ani_data, SETTER_METHOD_NAME(bundleName), string); + CallSetter(env, cls, ani_data, Builder::BuildSetterName("bundleName").c_str(), string); // set data [string] env->String_NewUTF8(commonEventData.GetData().c_str(), commonEventData.GetData().size(), &string); - CallSetter(env, cls, ani_data, SETTER_METHOD_NAME(data), string); + CallSetter(env, cls, ani_data, Builder::BuildSetterName("data").c_str(), string); // set code [int] ani_object codeObject; CreateAniIntObject(env, codeObject, commonEventData.GetCode()); - CallSetter(env, cls, ani_data, SETTER_METHOD_NAME(code), codeObject); + CallSetter(env, cls, ani_data, Builder::BuildSetterName("code").c_str(), codeObject); // set parameters [Record] ani_ref wantParamRef = WrapWantParams(env, commonEventData.GetWant().GetParams()); - CallSetter(env, cls, ani_data, SETTER_METHOD_NAME(parameters), wantParamRef); + CallSetter(env, cls, ani_data, Builder::BuildSetterName("parameters").c_str(), wantParamRef); } } // namespace EventManagerFwkAni -} // namespace OHOS \ No newline at end of file +} // namespace OHOS -- Gitee