Follow up for a comment from ag/7080956
Test: treehugger
Bug: 128459529
Change-Id: I79a559b3f992eae38bface74383a7a42d2261769
diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java
index 3c5c102..cff03c9 100644
--- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java
+++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java
@@ -27,6 +27,7 @@
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static com.android.systemui.statusbar.StatusBarState.SHADE;
+import static com.android.systemui.statusbar.notification.NotificationEntryManager.UNDEFINED_DISMISS_REASON;
import static java.lang.annotation.RetentionPolicy.SOURCE;
@@ -489,7 +490,7 @@
&& !bubble.entry.showInShadeWhenBubble()) {
// The bubble is gone & the notification is gone, time to actually remove it
mNotificationEntryManager.performRemoveNotification(bubble.entry.notification,
- 0 /* reason */);
+ UNDEFINED_DISMISS_REASON);
} else {
// The notification is still in the shade but we've removed the bubble so
// lets make sure NoMan knows it's not a bubble anymore
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java
index d59a5e8..9d5871e 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar;
import static com.android.systemui.statusbar.RemoteInputController.processForRemoteInput;
+import static com.android.systemui.statusbar.notification.NotificationEntryManager.UNDEFINED_DISMISS_REASON;
import static com.android.systemui.statusbar.phone.StatusBar.DEBUG;
import static com.android.systemui.statusbar.phone.StatusBar.ENABLE_CHILD_NOTIFICATIONS;
@@ -104,7 +105,7 @@
// Remove existing notification to avoid stale data.
if (isUpdate) {
- mEntryManager.removeNotification(key, rankingMap, 0 /* reason */);
+ mEntryManager.removeNotification(key, rankingMap, UNDEFINED_DISMISS_REASON);
} else {
mEntryManager.getNotificationData()
.updateRanking(rankingMap);
@@ -134,7 +135,7 @@
@Override
public void onNotificationRemoved(StatusBarNotification sbn, RankingMap rankingMap) {
- onNotificationRemoved(sbn, rankingMap, 0 /* reason */);
+ onNotificationRemoved(sbn, rankingMap, UNDEFINED_DISMISS_REASON);
}
@Override
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java
index d926f88..3ac5768 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java
@@ -67,6 +67,13 @@
private static final String TAG = "NotificationEntryMgr";
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
+ /**
+ * Used when a notification is removed and it doesn't have a reason that maps to one of the
+ * reasons defined in NotificationListenerService
+ * (e.g. {@link NotificationListenerService.REASON_CANCEL})
+ */
+ public static final int UNDEFINED_DISMISS_REASON = 0;
+
@VisibleForTesting
protected final HashMap<String, NotificationEntry> mPendingNotifications = new HashMap<>();
@@ -156,7 +163,8 @@
/** Adds a {@link NotificationLifetimeExtender}. */
public void addNotificationLifetimeExtender(NotificationLifetimeExtender extender) {
mNotificationLifetimeExtenders.add(extender);
- extender.setCallback(key -> removeNotification(key, mLatestRankingMap, 0));
+ extender.setCallback(key -> removeNotification(key, mLatestRankingMap,
+ UNDEFINED_DISMISS_REASON));
}
public NotificationData getNotificationData() {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java
index ec8dae2..2d697e3 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java
@@ -22,6 +22,8 @@
import static android.service.notification.NotificationListenerService.REASON_CANCEL;
import static android.service.notification.NotificationListenerService.REASON_CANCEL_ALL;
+import static com.android.systemui.statusbar.notification.NotificationEntryManager.UNDEFINED_DISMISS_REASON;
+
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
@@ -228,7 +230,7 @@
// Since the notif is dismissed, once the bubble is removed, performRemoveNotification gets
// called to really remove the notif
verify(mNotificationEntryManager, times(1)).performRemoveNotification(
- mRow.getEntry().notification, 0);
+ mRow.getEntry().notification, UNDEFINED_DISMISS_REASON);
assertFalse(mBubbleController.hasBubbles());
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java
index 70941d3..4d593c1 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java
@@ -18,6 +18,8 @@
import static android.service.notification.NotificationListenerService.REASON_CANCEL;
+import static com.android.systemui.statusbar.notification.NotificationEntryManager.UNDEFINED_DISMISS_REASON;
+
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
@@ -350,7 +352,7 @@
mEntry.setRow(mRow);
mEntryManager.getNotificationData().add(mEntry);
- mEntryManager.removeNotification(mSbn.getKey(), mRankingMap, 0 /* reason */);
+ mEntryManager.removeNotification(mSbn.getKey(), mRankingMap, UNDEFINED_DISMISS_REASON);
verify(mEntryListener, never()).onInflationError(any(), any());
@@ -366,7 +368,7 @@
public void testRemoveNotification_onEntryRemoveNotFiredIfEntryDoesntExist() {
com.android.systemui.util.Assert.isNotMainThread();
- mEntryManager.removeNotification("not_a_real_key", mRankingMap, 0 /* reason */);
+ mEntryManager.removeNotification("not_a_real_key", mRankingMap, UNDEFINED_DISMISS_REASON);
verify(mEntryListener, never()).onEntryRemoved(
eq(mEntry), any(), eq(false) /* removedByUser */);
@@ -379,7 +381,7 @@
mEntryManager.setRowBinder(mMockedRowBinder);
mEntryManager.addNotification(mSbn, mRankingMap);
- mEntryManager.removeNotification(mSbn.getKey(), mRankingMap, 0 /* reason */);
+ mEntryManager.removeNotification(mSbn.getKey(), mRankingMap, UNDEFINED_DISMISS_REASON);
verify(mEntryListener, never()).onEntryRemoved(
eq(mEntry), any(), eq(false /* removedByUser */));
@@ -458,7 +460,7 @@
mEntryManager.addNotificationLifetimeExtender(extender);
// WHEN the notification is removed
- mEntryManager.removeNotification(mEntry.key, mRankingMap, 0 /* reason */);
+ mEntryManager.removeNotification(mEntry.key, mRankingMap, UNDEFINED_DISMISS_REASON);
// THEN the extender is asked to manage the lifetime
verify(extender).setShouldManageLifetime(mEntry, true);
@@ -474,7 +476,7 @@
mEntryManager.getNotificationData().add(mEntry);
final FakeNotificationLifetimeExtender extender = new FakeNotificationLifetimeExtender();
mEntryManager.addNotificationLifetimeExtender(extender);
- mEntryManager.removeNotification(mEntry.key, mRankingMap, 0 /* reason */);
+ mEntryManager.removeNotification(mEntry.key, mRankingMap, UNDEFINED_DISMISS_REASON);
assertTrue(extender.isManaging(mEntry.key));
// WHEN the extender finishes its extension
@@ -494,7 +496,7 @@
NotificationLifetimeExtender extender = mock(NotificationLifetimeExtender.class);
when(extender.shouldExtendLifetime(mEntry)).thenReturn(true);
mEntryManager.addNotificationLifetimeExtender(extender);
- mEntryManager.removeNotification(mEntry.key, mRankingMap, 0 /* reason */);
+ mEntryManager.removeNotification(mEntry.key, mRankingMap, UNDEFINED_DISMISS_REASON);
// WHEN the notification is updated
mEntryManager.updateNotification(mEntry.notification, mRankingMap);
@@ -519,13 +521,13 @@
mEntryManager.addNotificationLifetimeExtender(extender2);
// GIVEN a notification was lifetime-extended and extender2 is managing it
- mEntryManager.removeNotification(mEntry.key, mRankingMap, 0 /* reason */);
+ mEntryManager.removeNotification(mEntry.key, mRankingMap, UNDEFINED_DISMISS_REASON);
verify(extender1, never()).setShouldManageLifetime(mEntry, true);
verify(extender2).setShouldManageLifetime(mEntry, true);
// WHEN the extender1 changes its mind and wants to extend the lifetime of the notif
when(extender1.shouldExtendLifetime(mEntry)).thenReturn(true);
- mEntryManager.removeNotification(mEntry.key, mRankingMap, 0 /* reason */);
+ mEntryManager.removeNotification(mEntry.key, mRankingMap, UNDEFINED_DISMISS_REASON);
// THEN extender2 stops managing the notif and extender1 starts managing it
verify(extender1).setShouldManageLifetime(mEntry, true);
@@ -553,7 +555,7 @@
.thenReturn(true);
// WHEN the notification is removed
- mEntryManager.removeNotification(mEntry.key, mRankingMap, 0 /* reason */);
+ mEntryManager.removeNotification(mEntry.key, mRankingMap, UNDEFINED_DISMISS_REASON);
// THEN the interceptor intercepts & the entry is not removed & no listeners are called
assertNotNull(mEntryManager.getNotificationData().get(mEntry.key));
@@ -572,7 +574,7 @@
.thenReturn(false);
// WHEN the notification is removed
- mEntryManager.removeNotification(mEntry.key, mRankingMap, 0 /* reason */);
+ mEntryManager.removeNotification(mEntry.key, mRankingMap, UNDEFINED_DISMISS_REASON);
// THEN the interceptor intercepts & the entry is not removed & no listeners are called
assertNull(mEntryManager.getNotificationData().get(mEntry.key));