diff options
| author | 2020-01-30 13:10:29 -0800 | |
|---|---|---|
| committer | 2020-02-05 09:47:21 -0800 | |
| commit | f400aee8435668136ede2bc9bd8577a65c14c34e (patch) | |
| tree | bc8b0e2d4a74642cc654ac5de1059af9a7229807 | |
| parent | 3d358dba3d5ae8675b6093e5f92d08b33aad7185 (diff) | |
Interface for notification collection being used
Add an interface for the active collection that is managing the list
of notifications that will be shown on screen.
This saves us from having to do a flag check in each class that can
potentially be used from both NotificationEntryManager and
NotifPipeline and makes it easy to swap them all out for
NotifPipeline once everything is eventually moved over.
We switch NotifRemoteViewCacheImpl to use this interface so that
NotificationContentInflater can now work in the new pipeline without
entry mismatching throwing things off.
Test: smoke test with Notify apk
Test: atest SystemUITests
Change-Id: I8e6a054562b9e7d0ddb385e8d35d81c3b1698833
6 files changed, 102 insertions, 29 deletions
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 6bb377e89278..c8bf51dbcf44 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java @@ -18,6 +18,7 @@ package com.android.systemui.statusbar.notification; import static android.service.notification.NotificationListenerService.REASON_CANCEL; import static android.service.notification.NotificationListenerService.REASON_ERROR; +import static com.android.systemui.statusbar.notification.collection.NotifCollection.REASON_UNKNOWN; import static com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationCallback; import android.annotation.NonNull; @@ -44,6 +45,8 @@ import com.android.systemui.statusbar.NotificationUiAdjustment; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.collection.NotificationRankingManager; import com.android.systemui.statusbar.notification.collection.inflation.NotificationRowBinder; +import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection; +import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener; import com.android.systemui.statusbar.notification.logging.NotifEvent; import com.android.systemui.statusbar.notification.logging.NotifLog; import com.android.systemui.statusbar.notification.logging.NotificationLogger; @@ -96,6 +99,7 @@ import dagger.Lazy; */ @Singleton public class NotificationEntryManager implements + CommonNotifCollection, Dumpable, InflationCallback, VisualStabilityManager.Callback { @@ -130,6 +134,7 @@ public class NotificationEntryManager implements private final Lazy<NotificationRowBinder> mNotificationRowBinderLazy; private final Lazy<NotificationRemoteInputManager> mRemoteInputManagerLazy; private final LeakDetector mLeakDetector; + private final List<NotifCollectionListener> mNotifCollectionListeners = new ArrayList<>(); private final KeyguardEnvironment mKeyguardEnvironment; private final NotificationGroupManager mGroupManager; @@ -488,6 +493,13 @@ public class NotificationEntryManager implements for (NotificationEntryListener listener : mNotificationEntryListeners) { listener.onEntryRemoved(entry, visibility, removedByUser); } + for (NotifCollectionListener listener : mNotifCollectionListeners) { + // NEM doesn't have a good knowledge of reasons so defaulting to unknown. + listener.onEntryRemoved(entry, REASON_UNKNOWN); + } + for (NotifCollectionListener listener : mNotifCollectionListeners) { + listener.onEntryCleanUp(entry); + } } } } @@ -553,6 +565,10 @@ public class NotificationEntryManager implements mLeakDetector.trackInstance(entry); + for (NotifCollectionListener listener : mNotifCollectionListeners) { + listener.onEntryInit(entry); + } + // Construct the expanded view. if (!mFeatureFlags.isNewNotifPipelineRenderingEnabled()) { mNotificationRowBinderLazy.get() @@ -566,6 +582,9 @@ public class NotificationEntryManager implements for (NotificationEntryListener listener : mNotificationEntryListeners) { listener.onPendingEntryAdded(entry); } + for (NotifCollectionListener listener : mNotifCollectionListeners) { + listener.onEntryAdded(entry); + } } public void addNotification(StatusBarNotification notification, RankingMap ranking) { @@ -600,6 +619,9 @@ public class NotificationEntryManager implements for (NotificationEntryListener listener : mNotificationEntryListeners) { listener.onPreEntryUpdated(entry); } + for (NotifCollectionListener listener : mNotifCollectionListeners) { + listener.onEntryUpdated(entry); + } if (!mFeatureFlags.isNewNotifPipelineRenderingEnabled()) { mNotificationRowBinderLazy.get() @@ -674,6 +696,9 @@ public class NotificationEntryManager implements for (NotificationEntryListener listener : mNotificationEntryListeners) { listener.onNotificationRankingUpdated(rankingMap); } + for (NotifCollectionListener listener : mNotifCollectionListeners) { + listener.onRankingUpdate(rankingMap); + } } private void updateRankingOfPendingNotifications(@Nullable RankingMap rankingMap) { @@ -862,6 +887,11 @@ public class NotificationEntryManager implements return mReadOnlyNotifications.size() != 0; } + @Override + public void addCollectionListener(NotifCollectionListener listener) { + mNotifCollectionListeners.add(listener); + } + /* * End annexation * ----- diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifPipeline.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifPipeline.java index 9142388374e3..5767ad93014e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifPipeline.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifPipeline.java @@ -23,6 +23,7 @@ import com.android.systemui.statusbar.notification.collection.listbuilder.plugga import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifFilter; import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifPromoter; import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifSection; +import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection; import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener; import com.android.systemui.statusbar.notification.collection.notifcollection.NotifLifetimeExtender; @@ -66,7 +67,7 @@ import javax.inject.Singleton; * 9. The list is handed off to the view layer to be rendered */ @Singleton -public class NotifPipeline { +public class NotifPipeline implements CommonNotifCollection { private final NotifCollection mNotifCollection; private final ShadeListBuilder mShadeListBuilder; @@ -89,10 +90,7 @@ public class NotifPipeline { return mNotifCollection.getActiveNotifs(); } - /** - * Registers a listener to be informed when there is a notification entry event such as an add, - * update, or remove. - */ + @Override public void addCollectionListener(NotifCollectionListener listener) { mNotifCollection.addCollectionListener(listener); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/CommonNotifCollection.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/CommonNotifCollection.java new file mode 100644 index 000000000000..171816fd28da --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/CommonNotifCollection.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.statusbar.notification.collection.notifcollection; + +import com.android.systemui.statusbar.notification.NotificationEntryManager; +import com.android.systemui.statusbar.notification.collection.NotifPipeline; +import com.android.systemui.statusbar.notification.collection.NotificationEntry; + +/** + * A notification collection that manages the list of {@link NotificationEntry}s that will be + * rendered. + * + * TODO: (b/145659174) Once we fully switch off {@link NotificationEntryManager} to + * {@link NotifPipeline}, we probably won't need this, but having it for now makes it easy to + * switch between the two. + */ +public interface CommonNotifCollection { + /** + * Registers a listener to be informed when notifications are created, added, updated, removed, + * or deleted. + */ + void addCollectionListener(NotifCollectionListener listener); +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java index c7666e47d4b4..39f4dfacc2c5 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java @@ -19,6 +19,10 @@ package com.android.systemui.statusbar.notification.dagger; import android.content.Context; import com.android.systemui.R; +import com.android.systemui.statusbar.FeatureFlags; +import com.android.systemui.statusbar.notification.NotificationEntryManager; +import com.android.systemui.statusbar.notification.collection.NotifPipeline; +import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection; import com.android.systemui.statusbar.notification.init.NotificationsController; import com.android.systemui.statusbar.notification.init.NotificationsControllerImpl; import com.android.systemui.statusbar.notification.init.NotificationsControllerStub; @@ -45,4 +49,16 @@ public class NotificationsModule { return stubController.get(); } } + + /** + * Provide the active notification collection managing the notifications to render. + */ + @Provides + @Singleton + public CommonNotifCollection provideCommonNotifCollection( + FeatureFlags featureFlags, + Lazy<NotifPipeline> pipeline, + NotificationEntryManager entryManager) { + return featureFlags.isNewNotifPipelineRenderingEnabled() ? pipeline.get() : entryManager; + } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotifRemoteViewCacheImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotifRemoteViewCacheImpl.java index a6e5c2b79968..b62dfa8a20f9 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotifRemoteViewCacheImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotifRemoteViewCacheImpl.java @@ -22,10 +22,9 @@ import android.widget.RemoteViews; import androidx.annotation.Nullable; -import com.android.internal.statusbar.NotificationVisibility; -import com.android.systemui.statusbar.notification.NotificationEntryListener; -import com.android.systemui.statusbar.notification.NotificationEntryManager; import com.android.systemui.statusbar.notification.collection.NotificationEntry; +import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection; +import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener; import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationFlag; import java.util.Map; @@ -40,8 +39,8 @@ public class NotifRemoteViewCacheImpl implements NotifRemoteViewCache { new ArrayMap<>(); @Inject - NotifRemoteViewCacheImpl(NotificationEntryManager entryManager) { - entryManager.addNotificationEntryListener(mEntryListener); + NotifRemoteViewCacheImpl(CommonNotifCollection collection) { + collection.addCollectionListener(mCollectionListener); } @Override @@ -93,17 +92,14 @@ public class NotifRemoteViewCacheImpl implements NotifRemoteViewCache { contentViews.clear(); } - private final NotificationEntryListener mEntryListener = new NotificationEntryListener() { + private final NotifCollectionListener mCollectionListener = new NotifCollectionListener() { @Override - public void onPendingEntryAdded(NotificationEntry entry) { + public void onEntryInit(NotificationEntry entry) { mNotifCachedContentViews.put(entry, new SparseArray<>()); } @Override - public void onEntryRemoved( - NotificationEntry entry, - @Nullable NotificationVisibility visibility, - boolean removedByUser) { + public void onEntryCleanUp(NotificationEntry entry) { mNotifCachedContentViews.remove(entry); } }; diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotifRemoteViewCacheImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotifRemoteViewCacheImplTest.java index d7214f3b9228..20cc01accbc3 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotifRemoteViewCacheImplTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotifRemoteViewCacheImplTest.java @@ -32,10 +32,10 @@ import android.widget.RemoteViews; import androidx.test.filters.SmallTest; import com.android.systemui.SysuiTestCase; -import com.android.systemui.statusbar.notification.NotificationEntryListener; -import com.android.systemui.statusbar.notification.NotificationEntryManager; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder; +import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection; +import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener; import org.junit.Before; import org.junit.Test; @@ -50,7 +50,7 @@ public class NotifRemoteViewCacheImplTest extends SysuiTestCase { private NotifRemoteViewCacheImpl mNotifRemoteViewCache; private NotificationEntry mEntry; - private NotificationEntryListener mEntryListener; + private NotifCollectionListener mEntryListener; @Mock private RemoteViews mRemoteViews; @Before @@ -58,19 +58,17 @@ public class NotifRemoteViewCacheImplTest extends SysuiTestCase { MockitoAnnotations.initMocks(this); mEntry = new NotificationEntryBuilder().build(); - NotificationEntryManager entryManager = mock(NotificationEntryManager.class); - mNotifRemoteViewCache = new NotifRemoteViewCacheImpl(entryManager); - ArgumentCaptor<NotificationEntryListener> entryListenerCaptor = - ArgumentCaptor.forClass(NotificationEntryListener.class); - verify(entryManager).addNotificationEntryListener(entryListenerCaptor.capture()); + CommonNotifCollection collection = mock(CommonNotifCollection.class); + mNotifRemoteViewCache = new NotifRemoteViewCacheImpl(collection); + ArgumentCaptor<NotifCollectionListener> entryListenerCaptor = + ArgumentCaptor.forClass(NotifCollectionListener.class); + verify(collection).addCollectionListener(entryListenerCaptor.capture()); mEntryListener = entryListenerCaptor.getValue(); + mEntryListener.onEntryInit(mEntry); } @Test public void testPutCachedView() { - // GIVEN an initialized cache for an entry. - mEntryListener.onPendingEntryAdded(mEntry); - // WHEN a notification's cached remote views is put in. mNotifRemoteViewCache.putCachedView(mEntry, FLAG_CONTENT_VIEW_CONTRACTED, mRemoteViews); @@ -85,7 +83,6 @@ public class NotifRemoteViewCacheImplTest extends SysuiTestCase { @Test public void testRemoveCachedView() { // GIVEN a cache with a cached view. - mEntryListener.onPendingEntryAdded(mEntry); mNotifRemoteViewCache.putCachedView(mEntry, FLAG_CONTENT_VIEW_CONTRACTED, mRemoteViews); // WHEN we remove the cached view. @@ -98,7 +95,6 @@ public class NotifRemoteViewCacheImplTest extends SysuiTestCase { @Test public void testClearCache() { // GIVEN a non-empty cache. - mEntryListener.onPendingEntryAdded(mEntry); mNotifRemoteViewCache.putCachedView(mEntry, FLAG_CONTENT_VIEW_CONTRACTED, mRemoteViews); mNotifRemoteViewCache.putCachedView(mEntry, FLAG_CONTENT_VIEW_EXPANDED, mRemoteViews); |