diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 2173274d06ad739c492623961dc1c3d35cca7682..a6d4a388fa894ed03d8b7b77def2c37752dd301f 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -190,6 +190,7 @@ private: bool GetActiveUserId(int& userId); void TriggerRemoveWantAgent(const sptr &request); bool CheckApiCompatibility(const sptr &bundleOption); + ErrCode IsAllowedNotifySelf(const sptr &bundleOption, bool &allowed); ErrCode SetNotificationRemindType(sptr notification, bool isLocal); #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 85154907ce070babfb31c60d6f682475de22deef..edf337dd5e41cf53770f3cf8a978453ec2c84bd3 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1381,7 +1381,7 @@ ErrCode AdvancedNotificationService::RequestEnableNotification(const std::string } bool allowedNotify = false; - result = IsSpecialBundleAllowedNotify(bundleOption, allowedNotify); + result = IsAllowedNotifySelf(bundleOption, allowedNotify); if (result != ERR_OK || allowedNotify) { ANS_LOGD("Already granted permission"); return result; @@ -1529,21 +1529,38 @@ ErrCode AdvancedNotificationService::IsAllowedNotifySelf(bool &allowed) { ANS_LOGD("%{public}s", __FUNCTION__); - ErrCode result = ERR_OK; sptr bundleOption = GenerateBundleOption(); if (bundleOption == nullptr) { return ERR_ANS_INVALID_BUNDLE; } + return IsAllowedNotifySelf(bundleOption, allowed); +} + +ErrCode AdvancedNotificationService::IsAllowedNotifySelf(const sptr &bundleOption, + bool &allowed) +{ + if (bundleOption == nullptr) { + return ERR_ANS_INVALID_BUNDLE; + } + + int userId = SUBSCRIBE_USER_INIT; + if (!GetActiveUserId(userId)) { + return ERR_ANS_GET_ACTIVE_USER_FAILED; + } + ErrCode result = ERR_OK; handler_->PostSyncTask(std::bind([&]() { - result = NotificationPreferences::GetInstance().GetNotificationsEnabledForBundle(bundleOption, allowed); - if (result == ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST) { - result = ERR_OK; - allowed = CheckApiCompatibility(bundleOption); - SetNotificationsEnabledForSpecialBundle("", bundleOption, allowed); + allowed = false; + result = NotificationPreferences::GetInstance().GetNotificationsEnabled(userId, allowed); + if (result == ERR_OK && allowed) { + result = NotificationPreferences::GetInstance().GetNotificationsEnabledForBundle(bundleOption, allowed); + if (result == ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST) { + result = ERR_OK; + allowed = CheckApiCompatibility(bundleOption); + SetNotificationsEnabledForSpecialBundle("", bundleOption, allowed); + } } })); - return result; }