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

Commit 3d5f41bb authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "MediaSessionService: Nullify the media button sesison when it's removed" into oc-dev

parents a532f4d7 fc1f7ab8
Loading
Loading
Loading
Loading
+13 −20
Original line number Diff line number Diff line
@@ -121,9 +121,12 @@ class MediaSessionStack {
    public void removeSession(MediaSessionRecord record) {
        mSessions.remove(record);
        if (mMediaButtonSession == record) {
            // When the media button session is gone, try to find the alternative media session
            // in the media button session app.
            onMediaSessionChangeInMediaButtonSessionApp();
            // When the media button session is removed, nullify the media button session and do not
            // search for the alternative media session within the app. It's because the alternative
            // media session might be a dummy which isn't able to handle the media key events.
            mOnMediaButtonSessionChangedListener.onMediaButtonSessionChanged(
                    mMediaButtonSession, null);
            mMediaButtonSession = null;
        }
        clearCache(record.getUserId());
    }
@@ -157,7 +160,13 @@ class MediaSessionStack {
        // In that case, we pick the media session whose PlaybackState matches
        // the audio playback configuration.
        if (mMediaButtonSession != null && mMediaButtonSession.getUid() == record.getUid()) {
            onMediaSessionChangeInMediaButtonSessionApp();
            MediaSessionRecord newMediaButtonSession =
                    findMediaButtonSession(mMediaButtonSession.getUid());
            if (newMediaButtonSession != mMediaButtonSession) {
                mOnMediaButtonSessionChangedListener.onMediaButtonSessionChanged(
                        mMediaButtonSession, newMediaButtonSession);
                mMediaButtonSession = newMediaButtonSession;
            }
        }
    }

@@ -199,22 +208,6 @@ class MediaSessionStack {
        }
    }

    /**
     * Handle the change in a media session in the media button session app.
     * <p>If the app has multiple media sessions, change in a media sesion in the app may change
     * the media button session.
     * @see #findMediaButtonSession
     */
    private void onMediaSessionChangeInMediaButtonSessionApp() {
        MediaSessionRecord newMediaButtonSession =
                findMediaButtonSession(mMediaButtonSession.getUid());
        if (newMediaButtonSession != mMediaButtonSession) {
            mOnMediaButtonSessionChangedListener.onMediaButtonSessionChanged(mMediaButtonSession,
                    newMediaButtonSession);
            mMediaButtonSession = newMediaButtonSession;
        }
    }

    /**
     * Find the media button session with the given {@param uid}.
     * If the app has multiple media sessions, the media session matches the audio playback state