From e74538dfcf3b31f0ecce021fb874c9a0d3f84f01 Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Wed, 16 Mar 2022 14:22:24 +0800 Subject: [PATCH] support subsystem get notification enable Signed-off-by: fangJinliang1 Change-Id: Ia06491adbfa727127a7e02fdabfda08a7b00fa09 --- .../include/advanced_notification_service.h | 2 ++ .../ans/src/advanced_notification_service.cpp | 35 ++++++++++++++----- .../src/notification_preferences_database.cpp | 4 +-- 3 files changed, 30 insertions(+), 11 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; diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index dd8493b03..003344ce9 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -116,7 +116,7 @@ const std::map(StringToInt(value))); + bundleInfo.SetHasPoppedDialog(static_cast(StringToInt(value))); } void NotificationPreferencesDatabase::ParseBundleUid( -- Gitee