diff --git a/frameworks/ans/native/src/reminder_request.cpp b/frameworks/ans/native/src/reminder_request.cpp index 381d0bb5db61d5808adde21dbfa8374ef2aba3a9..d799cd5a845b8db20598a2a85c8986df38368037 100644 --- a/frameworks/ans/native/src/reminder_request.cpp +++ b/frameworks/ans/native/src/reminder_request.cpp @@ -1421,6 +1421,7 @@ void ReminderRequest::UpdateNotificationCommon() flags->SetSoundEnabled(NotificationConstant::FlagStatus::CLOSE); flags->SetVibrationEnabled(NotificationConstant::FlagStatus::CLOSE); notificationRequest_->SetFlags(flags); + notificationRequest_->SetDistributed(false); } void ReminderRequest::UpdateNotificationBundleInfo() diff --git a/interfaces/kits/napi/ans/src/common.cpp b/interfaces/kits/napi/ans/src/common.cpp index 92155b0486aef76e08631b471312a124226d8c3b..fb701e4e1e776349cf91b33e60f71b77fd933ca7 100644 --- a/interfaces/kits/napi/ans/src/common.cpp +++ b/interfaces/kits/napi/ans/src/common.cpp @@ -173,7 +173,11 @@ napi_value Common::SetNotificationByDistributedOptions( NotificationDistributedOptions options = notification->GetNotificationRequest().GetNotificationDistributedOptions(); napi_value value = nullptr; // isDistributed?: boolean - napi_get_boolean(env, options.IsDistributed(), &value); + if (notification->GetDeviceId().empty()) { + napi_get_boolean(env, false, &value); + } else { + napi_get_boolean(env, options.IsDistributed(), &value); + } napi_set_named_property(env, result, "isDistributed", value); // supportDisplayDevices?: Array 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 e9b19de4514866ae1b2728971937d8a8351e5138..0962dfccb29c134aaac958e901edb72664353945 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; } @@ -1582,7 +1599,7 @@ ErrCode AdvancedNotificationService::IsSpecialBundleAllowedNotify( sptr targetBundle = nullptr; if (IPCSkeleton::GetCallingUid() == SYSTEM_SERVICE_UID) { - if (bundleOption == nullptr) { + if (bundleOption != nullptr) { targetBundle = GenerateValidBundleOption(bundleOption); } } else { diff --git a/services/distributed/src/distributed_database.cpp b/services/distributed/src/distributed_database.cpp index 4b60727714d2f98101373a90123b666f4bdbf5ca..8dccefc9b6fa53d5b99ce9c42f327eb4667e12f5 100644 --- a/services/distributed/src/distributed_database.cpp +++ b/services/distributed/src/distributed_database.cpp @@ -69,6 +69,7 @@ void DistributedDatabase::GetKvStore(void) DistributedKv::Options options; options.createIfMissing = true; + options.securityLevel = DistributedKv::SecurityLevel::S1; options.autoSync = true; options.kvStoreType = DistributedKv::KvStoreType::SINGLE_VERSION; DistributedKv::AppId appId = {.appId = APP_ID};