diff --git a/services/ans/include/notification_app_privileges.h b/services/ans/include/notification_app_privileges.h index 3135c7c4fa44ec648ef36de90f640d5a3a81052d..e22e9401b4e62a9edf7e3e9c1c1452224106dbdf 100644 --- a/services/ans/include/notification_app_privileges.h +++ b/services/ans/include/notification_app_privileges.h @@ -30,8 +30,10 @@ public: bool IsBannerEnabled() const; bool IsReminderEnabled() const; bool IsDistributedReplyEnabled() const; + bool IsNotificationForcedEnable() const; private: + static constexpr int32_t NOTIFICATION_FORCED_ENABLE = 5; static constexpr int32_t DISTRIBUTED_REPLY_SEQ = 4; static constexpr int32_t REMINDER_ENABLED_SEQ = 2; static constexpr int32_t BANNER_ENABLED_SEQ = 1; diff --git a/services/ans/include/notification_config_parse.h b/services/ans/include/notification_config_parse.h index cb3923f82fe7f42c846c0ce87db553af07c940eb..b5229c1fb0d999234ad61a3d07c0ce5c969b9251 100644 --- a/services/ans/include/notification_config_parse.h +++ b/services/ans/include/notification_config_parse.h @@ -52,6 +52,7 @@ public: bool IsBannerEnabled(const std::string bundleName) const; bool IsReminderEnabled(const std::string& bundleName) const; bool IsDistributedReplyEnabled(const std::string& bundleName) const; + bool IsNotificationForcedEnable(const std::string& bundleName) const; void GetFlowCtrlConfigFromCCM(FlowControlThreshold &threshold); bool GetSmartReminderEnableList(std::vector& deviceTypes); bool GetMirrorNotificationEnabledStatus(std::vector& deviceTypes); diff --git a/services/ans/src/common/notification_app_privileges.cpp b/services/ans/src/common/notification_app_privileges.cpp index 11bb6fb44a2236fb8e66ea3f35c72d9f9a758404..f61994d685a041c4cbd1d28f7f2f7ca11a2a7ebf 100644 --- a/services/ans/src/common/notification_app_privileges.cpp +++ b/services/ans/src/common/notification_app_privileges.cpp @@ -31,6 +31,9 @@ NotificationAppPrivileges::NotificationAppPrivileges(const std::string &flagStr) if (flagStr.size() > DISTRIBUTED_REPLY_SEQ && flagStr[DISTRIBUTED_REPLY_SEQ] == '1') { privileges_ |= 1 << DISTRIBUTED_REPLY_SEQ; } + if (flagStr.size() >= NOTIFICATION_FORCED_ENABLE && flagStr[NOTIFICATION_FORCED_ENABLE] == '1') { + privileges_ |= 1 << NOTIFICATION_FORCED_ENABLE; + } } bool NotificationAppPrivileges::IsLiveViewEnabled() const { @@ -60,5 +63,13 @@ bool NotificationAppPrivileges::IsDistributedReplyEnabled() const } return false; } + +bool NotificationAppPrivileges::IsNotificationForcedEnable() const +{ + if ((privileges_ & (1 << NOTIFICATION_FORCED_ENABLE)) != 0) { + return true; + } + return false; +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/common/notification_config_parse.cpp b/services/ans/src/common/notification_config_parse.cpp index df49e3fe361995b78e9657d8d27d2ac08b69199b..971829f6309e0e0109547e2b2c1b75c5e586997e 100644 --- a/services/ans/src/common/notification_config_parse.cpp +++ b/services/ans/src/common/notification_config_parse.cpp @@ -207,6 +207,15 @@ bool NotificationConfigParse::IsBannerEnabled(const std::string bundleName) cons #endif } +bool NotificationConfigParse::IsNotificationForcedEnable(const std::string& bundleName) const +{ + std::shared_ptr appPrivileges = GetAppPrivileges(bundleName); + if (appPrivileges == nullptr) { + return false; + } + return appPrivileges->IsNotificationForcedEnable(); +} + void NotificationConfigParse::GetFlowCtrlConfigFromCCM(FlowControlThreshold &threshold) { nlohmann::json root; diff --git a/services/ans/src/permission_filter.cpp b/services/ans/src/permission_filter.cpp index b082a9b9da222ec1065eada3a3f0a788624267af..e49836e9d4bb384cd9f2586045bcf7647c833d9d 100644 --- a/services/ans/src/permission_filter.cpp +++ b/services/ans/src/permission_filter.cpp @@ -20,12 +20,11 @@ #include "bundle_manager_helper.h" #include "notification_preferences.h" #include "notification_analytics_util.h" +#include "notification_config_parse.h" namespace OHOS { namespace Notification { -constexpr const char *PRIVACYCENTER_BUNDLE_NAME = "com.huawei.hmos.security.privacycenter"; - void PermissionFilter::OnStart() {} @@ -74,7 +73,8 @@ ErrCode PermissionFilter::OnPublish(const std::shared_ptr &r } if (result == ERR_OK) { - if (record->bundleOption->GetBundleName().compare(PRIVACYCENTER_BUNDLE_NAME) == 0 && !enable) { + if (!enable && DelayedSingleton::GetInstance()-> + IsNotificationForcedEnable(record->bundleOption->GetBundleName())) { AdvancedNotificationService::GetInstance()-> SetNotificationsEnabledForSpecialBundle("", record->bundleOption, true); return result; diff --git a/services/ans/test/unittest/notification_extension/notification_config_parse_mock.cpp b/services/ans/test/unittest/notification_extension/notification_config_parse_mock.cpp index 1d0e6cd388bf03fdd05854f85e4b9474f1690ddf..b34baaacb51cb4f7fbef350c49130feea21facf1 100644 --- a/services/ans/test/unittest/notification_extension/notification_config_parse_mock.cpp +++ b/services/ans/test/unittest/notification_extension/notification_config_parse_mock.cpp @@ -129,6 +129,11 @@ bool NotificationConfigParse::IsBannerEnabled(const std::string bundleName) cons return false; } +bool NotificationConfigParse::IsNotificationForcedEnable(const std::string& bundleName) const +{ + return false; +} + void NotificationConfigParse::GetFlowCtrlConfigFromCCM(FlowControlThreshold &threshold) { }