OSDN Git Service

MediaBrowserService: Provide a way to retrieve root hints
authorSungsoo Lim <sungsoo@google.com>
Thu, 14 Apr 2016 21:05:02 +0000 (14:05 -0700)
committerSungsoo Lim <sungsoo@google.com>
Fri, 15 Apr 2016 21:37:36 +0000 (14:37 -0700)
Bug: 28075963
Change-Id: Id8993e67732a2dda5bf75ecab6037dbbba8c8c99

api/current.txt
api/system-current.txt
api/test-current.txt
media/java/android/media/browse/MediaBrowser.java
media/java/android/service/media/IMediaBrowserService.aidl
media/java/android/service/media/MediaBrowserService.java

index f924b5b..1f5c85e 100644 (file)
@@ -34650,6 +34650,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);
index 915ceb2..a70b58a 100644 (file)
@@ -37116,6 +37116,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);
index 0c86fd1..54ff7cc 100644 (file)
@@ -34725,6 +34725,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);
index 2cd9872..baa6b0f 100644 (file)
@@ -135,7 +135,7 @@ public final class MediaBrowser {
         mContext = context;
         mServiceComponent = serviceComponent;
         mCallback = callback;
-        mRootHints = rootHints;
+        mRootHints = rootHints == null ? null : new Bundle(rootHints);
     }
 
     /**
@@ -444,7 +444,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() {
index eef5a7c..6b6a561 100644 (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);
 }
index ddc0e88..4b88926 100644 (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);
                 }
             });
         }
@@ -470,6 +478,20 @@ public abstract class MediaBrowserService extends Service {
     }
 
     /**
+     * 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.
      * This will cause browsers to fetch subscribed content again.
@@ -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()"