From 89c150dac053efbd332a1321e4c3199a1c5845e9 Mon Sep 17 00:00:00 2001 From: Julia Tuttle Date: Thu, 8 Jun 2023 16:39:43 -0400 Subject: [PATCH] Demote tryRemoveNotification crash to Log.wtf We're ending up removing a notification twice -- probably a race between clear all and dismissing or cancelling one of the notifications hit by the clear all. Short term, we don't want to bother our users with a crash, and we think the end state is okay -- a notification removed twice will be removed the first time, so the UI state should be okay -- so this changes the "throw IllegalStateException" in tryRemoveNotification to a Log.wtf, which will only crash *droidfood* builds. Bug: 282945192 Test: presubmit Change-Id: I65d7a9587946c51258263e5ea3069b4b5cdbc82e --- .../notification/collection/NotifCollection.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 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 b116246586b57..fb16d6ee6b010 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 @@ -61,6 +61,7 @@ import android.service.notification.NotificationListenerService.Ranking; import android.service.notification.NotificationListenerService.RankingMap; import android.service.notification.StatusBarNotification; import android.util.ArrayMap; +import android.util.Log; import android.util.Pair; import androidx.annotation.NonNull; @@ -513,10 +514,16 @@ public class NotifCollection implements Dumpable, PipelineDumpable { * @return True if the notification was removed, false otherwise. */ private boolean tryRemoveNotification(NotificationEntry entry) { - if (mNotificationSet.get(entry.getKey()) != entry) { + final NotificationEntry storedEntry = mNotificationSet.get(entry.getKey()); + if (storedEntry == null) { + Log.wtf(TAG, "TRY REMOVE non-existent notification " + logKey(entry)); + return false; + } else if (storedEntry != entry) { throw mEulogizer.record( - new IllegalStateException("No notification to remove with key " - + logKey(entry))); + new IllegalStateException("Mismatched stored and tryRemoved entries" + + " for key " + logKey(entry) + ":" + + " stored=@" + Integer.toHexString(storedEntry.hashCode()) + + " tryRemoved=@" + Integer.toHexString(entry.hashCode()))); } if (!entry.isCanceled()) {