From 360f76ea290b10ea25fdf36eebeb61a137f85aa7 Mon Sep 17 00:00:00 2001 From: heguokai Date: Thu, 29 May 2025 18:21:01 +0800 Subject: [PATCH 1/4] fixed for addDoNotDisturbProfile & setSlotFlagByBundle Signed-off-by: heguokai --- frameworks/ets/ani/include/manager/ani_slot.h | 2 +- frameworks/ets/ani/src/manager/ani_slot.cpp | 6 +++--- frameworks/ets/ani/src/sts_bundle_option.cpp | 2 +- frameworks/ets/ani/src/sts_disturb_mode.cpp | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/frameworks/ets/ani/include/manager/ani_slot.h b/frameworks/ets/ani/include/manager/ani_slot.h index 127dcfff8..044d5a877 100644 --- a/frameworks/ets/ani/include/manager/ani_slot.h +++ b/frameworks/ets/ani/include/manager/ani_slot.h @@ -20,7 +20,7 @@ namespace OHOS { namespace NotificationManagerSts { ani_int AniGetSlotFlagsByBundle(ani_env *env, ani_object obj); -void AniSetSlotFlagsByBundle(ani_env *env, ani_object obj); +void AniSetSlotFlagsByBundle(ani_env *env, ani_object obj, ani_double slotFlags); ani_object AniGetSlotsByBundle(ani_env *env, ani_object bundleOption); ani_boolean AniIsNotificationSlotEnabled(ani_env *env, ani_object bundleOption, ani_enum_item type); diff --git a/frameworks/ets/ani/src/manager/ani_slot.cpp b/frameworks/ets/ani/src/manager/ani_slot.cpp index d9ce7326b..86224ee2b 100644 --- a/frameworks/ets/ani/src/manager/ani_slot.cpp +++ b/frameworks/ets/ani/src/manager/ani_slot.cpp @@ -145,7 +145,7 @@ ani_int AniGetSlotFlagsByBundle(ani_env *env, ani_object obj) return slotFlags; } -void AniSetSlotFlagsByBundle(ani_env *env, ani_object obj) +void AniSetSlotFlagsByBundle(ani_env *env, ani_object obj, ani_double slotFlags) { ANS_LOGD("sts setSlotFlagsByBundle call"); Notification::NotificationBundleOption option; @@ -153,8 +153,8 @@ void AniSetSlotFlagsByBundle(ani_env *env, ani_object obj) NotificationSts::ThrowStsErroWithMsg(env, "AniSetSlotFlagsByBundle : erro arguments."); return; } - uint32_t slotFlags = 0; - int returncode = Notification::NotificationHelper::SetNotificationSlotFlagsAsBundle(option, slotFlags); + int returncode = + Notification::NotificationHelper::SetNotificationSlotFlagsAsBundle(option, static_cast(slotFlags)); int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); if (externalCode != 0) { ANS_LOGE("AniSetSlotFlagsByBundle -> error, errorCode: %{public}d", externalCode); diff --git a/frameworks/ets/ani/src/sts_bundle_option.cpp b/frameworks/ets/ani/src/sts_bundle_option.cpp index 4da10d202..938b388b3 100644 --- a/frameworks/ets/ani/src/sts_bundle_option.cpp +++ b/frameworks/ets/ani/src/sts_bundle_option.cpp @@ -63,7 +63,7 @@ bool UnwrapArrayBundleOption(ani_env *env, for (int32_t i = 0; i < static_cast(length); i++) { ani_ref optionRef; status = env->Object_CallMethodByName_Ref(static_cast(arrayObj), - "$_get", "I:Lnotification/NotificationCommonDef/BundleOption;", &optionRef, i); + "$_get", "I:Lstd/core/Object;", &optionRef, i); if (status != ANI_OK) { ANS_LOGE("UnwrapArrayBundleOption: get bundleOptionRef failed, status = %{public}d", status); return false; diff --git a/frameworks/ets/ani/src/sts_disturb_mode.cpp b/frameworks/ets/ani/src/sts_disturb_mode.cpp index 345d36319..a24e389b8 100644 --- a/frameworks/ets/ani/src/sts_disturb_mode.cpp +++ b/frameworks/ets/ani/src/sts_disturb_mode.cpp @@ -30,16 +30,16 @@ bool UnwrapDoNotDisturbProfile(ani_env *env, ani_object param, } ani_boolean isUndefined = ANI_TRUE; ani_double idAni = 0.0; - if (ANI_OK != GetPropertyDouble(env, param, "id", isUndefined, idAni) || isUndefined == ANI_TRUE) { + if (ANI_OK != env->Object_GetPropertyByName_Double(param, "id", &idAni)) { ANS_LOGE("UnwrapDoNotDisturbProfile: get id failed"); return false; } + profile->SetProfileId(static_cast(idAni)); std::string nameStr = ""; if (ANI_OK != GetPropertyString(env, param, "name", isUndefined, nameStr) || isUndefined == ANI_TRUE) { ANS_LOGE("UnwrapDoNotDisturbProfile: get name failed"); return false; } - profile->SetProfileId(static_cast(idAni)); profile->SetProfileName(nameStr); ani_ref trustlistRef; if (ANI_OK != GetPropertyRef(env, param, "trustlist", isUndefined, trustlistRef) || isUndefined == ANI_TRUE) { @@ -70,15 +70,15 @@ bool UnwrapArrayDoNotDisturbProfile(ani_env *env, ani_object arrayObj, ANS_LOGD("UnwrapArrayDoNotDisturbProfile: status = %{public}d", status); return false; } - sptr profile; for (int i = 0; i < static_cast(length); i++) { ani_ref optionRef; status = env->Object_CallMethodByName_Ref(arrayObj, "$_get", - "I:L@ohos/notificationManager/notificationManager/DoNotDisturbProfile;", &optionRef, (ani_int)i); + "I:Lstd/core/Object;", &optionRef, (ani_int)i); if (status != ANI_OK) { ANS_LOGE("UnwrapArrayDoNotDisturbProfile: status : %{public}d, index: %{public}d", status, i); return false; } + sptr profile = new (std::nothrow)NotificationDoNotDisturbProfile(); if (!UnwrapDoNotDisturbProfile(env, static_cast(optionRef), profile)) { ANS_LOGE("Get profile failed, index: %{public}d", i); return false; -- Gitee From 2525e1c3fd0bb4c23193abb4cd2b0e7abc7797a9 Mon Sep 17 00:00:00 2001 From: heguokai Date: Thu, 29 May 2025 18:55:42 +0800 Subject: [PATCH 2/4] modify Signed-off-by: heguokai --- frameworks/ets/ani/src/sts_subscriber.cpp | 2 +- frameworks/ets/ets/notification/notificationFlags.ets | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/ets/ani/src/sts_subscriber.cpp b/frameworks/ets/ani/src/sts_subscriber.cpp index fc0142b74..19c966c15 100644 --- a/frameworks/ets/ani/src/sts_subscriber.cpp +++ b/frameworks/ets/ani/src/sts_subscriber.cpp @@ -191,7 +191,7 @@ bool WarpSubscribeCallbackDataArray( } if (ANI_OK != (status = env->Object_CallMethodByName_Void( outObj, "$_set", "ILstd/core/Object;:V", i, obj))) { - ANS_LOGE("set object faild. index %{public}d status %{public}d", i, status); + ANS_LOGE("set object faild. status %{public}d", status); return false; } } diff --git a/frameworks/ets/ets/notification/notificationFlags.ets b/frameworks/ets/ets/notification/notificationFlags.ets index e090d8d72..7c98b19f5 100644 --- a/frameworks/ets/ets/notification/notificationFlags.ets +++ b/frameworks/ets/ets/notification/notificationFlags.ets @@ -35,7 +35,7 @@ class NotificationFlagsInner implements NotificationFlags { public soundEnabled?: NotificationFlagStatus | undefined; - public vibrationEnabled?: NotificationFlagStatus| undefined; + public vibrationEnabled?: NotificationFlagStatus | undefined; public reminderFlags?: number | undefined; } \ No newline at end of file -- Gitee From ec1c25dd5064bf8bebdddaab83bc665823936d99 Mon Sep 17 00:00:00 2001 From: heguokai Date: Thu, 29 May 2025 20:12:44 +0800 Subject: [PATCH 3/4] modify Signed-off-by: heguokai --- frameworks/ets/ani/src/sts_notification_content.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/frameworks/ets/ani/src/sts_notification_content.cpp b/frameworks/ets/ani/src/sts_notification_content.cpp index 96fc4cbc6..b3aa635f9 100644 --- a/frameworks/ets/ani/src/sts_notification_content.cpp +++ b/frameworks/ets/ani/src/sts_notification_content.cpp @@ -1254,11 +1254,6 @@ bool SetNotificationMultiLineContent( if (allLinesObject == nullptr || !SetPropertyByRef(env, contentObj, "lines", allLinesObject)) { ANS_LOGD("SetNotificationMultiLineContent: set lines failed"); } - ani_object lineWantAgentsObject = GetAniWantAgentArray(env, content->GetLineWantAgents()); - if (lineWantAgentsObject == nullptr - || !SetPropertyByRef(env, contentObj, "lineWantAgents", lineWantAgentsObject)) { - ANS_LOGD("SetNotificationMultiLineContent: set lineWantAgents failed"); - } return SetPropertyByRef(env, ncObj, "multiLine", contentObj); } -- Gitee From fad59ff96f03297c4b0a7896625c763f0601f5bb Mon Sep 17 00:00:00 2001 From: heguokai Date: Thu, 29 May 2025 21:34:51 +0800 Subject: [PATCH 4/4] ani fixed for getActiveNotification Signed-off-by: heguokai --- .../ets/ani/src/manager/ani_get_active.cpp | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/frameworks/ets/ani/src/manager/ani_get_active.cpp b/frameworks/ets/ani/src/manager/ani_get_active.cpp index 8ae3e8957..74e1ccd83 100644 --- a/frameworks/ets/ani/src/manager/ani_get_active.cpp +++ b/frameworks/ets/ani/src/manager/ani_get_active.cpp @@ -19,6 +19,7 @@ #include "ans_log_wrapper.h" #include "sts_throw_erro.h" #include "sts_request.h" +#include "sts_common.h" namespace OHOS { namespace NotificationManagerSts { @@ -46,14 +47,19 @@ ani_object AniGetAllActiveNotifications(ani_env *env) int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); if (externalCode != 0) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); - ANS_LOGE("AniSetNotificationEnableSlotSync error, errorCode: %{public}d", externalCode); + ANS_LOGE("AniGetAllActiveNotifications error, errorCode: %{public}d", externalCode); return nullptr; } - ani_object arrayRequestObj = NotificationSts::GetAniNotificationRequestArrayByNotifocations(env, notifications); + ani_object arrayRequestObj; + if (notifications.size() == 0) { + arrayRequestObj = NotificationSts::newArrayClass(env, 0); + } else { + arrayRequestObj = NotificationSts::GetAniNotificationRequestArrayByNotifocations(env, notifications); + } if (arrayRequestObj == nullptr) { OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); - ANS_LOGE("AniTriggerSystemLiveView buttonOption ERROR_INTERNAL_ERROR"); + ANS_LOGE("AniGetAllActiveNotifications ERROR_INTERNAL_ERROR"); } ANS_LOGD("sts AniGetAllActiveNotifications end"); return arrayRequestObj; @@ -61,22 +67,27 @@ ani_object AniGetAllActiveNotifications(ani_env *env) ani_object AniGetActiveNotifications(ani_env *env) { - ANS_LOGD("sts AniGetAllActiveNotifications call"); + ANS_LOGD("sts AniGetActiveNotifications call"); std::vector> requests; int returncode = OHOS::Notification::NotificationHelper::GetActiveNotifications(requests); int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); if (externalCode != 0) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); - ANS_LOGE("AniSetNotificationEnableSlotSync error, errorCode: %{public}d", externalCode); + ANS_LOGE("AniGetActiveNotifications error, errorCode: %{public}d", externalCode); return nullptr; } - ani_object arrayRequestObj = NotificationSts::GetAniNotificationRequestArray(env, requests); + ani_object arrayRequestObj; + if (requests.size() == 0) { + arrayRequestObj = NotificationSts::newArrayClass(env, 0); + } else { + arrayRequestObj = NotificationSts::GetAniNotificationRequestArray(env, requests); + } if (arrayRequestObj == nullptr) { OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); - ANS_LOGE("AniTriggerSystemLiveView buttonOption ERROR_INTERNAL_ERROR"); + ANS_LOGE("AniGetActiveNotifications ERROR_INTERNAL_ERROR"); } - ANS_LOGD("sts AniGetAllActiveNotifications end"); + ANS_LOGD("sts AniGetActiveNotifications end"); return arrayRequestObj; } } // namespace NotificationManagerSts -- Gitee