diff options
| author | 2019-05-04 15:25:58 +0000 | |
|---|---|---|
| committer | 2019-05-04 15:25:58 +0000 | |
| commit | 66a23bf4f4d040227ca92d7e51c1e91c16febcfd (patch) | |
| tree | 2c0729785ae4b95b420fb30d42d833116fdf3e2d | |
| parent | 165ac85b3354d22a9ceefa6aed4e9a43b9ff06be (diff) | |
| parent | 1a4e86fb33125c22cdedeb532ba7929881fa47b1 (diff) | |
Merge "Follow up for a comment from ag/7080956" into qt-dev
5 files changed, 29 insertions, 15 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java index 3c5c1028763b..cff03c9b4b9b 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.View.VISIBLE; 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 @@ public class BubbleController implements ConfigurationController.ConfigurationLi && !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 d59a5e8593cc..9d5871eb595c 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 @@ public class NotificationListener extends NotificationListenerWithPlugins { // 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 @@ public class NotificationListener extends NotificationListenerWithPlugins { @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 d926f88d9f60..3ac5768f091a 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 @@ public class NotificationEntryManager implements 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 @@ public class NotificationEntryManager implements /** 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 ec8dae27809a..2d697e34c626 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_AP 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 @@ public class BubbleControllerTest extends SysuiTestCase { // 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 70941d3a602b..4d593c101706 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 @@ package com.android.systemui.statusbar.notification; 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 @@ public class NotificationEntryManagerTest extends SysuiTestCase { 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 class NotificationEntryManagerTest extends SysuiTestCase { 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 @@ public class NotificationEntryManagerTest extends SysuiTestCase { 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 @@ public class NotificationEntryManagerTest extends SysuiTestCase { 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 @@ public class NotificationEntryManagerTest extends SysuiTestCase { 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 @@ public class NotificationEntryManagerTest extends SysuiTestCase { 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 @@ public class NotificationEntryManagerTest extends SysuiTestCase { 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 @@ public class NotificationEntryManagerTest extends SysuiTestCase { .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 @@ public class NotificationEntryManagerTest extends SysuiTestCase { .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)); |