diff --git a/services/ans/src/advanced_notification_live_view_service.cpp b/services/ans/src/advanced_notification_live_view_service.cpp index 83c7123604ddc05e39f15bda7adeaabf2d2002a4..b9345c323dcc42a9289b5418032d6323aaf5596a 100644 --- a/services/ans/src/advanced_notification_live_view_service.cpp +++ b/services/ans/src/advanced_notification_live_view_service.cpp @@ -116,6 +116,9 @@ ErrCode AdvancedNotificationService::UpdateNotificationTimerInfo(const std::shar ErrCode result = ERR_OK; if (!record->request->IsCommonLiveView()) { + if ((record->request->GetAutoDeletedTime() > GetCurrentTime())) { + StartAutoDeletedTimer(record); + } return ERR_OK; } diff --git a/services/ans/src/advanced_notification_manager/advanced_notification_publish.cpp b/services/ans/src/advanced_notification_manager/advanced_notification_publish.cpp index 70974cdd7b2781ea42216dafd7304d5ce7995150..f1bc5ce08eceee73c9fbf8cfa66c77437bc03d24 100644 --- a/services/ans/src/advanced_notification_manager/advanced_notification_publish.cpp +++ b/services/ans/src/advanced_notification_manager/advanced_notification_publish.cpp @@ -241,17 +241,15 @@ ErrCode AdvancedNotificationService::PublishNotificationForIndirectProxy(const s sptr sortingMap = GenerateSortingMap(); NotificationSubscriberManager::GetInstance()->NotifyConsumed(record->notification, sortingMap); + if ((record->request->GetAutoDeletedTime() > GetCurrentTime()) && !record->request->IsCommonLiveView()) { + StartAutoDeletedTimer(record); + } }); notificationSvrQueue_->wait(handler); if (result != ERR_OK) { NotificationAnalyticsUtil::ReportPublishFailedEvent(request, message); return result; } - - if ((record->request->GetAutoDeletedTime() > GetCurrentTime()) && !record->request->IsCommonLiveView()) { - StartAutoDelete(record, - record->request->GetAutoDeletedTime(), NotificationConstant::TRIGGER_AUTO_DELETE_REASON_DELETE); - } return ERR_OK; } diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index 918387de0ae56a725e26d146dcf33f541f34ddbc..5669f34e5245772e2889b1d4333e0f5f69536eab 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -112,6 +112,9 @@ void AdvancedNotificationService::SetCollaborateReminderFlag(const sptr &record) { if (!record->request->IsCommonLiveView()) { + if ((record->request->GetAutoDeletedTime() > GetCurrentTime())) { + StartAutoDeletedTimer(record); + } return; } @@ -760,15 +763,14 @@ ErrCode AdvancedNotificationService::PublishNotificationBySa(const sptrnotification, false, 0); sptr sortingMap = GenerateSortingMap(); NotificationSubscriberManager::GetInstance()->NotifyConsumed(record->notification, sortingMap); + if ((record->request->GetAutoDeletedTime() > GetCurrentTime()) && !record->request->IsCommonLiveView()) { + StartAutoDeletedTimer(record); + } }); notificationSvrQueue_->wait(handler); if (result != ERR_OK) { return result; } - - if ((record->request->GetAutoDeletedTime() > GetCurrentTime()) && !record->request->IsCommonLiveView()) { - StartAutoDeletedTimer(record); - } return ERR_OK; } diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 3b3c07d4405cc41e4e2ed75672ef5f5890f5bffb..51da9646601c2c784a109c474562cd1dc3fd1cc6 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -608,6 +608,10 @@ ErrCode AdvancedNotificationService::StartAutoDeletedTimer(const std::shared_ptr ANS_LOGE("%{public}s", message.c_str()); return ERR_ANS_TASK_ERR; } + uint64_t originTimerId = record->notification->GetAutoDeletedTimer(); + if (originTimerId != NotificationConstant::INVALID_TIMER_ID) { + CancelTimer(originTimerId); + } record->notification->SetAutoDeletedTimer(timerId); return ERR_OK; } @@ -755,10 +759,6 @@ ErrCode AdvancedNotificationService::PublishPreparedNotification(const sptrwait(handler); - // live view handled in UpdateNotificationTimerInfo, ignore here. - if ((record->request->GetAutoDeletedTime() > GetCurrentTime()) && !record->request->IsCommonLiveView()) { - StartAutoDeletedTimer(record); - } return result; } @@ -1128,6 +1128,8 @@ ErrCode AdvancedNotificationService::UpdateInNotificationList(const std::shared_ LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->UpdateLiveviewVoiceContent(record->request); } FillLockScreenPicture(record->request, (*iter)->request); + record->notification->SetAutoDeletedTimer((*iter)->notification->GetAutoDeletedTimer()); + record->notification->SetArchiveTimer((*iter)->notification->GetArchiveTimer()); record->notification->SetUpdateTimer((*iter)->notification->GetUpdateTimer()); if (!record->request->IsSystemLiveView()) { record->notification->SetFinishTimer((*iter)->notification->GetFinishTimer()); @@ -1834,6 +1836,7 @@ void AdvancedNotificationService::TriggerAutoDelete(const std::string &hashCode, if (record->notification->GetKey() == hashCode) { UpdateRecentNotification(record->notification, true, reason); + TriggerRemoveWantAgent(record->request, reason, record->isThirdparty); CancelTimer(record->notification->GetAutoDeletedTimer()); NotificationSubscriberManager::GetInstance()->NotifyCanceled(record->notification, nullptr, reason); ProcForDeleteLiveView(record); diff --git a/services/ans/test/unittest/advanced_notification_service_branch_test.cpp b/services/ans/test/unittest/advanced_notification_service_branch_test.cpp index f203eef34743f4f8ada8554dbf4053aad983c002..d48872dd6860b1d433b53ed4cdc2beeede01b7ae 100644 --- a/services/ans/test/unittest/advanced_notification_service_branch_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_branch_test.cpp @@ -1256,6 +1256,25 @@ HWTEST_F(AnsBranchTest, AnsBranchTest_279002, Function | SmallTest | Level1) ASSERT_EQ(record->notification->GetFinishTimer(), NotificationConstant::INVALID_TIMER_ID); } +HWTEST_F(AnsBranchTest, AnsBranchTest_279003, Function | SmallTest | Level1) +{ + auto record = std::make_shared(); + NotificationRequest notificationRequest; + notificationRequest.SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); + auto basicContent = std::make_shared(); + auto content = std::make_shared(basicContent); + notificationRequest.SetContent(content); + + record->request = sptr::MakeSptr(notificationRequest); + record->notification = new (std::nothrow) Notification(record->request); + + auto result = advancedNotificationService_->UpdateNotificationTimerInfo(record); + + ASSERT_EQ(result, ERR_OK); + /* finish timer not change, but update timer changed */ + ASSERT_EQ(record->notification->GetAutoDeletedTimer(), NotificationConstant::INVALID_TIMER_ID); +} + /** * @tc.number : GetDeviceRemindType_3000 * @tc.name : GetDeviceRemindType_3000 diff --git a/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_service_unit_test.cpp b/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_service_unit_test.cpp index a457a8b7a81affc8ff655f681aac4fbf05557178..dd5e4a78fa5c9cd3dbef6eb72f8cf08d999df9f9 100644 --- a/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_service_unit_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_service_unit_test.cpp @@ -692,6 +692,24 @@ HWTEST_F(AdvancedNotificationServiceUnitTest, StartAutoDeletedTimer_200, Functio ASSERT_EQ(ret, (int)ERR_OK); } +/** + * @tc.name: StartAutoDeletedTimer_300 + * @tc.desc: Test StartAutoDeletedTimer when timer succeeded to create and cancel origin timer. + * @tc.type: FUNC + */ +HWTEST_F(AdvancedNotificationServiceUnitTest, StartAutoDeletedTimer_300, Function | SmallTest | Level1) +{ + sptr request = new (std::nothrow) NotificationRequest(); + auto bundle = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID); + auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle); + record->notification->SetAutoDeletedTimer(1); + + auto ret = advancedNotificationService_->StartAutoDeletedTimer(record); + advancedNotificationService_->TriggerAutoDelete("hashCode", 27); + + ASSERT_EQ(ret, (int)ERR_OK); +} + /** * @tc.name: ReportDoNotDisturbModeChanged_100 * @tc.desc: Test ReportDoNotDisturbModeChanged.