From 0ad5b9defd621c99d35f324538ee8e3af41e3cc2 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Tue, 8 Jan 2019 14:59:55 -0800 Subject: NotificationEntryListener: pre & post onEntryUpdated Some of the listeners care about doing things to notifications prior to the entries being filtered and some of them care about it after the entries are filtered. This CL introduces new method onPreEntryUpdated and alters the existing method to be onPostEntryUpdated so that listeners can know about both events. Test: atest NotificationEntryManagerTest#estUpdateNotification_prePostEntryOrder Change-Id: Ifa56fbf27cbc8f58c8eda9c95c79a57f1a52c9ac --- .../ForegroundServiceNotificationListener.java | 2 +- .../notification/NotificationAlertingManager.java | 2 +- .../notification/NotificationEntryListener.java | 10 ++++-- .../notification/NotificationEntryManager.java | 6 +++- .../stack/NotificationStackScrollLayout.java | 2 +- .../phone/StatusBarNotificationPresenter.java | 2 +- .../systemui/ForegroundServiceControllerTest.java | 2 +- .../notification/NotificationEntryManagerTest.java | 38 +++++++++++++++++++++- 8 files changed, 55 insertions(+), 9 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/ForegroundServiceNotificationListener.java b/packages/SystemUI/src/com/android/systemui/ForegroundServiceNotificationListener.java index 96f216e357af..96b62ac918ab 100644 --- a/packages/SystemUI/src/com/android/systemui/ForegroundServiceNotificationListener.java +++ b/packages/SystemUI/src/com/android/systemui/ForegroundServiceNotificationListener.java @@ -54,7 +54,7 @@ public class ForegroundServiceNotificationListener { } @Override - public void onEntryUpdated(NotificationEntry entry) { + public void onPostEntryUpdated(NotificationEntry entry) { updateNotification(entry.notification, entry.importance); } 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 c24698deabde..60d8cf460627 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationAlertingManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationAlertingManager.java @@ -77,7 +77,7 @@ public class NotificationAlertingManager { } @Override - public void onEntryUpdated(NotificationEntry entry) { + public void onPostEntryUpdated(NotificationEntry entry) { updateAlertState(entry); } 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 c6407604290f..eea44906029d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryListener.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryListener.java @@ -40,9 +40,15 @@ public interface NotificationEntryListener { } /** - * Called when a notification was updated. + * Called when a notification is updated, before any filtering of notifications have occurred. */ - default void onEntryUpdated(NotificationEntry entry) { + default void onPreEntryUpdated(NotificationEntry entry) { + } + + /** + * Called when a notification was updated, after any filtering of notifications have occurred. + */ + default void onPostEntryUpdated(NotificationEntry entry) { } /** 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 a4e3f339b58f..b7f17a158766 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java @@ -463,6 +463,10 @@ public class NotificationEntryManager implements getRowBinder().inflateViews(entry, () -> performRemoveNotification(notification), mNotificationData.get(entry.key) != null); + for (NotificationEntryListener listener : mNotificationEntryListeners) { + listener.onPreEntryUpdated(entry); + } + updateNotifications(); if (DEBUG) { @@ -473,7 +477,7 @@ public class NotificationEntryManager implements } for (NotificationEntryListener listener : mNotificationEntryListeners) { - listener.onEntryUpdated(entry); + listener.onPostEntryUpdated(entry); } maybeScheduleUpdateNotificationViews(entry); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java index e4b00dd6d38c..80db6c11e324 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java @@ -521,7 +521,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd mEntryManager.addNotificationEntryListener(new NotificationEntryListener() { @Override - public void onEntryUpdated(NotificationEntry entry) { + public void onPostEntryUpdated(NotificationEntry entry) { if (!entry.notification.isClearable()) { // The user may have performed a dismiss action on the notification, since it's // not clearable we should snap it back. 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 16c8e6232b00..b648fff124da 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java @@ -189,7 +189,7 @@ public class StatusBarNotificationPresenter implements NotificationPresenter, } @Override - public void onEntryUpdated(NotificationEntry entry) { + public void onPostEntryUpdated(NotificationEntry entry) { mShadeController.updateAreThereNotifications(); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java index 9400d6d723e9..31e8071f5677 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java @@ -404,6 +404,6 @@ public class ForegroundServiceControllerTest extends SysuiTestCase { private void entryUpdated(StatusBarNotification notification, int importance) { NotificationEntry entry = new NotificationEntry(notification); entry.importance = importance; - mEntryListener.onEntryUpdated(entry); + mEntryListener.onPostEntryUpdated(entry); } } 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 4d22536f34f0..d937f93482d5 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 @@ -26,6 +26,7 @@ import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; @@ -65,6 +66,7 @@ import com.android.systemui.statusbar.NotificationRemoteInputManager; import com.android.systemui.statusbar.RemoteInputController; import com.android.systemui.statusbar.SmartReplyController; import com.android.systemui.statusbar.StatusBarIconView; +import com.android.systemui.statusbar.notification.collection.NotificationData; import com.android.systemui.statusbar.notification.collection.NotificationData.KeyguardEnvironment; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; @@ -83,6 +85,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; +import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -137,6 +140,10 @@ public class NotificationEntryManagerTest extends SysuiTestCase { mCountDownLatch = new CountDownLatch(1); } + public void setNotificationData(NotificationData data) { + mNotificationData = data; + } + @Override public void onAsyncInflationFinished(NotificationEntry entry, @NotificationInflater.InflationFlag int inflatedFlags) { @@ -292,13 +299,42 @@ public class NotificationEntryManagerTest extends SysuiTestCase { verify(mEntryListener, never()).onInflationError(any(), any()); + verify(mEntryListener).onPreEntryUpdated(mEntry); verify(mPresenter).updateNotificationViews(); - verify(mEntryListener).onEntryUpdated(mEntry); + verify(mEntryListener).onPostEntryUpdated(mEntry); + assertNotNull(mEntry.getRow()); assertEquals(mEntry.userSentiment, NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE); } + @Test + public void testUpdateNotification_prePostEntryOrder() throws Exception { + com.android.systemui.util.Assert.isNotMainThread(); + TestableLooper.get(this).processAllMessages(); + + NotificationData notifData = mock(NotificationData.class); + when(notifData.get(mEntry.key)).thenReturn(mEntry); + + mEntryManager.setNotificationData(notifData); + + mEntryManager.updateNotification(mSbn, mRankingMap); + TestableLooper.get(this).processMessages(1); + // Wait for content update. + assertTrue(mEntryManager.getCountDownLatch().await(10, TimeUnit.SECONDS)); + + verify(mEntryListener, never()).onInflationError(any(), any()); + + // Ensure that update callbacks happen in correct order + InOrder order = inOrder(mEntryListener, notifData, mPresenter, mEntryListener); + order.verify(mEntryListener).onPreEntryUpdated(mEntry); + order.verify(notifData).filterAndSort(); + order.verify(mPresenter).updateNotificationViews(); + order.verify(mEntryListener).onPostEntryUpdated(mEntry); + + assertNotNull(mEntry.getRow()); + } + @Test public void testRemoveNotification() throws Exception { com.android.systemui.util.Assert.isNotMainThread(); -- cgit v1.2.3-59-g8ed1b