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
This commit is contained in:
Beverly
2019-10-23 17:56:48 -04:00
parent aa88bb6bac
commit 6fc9f22c63
3 changed files with 25 additions and 10 deletions

View File

@@ -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<NotificationEntry> activeNotifications =
mEntryManager.getNotificationData().getActiveNotifications();
final int N = activeNotifications.size();
Set<NotificationEntry> 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 "

View File

@@ -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<NotificationEntry> getAllNotifs() {
Set<NotificationEntry> 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.

View File

@@ -1526,7 +1526,6 @@ public class StatusBar extends SystemUI implements DemoMode,
.start();
}
}
mMediaManager.findAndUpdateMediaNotifications();
}
private void updateReportRejectedTouchVisibility() {