Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 09867613 authored by tonihei's avatar tonihei
Browse files

Remove no-op calls to ActivityManager

When a FGS notification is first added and the session is already
considered "engaged", there is no need to tell the ActivityManager
about it as it will consider new FGSs as active anyway.

When a notification is removed, the associated FGS must be stopped
anyway, so no need to tell the ActivityManager whether the session
is considered user-engaged.

Flag: com.android.media.flags.enable_notifying_activity_manager_with_media_session_status_change
Test: ActivityManagerNotifyMediaFGSTypeTest covers use cases, should not
be affected
Bug: 281762171

Change-Id: Ie9c3fe191e22856ed763bc999f339ef8e5351145
parent 5234819d
Loading
Loading
Loading
Loading
+3 −13
Original line number Diff line number Diff line
@@ -3287,12 +3287,14 @@ public class MediaSessionService extends SystemService implements Monitor {
                MediaSessionRecordImpl userEngagedRecord =
                        getUserEngagedMediaSessionRecordForNotification(uid, postedNotification);
                if (userEngagedRecord != null) {
                    setFgsActiveLocked(userEngagedRecord, sbn);
                    // Session is considered user engaged, nothing to do.
                    return;
                }
                MediaSessionRecordImpl notificationRecord =
                        getAnyMediaSessionRecordForNotification(uid, userId, postedNotification);
                if (notificationRecord != null) {
                    // A session exists for this notification, but it's not considered user engaged,
                    // so immediately inform ActivityManager that it is inactive.
                    setFgsInactiveIfNoSessionIsLinkedToNotification(notificationRecord);
                }
            }
@@ -3301,11 +3303,7 @@ public class MediaSessionService extends SystemService implements Monitor {
        @Override
        public void onNotificationRemoved(StatusBarNotification sbn) {
            super.onNotificationRemoved(sbn);
            Notification removedNotification = sbn.getNotification();
            int uid = sbn.getUid();
            if (!removedNotification.isMediaNotification()) {
                return;
            }
            synchronized (mLock) {
                Map<String, StatusBarNotification> notifications = mMediaNotifications.get(uid);
                if (notifications != null) {
@@ -3314,14 +3312,6 @@ public class MediaSessionService extends SystemService implements Monitor {
                        mMediaNotifications.remove(uid);
                    }
                }

                MediaSessionRecordImpl notificationRecord =
                        getUserEngagedMediaSessionRecordForNotification(uid, removedNotification);

                if (notificationRecord == null) {
                    return;
                }
                setFgsInactiveIfNoSessionIsLinkedToNotification(notificationRecord);
            }
        }