summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorRoboErik <epastern@google.com>2014-12-04 09:41:25 -0800
committerRoboErik <epastern@google.com>2014-12-04 14:48:38 -0800
commitfd228a383c0844d69da952460145b1aa3e00ffd7 (patch)
treebe2fe7c261e330ac2685e7c745749f6f6605b402 /media
parent7fbcac6a03db6d09ab3816738754a64f62de22b9 (diff)
downloadframeworks_base-fd228a383c0844d69da952460145b1aa3e00ffd7.zip
frameworks_base-fd228a383c0844d69da952460145b1aa3e00ffd7.tar.gz
frameworks_base-fd228a383c0844d69da952460145b1aa3e00ffd7.tar.bz2
Make setting the session token in MediaBrowserService synchronous
The MusicDemo was depending on the fact that setting the session token is done synchronously and that getSessionToken can be called immediately after. This makes setting the token synchronous again but leaves the post to update any MediaBrowsers that are waiting on a connection. This does introduce a small race condition if an app tries to set it twice from different threads, but this is a very unlikely situation and MediaBrowserService is not guaranteed to be thread safe. bug:18603085 Change-Id: Id934c9f3b6520225cd92d1d8a6e2b3d606b8c6c8
Diffstat (limited to 'media')
-rw-r--r--media/java/android/service/media/MediaBrowserService.java12
1 files changed, 5 insertions, 7 deletions
diff --git a/media/java/android/service/media/MediaBrowserService.java b/media/java/android/service/media/MediaBrowserService.java
index 779d486..26aedbd 100644
--- a/media/java/android/service/media/MediaBrowserService.java
+++ b/media/java/android/service/media/MediaBrowserService.java
@@ -323,24 +323,22 @@ public abstract class MediaBrowserService extends Service {
* <p>
* This should be called as soon as possible during the service's startup.
* It may only be called once.
- *
- * @return The media session token, must not be null.
*/
public void setSessionToken(final MediaSession.Token token) {
if (token == null) {
throw new IllegalArgumentException("Session token may not be null.");
}
+ if (mSession != null) {
+ throw new IllegalStateException("The session token has already been set.");
+ }
+ mSession = token;
mHandler.post(new Runnable() {
@Override
public void run() {
- if (mSession != null) {
- throw new IllegalStateException("The session token has already been set.");
- }
- mSession = token;
for (IBinder key : mConnections.keySet()) {
ConnectionRecord connection = mConnections.get(key);
try {
- connection.callbacks.onConnect(connection.root.getRootId(), mSession,
+ connection.callbacks.onConnect(connection.root.getRootId(), token,
connection.root.getExtras());
} catch (RemoteException e) {
Log.w(TAG, "Connection for " + connection.pkg + " is no longer valid.");