From 4a1e93eb14b9a398c44784e505b66f1adeb8b254 Mon Sep 17 00:00:00 2001 From: heguokai Date: Tue, 17 Jun 2025 19:18:57 +0800 Subject: [PATCH 1/3] fixed function for RemoveAll Signed-off-by: heguokai --- .../ets/ani/include/subscribe/ani_remove.h | 1 + .../ets/ani/src/subscribe/ani_remove.cpp | 56 ++++++++++--------- .../ets/ani/src/subscribe/ani_subscribe.cpp | 2 + 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/frameworks/ets/ani/include/subscribe/ani_remove.h b/frameworks/ets/ani/include/subscribe/ani_remove.h index c10e15dc4..5b7680a87 100644 --- a/frameworks/ets/ani/include/subscribe/ani_remove.h +++ b/frameworks/ets/ani/include/subscribe/ani_remove.h @@ -24,6 +24,7 @@ void AniRemoveForHashCode(ani_env *env, ani_string hashCode, ani_object reasonEn void AniRemoveForHashCodes(ani_env *env, ani_object hashCodes, ani_object reasonEnum); void AniRemoveAllForUserId(ani_env *env, ani_double userId); void AniRemoveAllForBundle(ani_env *env, ani_object bundle); +void AniRemoveAll(ani_env *env); } } #endif \ No newline at end of file diff --git a/frameworks/ets/ani/src/subscribe/ani_remove.cpp b/frameworks/ets/ani/src/subscribe/ani_remove.cpp index 8db7371bd..64e59665d 100644 --- a/frameworks/ets/ani/src/subscribe/ani_remove.cpp +++ b/frameworks/ets/ani/src/subscribe/ani_remove.cpp @@ -35,19 +35,19 @@ void AniRemoveForBundle(ani_env *env, ani_object bundle, ani_object notification int32_t reasonType = 0; if (!NotificationSts::UnwrapBundleOption(env, bundle, option)) { ANS_LOGE("bundle is valid"); - std::string msg = "UnwrapBundleOption faild"; + std::string msg = "UnwrapBundleOption failed"; OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); return; } if (!NotificationSts::UnWarpNotificationKey(env, notificationKey, key)) { ANS_LOGE("notificationKey is valid"); - std::string msg = "UnWarpNotificationKey faild"; + std::string msg = "UnWarpNotificationKey failed"; OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); return; } if (!NotificationSts::UnWarpReasonEnum(env, reasonEnum, reasonType)) { ANS_LOGE("enum convert failed"); - std::string msg = "UnWarpReasonEnum faild"; + std::string msg = "UnWarpReasonEnum failed"; OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); return; } @@ -58,9 +58,9 @@ void AniRemoveForBundle(ani_env *env, ani_object bundle, ani_object notification return; } int ret = NotificationHelper::RemoveNotification(option, key.id, key.label, reasonType); - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); - ANS_LOGD("StsRemoveForBundle ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); if (ret != ERR_OK) { + int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); + ANS_LOGD("StsRemoveForBundle ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); } @@ -79,7 +79,7 @@ void AniRemoveForHashCode(ani_env *env, ani_string hashCode, ani_object reasonEn } if (!NotificationSts::UnWarpReasonEnum(env, reasonEnum, reasonType)) { ANS_LOGE("enum convert failed"); - std::string msg = "UnWarpReasonEnum faild"; + std::string msg = "UnWarpReasonEnum failed"; OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); return; } @@ -91,9 +91,9 @@ void AniRemoveForHashCode(ani_env *env, ani_string hashCode, ani_object reasonEn } ANS_LOGD("hashCode: %{public}s, reasonType: %{public}d", hashCodeStd.c_str(), reasonType); int ret = NotificationHelper::RemoveNotification(hashCodeStd, reasonType); - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); - ANS_LOGD("StsRemoveForHashCode ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); if (ret != ERR_OK) { + int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); + ANS_LOGD("StsRemoveForHashCode ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); } @@ -112,7 +112,7 @@ void AniRemoveForHashCodes(ani_env *env, ani_object hashCodes, ani_object reason } if (!NotificationSts::UnWarpReasonEnum(env, reasonEnum, reasonType)) { ANS_LOGE("enum convert failed"); - std::string msg = "UnWarpReasonEnum faild"; + std::string msg = "UnWarpReasonEnum failed"; OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); return; } @@ -123,37 +123,40 @@ void AniRemoveForHashCodes(ani_env *env, ani_object hashCodes, ani_object reason return; } int ret = NotificationHelper::RemoveNotifications(hashCodesStd, reasonType); - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); - ANS_LOGD("StsRemoveForHashCodes ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); if (ret != ERR_OK) { + int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); + ANS_LOGD("StsRemoveForHashCodes ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); } } -void AniRemoveAllForBundle(ani_env *env, ani_object bundle) +void AniRemoveAll(ani_env *env) { ANS_LOGD("removeAll enter"); - int retcode = ERR_OK; - bool isForBundleUndefine = NotificationSts::IsUndefine(env, bundle); - if (isForBundleUndefine) { - retcode = NotificationHelper::RemoveNotifications(); - std::string msg = "IsUndefine falid"; - ANS_LOGE("IsUndefine is falid"); - OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); - return; + int ret = NotificationHelper::RemoveNotifications(); + if (ret != ERR_OK) { + int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); + ANS_LOGD("AniRemoveAll ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); + std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); } +} + +void AniRemoveAllForBundle(ani_env *env, ani_object bundle) +{ + ANS_LOGD("AniRemoveAllForBundle enter"); BundleOption option; if (!NotificationSts::UnwrapBundleOption(env, bundle, option)) { ANS_LOGE("bundle is valid"); - std::string msg = "UnwrapBundleOption faild"; + std::string msg = "UnwrapBundleOption failed"; OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); return; } int ret = NotificationHelper::RemoveAllNotifications(option); - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); - ANS_LOGD("StsRemoveForBundle ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); if (ret != ERR_OK) { + int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); + ANS_LOGD("StsRemoveForBundle ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); } @@ -161,12 +164,11 @@ void AniRemoveAllForBundle(ani_env *env, ani_object bundle) void AniRemoveAllForUserId(ani_env *env, ani_double userId) { - ANS_LOGD("removeAll enter"); - ANS_LOGD("sts RemoveAll call, userId:%{public}lf", userId); + ANS_LOGD("AniRemoveAllForUserId enter"); int ret = NotificationHelper::RemoveNotifications(userId); - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); - ANS_LOGD("StsRemoveForBundle ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); if (ret != ERR_OK) { + int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); + ANS_LOGD("StsRemoveForBundle ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); } diff --git a/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp b/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp index 26bfbad84..00bea6b3e 100644 --- a/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp +++ b/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp @@ -42,6 +42,7 @@ static const char *UNSUBSCRIBE_SIGNATURE = static const char *REMOVEALL_FOR_BUNDLEOPTION_SIGNATURE = "Lnotification/NotificationCommonDef/BundleOption;:V"; static const char *REMOVEALL_FOR_USERID_STGNATURE = "D:V"; +static const char *REMOVEALL_SIGNATURE =":V"; ani_object AniDistributeOperation(ani_env *env, ani_string hashcode, ani_object operationInfo) { @@ -125,6 +126,7 @@ void AniSubScribeRegistryInit(ani_env *env) REMOVEALL_FOR_BUNDLEOPTION_SIGNATURE, reinterpret_cast(AniRemoveAllForBundle)}, ani_native_function {"nativeRemoveAllForUserId", REMOVEALL_FOR_USERID_STGNATURE, reinterpret_cast(AniRemoveAllForUserId)}, + ani_native_function {"nativeRemoveAll", REMOVEALL_SIGNATURE, reinterpret_cast(AniRemoveAll)}, }; ANS_LOGD("Start bind native methods to '%{public}s'", npName); -- Gitee From 1eb28f92930f101d913096287c8d43535b3e2e8d Mon Sep 17 00:00:00 2001 From: heguokai Date: Tue, 17 Jun 2025 19:29:34 +0800 Subject: [PATCH 2/3] add ets Signed-off-by: heguokai --- frameworks/ets/ets/@ohos.notificationSubscribe.ets | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/ets/ets/@ohos.notificationSubscribe.ets b/frameworks/ets/ets/@ohos.notificationSubscribe.ets index 9bad8d255..00a67dd0e 100644 --- a/frameworks/ets/ets/@ohos.notificationSubscribe.ets +++ b/frameworks/ets/ets/@ohos.notificationSubscribe.ets @@ -82,6 +82,7 @@ export default namespace notificationSubscribe { export native function nativeSubscribeSelf(subscriber: NotificationSubscriber): void export native function nativeRemoveAllForBundle(bundle?: BundleOption): void; export native function nativeRemoveAllForUserId(userId: number): void; + export native function nativeRemoveAll(): void; export function subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback): void { if (subscriber == undefined || callback == undefined) { @@ -369,11 +370,10 @@ export default namespace notificationSubscribe { export function removeAll(bundle?: BundleOption): Promise { - let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { let p = taskpool.execute((): void => { if (bundle == undefined) { - return notificationSubscribe.nativeRemoveAllForBundle(); + return notificationSubscribe.nativeRemoveAll(); } else { return notificationSubscribe.nativeRemoveAllForBundle(bundle); } @@ -392,7 +392,7 @@ export default namespace notificationSubscribe { throw errorParamInvalid; } let p = taskpool.execute((): void => { - return notificationSubscribe.nativeRemoveAllForBundle(); + return notificationSubscribe.nativeRemoveAll(); }); p.then( (e: NullishType): void => { -- Gitee From b665e6c04427d7433745823aa20737f58c8cf266 Mon Sep 17 00:00:00 2001 From: heguokai Date: Tue, 17 Jun 2025 11:44:49 +0000 Subject: [PATCH 3/3] update frameworks/ets/ani/src/subscribe/ani_subscribe.cpp. Signed-off-by: heguokai --- frameworks/ets/ani/src/subscribe/ani_subscribe.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp b/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp index 00bea6b3e..f73b6c60b 100644 --- a/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp +++ b/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp @@ -42,7 +42,7 @@ static const char *UNSUBSCRIBE_SIGNATURE = static const char *REMOVEALL_FOR_BUNDLEOPTION_SIGNATURE = "Lnotification/NotificationCommonDef/BundleOption;:V"; static const char *REMOVEALL_FOR_USERID_STGNATURE = "D:V"; -static const char *REMOVEALL_SIGNATURE =":V"; +static const char *REMOVEALL_SIGNATURE = ":V"; ani_object AniDistributeOperation(ani_env *env, ani_string hashcode, ani_object operationInfo) { -- Gitee