From 0793f30afce7f563fb6c62064dc3dd529ee54ae5 Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Tue, 26 Oct 2021 15:48:52 +0000 Subject: [PATCH] fixed bc6ecb8 from https://gitee.com/skyblackleon/notification_ans_standard/pulls/62 Remove notifications on app deleted Signed-off-by: zhaoyuan17 --- .../ans/src/advanced_notification_service.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 153e6bc72..3d8eb02a9 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1453,11 +1453,27 @@ void AdvancedNotificationService::OnBundleRemoved(const sptrPostTask(std::bind([bundleOption]() { + handler_->PostTask(std::bind([this, bundleOption]() { ErrCode result = NotificationPreferences::GetInstance().RemoveNotificationForBundle(bundleOption); if (result != ERR_OK) { ANS_LOGW("NotificationPreferences::RemoveNotificationForBundle failed: %{public}d", result); } + + std::vector keys = GetNotificationKeys(bundleOption); + for (auto key : keys) { + sptr notification = nullptr; + result = RemoveFromNotificationList(key, notification, true); + if (result != ERR_OK) { + continue; + } + + if (notification != nullptr) { + int reason = NotificationConstant::PACKAGE_CHANGED_REASON_DELETE; + UpdateRecentNotification(notification, true, reason); + sptr sortingMap = GenerateSortingMap(); + NotificationSubscriberManager::GetInstance()->NotifyCanceled(notification, sortingMap, reason); + } + } })); } -- Gitee