Merge "Follow up for a comment from ag/7080956" into qt-dev

am: 66a23bf4f4

Change-Id: I42e3dca99ed66ff8a960b1e80b908d2f4b422f7d
This commit is contained in:
Mady Mellor
2019-05-04 08:45:27 -07:00
committed by android-build-merger
5 changed files with 29 additions and 15 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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() {

View File

@@ -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());
}

View File

@@ -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));