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

Commit 7032f5d9 authored by Toni Heidenreich's avatar Toni Heidenreich
Browse files

Don't check record.isActive() to determine if a session is engaged

This isActive flag is only used to publish sessions to other parts
of the system and says nothing about whether the session is actively
being used for playback.

Bug: 417853575
Flag: com.android.media.flags.enable_notifying_activity_manager_with_media_session_status_change
Test: ActivityManagerNotifyMediaFGSTypeTest
Change-Id: I193761ea45bc1827edd7cd023cec323e907bbd93
parent e7864abe
Loading
Loading
Loading
Loading
+7 −10
Original line number Diff line number Diff line
@@ -259,24 +259,24 @@ public class MediaSessionRecord extends MediaSessionRecordImpl implements IBinde
    private static final int USER_ENGAGEMENT_UNSET = -1;

    /**
     * Indicates that the session is {@linkplain MediaSession#isActive() active} and in one of the
     * {@linkplain PlaybackState#isActive() active states}.
     * Indicates that the session is in one of the {@linkplain PlaybackState#isActive() active
     * states}.
     *
     * @see #updateUserEngagedStateIfNeededLocked(boolean, boolean)
     */
    private static final int USER_PERMANENTLY_ENGAGED = 0;

    /**
     * Indicates that the session is {@linkplain MediaSession#isActive() active} and has recently
     * switched to one of the {@linkplain PlaybackState#isActive() inactive states}.
     * Indicates that the session has recently switched to one of the {@linkplain
     * PlaybackState#isActive() inactive states}.
     *
     * @see #updateUserEngagedStateIfNeededLocked(boolean, boolean)
     */
    private static final int USER_TEMPORARILY_ENGAGED = 1;

    /**
     * Indicates that the session is either not {@linkplain MediaSession#isActive() active} or in
     * one of the {@linkplain PlaybackState#isActive() inactive states}.
     * Indicates that the session is in one of the {@linkplain PlaybackState#isActive() inactive
     * states}.
     *
     * @see #updateUserEngagedStateIfNeededLocked(boolean, boolean)
     */
@@ -1299,11 +1299,8 @@ public class MediaSessionRecord extends MediaSessionRecordImpl implements IBinde
                            callingUid,
                            callingPid);
        }
        boolean isGlobalPrioritySessionActive = mService.isGlobalPrioritySessionActive();
        synchronized (mLock) {
            mIsActive = active;
            updateUserEngagedStateIfNeededLocked(
                    /* isTimeoutExpired= */ false, isGlobalPrioritySessionActive);
        }
        final long token = Binder.clearCallingIdentity();
        try {
@@ -1597,7 +1594,7 @@ public class MediaSessionRecord extends MediaSessionRecordImpl implements IBinde
        }
        int oldUserEngagedState = mUserEngagementState;
        int newUserEngagedState;
        if (isActive() && mPlaybackState != null && mPlaybackState.isActive()) {
        if (mPlaybackState != null && mPlaybackState.isActive()) {
            newUserEngagedState = USER_PERMANENTLY_ENGAGED;
        } else if (oldUserEngagedState == USER_PERMANENTLY_ENGAGED
                || oldUserEngagedState == USER_ENGAGEMENT_UNSET
+1 −1
Original line number Diff line number Diff line
@@ -395,7 +395,7 @@ public class MediaSessionService extends SystemService implements Monitor {
            // MediaSession2 case
            return record.checkPlaybackActiveState(/* expected= */ true);
        }
        return playbackState.isActive() && record.isActive();
        return playbackState.isActive();
    }

    // Currently only media1 can become global priority session.