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

Commit 009c393c authored by Jaewan Kim's avatar Jaewan Kim
Browse files

MediaSession2: Refactor incoming binder calls to the MediaSession2Stub

This CL refactors methods in MediaSession2Stub that handles incoming
binder calls from the controller by adding methods to do followings
in one place.
  1. Check if the session hasn't closed.
  2. Check if the controller is allowed for the command
  3. Call SessionCallback#onCommandRequest() for APIs that would be
     sent directly to the MediaPlayerBase or MediaPlaylistAgent if
     allowed.

This CL also adds missing command code for setRating().

Bug: 74581821
Test: Run CTS tests with MediaComponents/runcts.sh
Change-Id: I9b96e26b7644cff3c54269773590c73ff30f956c
parent 4d1390e4
Loading
Loading
Loading
Loading
+21 −16
Original line number Diff line number Diff line
@@ -181,16 +181,6 @@ public class MediaSession2 implements AutoCloseable {
     */
    public static final int COMMAND_CODE_PLAYBACK_ADJUST_VOLUME = 11;

    /**
     * Command code for {@link MediaController2#setPlaylistParams(PlaylistParams)}.
     * <p>
     * Command would be sent directly to the player if the session doesn't reject the request
     * through the {@link SessionCallback#onCommandRequest(MediaSession2, ControllerInfo, Command)}.
     * @hide
     */
    // TODO(jaewan): Remove (b/74116823)
    public static final int COMMAND_CODE_PLAYBACK_SET_PLAYLIST_PARAMS = 12;

    /**
     * Command code for {@link MediaController2#skipToPlaylistItem(MediaItem2)}.
     * <p>
@@ -313,6 +303,13 @@ public class MediaSession2 implements AutoCloseable {
     */
    public static final int COMMAND_CODE_PREPARE_FROM_SEARCH = 27;

    /**
     * Command code for {@link MediaController2#setRating(String, Rating2)}.
     * @hide
     */
    // TODO(jaewan): Unhide
    public static final int COMMAND_CODE_SET_RATING = 29;

    /**
     * Command code for {@link MediaBrowser2} specific functions that allows navigation and search
     * from the {@link MediaLibraryService2}. This would be ignored for a {@link MediaSession2},
@@ -322,11 +319,6 @@ public class MediaSession2 implements AutoCloseable {
     */
    public static final int COMMAND_CODE_BROWSER = 28;

    /**
     * @hide
     */
    public static final int COMMAND_CODE_MAX = 28;

    /**
     * @hide
     */
@@ -452,6 +444,13 @@ public class MediaSession2 implements AutoCloseable {
                    .createMediaSession2Command(this, COMMAND_CODE_CUSTOM, action, extras);
        }

        /**
         * @hide
         */
        public CommandProvider getProvider() {
            return mProvider;
        }

        public int getCommandCode() {
            return mProvider.getCommandCode_impl();
        }
@@ -510,6 +509,13 @@ public class MediaSession2 implements AutoCloseable {
                    .createMediaSession2CommandGroup(context, this, others);
        }

        /**
         * @hide
         */
        public CommandGroup(@NonNull CommandGroupProvider provider) {
            mProvider = provider;
        }

        public void addCommand(@NonNull Command command) {
            mProvider.addCommand_impl(command);
        }
@@ -622,7 +628,6 @@ public class MediaSession2 implements AutoCloseable {
         * @see #COMMAND_CODE_PLAYBACK_REWIND
         * @see #COMMAND_CODE_PLAYBACK_SEEK_TO
         * @see #COMMAND_CODE_PLAYLIST_SKIP_TO_PLAYLIST_ITEM
         * @see #COMMAND_CODE_PLAYBACK_SET_PLAYLIST_PARAMS
         * @see #COMMAND_CODE_PLAYLIST_ADD_ITEM
         * @see #COMMAND_CODE_PLAYLIST_REMOVE_ITEM
         * @see #COMMAND_CODE_PLAYLIST_GET_LIST