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

Commit 3117c0c2 authored by Jaewan Kim's avatar Jaewan Kim
Browse files

MediaSession2: Move MediaSession2.PlaylistParams to updatable

Bug: 72670266
Test: Run all MediaComponents tests once
Change-Id: I5bf0ae9b97f2f60baabfe05e9df893308ee8d41a
parent f641c097
Loading
Loading
Loading
Loading
+48 −60
Original line number Diff line number Diff line
@@ -795,7 +795,7 @@ public class MediaSession2 implements AutoCloseable {
    /**
     * Parameter for the playlist.
     */
    public static class PlaylistParams {
    public final static class PlaylistParams {
        /**
         * @hide
         */
@@ -850,83 +850,71 @@ public class MediaSession2 implements AutoCloseable {
         */
        public static final int SHUFFLE_MODE_GROUP = 2;

        /**
         * Keys used for converting a PlaylistParams object to a bundle object and vice versa.
         */
        private static final String KEY_REPEAT_MODE =
                "android.media.session2.playlistparams2.repeat_mode";
        private static final String KEY_SHUFFLE_MODE =
                "android.media.session2.playlistparams2.shuffle_mode";
        private static final String KEY_MEDIA_METADATA2_BUNDLE =
                "android.media.session2.playlistparams2.metadata2_bundle";

        private @RepeatMode int mRepeatMode;
        private @ShuffleMode int mShuffleMode;

        private MediaMetadata2 mPlaylistMetadata;

        public PlaylistParams(@RepeatMode int repeatMode, @ShuffleMode int shuffleMode,
                @Nullable MediaMetadata2 playlistMetadata) {
            mRepeatMode = repeatMode;
            mShuffleMode = shuffleMode;
            mPlaylistMetadata = playlistMetadata;
        }
        private final MediaSession2Provider.PlaylistParamsProvider mProvider;

        public @RepeatMode int getRepeatMode() {
            return mRepeatMode;
        /**
         * Instantiate {@link PlaylistParams}
         *
         * @param context context
         * @param repeatMode repeat mode
         * @param shuffleMode shuffle mode
         * @param playlistMetadata metadata for the list
         */
        public PlaylistParams(@NonNull Context context, @RepeatMode int repeatMode,
                @ShuffleMode int shuffleMode, @Nullable MediaMetadata2 playlistMetadata) {
            mProvider = ApiLoader.getProvider(context).createMediaSession2PlaylistParams(
                    context, this, repeatMode, shuffleMode, playlistMetadata);
        }

        public @ShuffleMode int getShuffleMode() {
            return mShuffleMode;
        /**
         * Create a new bundle for this object.
         *
         * @return
         */
        public @NonNull Bundle toBundle() {
            return mProvider.toBundle_impl();
        }

        public MediaMetadata2 getPlaylistMetadata() {
            return mPlaylistMetadata;
        /**
         * Create a new playlist params from the bundle that was previously returned by
         * {@link #toBundle}.
         *
         * @param context context
         * @return a new playlist params. Can be {@code null} for error.
         */
        public static @Nullable PlaylistParams fromBundle(
                @NonNull Context context, @Nullable Bundle bundle) {
            return ApiLoader.getProvider(context).fromBundle_PlaylistParams(context, bundle);
        }

        /**
         * Returns this object as a bundle to share between processes.
         * Get repeat mode
         *
         * @hide
         * @return repeat mode
         * @see #REPEAT_MODE_NONE, #REPEAT_MODE_ONE, #REPEAT_MODE_ALL, #REPEAT_MODE_GROUP
         */
        public Bundle toBundle() {
            Bundle bundle = new Bundle();
            bundle.putInt(KEY_REPEAT_MODE, mRepeatMode);
            bundle.putInt(KEY_SHUFFLE_MODE, mShuffleMode);
            if (mPlaylistMetadata != null) {
                bundle.putBundle(KEY_MEDIA_METADATA2_BUNDLE, mPlaylistMetadata.toBundle());
            }
            return bundle;
        public @RepeatMode int getRepeatMode() {
            return mProvider.getRepeatMode_impl();
        }

        /**
         * Creates an instance from a bundle which is previously created by {@link #toBundle()}.
         * Get shuffle mode
         *
         * @param bundle A bundle created by {@link #toBundle()}.
         * @return A new {@link PlaylistParams} instance. Returns {@code null} if the given
         *         {@param bundle} is null, or if the {@param bundle} has no playlist parameters.
         * @hide
         * @return shuffle mode
         * @see #SHUFFLE_MODE_NONE, #SHUFFLE_MODE_ALL, #SHUFFLE_MODE_GROUP
         */
        public static PlaylistParams fromBundle(Bundle bundle) {
            if (bundle == null) {
                return null;
            }
            if (!bundle.containsKey(KEY_REPEAT_MODE) || !bundle.containsKey(KEY_SHUFFLE_MODE)) {
                return null;
        public @ShuffleMode int getShuffleMode() {
            return mProvider.getShuffleMode_impl();
        }

            Bundle metadataBundle = bundle.getBundle(KEY_MEDIA_METADATA2_BUNDLE);
            MediaMetadata2 metadata = null;
            // TODO(jaewan): Uncomment here when the PlaylistParam becomes updatable.
            /*
            MediaMetadata2 metadata = metadataBundle == null
                    ? null : MediaMetadata2.fromBundle(mContext, metadataBundle);
        /**
         * Get metadata for the playlist
         *
         * @return metadata. Can be {@code null}
         */

            return new PlaylistParams(
                    bundle.getInt(KEY_REPEAT_MODE),
                    bundle.getInt(KEY_SHUFFLE_MODE),
                    metadata);
        public @Nullable MediaMetadata2 getPlaylistMetadata() {
            return mProvider.getPlaylistMetadata_impl();
        }
    }

+8 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.media.update;

import android.media.MediaItem2;
import android.media.MediaMetadata2;
import android.media.MediaPlayerInterface;
import android.media.MediaPlayerInterface.PlaybackListener;
import android.media.MediaSession2.Command;
@@ -87,4 +88,11 @@ public interface MediaSession2Provider extends TransportControlProvider {
        int hashCode_impl();
        boolean equals_impl(ControllerInfoProvider obj);
    }

    interface PlaylistParamsProvider {
        int getRepeatMode_impl();
        int getShuffleMode_impl();
        MediaMetadata2 getPlaylistMetadata_impl();
        Bundle toBundle_impl();
    }
}
+6 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.media.MediaLibraryService2.MediaLibrarySessionCallback;
import android.media.MediaMetadata2;
import android.media.MediaPlayerInterface;
import android.media.MediaSession2;
import android.media.MediaSession2.PlaylistParams;
import android.media.MediaSession2.SessionCallback;
import android.media.MediaSessionService2;
import android.media.SessionPlayer2;
@@ -40,6 +41,7 @@ import android.media.update.MediaLibraryService2Provider.MediaLibrarySessionProv
import android.media.update.MediaSession2Provider.CommandGroupProvider;
import android.media.update.MediaSession2Provider.CommandProvider;
import android.media.update.MediaSession2Provider.ControllerInfoProvider;
import android.media.update.MediaSession2Provider.PlaylistParamsProvider;
import android.os.Bundle;
import android.os.IInterface;
import android.util.AttributeSet;
@@ -74,7 +76,10 @@ public interface StaticProvider {
    ControllerInfoProvider createMediaSession2ControllerInfo(Context context,
            MediaSession2.ControllerInfo instance, int uid, int pid,
            String packageName, IInterface callback);

    PlaylistParamsProvider createMediaSession2PlaylistParams(Context context,
            PlaylistParams playlistParams, int repeatMode, int shuffleMode,
            MediaMetadata2 playlistMetadata);
    PlaylistParams fromBundle_PlaylistParams(Context context, Bundle bundle);
    MediaController2Provider createMediaController2(Context context, MediaController2 instance,
            SessionToken2 token, Executor executor, ControllerCallback callback);