From fea369377124101da9f43c32752a1580b0e81323 Mon Sep 17 00:00:00 2001 From: Ned Burns Date: Fri, 26 Jun 2020 12:09:21 -0400 Subject: [PATCH] Ignore nonsensical clears from NoMan It appears that NoMan sometimes fails to send onNotificationPosted events for some notifications (possibly due to the notification limit?). It's possible to still receive onNotificationRemoved events for those notifications, so we ignore those events for now (long-term we should figure out if this is indeed a problem in NoMan). Bug: 159652654 Test: atest Change-Id: Ib15320f537e31a675d2766ba458b7bd019764c73 --- .../notification/collection/NotifCollection.java | 5 ++--- .../collection/notifcollection/NotifCollectionLogger.kt | 8 ++++++++ .../notification/collection/NotifCollectionTest.java | 7 ++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java index c1acfbadef459..285cf7abce201 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java @@ -382,9 +382,8 @@ public class NotifCollection implements Dumpable { final NotificationEntry entry = mNotificationSet.get(sbn.getKey()); if (entry == null) { - crashIfNotInitializing( - new IllegalStateException("No notification to remove with key " - + sbn.getKey())); + // TODO (b/160008901): Throw an exception here + mLogger.logNoNotificationToRemoveWithKey(sbn.getKey()); return; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/NotifCollectionLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/NotifCollectionLogger.kt index 76751eaaecb13..f8a778d6b1d2e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/NotifCollectionLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/NotifCollectionLogger.kt @@ -121,6 +121,14 @@ class NotifCollectionLogger @Inject constructor( }) } + fun logNoNotificationToRemoveWithKey(key: String) { + buffer.log(TAG, ERROR, { + str1 = key + }, { + "No notification to remove with key $str1" + }) + } + fun logRankingMissing(key: String, rankingMap: RankingMap) { buffer.log(TAG, WARNING, { str1 = key }, { "Ranking update is missing ranking for $str1" }) buffer.log(TAG, DEBUG, {}, { "Ranking map contents:" }) diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java index 363fe95aae18f..359faba48f084 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java @@ -1273,8 +1273,8 @@ public class NotifCollectionTest extends SysuiTestCase { verify(mInterceptor3, never()).shouldInterceptDismissal(clearable); } - @Test(expected = IllegalStateException.class) - public void testClearNotificationThrowsIfMissing() { + @Test + public void testClearNotificationDoesntThrowIfMissing() { // GIVEN that enough time has passed that we're beyond the forgiveness window mClock.advanceTime(5001); @@ -1287,7 +1287,8 @@ public class NotifCollectionTest extends SysuiTestCase { container.getSbn(), new RankingMap(new Ranking[]{ container.getRanking() })); - // THEN an exception is thrown + // THEN the event is ignored + verify(mCollectionListener, never()).onEntryRemoved(any(NotificationEntry.class), anyInt()); } @Test