diff options
-rw-r--r-- | media/java/android/service/media/MediaBrowserService.java | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/media/java/android/service/media/MediaBrowserService.java b/media/java/android/service/media/MediaBrowserService.java index 90c6b6bf9707..d17b341782ce 100644 --- a/media/java/android/service/media/MediaBrowserService.java +++ b/media/java/android/service/media/MediaBrowserService.java @@ -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( |