diff --git a/frameworks/ans/IAnsManager.idl b/frameworks/ans/IAnsManager.idl index 87d8151ce43734be8cc27ab2755fa6e2ed27baf3..305d79df24e5545e0e2321b34af6901c1f3cf2bf 100644 --- a/frameworks/ans/IAnsManager.idl +++ b/frameworks/ans/IAnsManager.idl @@ -128,7 +128,7 @@ interface OHOS.Notification.IAnsManager { void SetNotificationsEnabledForAllBundles([in] String deviceId, [in] boolean enabled); void SetNotificationsEnabledForSpecialBundle( - [in] String deviceId, [in] sptr bundleOption, [in] boolean enabled); + [in] String deviceId, [in] sptr bundleOption, [in] boolean enabled, [in] boolean updateUnEnbaleTime); void SetShowBadgeEnabledForBundle([in] sptr bundleOption, [in] boolean enabled); diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index d91ca8db7d427477608fb1e0ee459e58718ffad9..d4a2d0ac5bb4401cd68d0dfa072b7bef40faf54d 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -1149,7 +1149,7 @@ ErrCode AnsNotification::SetNotificationsEnabledForSpecifiedBundle( ANS_LOGE("Fail: bundle is nullptr."); return ERR_ANS_INVALID_PARAM; } - return proxy->SetNotificationsEnabledForSpecialBundle(deviceId, bo, enabled); + return proxy->SetNotificationsEnabledForSpecialBundle(deviceId, bo, enabled, true); } ErrCode AnsNotification::SetShowBadgeEnabledForBundle(const NotificationBundleOption &bundleOption, bool enabled) diff --git a/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp index f55a3ebfba32de6880bb73deaa3189b366cb4cc0..7d464cec1f2e2b7f5fc8ef22034cf2c164f32558 100644 --- a/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp +++ b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp @@ -3639,7 +3639,7 @@ HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_01 std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); sptr bundleOption = new (std::nothrow) NotificationBundleOption(); - int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true); + int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true, true); EXPECT_EQ(ERR_INVALID_VALUE, result); } @@ -3662,7 +3662,7 @@ HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_02 std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); sptr bundleOption = new (std::nothrow) NotificationBundleOption(); - int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true); + int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true, true); EXPECT_EQ(ERR_OK, result); } /* @@ -3682,7 +3682,7 @@ HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_03 std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); sptr bundleOption = new (std::nothrow) NotificationBundleOption(); - int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true); + int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true, true); EXPECT_EQ(DEAD_OBJECT, result); } @@ -3704,7 +3704,7 @@ HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_04 std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); sptr bundleOption = new (std::nothrow) NotificationBundleOption(); - int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true); + int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true, true); EXPECT_EQ(IPC_READ_ERROR, result); } diff --git a/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp b/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp index 42f37eca23e22dc802dfc96ef39857a5fc0c3903..0b4c0218b0470a37c96c22f976ffd02f04ba8457 100644 --- a/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp +++ b/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp @@ -250,7 +250,8 @@ public: } ErrCode SetNotificationsEnabledForSpecialBundle( - const std::string &deviceId, const sptr &bundleOption, bool enabled) override + const std::string &deviceId, const sptr &bundleOption, + bool enabled, bool updateUnEnableTime) override { return ERR_ANS_INVALID_PARAM; } diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 389b5bb2414b696ed2592faf3abd421c52c3b5f2..506483887419204d190e5512e4b37f9b873db7dc 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -495,10 +495,12 @@ public: * * @param bundleOption Indicates the NotificationBundleOption object. * @param enabled Indicates the flag that allows notification to be pulished. + * @param updateUnEnableTime Indicates whether update the unenable time. * @return Returns ERR_OK on success, others on failure. */ ErrCode SetNotificationsEnabledForSpecialBundle( - const std::string &deviceId, const sptr &bundleOption, bool enabled) override; + const std::string &deviceId, const sptr &bundleOption, + bool enabled, bool updateUnEnableTime = true) override; /** * @brief Sets whether the bundle allows the banner to display notification. diff --git a/services/ans/src/enable_manager/enable_manager.cpp b/services/ans/src/enable_manager/enable_manager.cpp index d33db27488ab02f27eb153b905286f39263ec632..cd2a5158e964ae424116931c750052492ea64236 100644 --- a/services/ans/src/enable_manager/enable_manager.cpp +++ b/services/ans/src/enable_manager/enable_manager.cpp @@ -223,7 +223,8 @@ ErrCode AdvancedNotificationService::SetNotificationsEnabledForAllBundles(const } ErrCode AdvancedNotificationService::SetNotificationsEnabledForSpecialBundle( - const std::string &deviceId, const sptr &bundleOption, bool enabled) + const std::string &deviceId, const sptr &bundleOption, bool enabled, + bool updateUnEnableTime) { HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_13, EventBranchId::BRANCH_5); HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); @@ -276,10 +277,12 @@ ErrCode AdvancedNotificationService::SetNotificationsEnabledForSpecialBundle( if (result == ERR_OK) { if (!enabled) { result = RemoveAllNotificationsForDisable(bundle); + } #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER + if (!enabled && result == ERR_OK && updateUnEnableTime) { SetDialogPoppedUnEnableTime(bundleOption); -#endif } +#endif SetSlotFlagsTrustlistsAsBundle(bundle); NotificationSubscriberManager::GetInstance()->NotifyEnabledNotificationChanged(bundleData); PublishSlotChangeCommonEvent(bundle); @@ -337,10 +340,21 @@ ErrCode AdvancedNotificationService::CanPopEnableNotificationDialog( return ERROR_INTERNAL_ERROR; } if (hasPopped) { - ANS_LOGE("Has popped is true."); - message.ErrorCode(ERR_ANS_NOT_ALLOWED).Append(" Haspopped true"); - NotificationAnalyticsUtil::ReportModifyEvent(message); - return ERR_ANS_NOT_ALLOWED; +#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER + int32_t userId = -1; + OsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(bundleOption->GetUid(), userId); + if (!EXTENTION_WRAPPER->GetPrivilegeDialogPopped(bundleOption, userId)) { +#endif + ANS_LOGE("Has popped is true."); + message.ErrorCode(ERR_ANS_NOT_ALLOWED).Append(" Haspopped true"); + NotificationAnalyticsUtil::ReportModifyEvent(message); + return ERR_ANS_NOT_ALLOWED; +#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER + } else { + ANS_LOGI("duplicated popped."); + message.Append(" duplicated popped."); + } +#endif } if (!EXTENTION_WRAPPER->NotificationDialogControl()) { return ERR_ANS_NOT_ALLOWED; diff --git a/services/ans/src/notification_dialog_manager.cpp b/services/ans/src/notification_dialog_manager.cpp index 1634fb469d4ecbbb8b8d0e6940706ea50dd5f9f0..c58cdf8d4e8429e1b5412416de440b55b605dc58 100644 --- a/services/ans/src/notification_dialog_manager.cpp +++ b/services/ans/src/notification_dialog_manager.cpp @@ -265,7 +265,7 @@ bool NotificationDialogManager::OnDialogCrashed(const std::string& bundleName, c ErrCode result = ans_.SetNotificationsEnabledForSpecialBundle( NotificationDialogManager::DEFAULT_DEVICE_ID, - bundleOption, false); + bundleOption, false, false); if (result != ERR_OK) { ANS_LOGE("SetNotificationsEnabledForSpecialBundle Failed, code is %{public}d", result); // Do not return here, need to clear the data diff --git a/tools/test/mock/mock_ans_manager_stub.h b/tools/test/mock/mock_ans_manager_stub.h index 6e602d4b5b85f6bb2d8f82daff3c3bb4c0acef83..507cce815f4bb1d09e186a4c2ccd581fd677c27f 100644 --- a/tools/test/mock/mock_ans_manager_stub.h +++ b/tools/test/mock/mock_ans_manager_stub.h @@ -239,7 +239,8 @@ public: } ErrCode SetNotificationsEnabledForSpecialBundle( - const std::string& deviceId, const sptr& bundleOption, bool enabled) override + const std::string& deviceId, const sptr& bundleOption, bool enabled, + bool updateUnEnableTime) override { return ERR_ANS_INVALID_PARAM; }