OSDN Git Service

MediaSession2: Implement MediaLibrarySession#notifyChildrenChanged()
authorJaewan Kim <jaewan@google.com>
Mon, 19 Feb 2018 08:49:35 +0000 (17:49 +0900)
committerJaewan Kim <jaewan@google.com>
Wed, 21 Feb 2018 17:01:49 +0000 (02:01 +0900)
Test: Run all MediaComponents tests once
Bug: 72787989
Change-Id: I5bdcb8460109831fb5349d1437b775f8f7b7ddf0

media/java/android/media/MediaBrowser2.java
media/java/android/media/MediaLibraryService2.java
media/java/android/media/update/MediaLibraryService2Provider.java

index 97f0193..e1d078d 100644 (file)
@@ -20,6 +20,8 @@ import android.annotation.CallbackExecutor;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.content.Context;
+import android.media.MediaLibraryService2.MediaLibrarySession;
+import android.media.MediaSession2.ControllerInfo;
 import android.media.update.ApiLoader;
 import android.media.update.MediaBrowser2Provider;
 import android.os.Bundle;
@@ -54,11 +56,18 @@ public class MediaBrowser2 extends MediaController2 {
 
         /**
          * Called when there's change in the parent's children.
+         * <p>
+         * This API is called when the library service called
+         * {@link MediaLibrarySession#notifyChildrenChanged(ControllerInfo, String, int, Bundle)} or
+         * {@link MediaLibrarySession#notifyChildrenChanged(String, int, Bundle)} for the parent.
          *
          * @param parentId parent id that you've specified with {@link #subscribe(String, Bundle)}
-         * @param extras extra bundle from the library service
+         * @param childCount number of children
+         * @param extras extra bundle from the library service. Can be differ from extras that
+         *               you've specified with {@link #subscribe(String, Bundle)}.
          */
-        public void onChildrenChanged(@NonNull String parentId, @Nullable Bundle extras) { }
+        public void onChildrenChanged(@NonNull String parentId, int childCount,
+                @Nullable Bundle extras) { }
 
         /**
          * Called when the list of items has been returned by the library service for the previous
@@ -142,7 +151,7 @@ public class MediaBrowser2 extends MediaController2 {
 
     /**
      * Subscribe to a parent id for the change in its children. When there's a change,
-     * {@link BrowserCallback#onChildrenChanged(String, Bundle)} will be called with the bundle
+     * {@link BrowserCallback#onChildrenChanged(String, int, Bundle)} will be called with the bundle
      * that you've specified. You should call {@link #getChildren(String, int, int, Bundle)} to get
      * the actual contents for the parent.
      *
index fac773b..ec37d0e 100644 (file)
@@ -78,26 +78,36 @@ public abstract class MediaLibraryService2 extends MediaSessionService2 {
         }
 
         /**
-         * Notify subscribed controller about change in a parent's children.
+         * Notify the controller of the change in a parent's children.
+         * <p>
+         * If the controller hasn't subscribed to the parent, the API will do nothing.
+         * <p>
+         * Controllers will use {@link MediaBrowser2#getChildren(String, int, int, Bundle)} to get
+         * the list of children.
          *
          * @param controller controller to notify
-         * @param parentId
-         * @param extras
+         * @param parentId parent id with changes in its children
+         * @param childCount number of children.
+         * @param extras extra information from session to controller
          */
         public void notifyChildrenChanged(@NonNull ControllerInfo controller,
-                @NonNull String parentId, @NonNull Bundle extras) {
-            mProvider.notifyChildrenChanged_impl(controller, parentId, extras);
+                @NonNull String parentId, int childCount, @Nullable Bundle extras) {
+            mProvider.notifyChildrenChanged_impl(controller, parentId, childCount, extras);
         }
 
         /**
-         * Notify subscribed controller about change in a parent's children.
+         * Notify all controllers that subscribed to the parent about change in the parent's
+         * children, regardless of the extra bundle supplied by
+         * {@link MediaBrowser2#subscribe(String, Bundle)}.
          *
          * @param parentId parent id
-         * @param extras extra bundle
+         * @param childCount number of children
+         * @param extras extra information from session to controller
          */
         // This is for the backward compatibility.
-        public void notifyChildrenChanged(@NonNull String parentId, @Nullable Bundle extras) {
-            mProvider.notifyChildrenChanged_impl(parentId, extras);
+        public void notifyChildrenChanged(@NonNull String parentId, int childCount,
+                @Nullable Bundle extras) {
+            mProvider.notifyChildrenChanged_impl(parentId, childCount, extras);
         }
 
         /**
index 17eea84..5b5d36e 100644 (file)
@@ -30,8 +30,9 @@ public interface MediaLibraryService2Provider extends MediaSessionService2Provid
     // Nothing new for now
 
     interface MediaLibrarySessionProvider extends MediaSession2Provider {
-        void notifyChildrenChanged_impl(ControllerInfo controller, String parentId, Bundle extras);
-        void notifyChildrenChanged_impl(String parentId, Bundle extras);
+        void notifyChildrenChanged_impl(ControllerInfo controller, String parentId,
+                int childCount, Bundle extras);
+        void notifyChildrenChanged_impl(String parentId, int childCount, Bundle extras);
         void notifySearchResultChanged_impl(ControllerInfo controller, String query, int itemCount,
                 Bundle extras);
     }