summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Pradeep Sawlani <sawlani@google.com> 2025-03-17 10:58:20 -0700
committer Android (Google) Code Review <android-gerrit@google.com> 2025-03-17 10:58:20 -0700
commit34eaed1aa7e355c0e48acdf0b36e94cf21f9ba2a (patch)
tree798236c42043a5429316208c3c9802e73eeb3ec8
parent678b8b79f4ab9bfd0e8a5e02bfd7e572ffb2aad7 (diff)
parent32c0da4332390b8f1dfdb1ac936afa40f87d0325 (diff)
Merge "Fix duplicate bitmaps." into main
-rw-r--r--services/core/java/com/android/server/media/MediaSessionService.java34
1 files changed, 23 insertions, 11 deletions
diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java
index 58cf29b59961..c174451e8f5b 100644
--- a/services/core/java/com/android/server/media/MediaSessionService.java
+++ b/services/core/java/com/android/server/media/MediaSessionService.java
@@ -192,9 +192,15 @@ public class MediaSessionService extends SystemService implements Monitor {
private final Map<Integer, Set<MediaSessionRecordImpl>> mUserEngagedSessionsForFgs =
new HashMap<>();
- /* Maps uid with all media notifications associated to it */
+ /**
+ * Maps UIDs to their associated media notifications: UID -> (Notification ID ->
+ * {@link android.service.notification.StatusBarNotification}).
+ * Each UID maps to a collection of notifications, identified by their
+ * {@link android.service.notification.StatusBarNotification#getId()}.
+ */
@GuardedBy("mLock")
- private final Map<Integer, Set<StatusBarNotification>> mMediaNotifications = new HashMap<>();
+ private final Map<Integer, Map<String, StatusBarNotification>> mMediaNotifications =
+ new HashMap<>();
// The FullUserRecord of the current users. (i.e. The foreground user that isn't a profile)
// It's always not null after the MediaSessionService is started.
@@ -737,7 +743,8 @@ public class MediaSessionService extends SystemService implements Monitor {
}
synchronized (mLock) {
int uid = mediaSessionRecord.getUid();
- for (StatusBarNotification sbn : mMediaNotifications.getOrDefault(uid, Set.of())) {
+ for (StatusBarNotification sbn : mMediaNotifications.getOrDefault(uid,
+ Map.of()).values()) {
if (mediaSessionRecord.isLinkedToNotification(sbn.getNotification())) {
setFgsActiveLocked(mediaSessionRecord, sbn);
return;
@@ -771,7 +778,7 @@ public class MediaSessionService extends SystemService implements Monitor {
int uid, MediaSessionRecordImpl record) {
synchronized (mLock) {
for (StatusBarNotification sbn :
- mMediaNotifications.getOrDefault(uid, Set.of())) {
+ mMediaNotifications.getOrDefault(uid, Map.of()).values()) {
if (record.isLinkedToNotification(sbn.getNotification())) {
return sbn;
}
@@ -794,7 +801,8 @@ public class MediaSessionService extends SystemService implements Monitor {
for (MediaSessionRecordImpl record :
mUserEngagedSessionsForFgs.getOrDefault(uid, Set.of())) {
for (StatusBarNotification sbn :
- mMediaNotifications.getOrDefault(uid, Set.of())) {
+ mMediaNotifications.getOrDefault(uid, Map.of()).values()) {
+ //
if (record.isLinkedToNotification(sbn.getNotification())) {
// A user engaged session linked with a media notification is found.
// We shouldn't call stop FGS in this case.
@@ -3262,8 +3270,12 @@ public class MediaSessionService extends SystemService implements Monitor {
return;
}
synchronized (mLock) {
- mMediaNotifications.putIfAbsent(uid, new HashSet<>());
- mMediaNotifications.get(uid).add(sbn);
+ Map<String, StatusBarNotification> notifications = mMediaNotifications.get(uid);
+ if (notifications == null) {
+ notifications = new HashMap<>();
+ mMediaNotifications.put(uid, notifications);
+ }
+ notifications.put(sbn.getKey(), sbn);
MediaSessionRecordImpl userEngagedRecord =
getUserEngagedMediaSessionRecordForNotification(uid, postedNotification);
if (userEngagedRecord != null) {
@@ -3287,10 +3299,10 @@ public class MediaSessionService extends SystemService implements Monitor {
return;
}
synchronized (mLock) {
- Set<StatusBarNotification> uidMediaNotifications = mMediaNotifications.get(uid);
- if (uidMediaNotifications != null) {
- uidMediaNotifications.remove(sbn);
- if (uidMediaNotifications.isEmpty()) {
+ Map<String, StatusBarNotification> notifications = mMediaNotifications.get(uid);
+ if (notifications != null) {
+ notifications.remove(sbn.getKey());
+ if (notifications.isEmpty()) {
mMediaNotifications.remove(uid);
}
}