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

Commit 1383c120 authored by Bishoy Gendy's avatar Bishoy Gendy
Browse files

Fix isUserEngaged for MediaSession2

Bug: 295518668
Bug: 297052684
Test: Manual playback
Change-Id: Ib53cf3d4fc6b248519fc8eaaab17ec565659f6e2
parent 4ff1c86c
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) {