Loading packages/MediaComponents/src/com/android/media/MediaController2Impl.java +6 −5 Original line number Diff line number Diff line Loading @@ -341,27 +341,28 @@ public class MediaController2Impl implements MediaController2Provider { @Override public void prepare_impl() { // TODO(jaewan): Implement sendTransportControlCommand(MediaSession2.COMMAND_CODE_PLAYBACK_PREPARE); } @Override public void fastForward_impl() { // TODO(jaewan): Implement sendTransportControlCommand(MediaSession2.COMMAND_CODE_PLAYBACK_FAST_FORWARD); } @Override public void rewind_impl() { // TODO(jaewan): Implement sendTransportControlCommand(MediaSession2.COMMAND_CODE_PLAYBACK_REWIND); } @Override public void seekTo_impl(long pos) { // TODO(jaewan): Implement sendTransportControlCommand(MediaSession2.COMMAND_CODE_PLAYBACK_SEEK_TO, pos); } @Override public void setCurrentPlaylistItem_impl(int index) { // TODO(jaewan): Implement sendTransportControlCommand( MediaSession2.COMMAND_CODE_PLAYBACK_SET_CURRENT_PLAYLIST_ITEM, index); } @Override Loading packages/MediaComponents/src/com/android/media/MediaSession2Impl.java +15 −5 Original line number Diff line number Diff line Loading @@ -273,27 +273,37 @@ public class MediaSession2Impl implements MediaSession2Provider { @Override public void prepare_impl() { // TODO(jaewan): Implement ensureCallingThread(); ensurePlayer(); mPlayer.prepare(); } @Override public void fastForward_impl() { // TODO(jaewan): Implement ensureCallingThread(); ensurePlayer(); mPlayer.fastForward(); } @Override public void rewind_impl() { // TODO(jaewan): Implement ensureCallingThread(); ensurePlayer(); mPlayer.rewind(); } @Override public void seekTo_impl(long pos) { // TODO(jaewan): Implement ensureCallingThread(); ensurePlayer(); mPlayer.seekTo(pos); } @Override public void setCurrentPlaylistItem_impl(int index) { // TODO(jaewan): Implement ensureCallingThread(); ensurePlayer(); mPlayer.setCurrentPlaylistItem(index); } /////////////////////////////////////////////////// Loading packages/MediaComponents/src/com/android/media/MediaSession2Stub.java +15 −0 Original line number Diff line number Diff line Loading @@ -187,6 +187,21 @@ public class MediaSession2Stub extends IMediaSession2.Stub { case MediaSession2.COMMAND_CODE_PLAYBACK_SKIP_NEXT_ITEM: session.getInstance().skipToNext(); break; case MediaSession2.COMMAND_CODE_PLAYBACK_PREPARE: session.getInstance().prepare(); break; case MediaSession2.COMMAND_CODE_PLAYBACK_FAST_FORWARD: session.getInstance().fastForward(); break; case MediaSession2.COMMAND_CODE_PLAYBACK_REWIND: session.getInstance().rewind(); break; case MediaSession2.COMMAND_CODE_PLAYBACK_SEEK_TO: session.getInstance().seekTo(arg); break; case MediaSession2.COMMAND_CODE_PLAYBACK_SET_CURRENT_PLAYLIST_ITEM: session.getInstance().setCurrentPlaylistItem((int) arg); break; default: // TODO(jaewan): Resend unknown (new) commands through the custom command. } Loading packages/MediaComponents/test/src/android/media/MediaController2Test.java +59 −1 Original line number Diff line number Diff line Loading @@ -101,7 +101,6 @@ public class MediaController2Test extends MediaSession2TestBase { assertTrue(mPlayer.mPauseCalled); } @Test public void testSkipToPrevious() throws InterruptedException { mController.skipToPrevious(); Loading Loading @@ -135,6 +134,65 @@ public class MediaController2Test extends MediaSession2TestBase { assertTrue(mPlayer.mStopCalled); } @Test public void testPrepare() throws InterruptedException { mController.prepare(); try { assertTrue(mPlayer.mCountDownLatch.await(WAIT_TIME_MS, TimeUnit.MILLISECONDS)); } catch (InterruptedException e) { fail(e.getMessage()); } assertTrue(mPlayer.mPrepareCalled); } @Test public void testFastForward() throws InterruptedException { mController.fastForward(); try { assertTrue(mPlayer.mCountDownLatch.await(WAIT_TIME_MS, TimeUnit.MILLISECONDS)); } catch (InterruptedException e) { fail(e.getMessage()); } assertTrue(mPlayer.mFastForwardCalled); } @Test public void testRewind() throws InterruptedException { mController.rewind(); try { assertTrue(mPlayer.mCountDownLatch.await(WAIT_TIME_MS, TimeUnit.MILLISECONDS)); } catch (InterruptedException e) { fail(e.getMessage()); } assertTrue(mPlayer.mRewindCalled); } @Test public void testSeekTo() throws InterruptedException { final long seekPosition = 12125L; mController.seekTo(seekPosition); try { assertTrue(mPlayer.mCountDownLatch.await(WAIT_TIME_MS, TimeUnit.MILLISECONDS)); } catch (InterruptedException e) { fail(e.getMessage()); } assertTrue(mPlayer.mSeekToCalled); assertEquals(seekPosition, mPlayer.mSeekPosition); } @Test public void testSetCurrentPlaylistItem() throws InterruptedException { final int itemIndex = 9; mController.setCurrentPlaylistItem(itemIndex); try { assertTrue(mPlayer.mCountDownLatch.await(WAIT_TIME_MS, TimeUnit.MILLISECONDS)); } catch (InterruptedException e) { fail(e.getMessage()); } assertTrue(mPlayer.mSetCurrentPlaylistItemCalled); assertEquals(itemIndex, mPlayer.mItemIndex); } @Test public void testGetPackageName() { assertEquals(mContext.getPackageName(), mController.getSessionToken().getPackageName()); Loading packages/MediaComponents/test/src/android/media/MockPlayer.java +48 −21 Original line number Diff line number Diff line Loading @@ -37,6 +37,14 @@ public class MockPlayer implements MediaPlayerInterface { public boolean mStopCalled; public boolean mSkipToPreviousCalled; public boolean mSkipToNextCalled; public boolean mPrepareCalled; public boolean mFastForwardCalled; public boolean mRewindCalled; public boolean mSeekToCalled; public long mSeekPosition; public boolean mSetCurrentPlaylistItemCalled; public int mItemIndex; public List<PlaybackListenerHolder> mListeners = new ArrayList<>(); private PlaybackState2 mLastPlaybackState; Loading Loading @@ -84,7 +92,47 @@ public class MockPlayer implements MediaPlayerInterface { } } @Override public void prepare() { mPrepareCalled = true; if (mCountDownLatch != null) { mCountDownLatch.countDown(); } } @Override public void fastForward() { mFastForwardCalled = true; if (mCountDownLatch != null) { mCountDownLatch.countDown(); } } @Override public void rewind() { mRewindCalled = true; if (mCountDownLatch != null) { mCountDownLatch.countDown(); } } @Override public void seekTo(long pos) { mSeekToCalled = true; mSeekPosition = pos; if (mCountDownLatch != null) { mCountDownLatch.countDown(); } } @Override public void setCurrentPlaylistItem(int index) { mSetCurrentPlaylistItemCalled = true; mItemIndex = index; if (mCountDownLatch != null) { mCountDownLatch.countDown(); } } @Nullable @Override Loading Loading @@ -113,23 +161,6 @@ public class MockPlayer implements MediaPlayerInterface { } } // No-op. Should be added for test later. @Override public void prepare() { } @Override public void seekTo(long pos) { } @Override public void fastFoward() { } @Override public void rewind() { } @Override public AudioAttributes getAudioAttributes() { return null; Loading @@ -138,8 +169,4 @@ public class MockPlayer implements MediaPlayerInterface { @Override public void setPlaylist(List<MediaItem2> item, PlaylistParams param) { } @Override public void setCurrentPlaylistItem(int index) { } } Loading
packages/MediaComponents/src/com/android/media/MediaController2Impl.java +6 −5 Original line number Diff line number Diff line Loading @@ -341,27 +341,28 @@ public class MediaController2Impl implements MediaController2Provider { @Override public void prepare_impl() { // TODO(jaewan): Implement sendTransportControlCommand(MediaSession2.COMMAND_CODE_PLAYBACK_PREPARE); } @Override public void fastForward_impl() { // TODO(jaewan): Implement sendTransportControlCommand(MediaSession2.COMMAND_CODE_PLAYBACK_FAST_FORWARD); } @Override public void rewind_impl() { // TODO(jaewan): Implement sendTransportControlCommand(MediaSession2.COMMAND_CODE_PLAYBACK_REWIND); } @Override public void seekTo_impl(long pos) { // TODO(jaewan): Implement sendTransportControlCommand(MediaSession2.COMMAND_CODE_PLAYBACK_SEEK_TO, pos); } @Override public void setCurrentPlaylistItem_impl(int index) { // TODO(jaewan): Implement sendTransportControlCommand( MediaSession2.COMMAND_CODE_PLAYBACK_SET_CURRENT_PLAYLIST_ITEM, index); } @Override Loading
packages/MediaComponents/src/com/android/media/MediaSession2Impl.java +15 −5 Original line number Diff line number Diff line Loading @@ -273,27 +273,37 @@ public class MediaSession2Impl implements MediaSession2Provider { @Override public void prepare_impl() { // TODO(jaewan): Implement ensureCallingThread(); ensurePlayer(); mPlayer.prepare(); } @Override public void fastForward_impl() { // TODO(jaewan): Implement ensureCallingThread(); ensurePlayer(); mPlayer.fastForward(); } @Override public void rewind_impl() { // TODO(jaewan): Implement ensureCallingThread(); ensurePlayer(); mPlayer.rewind(); } @Override public void seekTo_impl(long pos) { // TODO(jaewan): Implement ensureCallingThread(); ensurePlayer(); mPlayer.seekTo(pos); } @Override public void setCurrentPlaylistItem_impl(int index) { // TODO(jaewan): Implement ensureCallingThread(); ensurePlayer(); mPlayer.setCurrentPlaylistItem(index); } /////////////////////////////////////////////////// Loading
packages/MediaComponents/src/com/android/media/MediaSession2Stub.java +15 −0 Original line number Diff line number Diff line Loading @@ -187,6 +187,21 @@ public class MediaSession2Stub extends IMediaSession2.Stub { case MediaSession2.COMMAND_CODE_PLAYBACK_SKIP_NEXT_ITEM: session.getInstance().skipToNext(); break; case MediaSession2.COMMAND_CODE_PLAYBACK_PREPARE: session.getInstance().prepare(); break; case MediaSession2.COMMAND_CODE_PLAYBACK_FAST_FORWARD: session.getInstance().fastForward(); break; case MediaSession2.COMMAND_CODE_PLAYBACK_REWIND: session.getInstance().rewind(); break; case MediaSession2.COMMAND_CODE_PLAYBACK_SEEK_TO: session.getInstance().seekTo(arg); break; case MediaSession2.COMMAND_CODE_PLAYBACK_SET_CURRENT_PLAYLIST_ITEM: session.getInstance().setCurrentPlaylistItem((int) arg); break; default: // TODO(jaewan): Resend unknown (new) commands through the custom command. } Loading
packages/MediaComponents/test/src/android/media/MediaController2Test.java +59 −1 Original line number Diff line number Diff line Loading @@ -101,7 +101,6 @@ public class MediaController2Test extends MediaSession2TestBase { assertTrue(mPlayer.mPauseCalled); } @Test public void testSkipToPrevious() throws InterruptedException { mController.skipToPrevious(); Loading Loading @@ -135,6 +134,65 @@ public class MediaController2Test extends MediaSession2TestBase { assertTrue(mPlayer.mStopCalled); } @Test public void testPrepare() throws InterruptedException { mController.prepare(); try { assertTrue(mPlayer.mCountDownLatch.await(WAIT_TIME_MS, TimeUnit.MILLISECONDS)); } catch (InterruptedException e) { fail(e.getMessage()); } assertTrue(mPlayer.mPrepareCalled); } @Test public void testFastForward() throws InterruptedException { mController.fastForward(); try { assertTrue(mPlayer.mCountDownLatch.await(WAIT_TIME_MS, TimeUnit.MILLISECONDS)); } catch (InterruptedException e) { fail(e.getMessage()); } assertTrue(mPlayer.mFastForwardCalled); } @Test public void testRewind() throws InterruptedException { mController.rewind(); try { assertTrue(mPlayer.mCountDownLatch.await(WAIT_TIME_MS, TimeUnit.MILLISECONDS)); } catch (InterruptedException e) { fail(e.getMessage()); } assertTrue(mPlayer.mRewindCalled); } @Test public void testSeekTo() throws InterruptedException { final long seekPosition = 12125L; mController.seekTo(seekPosition); try { assertTrue(mPlayer.mCountDownLatch.await(WAIT_TIME_MS, TimeUnit.MILLISECONDS)); } catch (InterruptedException e) { fail(e.getMessage()); } assertTrue(mPlayer.mSeekToCalled); assertEquals(seekPosition, mPlayer.mSeekPosition); } @Test public void testSetCurrentPlaylistItem() throws InterruptedException { final int itemIndex = 9; mController.setCurrentPlaylistItem(itemIndex); try { assertTrue(mPlayer.mCountDownLatch.await(WAIT_TIME_MS, TimeUnit.MILLISECONDS)); } catch (InterruptedException e) { fail(e.getMessage()); } assertTrue(mPlayer.mSetCurrentPlaylistItemCalled); assertEquals(itemIndex, mPlayer.mItemIndex); } @Test public void testGetPackageName() { assertEquals(mContext.getPackageName(), mController.getSessionToken().getPackageName()); Loading
packages/MediaComponents/test/src/android/media/MockPlayer.java +48 −21 Original line number Diff line number Diff line Loading @@ -37,6 +37,14 @@ public class MockPlayer implements MediaPlayerInterface { public boolean mStopCalled; public boolean mSkipToPreviousCalled; public boolean mSkipToNextCalled; public boolean mPrepareCalled; public boolean mFastForwardCalled; public boolean mRewindCalled; public boolean mSeekToCalled; public long mSeekPosition; public boolean mSetCurrentPlaylistItemCalled; public int mItemIndex; public List<PlaybackListenerHolder> mListeners = new ArrayList<>(); private PlaybackState2 mLastPlaybackState; Loading Loading @@ -84,7 +92,47 @@ public class MockPlayer implements MediaPlayerInterface { } } @Override public void prepare() { mPrepareCalled = true; if (mCountDownLatch != null) { mCountDownLatch.countDown(); } } @Override public void fastForward() { mFastForwardCalled = true; if (mCountDownLatch != null) { mCountDownLatch.countDown(); } } @Override public void rewind() { mRewindCalled = true; if (mCountDownLatch != null) { mCountDownLatch.countDown(); } } @Override public void seekTo(long pos) { mSeekToCalled = true; mSeekPosition = pos; if (mCountDownLatch != null) { mCountDownLatch.countDown(); } } @Override public void setCurrentPlaylistItem(int index) { mSetCurrentPlaylistItemCalled = true; mItemIndex = index; if (mCountDownLatch != null) { mCountDownLatch.countDown(); } } @Nullable @Override Loading Loading @@ -113,23 +161,6 @@ public class MockPlayer implements MediaPlayerInterface { } } // No-op. Should be added for test later. @Override public void prepare() { } @Override public void seekTo(long pos) { } @Override public void fastFoward() { } @Override public void rewind() { } @Override public AudioAttributes getAudioAttributes() { return null; Loading @@ -138,8 +169,4 @@ public class MockPlayer implements MediaPlayerInterface { @Override public void setPlaylist(List<MediaItem2> item, PlaylistParams param) { } @Override public void setCurrentPlaylistItem(int index) { } }