Loading packages/MediaComponents/src/com/android/media/MediaController2Impl.java +3 −3 Original line number Diff line number Diff line Loading @@ -351,7 +351,7 @@ public class MediaController2Impl implements MediaController2Provider { @Override public void setVolumeTo_impl(int value, int flags) { // TODO(hdmoon): sanity check final IMediaSession2 binder = getSessionBinderIfAble(COMMAND_CODE_SET_VOLUME); final IMediaSession2 binder = getSessionBinderIfAble(COMMAND_CODE_PLAYBACK_SET_VOLUME); if (binder != null) { try { binder.setVolumeTo(mSessionCallbackStub, value, flags); Loading @@ -366,7 +366,7 @@ public class MediaController2Impl implements MediaController2Provider { @Override public void adjustVolume_impl(int direction, int flags) { // TODO(hdmoon): sanity check final IMediaSession2 binder = getSessionBinderIfAble(COMMAND_CODE_SET_VOLUME); final IMediaSession2 binder = getSessionBinderIfAble(COMMAND_CODE_PLAYBACK_SET_VOLUME); if (binder != null) { try { binder.adjustVolume(mSessionCallbackStub, direction, flags); Loading Loading @@ -561,7 +561,7 @@ public class MediaController2Impl implements MediaController2Provider { Bundle args = new Bundle(); args.putInt(MediaSession2Stub.ARGUMENT_KEY_ITEM_INDEX, item); sendTransportControlCommand( MediaSession2.COMMAND_CODE_PLAYBACK_SKIP_TO_PLAYLIST_ITEM, args); MediaSession2.COMMAND_CODE_PLAYLIST_SKIP_TO_PLAYLIST_ITEM, args); */ } Loading packages/MediaComponents/src/com/android/media/MediaSession2Impl.java +1 −2 Original line number Diff line number Diff line Loading @@ -885,8 +885,7 @@ public class MediaSession2Impl implements MediaSession2Provider { @Override public void addAllPredefinedCommands_impl() { final int COMMAND_CODE_MAX = 22; for (int i = 1; i <= COMMAND_CODE_MAX; i++) { for (int i = 1; i <= MediaSession2.COMMAND_CODE_MAX; i++) { mCommands.add(new Command(mContext, i)); } } Loading packages/MediaComponents/src/com/android/media/MediaSession2Stub.java +14 −11 Original line number Diff line number Diff line Loading @@ -267,7 +267,7 @@ public class MediaSession2Stub extends IMediaSession2.Stub { final Bundle paramsBundle = (params != null) ? params.toBundle() : null; final PendingIntent sessionActivity = session.getSessionActivity(); final List<MediaItem2> playlist = allowedCommands.hasCommand(MediaSession2.COMMAND_CODE_PLAYLIST_GET) allowedCommands.hasCommand(MediaSession2.COMMAND_CODE_PLAYLIST_GET_LIST) ? session.getInstance().getPlaylist() : null; final List<Bundle> playlistBundle; if (playlist != null) { Loading Loading @@ -332,23 +332,23 @@ public class MediaSession2Stub extends IMediaSession2.Stub { throws RuntimeException { final MediaSession2Impl session = getSession(); final ControllerInfo controller = getControllerIfAble( caller, MediaSession2.COMMAND_CODE_SET_VOLUME); caller, MediaSession2.COMMAND_CODE_PLAYBACK_SET_VOLUME); if (session == null || controller == null) { return; } session.getCallbackExecutor().execute(() -> { if (getControllerIfAble(caller, MediaSession2.COMMAND_CODE_SET_VOLUME) == null) { if (getControllerIfAble(caller, MediaSession2.COMMAND_CODE_PLAYBACK_SET_VOLUME) == null) { return; } // TODO(jaewan): Sanity check. Command command = new Command( session.getContext(), MediaSession2.COMMAND_CODE_SET_VOLUME); session.getContext(), MediaSession2.COMMAND_CODE_PLAYBACK_SET_VOLUME); boolean accepted = session.getCallback().onCommandRequest(session.getInstance(), controller, command); if (!accepted) { // Don't run rejected command. if (DEBUG) { Log.d(TAG, "Command " + MediaSession2.COMMAND_CODE_SET_VOLUME + " from " Log.d(TAG, "Command " + MediaSession2.COMMAND_CODE_PLAYBACK_SET_VOLUME + " from " + controller + " was rejected by " + session); } return; Loading @@ -368,23 +368,23 @@ public class MediaSession2Stub extends IMediaSession2.Stub { throws RuntimeException { final MediaSession2Impl session = getSession(); final ControllerInfo controller = getControllerIfAble( caller, MediaSession2.COMMAND_CODE_SET_VOLUME); caller, MediaSession2.COMMAND_CODE_PLAYBACK_SET_VOLUME); if (session == null || controller == null) { return; } session.getCallbackExecutor().execute(() -> { if (getControllerIfAble(caller, MediaSession2.COMMAND_CODE_SET_VOLUME) == null) { if (getControllerIfAble(caller, MediaSession2.COMMAND_CODE_PLAYBACK_SET_VOLUME) == null) { return; } // TODO(jaewan): Sanity check. Command command = new Command( session.getContext(), MediaSession2.COMMAND_CODE_SET_VOLUME); session.getContext(), MediaSession2.COMMAND_CODE_PLAYBACK_SET_VOLUME); boolean accepted = session.getCallback().onCommandRequest(session.getInstance(), controller, command); if (!accepted) { // Don't run rejected command. if (DEBUG) { Log.d(TAG, "Command " + MediaSession2.COMMAND_CODE_SET_VOLUME + " from " Log.d(TAG, "Command " + MediaSession2.COMMAND_CODE_PLAYBACK_SET_VOLUME + " from " + controller + " was rejected by " + session); } return; Loading Loading @@ -452,18 +452,21 @@ public class MediaSession2Stub extends IMediaSession2.Stub { case MediaSession2.COMMAND_CODE_PLAYBACK_SEEK_TO: session.getInstance().seekTo(args.getLong(ARGUMENT_KEY_POSITION)); break; case MediaSession2.COMMAND_CODE_PLAYBACK_SKIP_TO_PLAYLIST_ITEM: case MediaSession2.COMMAND_CODE_PLAYLIST_SKIP_TO_PLAYLIST_ITEM: // TODO(jaewan): Implement /* session.getInstance().skipToPlaylistItem( args.getInt(ARGUMENT_KEY_ITEM_INDEX)); */ break; // TODO(jaewan): Remove (b/74116823) /* case MediaSession2.COMMAND_CODE_PLAYBACK_SET_PLAYLIST_PARAMS: session.getInstance().setPlaylistParams( PlaylistParams.fromBundle(session.getContext(), args.getBundle(ARGUMENT_KEY_PLAYLIST_PARAMS))); break; */ default: // TODO(jaewan): Resend unknown (new) commands through the custom command. } Loading Loading @@ -910,7 +913,7 @@ public class MediaSession2Stub extends IMediaSession2.Stub { final List<ControllerInfo> list = getControllers(); for (int i = 0; i < list.size(); i++) { final IMediaSession2Callback controllerBinder = getControllerBinderIfAble( list.get(i), MediaSession2.COMMAND_CODE_PLAYLIST_GET); list.get(i), MediaSession2.COMMAND_CODE_PLAYLIST_GET_LIST); if (controllerBinder != null) { try { controllerBinder.onPlaylistChanged(bundleList); Loading packages/MediaComponents/test/src/android/media/MediaSession2_PermissionTest.java +3 −6 Original line number Diff line number Diff line Loading @@ -28,7 +28,6 @@ import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.media.MediaSession2; import android.media.MediaSession2.Command; import android.media.MediaSession2.CommandGroup; import android.media.MediaSession2.SessionCallback; Loading @@ -41,8 +40,6 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentMatcher; import org.mockito.Mockito; /** * Tests whether {@link MediaSession2} receives commands that hasn't allowed. Loading Loading @@ -260,12 +257,12 @@ public class MediaSession2_PermissionTest extends MediaSession2TestBase { @Test public void testSetVolume() throws InterruptedException { createSessionWithAllowedActions(createCommandGroupWith(COMMAND_CODE_SET_VOLUME)); createSessionWithAllowedActions(createCommandGroupWith(COMMAND_CODE_PLAYBACK_SET_VOLUME)); createController(mSession.getToken()).setVolumeTo(0, 0); verify(mCallback, timeout(TIMEOUT_MS).atLeastOnce()).onCommandRequest( matchesSession(), matchesCaller(), matches(COMMAND_CODE_SET_VOLUME)); matchesSession(), matchesCaller(), matches(COMMAND_CODE_PLAYBACK_SET_VOLUME)); createSessionWithAllowedActions(createCommandGroupWithout(COMMAND_CODE_SET_VOLUME)); createSessionWithAllowedActions(createCommandGroupWithout(COMMAND_CODE_PLAYBACK_SET_VOLUME)); createController(mSession.getToken()).setVolumeTo(0, 0); verify(mCallback, after(WAIT_TIME_MS).never()).onCommandRequest(any(), any(), any()); } Loading Loading
packages/MediaComponents/src/com/android/media/MediaController2Impl.java +3 −3 Original line number Diff line number Diff line Loading @@ -351,7 +351,7 @@ public class MediaController2Impl implements MediaController2Provider { @Override public void setVolumeTo_impl(int value, int flags) { // TODO(hdmoon): sanity check final IMediaSession2 binder = getSessionBinderIfAble(COMMAND_CODE_SET_VOLUME); final IMediaSession2 binder = getSessionBinderIfAble(COMMAND_CODE_PLAYBACK_SET_VOLUME); if (binder != null) { try { binder.setVolumeTo(mSessionCallbackStub, value, flags); Loading @@ -366,7 +366,7 @@ public class MediaController2Impl implements MediaController2Provider { @Override public void adjustVolume_impl(int direction, int flags) { // TODO(hdmoon): sanity check final IMediaSession2 binder = getSessionBinderIfAble(COMMAND_CODE_SET_VOLUME); final IMediaSession2 binder = getSessionBinderIfAble(COMMAND_CODE_PLAYBACK_SET_VOLUME); if (binder != null) { try { binder.adjustVolume(mSessionCallbackStub, direction, flags); Loading Loading @@ -561,7 +561,7 @@ public class MediaController2Impl implements MediaController2Provider { Bundle args = new Bundle(); args.putInt(MediaSession2Stub.ARGUMENT_KEY_ITEM_INDEX, item); sendTransportControlCommand( MediaSession2.COMMAND_CODE_PLAYBACK_SKIP_TO_PLAYLIST_ITEM, args); MediaSession2.COMMAND_CODE_PLAYLIST_SKIP_TO_PLAYLIST_ITEM, args); */ } Loading
packages/MediaComponents/src/com/android/media/MediaSession2Impl.java +1 −2 Original line number Diff line number Diff line Loading @@ -885,8 +885,7 @@ public class MediaSession2Impl implements MediaSession2Provider { @Override public void addAllPredefinedCommands_impl() { final int COMMAND_CODE_MAX = 22; for (int i = 1; i <= COMMAND_CODE_MAX; i++) { for (int i = 1; i <= MediaSession2.COMMAND_CODE_MAX; i++) { mCommands.add(new Command(mContext, i)); } } Loading
packages/MediaComponents/src/com/android/media/MediaSession2Stub.java +14 −11 Original line number Diff line number Diff line Loading @@ -267,7 +267,7 @@ public class MediaSession2Stub extends IMediaSession2.Stub { final Bundle paramsBundle = (params != null) ? params.toBundle() : null; final PendingIntent sessionActivity = session.getSessionActivity(); final List<MediaItem2> playlist = allowedCommands.hasCommand(MediaSession2.COMMAND_CODE_PLAYLIST_GET) allowedCommands.hasCommand(MediaSession2.COMMAND_CODE_PLAYLIST_GET_LIST) ? session.getInstance().getPlaylist() : null; final List<Bundle> playlistBundle; if (playlist != null) { Loading Loading @@ -332,23 +332,23 @@ public class MediaSession2Stub extends IMediaSession2.Stub { throws RuntimeException { final MediaSession2Impl session = getSession(); final ControllerInfo controller = getControllerIfAble( caller, MediaSession2.COMMAND_CODE_SET_VOLUME); caller, MediaSession2.COMMAND_CODE_PLAYBACK_SET_VOLUME); if (session == null || controller == null) { return; } session.getCallbackExecutor().execute(() -> { if (getControllerIfAble(caller, MediaSession2.COMMAND_CODE_SET_VOLUME) == null) { if (getControllerIfAble(caller, MediaSession2.COMMAND_CODE_PLAYBACK_SET_VOLUME) == null) { return; } // TODO(jaewan): Sanity check. Command command = new Command( session.getContext(), MediaSession2.COMMAND_CODE_SET_VOLUME); session.getContext(), MediaSession2.COMMAND_CODE_PLAYBACK_SET_VOLUME); boolean accepted = session.getCallback().onCommandRequest(session.getInstance(), controller, command); if (!accepted) { // Don't run rejected command. if (DEBUG) { Log.d(TAG, "Command " + MediaSession2.COMMAND_CODE_SET_VOLUME + " from " Log.d(TAG, "Command " + MediaSession2.COMMAND_CODE_PLAYBACK_SET_VOLUME + " from " + controller + " was rejected by " + session); } return; Loading @@ -368,23 +368,23 @@ public class MediaSession2Stub extends IMediaSession2.Stub { throws RuntimeException { final MediaSession2Impl session = getSession(); final ControllerInfo controller = getControllerIfAble( caller, MediaSession2.COMMAND_CODE_SET_VOLUME); caller, MediaSession2.COMMAND_CODE_PLAYBACK_SET_VOLUME); if (session == null || controller == null) { return; } session.getCallbackExecutor().execute(() -> { if (getControllerIfAble(caller, MediaSession2.COMMAND_CODE_SET_VOLUME) == null) { if (getControllerIfAble(caller, MediaSession2.COMMAND_CODE_PLAYBACK_SET_VOLUME) == null) { return; } // TODO(jaewan): Sanity check. Command command = new Command( session.getContext(), MediaSession2.COMMAND_CODE_SET_VOLUME); session.getContext(), MediaSession2.COMMAND_CODE_PLAYBACK_SET_VOLUME); boolean accepted = session.getCallback().onCommandRequest(session.getInstance(), controller, command); if (!accepted) { // Don't run rejected command. if (DEBUG) { Log.d(TAG, "Command " + MediaSession2.COMMAND_CODE_SET_VOLUME + " from " Log.d(TAG, "Command " + MediaSession2.COMMAND_CODE_PLAYBACK_SET_VOLUME + " from " + controller + " was rejected by " + session); } return; Loading Loading @@ -452,18 +452,21 @@ public class MediaSession2Stub extends IMediaSession2.Stub { case MediaSession2.COMMAND_CODE_PLAYBACK_SEEK_TO: session.getInstance().seekTo(args.getLong(ARGUMENT_KEY_POSITION)); break; case MediaSession2.COMMAND_CODE_PLAYBACK_SKIP_TO_PLAYLIST_ITEM: case MediaSession2.COMMAND_CODE_PLAYLIST_SKIP_TO_PLAYLIST_ITEM: // TODO(jaewan): Implement /* session.getInstance().skipToPlaylistItem( args.getInt(ARGUMENT_KEY_ITEM_INDEX)); */ break; // TODO(jaewan): Remove (b/74116823) /* case MediaSession2.COMMAND_CODE_PLAYBACK_SET_PLAYLIST_PARAMS: session.getInstance().setPlaylistParams( PlaylistParams.fromBundle(session.getContext(), args.getBundle(ARGUMENT_KEY_PLAYLIST_PARAMS))); break; */ default: // TODO(jaewan): Resend unknown (new) commands through the custom command. } Loading Loading @@ -910,7 +913,7 @@ public class MediaSession2Stub extends IMediaSession2.Stub { final List<ControllerInfo> list = getControllers(); for (int i = 0; i < list.size(); i++) { final IMediaSession2Callback controllerBinder = getControllerBinderIfAble( list.get(i), MediaSession2.COMMAND_CODE_PLAYLIST_GET); list.get(i), MediaSession2.COMMAND_CODE_PLAYLIST_GET_LIST); if (controllerBinder != null) { try { controllerBinder.onPlaylistChanged(bundleList); Loading
packages/MediaComponents/test/src/android/media/MediaSession2_PermissionTest.java +3 −6 Original line number Diff line number Diff line Loading @@ -28,7 +28,6 @@ import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.media.MediaSession2; import android.media.MediaSession2.Command; import android.media.MediaSession2.CommandGroup; import android.media.MediaSession2.SessionCallback; Loading @@ -41,8 +40,6 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentMatcher; import org.mockito.Mockito; /** * Tests whether {@link MediaSession2} receives commands that hasn't allowed. Loading Loading @@ -260,12 +257,12 @@ public class MediaSession2_PermissionTest extends MediaSession2TestBase { @Test public void testSetVolume() throws InterruptedException { createSessionWithAllowedActions(createCommandGroupWith(COMMAND_CODE_SET_VOLUME)); createSessionWithAllowedActions(createCommandGroupWith(COMMAND_CODE_PLAYBACK_SET_VOLUME)); createController(mSession.getToken()).setVolumeTo(0, 0); verify(mCallback, timeout(TIMEOUT_MS).atLeastOnce()).onCommandRequest( matchesSession(), matchesCaller(), matches(COMMAND_CODE_SET_VOLUME)); matchesSession(), matchesCaller(), matches(COMMAND_CODE_PLAYBACK_SET_VOLUME)); createSessionWithAllowedActions(createCommandGroupWithout(COMMAND_CODE_SET_VOLUME)); createSessionWithAllowedActions(createCommandGroupWithout(COMMAND_CODE_PLAYBACK_SET_VOLUME)); createController(mSession.getToken()).setVolumeTo(0, 0); verify(mCallback, after(WAIT_TIME_MS).never()).onCommandRequest(any(), any(), any()); } Loading