Merge "Make setting the session token in MediaBrowserService synchronous" into lmp-mr1-dev

This commit is contained in:
RoboErik
2014-12-05 17:57:14 +00:00
committed by Android (Google) Code Review

View File

@@ -323,24 +323,22 @@ public abstract class MediaBrowserService extends Service {
* <p> * <p>
* This should be called as soon as possible during the service's startup. * This should be called as soon as possible during the service's startup.
* It may only be called once. * It may only be called once.
*
* @return The media session token, must not be null.
*/ */
public void setSessionToken(final MediaSession.Token token) { public void setSessionToken(final MediaSession.Token token) {
if (token == null) { if (token == null) {
throw new IllegalArgumentException("Session token may not be 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() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
if (mSession != null) {
throw new IllegalStateException("The session token has already been set.");
}
mSession = token;
for (IBinder key : mConnections.keySet()) { for (IBinder key : mConnections.keySet()) {
ConnectionRecord connection = mConnections.get(key); ConnectionRecord connection = mConnections.get(key);
try { try {
connection.callbacks.onConnect(connection.root.getRootId(), mSession, connection.callbacks.onConnect(connection.root.getRootId(), token,
connection.root.getExtras()); connection.root.getExtras());
} catch (RemoteException e) { } catch (RemoteException e) {
Log.w(TAG, "Connection for " + connection.pkg + " is no longer valid."); Log.w(TAG, "Connection for " + connection.pkg + " is no longer valid.");