From 7f14832c06ec7816b766d789356bbfe636e75d59 Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Tue, 15 Mar 2022 17:31:53 +0800 Subject: [PATCH] fixed ed89689 from https://gitee.com/fangJinliang1/notification_ans_standard/pulls/327 get notification enable modify Signed-off-by: fangJinliang1 Change-Id: I0254c5bf3e8d505a6037cc1916d096e2711e2ebc Signed-off-by: fangJinliang1 --- .../include/advanced_notification_service.h | 2 ++ .../ans/src/advanced_notification_service.cpp | 35 ++++++++++++++----- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 73aa6acaf..2173274d0 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 45736b64b..e9b19de45 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; -- Gitee