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

Commit 61330a33 authored by Insun Kang's avatar Insun Kang Committed by Android (Google) Code Review
Browse files

Merge "MediaSession: Remove pending callback messages when setCallback(null) is called."

parents c5db8617 62cef488
Loading
Loading
Loading
Loading
+10 −12
Original line number Diff line number Diff line
@@ -119,7 +119,7 @@ public final class MediaSession {
    private final ISession mBinder;
    private final CallbackStub mCbStub;

    private CallbackMessageHandler mCallback;
    private CallbackMessageHandler mCallbackHandler;
    private VolumeProvider mVolumeProvider;
    private PlaybackState mPlaybackState;

@@ -194,24 +194,22 @@ public final class MediaSession {
     */
    public void setCallback(@Nullable Callback callback, @Nullable Handler handler) {
        synchronized (mLock) {
            if (callback == null) {
                if (mCallback != null) {
                    mCallback.mCallback.mSession = null;
            if (mCallbackHandler != null) {
                // We're updating the callback, clear the session from the old one.
                mCallbackHandler.mCallback.mSession = null;
                mCallbackHandler.removeCallbacksAndMessages(null);
            }
                mCallback = null;
            if (callback == null) {
                mCallbackHandler = null;
                return;
            }
            if (mCallback != null) {
                // We're updating the callback, clear the session from the old one.
                mCallback.mCallback.mSession = null;
            }
            if (handler == null) {
                handler = new Handler();
            }
            callback.mSession = this;
            CallbackMessageHandler msgHandler = new CallbackMessageHandler(handler.getLooper(),
                    callback);
            mCallback = msgHandler;
            mCallbackHandler = msgHandler;
        }
    }

@@ -636,8 +634,8 @@ public final class MediaSession {

    private void postToCallback(int what, Object obj, Bundle extras) {
        synchronized (mLock) {
            if (mCallback != null) {
                mCallback.post(what, obj, extras);
            if (mCallbackHandler != null) {
                mCallbackHandler.post(what, obj, extras);
            }
        }
    }