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

Commit e1eca4a6 authored by Santiago Seifert's avatar Santiago Seifert Committed by Android (Google) Code Review
Browse files

Merge "Move mCurConnection to the service and rename" into main

parents 1d8fc144 b9143854
Loading
Loading
Loading
Loading
+17 −13
Original line number Diff line number Diff line
@@ -107,6 +107,10 @@ public abstract class MediaBrowserService extends Service {

    private final ServiceState mServiceState = new ServiceState();

    // Holds the connection record associated with the currently executing callback operation, if
    // any. See getCurrentBrowserInfo for an example. Must only be accessed on mHandler.
    @Nullable private ConnectionRecord mCurrentConnectionOnHandler;

    /**
     * All the info about a connection.
     */
@@ -462,12 +466,12 @@ public abstract class MediaBrowserService extends Service {
     * @see MediaBrowserService.BrowserRoot#EXTRA_SUGGESTED
     */
    public final Bundle getBrowserRootHints() {
        ConnectionRecord curConnection = mServiceState.mCurConnection;
        if (curConnection == null) {
        ConnectionRecord currentConnection = mCurrentConnectionOnHandler;
        if (currentConnection == null) {
            throw new IllegalStateException("This should be called inside of onGetRoot or"
                    + " onLoadChildren or onLoadItem methods");
        }
        return curConnection.rootHints == null ? null : new Bundle(curConnection.rootHints);
        return currentConnection.rootHints == null ? null : new Bundle(currentConnection.rootHints);
    }

    /**
@@ -478,12 +482,13 @@ public abstract class MediaBrowserService extends Service {
     * @see MediaSessionManager#isTrustedForMediaControl(RemoteUserInfo)
     */
    public final RemoteUserInfo getCurrentBrowserInfo() {
        ConnectionRecord curConnection = mServiceState.mCurConnection;
        if (curConnection == null) {
        ConnectionRecord currentConnection = mCurrentConnectionOnHandler;
        if (currentConnection == null) {
            throw new IllegalStateException("This should be called inside of onGetRoot or"
                    + " onLoadChildren or onLoadItem methods");
        }
        return new RemoteUserInfo(curConnection.pkg, curConnection.pid, curConnection.uid);
        return new RemoteUserInfo(
                currentConnection.pkg, currentConnection.pid, currentConnection.uid);
    }

    /**
@@ -622,7 +627,6 @@ public abstract class MediaBrowserService extends Service {

        // Fields accessed from mHandler only.
        @NonNull private final ArrayMap<IBinder, ConnectionRecord> mConnections = new ArrayMap<>();
        @Nullable private ConnectionRecord mCurConnection;

        public void postOnHandler(Runnable runnable) {
            mHandler.post(runnable);
@@ -705,7 +709,7 @@ public abstract class MediaBrowserService extends Service {

            // Temporarily sets a placeholder ConnectionRecord to make getCurrentBrowserInfo() work
            // in onGetRoot().
            mCurConnection =
            mCurrentConnectionOnHandler =
                    new ConnectionRecord(
                            /* serviceState= */ this,
                            pkg,
@@ -715,7 +719,7 @@ public abstract class MediaBrowserService extends Service {
                            callbacks,
                            /* root= */ null);
            BrowserRoot root = onGetRoot(pkg, uid, rootHints);
            mCurConnection = null;
            mCurrentConnectionOnHandler = null;

            // If they didn't return something, don't allow this client.
            if (root == null) {
@@ -831,13 +835,13 @@ public abstract class MediaBrowserService extends Service {
                        }
                    };

            mCurConnection = connection;
            mCurrentConnectionOnHandler = connection;
            if (options == null) {
                onLoadChildren(parentId, result);
            } else {
                onLoadChildren(parentId, result, options);
            }
            mCurConnection = null;
            mCurrentConnectionOnHandler = null;

            if (!result.isDone()) {
                throw new IllegalStateException(
@@ -886,9 +890,9 @@ public abstract class MediaBrowserService extends Service {
                        }
                    };

            mCurConnection = connection;
            mCurrentConnectionOnHandler = connection;
            onLoadItem(itemId, result);
            mCurConnection = null;
            mCurrentConnectionOnHandler = null;

            if (!result.isDone()) {
                throw new IllegalStateException(