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

Commit da215de7 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix isUserEngaged for MediaSession2" into main

parents e2c3b8b9 1383c120
Loading
Loading
Loading
Loading
+17 −12
Original line number Diff line number Diff line
@@ -312,8 +312,7 @@ public class MediaSessionService extends SystemService implements Monitor {
                }
                user.mPriorityStack.onSessionActiveStateChanged(record);
            }
            boolean isUserEngaged =
                    record.isActive() && (playbackState == null || playbackState.isActive());
            boolean isUserEngaged = isUserEngaged(record, playbackState);

            Log.d(TAG, "onSessionActiveStateChanged: "
                    + "record=" + record
@@ -325,6 +324,15 @@ public class MediaSessionService extends SystemService implements Monitor {
        }
    }

    private boolean isUserEngaged(MediaSessionRecordImpl record,
            @Nullable PlaybackState playbackState) {
        if (playbackState == null) {
            // MediaSession2 case
            return record.checkPlaybackActiveState(/* expected= */ true);
        }
        return playbackState.isActive() && record.isActive();
    }

    // Currently only media1 can become global priority session.
    void setGlobalPrioritySession(MediaSessionRecord record) {
        synchronized (mLock) {
@@ -417,18 +425,15 @@ public class MediaSessionService extends SystemService implements Monitor {
                return;
            }
            user.mPriorityStack.onPlaybackStateChanged(record, shouldUpdatePriority);
            if (playbackState != null) {
                boolean isUserEngaged = playbackState.isActive() && record.isActive();
            boolean isUserEngaged = isUserEngaged(record, playbackState);
            Log.d(TAG, "onSessionPlaybackStateChanged: "
                    + "record=" + record
                    + "playbackState=" + playbackState
                    + "allowRunningInForeground=" + isUserEngaged);
                setForegroundServiceAllowance(
                        record, /* allowRunningInForeground= */ isUserEngaged);
            setForegroundServiceAllowance(record, /* allowRunningInForeground= */ isUserEngaged);
            reportMediaInteractionEvent(record, isUserEngaged);
        }
    }
    }

    void onSessionPlaybackTypeChanged(MediaSessionRecord record) {
        synchronized (mLock) {