From d9dc2ef4dd2e13735a5fda23a46a1bfee5ebd9a9 Mon Sep 17 00:00:00 2001 From: liqiang Date: Sat, 29 Jan 2022 11:31:16 +0800 Subject: [PATCH] IssueNo:https://gitee.com/openharmony/notification_ans_standard/issues/I4SIQ5 Description:fix enableDistributedSelf api error bug Sig: SIG_ApplicationFramework Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: liqiang Change-Id: Ib7c956dff68e6a211118071fadd1151b3bfc2616 --- .../ans/src/advanced_notification_service.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index dd6a7b6aa..cb95e52d1 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -2448,8 +2448,13 @@ ErrCode AdvancedNotificationService::EnableDistributedByBundle( return ERR_ANS_PERMISSION_DENIED; } + sptr bundle = GenerateValidBundleOption(bundleOption); + if (bundle == nullptr) { + return ERR_ANS_INVALID_BUNDLE; + } + bool appInfoEnable = true; - GetDistributedEnableInApplicationInfo(bundleOption, appInfoEnable); + GetDistributedEnableInApplicationInfo(bundle, appInfoEnable); if (!appInfoEnable) { ANS_LOGD("Get from bms is %{public}d", appInfoEnable); return ERR_ANS_PERMISSION_DENIED; @@ -2457,7 +2462,7 @@ ErrCode AdvancedNotificationService::EnableDistributedByBundle( ErrCode result = ERR_OK; handler_->PostSyncTask(std::bind([&]() { - result = DistributedPreferences::GetInstance()->SetDistributedBundleEnable(bundleOption, enabled); + result = DistributedPreferences::GetInstance()->SetDistributedBundleEnable(bundle, enabled); if (result != ERR_OK) { result = ERR_OK; enabled = false; @@ -2508,8 +2513,13 @@ ErrCode AdvancedNotificationService::IsDistributedEnableByBundle( return ERR_ANS_PERMISSION_DENIED; } + sptr bundle = GenerateValidBundleOption(bundleOption); + if (bundle == nullptr) { + return ERR_ANS_INVALID_BUNDLE; + } + bool appInfoEnable = true; - GetDistributedEnableInApplicationInfo(bundleOption, appInfoEnable); + GetDistributedEnableInApplicationInfo(bundle, appInfoEnable); if (!appInfoEnable) { ANS_LOGD("Get from bms is %{public}d", appInfoEnable); enabled = appInfoEnable; @@ -2518,7 +2528,7 @@ ErrCode AdvancedNotificationService::IsDistributedEnableByBundle( ErrCode result = ERR_OK; handler_->PostSyncTask(std::bind([&]() { - result = DistributedPreferences::GetInstance()->GetDistributedBundleEnable(bundleOption, enabled); + result = DistributedPreferences::GetInstance()->GetDistributedBundleEnable(bundle, enabled); if (result != ERR_OK) { result = ERR_OK; enabled = false; -- Gitee