From 009c393ca111743a61885f6290eba03e2afe404f Mon Sep 17 00:00:00 2001 From: Jaewan Kim Date: Tue, 13 Mar 2018 19:15:59 +0900 Subject: [PATCH] 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 --- media/java/android/media/MediaSession2.java | 37 ++++++++++++--------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/media/java/android/media/MediaSession2.java b/media/java/android/media/MediaSession2.java index e60c5f9b3b8ca..91bfacee97897 100644 --- a/media/java/android/media/MediaSession2.java +++ b/media/java/android/media/MediaSession2.java @@ -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)}. - *

- * 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)}. *

@@ -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