diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 73aa6acaffac0b7f3b0f2902b0b3c1dc83e93f8d..2173274d06ad739c492623961dc1c3d35cca7682 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -213,6 +213,8 @@ private: ErrCode GetDoNotDisturbDateByUser(const int32_t &userId, sptr &date); ErrCode SetHasPoppedDialog(const sptr bundleOption, bool hasPopped); ErrCode GetHasPoppedDialog(const sptr bundleOption, bool &hasPopped); + ErrCode GetAppTargetBundle(const sptr &bundleOption, + sptr &targetBundle); private: static sptr instance_; diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 45736b64be85622854440e57172f89a1fcf17029..e9b19de4514866ae1b2728971937d8a8351e5138 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1547,33 +1547,50 @@ ErrCode AdvancedNotificationService::IsAllowedNotifySelf(bool &allowed) return result; } -ErrCode AdvancedNotificationService::IsSpecialBundleAllowedNotify( - const sptr &bundleOption, bool &allowed) +ErrCode AdvancedNotificationService::GetAppTargetBundle(const sptr &bundleOption, + sptr &targetBundle) { - ANS_LOGD("%{public}s", __FUNCTION__); - sptr clientBundle = GenerateBundleOption(); if (clientBundle == nullptr) { return ERR_ANS_INVALID_BUNDLE; } - sptr targetBundle = nullptr; if (bundleOption == nullptr) { targetBundle = clientBundle; } else { if ((clientBundle->GetBundleName() == bundleOption->GetBundleName()) && (clientBundle->GetUid() == bundleOption->GetUid())) { - targetBundle = bundleOption; + targetBundle = bundleOption; } else { if (!IsSystemApp()) { return ERR_ANS_NON_SYSTEM_APP; } - if (!CheckPermission()) { - return ERR_ANS_PERMISSION_DENIED; - } targetBundle = GenerateValidBundleOption(bundleOption); } } + return ERR_OK; +} + +ErrCode AdvancedNotificationService::IsSpecialBundleAllowedNotify( + const sptr &bundleOption, bool &allowed) +{ + ANS_LOGD("%{public}s", __FUNCTION__); + + if (!CheckPermission()) { + return ERR_ANS_PERMISSION_DENIED; + } + + sptr targetBundle = nullptr; + if (IPCSkeleton::GetCallingUid() == SYSTEM_SERVICE_UID) { + if (bundleOption == nullptr) { + targetBundle = GenerateValidBundleOption(bundleOption); + } + } else { + ErrCode result = GetAppTargetBundle(bundleOption, targetBundle); + if (result != ERR_OK) { + return result; + } + } if (targetBundle == nullptr) { return ERR_ANS_INVALID_BUNDLE;