From 70e0aa487df83aada56a40b5277a6de2f6f56a78 Mon Sep 17 00:00:00 2001 From: Koji Fukui Date: Mon, 2 Sep 2019 20:06:36 +0900 Subject: [PATCH] Update NotificationRecord of snooze even after it is cancelled Symptom: If a snoozed notification is cancelled and new notification that has same key is registered, the system continue to snooze the notification. But the notification won't be notified when the snoozing period expires. Root cause: SnoozeHelper doesn't update NotificationRecord if the existing record has already been cancelled. SnoozeHelper continue to use existing cancelled record. So SnoozeHelper doesn't repost notification when the snoozing period expires. Solution: SnoozeHelper updates NotificationRecord even if the existing record has been cancelled. Test: atest SnoozeHelperTest Fixes: 140462813 Change-Id: I43468bf8ac712e09c288d71965dae34de439c5a8 --- .../server/notification/SnoozeHelper.java | 3 --- .../server/notification/SnoozeHelperTest.java | 20 +++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/notification/SnoozeHelper.java b/services/core/java/com/android/server/notification/SnoozeHelper.java index 8125d0d653add..9e32d0e81a471 100644 --- a/services/core/java/com/android/server/notification/SnoozeHelper.java +++ b/services/core/java/com/android/server/notification/SnoozeHelper.java @@ -374,9 +374,6 @@ public class SnoozeHelper { return; } NotificationRecord existing = pkgRecords.get(record.getKey()); - if (existing != null && existing.isCanceled) { - return; - } pkgRecords.put(record.getKey(), record); } diff --git a/services/tests/uiservicestests/src/com/android/server/notification/SnoozeHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/SnoozeHelperTest.java index 36175a93f6678..5841e59ab3a0d 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/SnoozeHelperTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/SnoozeHelperTest.java @@ -349,6 +349,26 @@ public class SnoozeHelperTest extends UiServiceTestCase { verify(mCallback, times(1)).repost(UserHandle.USER_SYSTEM, r); } + @Test + public void testUpdateAfterCancel() throws Exception { + // snooze a notification + NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); + mSnoozeHelper.snooze(r , 1000); + + // cancel the notification + mSnoozeHelper.cancel(UserHandle.USER_SYSTEM, false); + + // update the notification + r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); + mSnoozeHelper.update(UserHandle.USER_SYSTEM, r); + + // verify callback is called when repost (snooze is expired) + verify(mCallback, never()).repost(anyInt(), any(NotificationRecord.class)); + mSnoozeHelper.repost(r.getKey(), UserHandle.USER_SYSTEM); + verify(mCallback, times(1)).repost(UserHandle.USER_SYSTEM, r); + assertFalse(r.isCanceled); + } + @Test public void testGetSnoozedByUser() throws Exception { NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM);