From 315dadf0c91f53e2827052336687789b76586dc8 Mon Sep 17 00:00:00 2001 From: songbao1 Date: Wed, 18 Jun 2025 10:32:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E9=94=80PC=E4=BA=91=E6=8E=A8=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E4=B8=8D=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- .../include/advanced_notification_service.h | 1 + .../ans/src/advanced_notification_utils.cpp | 54 ++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index dcd725510..a32be0f06 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -904,6 +904,7 @@ public: void OnResourceRemove(int32_t userId); void OnUserStopped(int32_t userId); void OnBundleDataCleared(const sptr &bundleOption); + void DeleteAllByUserStopped(int32_t userId); /** * @brief Obtains the event of bundle install. diff --git a/services/ans/src/advanced_notification_utils.cpp b/services/ans/src/advanced_notification_utils.cpp index a9faf05dd..b4bcc19f5 100644 --- a/services/ans/src/advanced_notification_utils.cpp +++ b/services/ans/src/advanced_notification_utils.cpp @@ -1248,7 +1248,59 @@ void AdvancedNotificationService::OnUserRemoved(const int32_t &userId) void AdvancedNotificationService::OnUserStopped(int32_t userId) { - DeleteAllByUserInner(userId, NotificationConstant::USER_LOGOUT_REASON_DELETE, true, true); + if (notificationSvrQueue_ == nullptr) { + ANS_LOGE("Serial queue is invalid."); + return; + } + + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([=]() { + DeleteAllByUserStopped(userId); + })); +} + +void AdvancedNotificationService::DeleteAllByUserStopped(int32_t userId) +{ + std::vector keys = GetNotificationKeys(nullptr); + std::vector> notifications; + std::vector timerIds; + for (auto key : keys) { +#ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED + std::string deviceId; + std::string bundleName; + GetDistributedInfo(key, deviceId, bundleName); +#endif + sptr notification = nullptr; + for (auto record : notificationList_) { + if ((record->notification->GetKey() == key) && + (record->notification->GetRecvUserId() == userId)) { + ProcForDeleteLiveView(record); + notification = record->notification; + notificationList_.remove(record); + break; + } + } + + if (notification == nullptr) { + continue; + } + if (notification->GetRecvUserId() == userId) { + UpdateRecentNotification(notification, true, NotificationConstant::USER_LOGOUT_REASON_DELETE); + notifications.emplace_back(notification); + timerIds.emplace_back(notification->GetAutoDeletedTimer()); +#ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED + DoDistributedDelete(deviceId, bundleName, notification); +#endif + } + if (notifications.size() >= MAX_CANCELED_PARCELABLE_VECTOR_NUM) { + SendNotificationsOnCanceled(notifications, nullptr, NotificationConstant::USER_LOGOUT_REASON_DELETE); + } + } + + if (!notifications.empty()) { + NotificationSubscriberManager::GetInstance()->BatchNotifyCanceled( + notifications, nullptr, NotificationConstant::USER_LOGOUT_REASON_DELETE); + } + BatchCancelTimer(timerIds); } ErrCode AdvancedNotificationService::DeleteAllByUser(int32_t userId) -- Gitee