From 4a9211aebb15fa99e54f0a57c240053129d6312c Mon Sep 17 00:00:00 2001 From: wangsen1994 Date: Fri, 12 Sep 2025 15:10:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E5=86=B5=E5=BC=80=E5=8F=91=E5=85=8B?= =?UTF-8?q?=E9=9A=86=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangsen1994 --- .../include/advanced_notification_service.h | 2 +- .../advanced_notification_slot_service.cpp | 20 +++++++++---- .../ans/src/advanced_notification_utils.cpp | 7 +++-- .../clone/notification_clone_bundle_info.cpp | 2 +- services/ans/src/system_event_observer.cpp | 3 +- ...dvanced_notification_slot_service_test.cpp | 30 +++++++++++++++++-- 6 files changed, 50 insertions(+), 14 deletions(-) diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index ed0e690f2..8538088f2 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1745,7 +1745,7 @@ private: void SetCollaborateReminderFlag(const sptr &request); ErrCode SetEnabledForBundleSlotInner(const sptr &bundleOption, const sptr &bundle, - const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl); + const NotificationConstant::SlotType &slotType, NotificationSlot slotInfo); ErrCode AddSlotThenPublishEvent( const sptr &slot, const sptr &bundle, diff --git a/services/ans/src/advanced_notification_slot_service.cpp b/services/ans/src/advanced_notification_slot_service.cpp index 780a1cabb..cf1edeedb 100644 --- a/services/ans/src/advanced_notification_slot_service.cpp +++ b/services/ans/src/advanced_notification_slot_service.cpp @@ -923,7 +923,7 @@ ErrCode AdvancedNotificationService::AddSlotThenPublishEvent( ErrCode AdvancedNotificationService::SetEnabledForBundleSlotInner( const sptr &bundleOption, const sptr &bundle, - const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) + const NotificationConstant::SlotType &slotType, NotificationSlot slotInfo) { sptr slot; ErrCode result = NotificationPreferences::GetInstance()->GetNotificationSlot(bundle, slotType, slot); @@ -935,16 +935,18 @@ ErrCode AdvancedNotificationService::SetEnabledForBundleSlotInner( return ERR_ANS_NO_MEMORY; } GenerateSlotReminderMode(slot, bundleOption); - return AddSlotThenPublishEvent(slot, bundle, enabled, isForceControl); + return AddSlotThenPublishEvent(slot, bundle, slotInfo.GetEnable(), + slotInfo.GetForceControl(), slotInfo.GetAuthorizedStatus()); } else if ((result == ERR_OK) && (slot != nullptr)) { - if (slot->GetEnable() == enabled && slot->GetForceControl() == isForceControl) { - slot->SetAuthorizedStatus(NotificationSlot::AuthorizedStatus::AUTHORIZED); + if (slot->GetEnable() == slotInfo.GetEnable() && slot->GetForceControl() == slotInfo.GetForceControl()) { + slot->SetAuthorizedStatus(slotInfo.GetAuthorizedStatus()); std::vector> slots; slots.push_back(slot); return NotificationPreferences::GetInstance()->AddNotificationSlots(bundle, slots); } NotificationPreferences::GetInstance()->RemoveNotificationSlot(bundle, slotType); - return AddSlotThenPublishEvent(slot, bundle, enabled, isForceControl); + return AddSlotThenPublishEvent(slot, bundle, slotInfo.GetEnable(), + slotInfo.GetForceControl(), slotInfo.GetAuthorizedStatus()); } ANS_LOGE("Set enable slot: GetNotificationSlot failed"); return result; @@ -972,7 +974,11 @@ ErrCode AdvancedNotificationService::SetEnabledForBundleSlot(const sptr(slotType)) + " enabled: " +std::to_string(enabled) + "isForceControl" + std::to_string(isForceControl)); ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { - result = SetEnabledForBundleSlotInner(bundleOption, bundle, slotType, enabled, isForceControl); + NotificationSlot slotInfo = NotificationSlot(slotType); + slotInfo.SetEnable(enabled); + slotInfo.SetForceControl(isForceControl); + slotInfo.SetAuthorizedStatus(NotificationSlot::AuthorizedStatus::AUTHORIZED); + result = SetEnabledForBundleSlotInner(bundleOption, bundle, slotType, slotInfo); })); notificationSvrQueue_->wait(handler); @@ -1260,6 +1266,7 @@ ErrCode AdvancedNotificationService::SetCheckConfig(int32_t response, const std: ANS_LOGE("Check handler is null."); return; } + ANS_LOGI("Push request retry %{public}s %{public}d.", requestId.c_str(), checkParam->retryTime); notificationSvrQueue_->submit_h([&, requestId]() { InvokeCheckConfig(requestId); }, ffrt::task_attr().name("checkLiveView").delay(DELAY_TIME_CHECK_LIVEVIEW)); })); @@ -1309,6 +1316,7 @@ ErrCode AdvancedNotificationService::GetLiveViewConfig(const std::vectorwait(handler); return result; diff --git a/services/ans/src/advanced_notification_utils.cpp b/services/ans/src/advanced_notification_utils.cpp index bcae685dd..4daf6d324 100644 --- a/services/ans/src/advanced_notification_utils.cpp +++ b/services/ans/src/advanced_notification_utils.cpp @@ -2025,8 +2025,11 @@ void AdvancedNotificationService::UpdateCloneBundleInfoFoSlot( } for (auto& cloneSlot : cloneBundleInfo.GetSlotInfo()) { - if (SetEnabledForBundleSlotInner(bundle, bundle, cloneSlot.slotType_, cloneSlot.enable_, - cloneSlot.isForceControl_) != ERR_OK) { + NotificationSlot slotInfo = NotificationSlot(cloneSlot.slotType_); + slotInfo.SetEnable(cloneSlot.enable_); + slotInfo.SetForceControl(cloneSlot.isForceControl_); + slotInfo.SetAuthorizedStatus(cloneSlot.GetAuthStaus()); + if (SetEnabledForBundleSlotInner(bundle, bundle, cloneSlot.slotType_, slotInfo) != ERR_OK) { ANS_LOGW("Set notification slots failed %{public}s.", cloneSlot.Dump().c_str()); } } diff --git a/services/ans/src/clone/notification_clone_bundle_info.cpp b/services/ans/src/clone/notification_clone_bundle_info.cpp index a189acbbd..3c25fc8d4 100644 --- a/services/ans/src/clone/notification_clone_bundle_info.cpp +++ b/services/ans/src/clone/notification_clone_bundle_info.cpp @@ -219,7 +219,7 @@ void NotificationCloneBundleInfo::FromJson(const nlohmann::json &jsonObject) std::string NotificationCloneBundleInfo::SlotInfo::Dump() const { return "type: " + std::to_string(slotType_) + " " + std::to_string(enable_) + " " - + std::to_string(isForceControl_); + + std::to_string(isForceControl_) + " " + std::to_string(authorizedStatus_); } int32_t NotificationCloneBundleInfo::SlotInfo::GetAuthStaus() const diff --git a/services/ans/src/system_event_observer.cpp b/services/ans/src/system_event_observer.cpp index ed18c9486..1659a5b7a 100644 --- a/services/ans/src/system_event_observer.cpp +++ b/services/ans/src/system_event_observer.cpp @@ -208,8 +208,7 @@ void SystemEventObserver::OnBundleUpdateEventInner(const EventFwk::CommonEventDa callbacks_.onBundleUpdate(bundleOption); } - AAFwk::Want want = data.GetWant(); - if (bundleOption != nullptr && want.GetBoolParam("isAppUpdate", false)) { + if (bundleOption != nullptr) { NotificationLiveViewUtils::GetInstance().NotifyLiveViewEvent( EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED, bundleOption); } diff --git a/services/ans/test/unittest/advanced_notification_slot_service_test.cpp b/services/ans/test/unittest/advanced_notification_slot_service_test.cpp index 682224a81..38a287632 100644 --- a/services/ans/test/unittest/advanced_notification_slot_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_slot_service_test.cpp @@ -912,12 +912,38 @@ HWTEST_F(AnsSlotServiceTest, SetEnabledForBundleSlotInner_00001, Function | Smal sptr bundle(new NotificationBundleOption("test7777", 7777)); NotificationConstant::SlotType slotType = NotificationConstant::SlotType::SERVICE_REMINDER; + NotificationSlot slotInfo = NotificationSlot(slotType); + slotInfo.SetEnable(true); + slotInfo.SetForceControl(true); auto ret = advancedNotificationService_->SetEnabledForBundleSlotInner( - bundleOption, bundle, slotType, true, true); + bundleOption, bundle, slotType, slotInfo); ASSERT_EQ(ret, ERR_OK); ret = advancedNotificationService_->SetEnabledForBundleSlotInner( - bundleOption, bundle, slotType, true, true); + bundleOption, bundle, slotType, slotInfo); + ASSERT_EQ(ret, ERR_OK); +} + +/** + * @tc.name: SetEnabledForBundleSlotInner_00002 + * @tc.desc: Test SetEnabledForBundleSlotInner_00002 + * @tc.type: FUNC + */ +HWTEST_F(AnsSlotServiceTest, SetEnabledForBundleSlotInner_00002, Function | SmallTest | Level1) +{ + sptr slot(new NotificationSlot()); + slot->SetEnable(true); + slot->SetForceControl(true); + sptr bundleOption(new NotificationBundleOption("test6666", 6666)); + sptr bundle(new NotificationBundleOption("test7777", 7777)); + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::LIVE_VIEW; + + NotificationSlot slotInfo = NotificationSlot(slotType); + slotInfo.SetEnable(true); + slotInfo.SetForceControl(true); + slotInfo.SetAuthorizedStatus(NotificationSlot::AuthorizedStatus::AUTHORIZED); + auto ret = advancedNotificationService_->SetEnabledForBundleSlotInner( + bundleOption, bundle, slotType, slotInfo); ASSERT_EQ(ret, ERR_OK); } -- Gitee