Merge "NotifMediaManager looks at pending + active notifs"

This commit is contained in:
TreeHugger Robot
2019-10-29 21:33:21 +00:00
committed by Android (Google) Code Review
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

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