Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ac9edc37 authored by Jaewan Kim's avatar Jaewan Kim
Browse files

MediaSession2: Rename BrowserRoot to LibraryRoot and move to updatable

Renaming was the one of the feedback from ag/3506231

Test: Run all MediaComponents tests once
Change-Id: I6499070502cd0e20ea53a1447278d680e586dec7
parent 435142ba
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package android.media;
import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.content.Context;
import android.media.update.ApiLoader;
import android.media.update.MediaBrowser2Provider;
@@ -41,14 +40,14 @@ public class MediaBrowser2 extends MediaController2 {
     */
    public static class BrowserCallback extends MediaController2.ControllerCallback {
        /**
         * Called with the result of {@link #getBrowserRoot(Bundle)}.
         * Called with the result of {@link #getLibraryRoot(Bundle)}.
         * <p>
         * {@code rootMediaId} and {@code rootExtra} can be {@code null} if the browser root isn't
         * {@code rootMediaId} and {@code rootExtra} can be {@code null} if the library root isn't
         * available.
         *
         * @param rootHints rootHints that you previously requested.
         * @param rootMediaId media id of the browser root. Can be {@code null}
         * @param rootExtra extra of the browser root. Can be {@code null}
         * @param rootMediaId media id of the library root. Can be {@code null}
         * @param rootExtra extra of the library root. Can be {@code null}
         */
        public void onGetRootResult(Bundle rootHints, @Nullable String rootMediaId,
                @Nullable Bundle rootExtra) { }
@@ -114,8 +113,15 @@ public class MediaBrowser2 extends MediaController2 {
                .createMediaBrowser2(context, this, token, executor, (BrowserCallback) callback);
    }

    public void getBrowserRoot(Bundle rootHints) {
        mProvider.getBrowserRoot_impl(rootHints);
    /**
     * Get the library root. Result would be sent back asynchronously with the
     * {@link BrowserCallback#onGetRootResult(Bundle, String, Bundle)}.
     *
     * @param rootHints hint for the root
     * @see BrowserCallback#onGetRootResult(Bundle, String, Bundle)
     */
    public void getLibraryRoot(Bundle rootHints) {
        mProvider.getLibraryRoot_impl(rootHints);
    }

    /**
+33 −36
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.content.Context;
import android.media.MediaSession2.BuilderBase;
import android.media.MediaSession2.ControllerInfo;
import android.media.update.ApiLoader;
import android.media.update.MediaLibraryService2Provider.LibraryRootProvider;
import android.media.update.MediaLibraryService2Provider.MediaLibrarySessionProvider;
import android.media.update.MediaSession2Provider;
import android.media.update.MediaSessionService2Provider;
@@ -116,15 +117,15 @@ public abstract class MediaLibraryService2 extends MediaSessionService2 {
         *
         * @param controllerInfo information of the controller requesting access to browse media.
         * @param rootHints An optional bundle of service-specific arguments to send
         * to the media browser service when connecting and retrieving the
         * to the media library service when connecting and retrieving the
         * root id for browsing, or null if none. The contents of this
         * bundle may affect the information returned when browsing.
         * @return The {@link BrowserRoot} for accessing this app's content or null.
         * @see BrowserRoot#EXTRA_RECENT
         * @see BrowserRoot#EXTRA_OFFLINE
         * @see BrowserRoot#EXTRA_SUGGESTED
         * @return The {@link LibraryRoot} for accessing this app's content or null.
         * @see LibraryRoot#EXTRA_RECENT
         * @see LibraryRoot#EXTRA_OFFLINE
         * @see LibraryRoot#EXTRA_SUGGESTED
         */
        public @Nullable BrowserRoot onGetRoot(@NonNull ControllerInfo controllerInfo,
        public @Nullable LibraryRoot onGetRoot(@NonNull ControllerInfo controllerInfo,
                @Nullable Bundle rootHints) {
            return null;
        }
@@ -237,17 +238,17 @@ public abstract class MediaLibraryService2 extends MediaSessionService2 {
    public @NonNull abstract MediaLibrarySession onCreateSession(String sessionId);

    /**
     * Contains information that the browser service needs to send to the client
     * when first connected.
     * Contains information that the library service needs to send to the client when
     * {@link MediaBrowser2#getLibraryRoot(Bundle)} is called.
     */
    public static final class BrowserRoot {
    public static final class LibraryRoot {
        /**
         * The lookup key for a boolean that indicates whether the browser service should return a
         * browser root for recently played media items.
         * The lookup key for a boolean that indicates whether the library service should return a
         * librar root for recently played media items.
         *
         * <p>When creating a media browser for a given media browser service, this key can be
         * <p>When creating a media browser for a given media library service, this key can be
         * supplied as a root hint for retrieving media items that are recently played.
         * If the media browser service can provide such media items, the implementation must return
         * If the media library service can provide such media items, the implementation must return
         * the key in the root hint when
         * {@link MediaLibrarySessionCallback#onGetRoot(ControllerInfo, Bundle)} is called back.
         *
@@ -259,13 +260,13 @@ public abstract class MediaLibraryService2 extends MediaSessionService2 {
        public static final String EXTRA_RECENT = "android.media.extra.RECENT";

        /**
         * The lookup key for a boolean that indicates whether the browser service should return a
         * browser root for offline media items.
         * The lookup key for a boolean that indicates whether the library service should return a
         * library root for offline media items.
         *
         * <p>When creating a media browser for a given media browser service, this key can be
         * <p>When creating a media browser for a given media library service, this key can be
         * supplied as a root hint for retrieving media items that are can be played without an
         * internet connection.
         * If the media browser service can provide such media items, the implementation must return
         * If the media library service can provide such media items, the implementation must return
         * the key in the root hint when
         * {@link MediaLibrarySessionCallback#onGetRoot(ControllerInfo, Bundle)} is called back.
         *
@@ -277,14 +278,14 @@ public abstract class MediaLibraryService2 extends MediaSessionService2 {
        public static final String EXTRA_OFFLINE = "android.media.extra.OFFLINE";

        /**
         * The lookup key for a boolean that indicates whether the browser service should return a
         * browser root for suggested media items.
         * The lookup key for a boolean that indicates whether the library service should return a
         * library root for suggested media items.
         *
         * <p>When creating a media browser for a given media browser service, this key can be
         * supplied as a root hint for retrieving the media items suggested by the media browser
         * <p>When creating a media browser for a given media library service, this key can be
         * supplied as a root hint for retrieving the media items suggested by the media library
         * service. The list of media items is considered ordered by relevance, first being the top
         * suggestion.
         * If the media browser service can provide such media items, the implementation must return
         * If the media library service can provide such media items, the implementation must return
         * the key in the root hint when
         * {@link MediaLibrarySessionCallback#onGetRoot(ControllerInfo, Bundle)} is called back.
         *
@@ -295,35 +296,31 @@ public abstract class MediaLibraryService2 extends MediaSessionService2 {
         */
        public static final String EXTRA_SUGGESTED = "android.media.extra.SUGGESTED";

        final private String mRootId;
        final private Bundle mExtras;
        private final LibraryRootProvider mProvider;

        /**
         * Constructs a browser root.
         * Constructs a library root.
         * @param rootId The root id for browsing.
         * @param extras Any extras about the browser service.
         * @param extras Any extras about the library service.
         */
        public BrowserRoot(@NonNull String rootId, @Nullable Bundle extras) {
            if (rootId == null) {
                throw new IllegalArgumentException("The root id in BrowserRoot cannot be null. " +
                        "Use null for BrowserRoot instead.");
            }
            mRootId = rootId;
            mExtras = extras;
        public LibraryRoot(@NonNull Context context,
                @NonNull String rootId, @Nullable Bundle extras) {
            mProvider = ApiLoader.getProvider(context).createMediaLibraryService2LibraryRoot(
                    context, this, rootId, extras);
        }

        /**
         * Gets the root id for browsing.
         */
        public String getRootId() {
            return mRootId;
            return mProvider.getRootId_impl();
        }

        /**
         * Gets any extras about the browser service.
         * Gets any extras about the library service.
         */
        public Bundle getExtras() {
            return mExtras;
            return mProvider.getExtras_impl();
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import android.os.Bundle;
 * @hide
 */
public interface MediaBrowser2Provider extends MediaController2Provider {
    void getBrowserRoot_impl(Bundle rootHints);
    void getLibraryRoot_impl(Bundle rootHints);

    void subscribe_impl(String parentId, Bundle options);
    void unsubscribe_impl(String parentId, Bundle options);
+5 −0
Original line number Diff line number Diff line
@@ -33,4 +33,9 @@ public interface MediaLibraryService2Provider extends MediaSessionService2Provid
        void notifyChildrenChanged_impl(ControllerInfo controller, String parentId, Bundle options);
        void notifyChildrenChanged_impl(String parentId, Bundle options);
    }

    interface LibraryRootProvider {
        String getRootId_impl();
        Bundle getExtras_impl();
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.media.MediaController2;
import android.media.MediaController2.ControllerCallback;
import android.media.MediaItem2;
import android.media.MediaLibraryService2;
import android.media.MediaLibraryService2.LibraryRoot;
import android.media.MediaLibraryService2.MediaLibrarySession;
import android.media.MediaLibraryService2.MediaLibrarySessionBuilder;
import android.media.MediaLibraryService2.MediaLibrarySessionCallback;
@@ -42,6 +43,7 @@ import android.media.Rating2;
import android.media.SessionPlayer2;
import android.media.SessionToken2;
import android.media.VolumeProvider2;
import android.media.update.MediaLibraryService2Provider.LibraryRootProvider;
import android.media.update.MediaSession2Provider.BuilderBaseProvider;
import android.media.update.MediaSession2Provider.CommandButtonProvider.BuilderProvider;
import android.media.update.MediaSession2Provider.CommandGroupProvider;
@@ -103,6 +105,8 @@ public interface StaticProvider {
        createMediaLibraryService2Builder(
            Context context, MediaLibrarySessionBuilder instance, MediaPlayerInterface player,
            Executor callbackExecutor, MediaLibrarySessionCallback callback);
    LibraryRootProvider createMediaLibraryService2LibraryRoot(Context context, LibraryRoot instance,
            String rootId, Bundle extras);

    SessionToken2Provider createSessionToken2(Context context, SessionToken2 instance,
            String packageName, String serviceName, int uid);