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

Commit ffa39ec1 authored by Toni Heidenreich's avatar Toni Heidenreich Committed by Android (Google) Code Review
Browse files

Merge "Start user-engaged timeout after creating a session" into main

parents 5bf5afe0 51d5a3d6
Loading
Loading
Loading
Loading
+18 −7
Original line number Diff line number Diff line
@@ -234,12 +234,24 @@ public class MediaSessionRecord extends MediaSessionRecordImpl implements IBinde
            };

    @GuardedBy("mLock")
    private @UserEngagementState int mUserEngagementState = USER_DISENGAGED;

    @IntDef({USER_PERMANENTLY_ENGAGED, USER_TEMPORARILY_ENGAGED, USER_DISENGAGED})
    private @UserEngagementState int mUserEngagementState = USER_ENGAGEMENT_UNSET;

    @IntDef({
        USER_ENGAGEMENT_UNSET,
        USER_PERMANENTLY_ENGAGED,
        USER_TEMPORARILY_ENGAGED,
        USER_DISENGAGED
    })
    @Retention(RetentionPolicy.SOURCE)
    private @interface UserEngagementState {}

    /**
     * Indicates that the {@link UserEngagementState} is not yet set.
     *
     * @see #updateUserEngagedStateIfNeededLocked(boolean)
     */
    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}.
@@ -1054,11 +1066,10 @@ public class MediaSessionRecord extends MediaSessionRecordImpl implements IBinde
        }
        int oldUserEngagedState = mUserEngagementState;
        int newUserEngagedState;
        if (!isActive() || mPlaybackState == null) {
            newUserEngagedState = USER_DISENGAGED;
        } else if (mPlaybackState.isActive()) {
        if (isActive() && mPlaybackState != null && mPlaybackState.isActive()) {
            newUserEngagedState = USER_PERMANENTLY_ENGAGED;
        } else if (oldUserEngagedState == USER_PERMANENTLY_ENGAGED
                || oldUserEngagedState == USER_ENGAGEMENT_UNSET
                || (oldUserEngagedState == USER_TEMPORARILY_ENGAGED && !isTimeoutExpired)) {
            newUserEngagedState = USER_TEMPORARILY_ENGAGED;
        } else {
@@ -1079,7 +1090,7 @@ public class MediaSessionRecord extends MediaSessionRecordImpl implements IBinde

        boolean wasUserEngaged = oldUserEngagedState != USER_DISENGAGED;
        boolean isNowUserEngaged = newUserEngagedState != USER_DISENGAGED;
        if (wasUserEngaged != isNowUserEngaged) {
        if (oldUserEngagedState == USER_ENGAGEMENT_UNSET || wasUserEngaged != isNowUserEngaged) {
            mHandler.post(
                    () ->
                            mService.onSessionUserEngagementStateChange(