From 20c3909ffc3a6792eb0efe358ad917ea5ef37a82 Mon Sep 17 00:00:00 2001 From: z00454238 Date: Sat, 7 Jun 2025 14:38:53 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E6=A8=A1=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=20Signed-off-by:=20z00454238=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/ans/IAnsManager.idl | 2 +- frameworks/core/src/ans_notification.cpp | 2 +- .../ans_manager_proxy_unit_test.cpp | 8 +++--- .../ans_notification_branch_test.cpp | 3 ++- .../include/advanced_notification_service.h | 4 ++- .../ans/src/enable_manager/enable_manager.cpp | 26 ++++++++++++++----- .../ans/src/notification_dialog_manager.cpp | 2 +- tools/test/mock/mock_ans_manager_stub.h | 3 ++- 8 files changed, 34 insertions(+), 16 deletions(-) diff --git a/frameworks/ans/IAnsManager.idl b/frameworks/ans/IAnsManager.idl index 87d8151ce..305d79df2 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 d91ca8db7..d4a2d0ac5 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 f55a3ebfb..7d464cec1 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 42f37eca2..0b4c0218b 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 389b5bb24..506483887 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 d33db2748..cd2a5158e 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 1634fb469..c58cdf8d4 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 6e602d4b5..507cce815 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; } -- Gitee