diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index ed0e690f262838a045adb77f25d7c771df1e9bf7..8538088f2a779fc0767feafd2f197895a2dcff3c 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 780a1cabb64a49291604766140a6ab44dcdf0e64..cf1edeedb9865da4f0457713847aa5776c1702d1 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 bcae685ddfb09b9d6301e63c5ccbb3914a3bc2c1..4daf6d324c9704854eb756dfca0aeda2e2f5eabf 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 a189acbbd8a0bc8a8844c6c8b506fa596202f790..3c25fc8d4d31049be48840d221f9849a23e1a3b7 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 ed18c9486103494c9228914fe0823dbc6e52f8b9..1659a5b7a29b50223406ddbadf4024c352e1ed6a 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 682224a811cc1698ed59bf7e954d8bc394fc2e0e..38a2876322d81112da248439cb7daabf504a2896 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); }