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

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

Merge "MediaSession2: Fix controller is disconnected immediatly after connected"

parents ce2b5758 f8e970a9
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -239,7 +239,7 @@ public class MediaSession2 implements AutoCloseable {
        final ControllerInfo controllerInfo = new ControllerInfo(remoteUserInfo,
                mSessionManager.isTrustedForMediaControl(remoteUserInfo), controller);
        mCallbackExecutor.execute(() -> {
            boolean accept = false;
            boolean connected = false;
            try {
                if (isClosed()) {
                    return;
@@ -249,8 +249,7 @@ public class MediaSession2 implements AutoCloseable {
                // Don't reject connection for the request from trusted app.
                // Otherwise server will fail to retrieve session's information to dispatch
                // media keys to.
                accept = controllerInfo.mAllowedCommands != null || controllerInfo.isTrusted();
                if (!accept) {
                if (controllerInfo.mAllowedCommands == null && !controllerInfo.isTrusted()) {
                    return;
                }
                if (controllerInfo.mAllowedCommands == null) {
@@ -283,14 +282,19 @@ public class MediaSession2 implements AutoCloseable {
                    return;
                }
                controllerInfo.notifyConnected(connectionResult);
                connected = true;
            } finally {
                if (!accept) {
                if (!connected) {
                    if (DEBUG) {
                        Log.d(TAG, "Rejecting connection, controllerInfo=" + controllerInfo);
                        Log.d(TAG, "Rejecting connection or notifying that session is closed"
                                + ", controllerInfo=" + controllerInfo);
                    }
                    synchronized (mLock) {
                        mConnectedControllers.remove(controller);
                    }
                    controllerInfo.notifyDisconnected();
                }
            }
        });
    }