From ff8a64c8d3fcb9f733abc17d75f26ec1345a11a9 Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Wed, 16 Mar 2022 19:40:22 +0800 Subject: [PATCH] Local notifications set isDistributed to false Signed-off-by: fangJinliang1 Change-Id: I98c86505b641dce28e7bd41bc60f7780089a1d0f Signed-off-by: fangJinliang1 --- .../ans/native/src/reminder_request.cpp | 1 + interfaces/kits/napi/ans/src/common.cpp | 6 +++- .../include/advanced_notification_service.h | 1 + .../ans/src/advanced_notification_service.cpp | 35 ++++++++++++++----- .../distributed/src/distributed_database.cpp | 1 + 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/frameworks/ans/native/src/reminder_request.cpp b/frameworks/ans/native/src/reminder_request.cpp index 381d0bb5d..d799cd5a8 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 92155b048..fb701e4e1 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 2173274d0..a6d4a388f 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 e9b19de45..0962dfccb 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 4b6072771..8dccefc9b 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}; -- Gitee