From dca2be5f93a971bfab04fdddf075e61c2a32afee Mon Sep 17 00:00:00 2001 From: Gus Prevas Date: Fri, 21 Dec 2018 11:25:10 -0500 Subject: [PATCH] Combines NotificationEntryManager listener interfaces (part 5). This change combines the onEntryRemoved() and onPerformRemoveNotification() methods on NotificationEntryListener to a single method. The latter method was called after the former method in all cases where the removal of the notification was precipitated by user action (swipe, bubble swipe, launching content intent), so it's replaced by a boolean parameter to the former method indicating whether a user action caused the removal. Test: atest SystemUITests, manual Change-Id: I448fdd68984e3c2489259940c4d3432ac5bfe320 --- .../NotificationAlertingManager.java | 3 ++- .../NotificationEntryListener.java | 18 +++++---------- .../NotificationEntryManager.java | 23 ++++++++++--------- .../NotificationGroupAlertTransferHelper.java | 3 ++- .../phone/StatusBarNotificationPresenter.java | 13 ++++------- .../NotificationEntryManagerTest.java | 6 +++-- ...ificationGroupAlertTransferHelperTest.java | 2 +- 7 files changed, 32 insertions(+), 36 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationAlertingManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationAlertingManager.java index 39d40dbf6fd5a..f8e4a90a19a11 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationAlertingManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationAlertingManager.java @@ -81,7 +81,8 @@ public class NotificationAlertingManager { @Override public void onEntryRemoved( - String key, StatusBarNotification old, boolean lifetimeExtended) { + String key, StatusBarNotification old, boolean lifetimeExtended, + boolean removedByUser) { stopAlerting(key); } }); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryListener.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryListener.java index bacb6fec16fc7..03a18dfdf3f16 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryListener.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryListener.java @@ -59,21 +59,15 @@ public interface NotificationEntryListener { /** * Called when a notification has been removed (either because the user swiped it away or * because the developer retracted it). - * - * @param key key of notification that was removed + * @param key key of notification that was removed * @param old StatusBarNotification of the notification before it was removed * @param lifetimeExtended true if something is artificially extending how long the notification - * stays visible after it's removed + * @param removedByUser true if the notification was removed by a user action */ default void onEntryRemoved( - String key, StatusBarNotification old, boolean lifetimeExtended) { - } - - /** - * Removes a notification immediately. - * - * TODO: combine this with onEntryRemoved(). - */ - default void onPerformRemoveNotification(StatusBarNotification statusBarNotification) { + String key, + StatusBarNotification old, + boolean lifetimeExtended, + boolean removedByUser) { } } 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 f8e438eee59b0..a137ea2b561a4 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java @@ -246,15 +246,11 @@ public class NotificationEntryManager implements int dismissalSentiment = NotificationStats.DISMISS_SENTIMENT_NEUTRAL; mBarService.onNotificationClear(pkg, tag, id, userId, n.getKey(), dismissalSurface, dismissalSentiment, nv); - removeNotification(n.getKey(), null); - + removeNotificationInternal( + n.getKey(), null, false /* forceRemove */, true /* removedByUser */); } catch (RemoteException ex) { // system process is dead if we're here. } - - for (NotificationEntryListener listener : mNotificationEntryListeners) { - listener.onPerformRemoveNotification(n); - } } @Override @@ -294,7 +290,8 @@ public class NotificationEntryManager implements */ @Override public void handleInflationException(StatusBarNotification n, Exception e) { - removeNotificationInternal(n.getKey(), null, true /* forceRemove */); + removeNotificationInternal( + n.getKey(), null, true /* forceRemove */, false /* removedByUser */); try { mBarService.onNotificationError(n.getPackageName(), n.getTag(), n.getId(), n.getUid(), n.getInitialPid(), e.getMessage(), n.getUserId()); @@ -355,11 +352,15 @@ public class NotificationEntryManager implements @Override public void removeNotification(String key, NotificationListenerService.RankingMap ranking) { - removeNotificationInternal(key, ranking, false /* forceRemove */); + removeNotificationInternal( + key, ranking, false /* forceRemove */, false /* removedByUser */); } - private void removeNotificationInternal(String key, - @Nullable NotificationListenerService.RankingMap ranking, boolean forceRemove) { + private void removeNotificationInternal( + String key, + @Nullable NotificationListenerService.RankingMap ranking, + boolean forceRemove, + boolean removedByUser) { final NotificationData.Entry entry = mNotificationData.get(key); abortExistingInflation(key); @@ -405,7 +406,7 @@ public class NotificationEntryManager implements } for (NotificationEntryListener listener : mNotificationEntryListeners) { - listener.onEntryRemoved(key, old, lifetimeExtended); + listener.onEntryRemoved(key, old, lifetimeExtended, removedByUser); } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationGroupAlertTransferHelper.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationGroupAlertTransferHelper.java index 4217f8dfc382f..8be39f2c5025d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationGroupAlertTransferHelper.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationGroupAlertTransferHelper.java @@ -217,7 +217,8 @@ public class NotificationGroupAlertTransferHelper implements OnHeadsUpChangedLis @Override public void onEntryRemoved( - String key, StatusBarNotification old, boolean lifetimeExtended) { + String key, StatusBarNotification old, boolean lifetimeExtended, + boolean removedByUser) { // Removes any alerts pending on this entry. Note that this will not stop any inflation // tasks started by a transfer, so this should only be used as clean-up for when // inflation is stopped and the pending alert no longer needs to happen. diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java index 42b3d41d4f0ca..0a34ae4456d8c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java @@ -189,16 +189,13 @@ public class StatusBarNotificationPresenter implements NotificationPresenter, @Override public void onEntryRemoved(String key, StatusBarNotification old, - boolean lifetimeExtended) { + boolean lifetimeExtended, boolean removedByUser) { if (!lifetimeExtended) { StatusBarNotificationPresenter.this.onNotificationRemoved(key, old); } - } - - @Override - public void onPerformRemoveNotification( - StatusBarNotification statusBarNotification) { - StatusBarNotificationPresenter.this.onPerformRemoveNotification(); + if (removedByUser) { + maybeEndAmbientPulse(); + } } }; @@ -260,7 +257,7 @@ public class StatusBarNotificationPresenter implements NotificationPresenter, || mActivityLaunchAnimator.isAnimationRunning(); } - private void onPerformRemoveNotification() { + private void maybeEndAmbientPulse() { if (mNotificationPanel.hasPulsingNotifications() && !mAmbientPulseManager.hasNotifications()) { // We were showing a pulse for a notification, but no notifications are pulsing anymore. 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 69aae11a146f7..bed661d2daa23 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 @@ -323,7 +323,8 @@ public class NotificationEntryManagerTest extends SysuiTestCase { verify(mForegroundServiceController).removeNotification(mSbn); verify(mListContainer).cleanUpViewStateForEntry(mEntry); verify(mPresenter).updateNotificationViews(); - verify(mEntryListener).onEntryRemoved(mSbn.getKey(), mSbn, false /* lifetimeExtended */); + verify(mEntryListener).onEntryRemoved(mSbn.getKey(), mSbn, false /* lifetimeExtended */, + false /* removedByUser */); verify(mRow).setRemoved(); assertNull(mEntryManager.getNotificationData().get(mSbn.getKey())); @@ -347,7 +348,8 @@ public class NotificationEntryManagerTest extends SysuiTestCase { assertNotNull(mEntryManager.getNotificationData().get(mSbn.getKey())); verify(extender).setShouldManageLifetime(mEntry, true /* shouldManage */); - verify(mEntryListener).onEntryRemoved(mSbn.getKey(), null, true /* lifetimeExtended */); + verify(mEntryListener).onEntryRemoved(mSbn.getKey(), null, true /* lifetimeExtended */, + false /* removedByUser */); } @Test diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationGroupAlertTransferHelperTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationGroupAlertTransferHelperTest.java index a074bfdd79bd2..6c00f8ea755c6 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationGroupAlertTransferHelperTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationGroupAlertTransferHelperTest.java @@ -237,7 +237,7 @@ public class NotificationGroupAlertTransferHelperTest extends SysuiTestCase { mGroupManager.onEntryAdded(summaryEntry); mGroupManager.onEntryAdded(childEntry); - mNotificationEntryListener.onEntryRemoved(childEntry.key, null, false); + mNotificationEntryListener.onEntryRemoved(childEntry.key, null, false, false); assertFalse(mGroupAlertTransferHelper.isAlertTransferPending(childEntry)); }