From 24bea9344850f73ebb8a2508267319be1d0877fb Mon Sep 17 00:00:00 2001 From: songbao1 Date: Thu, 10 Apr 2025 10:00:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E8=B6=85=E5=A4=A7?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- .../include/advanced_notification_service.h | 1 + .../advanced_notification_publish_service.cpp | 44 +++++++++++-------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index a2001aef2..c88efbea2 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1562,6 +1562,7 @@ private: const sptr bundleOption, const bool innerLake); void ClearSlotTypeData(const sptr &request, int32_t callingUid); + ErrCode CheckCancelPermission(const int32_t reason); template bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &data) diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index 461958549..4c8c1a078 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -557,24 +557,9 @@ ErrCode AdvancedNotificationService::CancelAsBundle( ANS_LOGE("%{public}s", message.c_str()); return ERR_ANS_INVALID_PARAM; } - bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID()); - if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) { - std::string message = "not systemApp"; - OHOS::Notification::HaMetaMessage haMetaMessage = HaMetaMessage(2, 1) - .ErrorCode(ERR_ANS_NON_SYSTEM_APP).NotificationId(notificationId); - ReportDeleteFailedEventPush(haMetaMessage, reason, message); - ANS_LOGE("%{public}s", message.c_str()); - return ERR_ANS_NON_SYSTEM_APP; - } - - if (!AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER) || - !AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER)) { - std::string message = "no acl permission"; - OHOS::Notification::HaMetaMessage haMetaMessage = HaMetaMessage(2, 2) - .ErrorCode(ERR_ANS_PERMISSION_DENIED).NotificationId(notificationId); - ReportDeleteFailedEventPush(haMetaMessage, reason, message); - ANS_LOGE("%{public}s", message.c_str()); - return ERR_ANS_PERMISSION_DENIED; + ErrCode permissionResult = CheckCancelPermission(const int32_t reason); + if (permissionResult != ERR_OK) { + return permissionResult; } int32_t errCode = CheckUserIdParams(userId); @@ -3462,5 +3447,28 @@ ErrCode AdvancedNotificationService::SetHashCodeRule(const uint32_t type) return result; } + +ErrCode AdvancedNotificationService::CheckCancelPermission(const int32_t reason) +{ + bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID()); + if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) { + std::string message = "not systemApp"; + haPermissionMessage.ErrorCode(ERR_ANS_NON_SYSTEM_APP); + ReportDeleteFailedEventPush(haMetaMessage, reason, message); + ANS_LOGE("%{public}s", message.c_str()); + return ERR_ANS_NON_SYSTEM_APP; + } + + if (!AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER) || + !AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER)) { + std::string message = "no acl permission"; + OHOS::Notification::HaMetaMessage haMetaMessage = HaMetaMessage(2, 2) + .ErrorCode(ERR_ANS_PERMISSION_DENIED).NotificationId(notificationId); + ReportDeleteFailedEventPush(haMetaMessage, reason, message); + ANS_LOGE("%{public}s", message.c_str()); + return ERR_ANS_PERMISSION_DENIED; + } + return ERR_OK; +} } // namespace Notification } // namespace OHOS -- Gitee From 8747941b6ab43ebaa72e030dbc9009592f99f864 Mon Sep 17 00:00:00 2001 From: songbao1 Date: Thu, 10 Apr 2025 11:23:30 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E8=B6=85=E5=A4=A7?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- services/ans/src/advanced_notification_publish_service.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index 4c8c1a078..f257e5004 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -557,7 +557,7 @@ ErrCode AdvancedNotificationService::CancelAsBundle( ANS_LOGE("%{public}s", message.c_str()); return ERR_ANS_INVALID_PARAM; } - ErrCode permissionResult = CheckCancelPermission(const int32_t reason); + ErrCode permissionResult = CheckCancelPermission(reason); if (permissionResult != ERR_OK) { return permissionResult; } @@ -3453,7 +3453,8 @@ ErrCode AdvancedNotificationService::CheckCancelPermission(const int32_t reason) bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID()); if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) { std::string message = "not systemApp"; - haPermissionMessage.ErrorCode(ERR_ANS_NON_SYSTEM_APP); + OHOS::Notification::HaMetaMessage haMetaMessage = HaMetaMessage(2, 1) + .ErrorCode(ERR_ANS_NON_SYSTEM_APP).NotificationId(notificationId); ReportDeleteFailedEventPush(haMetaMessage, reason, message); ANS_LOGE("%{public}s", message.c_str()); return ERR_ANS_NON_SYSTEM_APP; -- Gitee