Merge "MediaBrowserService: Provide a way to retrieve root hints" into nyc-dev am: bfa6d23 am: 33de442

am: c0b10c2

* commit 'c0b10c2515f289495f854c045cdfca9e129ef2a0':
  MediaBrowserService: Provide a way to retrieve root hints

Change-Id: Ieca1f45e3f46a4719f9b7993fd1fe7a36b98dba5
This commit is contained in:
Sungsoo Lim
2016-04-18 17:42:24 +00:00
committed by android-build-merger
6 changed files with 37 additions and 7 deletions

View File

@@ -34654,6 +34654,7 @@ package android.service.media {
public abstract class MediaBrowserService extends android.app.Service {
ctor public MediaBrowserService();
method public void dump(java.io.FileDescriptor, java.io.PrintWriter, java.lang.String[]);
method public final android.os.Bundle getBrowserRootHints();
method public android.media.session.MediaSession.Token getSessionToken();
method public void notifyChildrenChanged(java.lang.String);
method public void notifyChildrenChanged(java.lang.String, android.os.Bundle);

View File

@@ -37309,6 +37309,7 @@ package android.service.media {
public abstract class MediaBrowserService extends android.app.Service {
ctor public MediaBrowserService();
method public void dump(java.io.FileDescriptor, java.io.PrintWriter, java.lang.String[]);
method public final android.os.Bundle getBrowserRootHints();
method public android.media.session.MediaSession.Token getSessionToken();
method public void notifyChildrenChanged(java.lang.String);
method public void notifyChildrenChanged(java.lang.String, android.os.Bundle);

View File

@@ -34729,6 +34729,7 @@ package android.service.media {
public abstract class MediaBrowserService extends android.app.Service {
ctor public MediaBrowserService();
method public void dump(java.io.FileDescriptor, java.io.PrintWriter, java.lang.String[]);
method public final android.os.Bundle getBrowserRootHints();
method public android.media.session.MediaSession.Token getSessionToken();
method public void notifyChildrenChanged(java.lang.String);
method public void notifyChildrenChanged(java.lang.String, android.os.Bundle);

View File

@@ -136,7 +136,7 @@ public final class MediaBrowser {
mContext = context;
mServiceComponent = serviceComponent;
mCallback = callback;
mRootHints = rootHints;
mRootHints = rootHints == null ? null : new Bundle(rootHints);
}
/**
@@ -449,7 +449,7 @@ public final class MediaBrowser {
}
};
try {
mServiceBinder.getMediaItem(mediaId, receiver);
mServiceBinder.getMediaItem(mediaId, receiver, mServiceCallbacks);
} catch (RemoteException e) {
Log.i(TAG, "Remote error getting media item.");
mHandler.post(new Runnable() {

View File

@@ -20,5 +20,5 @@ oneway interface IMediaBrowserService {
void addSubscription(String uri, in IBinder token, in Bundle options,
IMediaBrowserServiceCallbacks callbacks);
void removeSubscription(String uri, in IBinder token, IMediaBrowserServiceCallbacks callbacks);
void getMediaItem(String uri, in ResultReceiver cb);
void getMediaItem(String uri, in ResultReceiver cb, IMediaBrowserServiceCallbacks callbacks);
}

View File

@@ -97,6 +97,7 @@ public abstract class MediaBrowserService extends Service {
private @interface ResultFlags { }
private final ArrayMap<IBinder, ConnectionRecord> mConnections = new ArrayMap<>();
private ConnectionRecord mCurConnection;
private final Handler mHandler = new Handler();
private ServiceBinder mBinder;
MediaSession.Token mSession;
@@ -291,7 +292,8 @@ public abstract class MediaBrowserService extends Service {
}
@Override
public void getMediaItem(final String mediaId, final ResultReceiver receiver) {
public void getMediaItem(final String mediaId, final ResultReceiver receiver,
final IMediaBrowserServiceCallbacks callbacks) {
if (TextUtils.isEmpty(mediaId) || receiver == null) {
return;
}
@@ -299,7 +301,13 @@ public abstract class MediaBrowserService extends Service {
mHandler.post(new Runnable() {
@Override
public void run() {
performLoadItem(mediaId, receiver);
final IBinder b = callbacks.asBinder();
ConnectionRecord connection = mConnections.get(b);
if (connection == null) {
Log.w(TAG, "getMediaItem for callback that isn't registered id=" + mediaId);
return;
}
performLoadItem(mediaId, connection, receiver);
}
});
}
@@ -469,6 +477,20 @@ public abstract class MediaBrowserService extends Service {
return mSession;
}
/**
* Gets the root hints sent from the currently connected {@link MediaBrowser}.
*
* @throws IllegalStateException If this method is called outside of {@link #onLoadChildren}
* or {@link #onLoadItem}
*/
public final Bundle getBrowserRootHints() {
if (mCurConnection == null) {
throw new IllegalStateException("This should be called inside of onLoadChildren or"
+ " onLoadItem methods");
}
return mCurConnection.rootHints == null ? null : new Bundle(mCurConnection.rootHints);
}
/**
* Notifies all connected media browsers that the children of
* the specified parent id have changed in some way.
@@ -619,11 +641,13 @@ public abstract class MediaBrowserService extends Service {
}
};
mCurConnection = connection;
if (options == null) {
onLoadChildren(parentId, result);
} else {
onLoadChildren(parentId, result, options);
}
mCurConnection = null;
if (!result.isDone()) {
throw new IllegalStateException("onLoadChildren must call detach() or sendResult()"
@@ -652,7 +676,8 @@ public abstract class MediaBrowserService extends Service {
return list.subList(fromIndex, toIndex);
}
private void performLoadItem(String itemId, final ResultReceiver receiver) {
private void performLoadItem(String itemId, final ConnectionRecord connection,
final ResultReceiver receiver) {
final Result<MediaBrowser.MediaItem> result =
new Result<MediaBrowser.MediaItem>(itemId) {
@Override
@@ -663,7 +688,9 @@ public abstract class MediaBrowserService extends Service {
}
};
MediaBrowserService.this.onLoadItem(itemId, result);
mCurConnection = connection;
onLoadItem(itemId, result);
mCurConnection = null;
if (!result.isDone()) {
throw new IllegalStateException("onLoadItem must call detach() or sendResult()"