diff options
author | RoboErik <epastern@google.com> | 2014-11-21 11:19:35 -0800 |
---|---|---|
committer | RoboErik <epastern@google.com> | 2014-11-24 12:35:20 -0800 |
commit | d64c425f32174a66a3974c63211bf457005a8d6a (patch) | |
tree | c8d1c307e15930947abccb641458dc25d486d94b /media/java/android/service | |
parent | 85f463c5b59350fa4c4a05007f8a7b65a9a89da3 (diff) | |
download | frameworks_base-d64c425f32174a66a3974c63211bf457005a8d6a.zip frameworks_base-d64c425f32174a66a3974c63211bf457005a8d6a.tar.gz frameworks_base-d64c425f32174a66a3974c63211bf457005a8d6a.tar.bz2 |
Delay calling onConnected until a session is set in MediaBrowser
This will delay all calls to onConnected from the MediaBrowserService
until a session token has been set. This also requires making it an
exception to try setting the session twice.
bug:18052336
Change-Id: Iecf186c53364183e1696af83a855c8db3294a5d0
Diffstat (limited to 'media/java/android/service')
-rw-r--r-- | media/java/android/service/media/MediaBrowserService.java | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/media/java/android/service/media/MediaBrowserService.java b/media/java/android/service/media/MediaBrowserService.java index 0754fd4..779d486 100644 --- a/media/java/android/service/media/MediaBrowserService.java +++ b/media/java/android/service/media/MediaBrowserService.java @@ -189,8 +189,10 @@ public abstract class MediaBrowserService extends Service { } else { try { mConnections.put(b, connection); - callbacks.onConnect(connection.root.getRootId(), - mSession, connection.root.getExtras()); + if (mSession != null) { + callbacks.onConnect(connection.root.getRootId(), + mSession, connection.root.getExtras()); + } } catch (RemoteException ex) { Log.w(TAG, "Calling onConnect() failed. Dropping client. " + "pkg=" + pkg); @@ -319,16 +321,34 @@ public abstract class MediaBrowserService extends Service { /** * Call to set the media session. * <p> - * This must be called before onCreate returns. + * 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(MediaSession.Token token) { + public void setSessionToken(final MediaSession.Token token) { if (token == null) { - throw new IllegalStateException(this.getClass().getName() - + ".onCreateSession() set invalid MediaSession.Token"); + throw new IllegalArgumentException("Session token may not be null."); } - 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.root.getExtras()); + } catch (RemoteException e) { + Log.w(TAG, "Connection for " + connection.pkg + " is no longer valid."); + mConnections.remove(key); + } + } + } + }); } /** |