diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index a2001aef2ebc7e81b134589698fc2b6d11cf19fd..c88efbea28d7d4cbc7f89669686b89d41556f97e 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 46195854939d1d4be7f9708083307d28ebc8219f..f257e5004564843a157924b0a9e38711fdb47e4d 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(reason); + if (permissionResult != ERR_OK) { + return permissionResult; } int32_t errCode = CheckUserIdParams(userId); @@ -3462,5 +3447,29 @@ 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"; + 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; + } + return ERR_OK; +} } // namespace Notification } // namespace OHOS