From 6fc9f22c6325dc0e445b90ae6a14d9306ad7c120 Mon Sep 17 00:00:00 2001 From: Beverly Date: Wed, 23 Oct 2019 17:56:48 -0400 Subject: [PATCH] NotifMediaManager looks at pending + active notifs So it doesn't care whether the notifications are inflated or not yet Test: atest SystemUiTests Change-Id: Ida77098cf5a760e9ac578271c387bbf345c3c887 --- .../statusbar/NotificationMediaManager.java | 23 +++++++++++-------- .../NotificationEntryManager.java | 11 +++++++++ .../systemui/statusbar/phone/StatusBar.java | 1 - 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationMediaManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationMediaManager.java index 0988e347945c3..d668665f062cc 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationMediaManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationMediaManager.java @@ -163,7 +163,7 @@ public class NotificationMediaManager implements Dumpable { if (!isPlaybackActive(state.getState())) { clearCurrentMediaNotification(); } - dispatchUpdateMediaMetaData(true /* changed */, true /* allowAnimation */); + findAndUpdateMediaNotifications(); } } @@ -199,6 +199,16 @@ public class NotificationMediaManager implements Dumpable { mStatusBarWindowController = statusBarWindowController; mEntryManager = notificationEntryManager; notificationEntryManager.addNotificationEntryListener(new NotificationEntryListener() { + @Override + public void onPendingEntryAdded(NotificationEntry entry) { + findAndUpdateMediaNotifications(); + } + + @Override + public void onPreEntryUpdated(NotificationEntry entry) { + findAndUpdateMediaNotifications(); + } + @Override public void onEntryRemoved( NotificationEntry entry, @@ -272,16 +282,12 @@ public class NotificationMediaManager implements Dumpable { boolean metaDataChanged = false; synchronized (mEntryManager.getNotificationData()) { - ArrayList activeNotifications = - mEntryManager.getNotificationData().getActiveNotifications(); - final int N = activeNotifications.size(); + Set allNotifications = mEntryManager.getAllNotifs(); // Promote the media notification with a controller in 'playing' state, if any. NotificationEntry mediaNotification = null; MediaController controller = null; - for (int i = 0; i < N; i++) { - final NotificationEntry entry = activeNotifications.get(i); - + for (NotificationEntry entry : allNotifications) { if (entry.isMediaNotification()) { final MediaSession.Token token = entry.getSbn().getNotification().extras.getParcelable( @@ -319,8 +325,7 @@ public class NotificationMediaManager implements Dumpable { // now to see if we have one like this final String pkg = aController.getPackageName(); - for (int i = 0; i < N; i++) { - final NotificationEntry entry = activeNotifications.get(i); + for (NotificationEntry entry : allNotifications) { if (entry.getSbn().getPackageName().equals(pkg)) { if (DEBUG_MEDIA) { Log.v(TAG, "DEBUG_MEDIA: found controller matching " 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 bde097a89f6b8..404087d9b9738 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java @@ -53,8 +53,10 @@ import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import javax.inject.Inject; import javax.inject.Singleton; @@ -560,6 +562,15 @@ public class NotificationEntryManager implements return mPendingNotifications.values(); } + /** + * @return all notification we're currently aware of (both pending and visible notifications) + */ + public Set getAllNotifs() { + Set allNotifs = new HashSet<>(mPendingNotifications.values()); + allNotifs.addAll(mNotificationData.getActiveNotifications()); + return allNotifs; + } + /** * Gets the pending or visible notification entry with the given key. Returns null if * notification doesn't exist. diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index 2e0fbfa6ea0b1..007edfdfc33af 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -1526,7 +1526,6 @@ public class StatusBar extends SystemUI implements DemoMode, .start(); } } - mMediaManager.findAndUpdateMediaNotifications(); } private void updateReportRejectedTouchVisibility() {