Loading android/app/src/com/android/bluetooth/audio_util/MediaPlayerWrapper.java +14 −8 Original line number Diff line number Diff line Loading @@ -461,8 +461,11 @@ public class MediaPlayerWrapper { @Override public void onMetadataChanged(@Nullable MediaMetadata mediaMetadata) { if (!isMetadataReady()) { Log.v(TAG, "onMetadataChanged(): " + mPackageName + " tried to update with no queue"); Log.v( TAG, "onMetadataChanged(): " + mPackageName + " tried to update with no metadata"); return; } Loading Loading @@ -495,13 +498,16 @@ public class MediaPlayerWrapper { @Override public void onPlaybackStateChanged(@Nullable PlaybackState state) { if (!isPlaybackStateReady()) { Log.v(TAG, "onPlaybackStateChanged(): " + mPackageName + " tried to update with no queue"); Log.v( TAG, "onPlaybackStateChanged(): " + mPackageName + " tried to update with no state"); return; } mPlaybackStateChangeEventLogger.logv(TAG, "onPlaybackStateChanged(): " + mPackageName + " : " + state.toString()); mPlaybackStateChangeEventLogger.logv( TAG, "onPlaybackStateChanged(): " + mPackageName + " : " + state); if (!playstateEquals(state, getPlaybackState())) { e("The callback playback state doesn't match the current state"); Loading @@ -513,8 +519,8 @@ public class MediaPlayerWrapper { return; } // If there is no playstate, ignore the update. if (state.getState() == PlaybackState.STATE_NONE) { // If state isn't null and there is no playstate, ignore the update. if (state != null && state.getState() == PlaybackState.STATE_NONE) { Log.v(TAG, "Waiting to send update as controller has no playback state"); return; } Loading android/app/tests/unit/src/com/android/bluetooth/audio_util/MediaPlayerWrapperTest.java +32 −1 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.*; import android.content.Context; import android.content.pm.PackageManager; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; Loading Loading @@ -377,6 +376,38 @@ public class MediaPlayerWrapperTest { Util.toMetadata(mMockContext, mTestMetadata.build())); } @Test public void testNullPlayback() { // Create the wrapper object and register the looper with the timeout handler TestLooperManager looperManager = new TestLooperManager(mThread.getLooper()); MediaPlayerWrapper wrapper = MediaPlayerWrapperFactory.wrap(mMockContext, mMockController, mThread.getLooper()); wrapper.registerCallback(mTestCbs); // Return null when getting the queue doReturn(null).when(mMockController).getQueue(); // Grab the callbacks the wrapper registered with the controller verify(mMockController).registerCallback(mControllerCbs.capture(), any()); MediaController.Callback controllerCallbacks = mControllerCbs.getValue(); // Update Metadata returned by controller mTestState.setState(PlaybackState.STATE_PLAYING, 1000, 1.0f); doReturn(mTestState.build()).when(mMockController).getPlaybackState(); // Call the callback controllerCallbacks.onPlaybackStateChanged(null); // Assert that the metadata returned by getPlaybackState() is used instead of null verify(mTestCbs, times(1)).mediaUpdatedCallback(mMediaUpdateData.capture()); MediaData data = mMediaUpdateData.getValue(); Assert.assertEquals( "Returned PlaybackState is incorrect", data.state.toString(), mTestState.build().toString()); } @Test public void testNullQueue() { // Create the wrapper object and register the looper with the timeout handler Loading Loading
android/app/src/com/android/bluetooth/audio_util/MediaPlayerWrapper.java +14 −8 Original line number Diff line number Diff line Loading @@ -461,8 +461,11 @@ public class MediaPlayerWrapper { @Override public void onMetadataChanged(@Nullable MediaMetadata mediaMetadata) { if (!isMetadataReady()) { Log.v(TAG, "onMetadataChanged(): " + mPackageName + " tried to update with no queue"); Log.v( TAG, "onMetadataChanged(): " + mPackageName + " tried to update with no metadata"); return; } Loading Loading @@ -495,13 +498,16 @@ public class MediaPlayerWrapper { @Override public void onPlaybackStateChanged(@Nullable PlaybackState state) { if (!isPlaybackStateReady()) { Log.v(TAG, "onPlaybackStateChanged(): " + mPackageName + " tried to update with no queue"); Log.v( TAG, "onPlaybackStateChanged(): " + mPackageName + " tried to update with no state"); return; } mPlaybackStateChangeEventLogger.logv(TAG, "onPlaybackStateChanged(): " + mPackageName + " : " + state.toString()); mPlaybackStateChangeEventLogger.logv( TAG, "onPlaybackStateChanged(): " + mPackageName + " : " + state); if (!playstateEquals(state, getPlaybackState())) { e("The callback playback state doesn't match the current state"); Loading @@ -513,8 +519,8 @@ public class MediaPlayerWrapper { return; } // If there is no playstate, ignore the update. if (state.getState() == PlaybackState.STATE_NONE) { // If state isn't null and there is no playstate, ignore the update. if (state != null && state.getState() == PlaybackState.STATE_NONE) { Log.v(TAG, "Waiting to send update as controller has no playback state"); return; } Loading
android/app/tests/unit/src/com/android/bluetooth/audio_util/MediaPlayerWrapperTest.java +32 −1 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.*; import android.content.Context; import android.content.pm.PackageManager; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; Loading Loading @@ -377,6 +376,38 @@ public class MediaPlayerWrapperTest { Util.toMetadata(mMockContext, mTestMetadata.build())); } @Test public void testNullPlayback() { // Create the wrapper object and register the looper with the timeout handler TestLooperManager looperManager = new TestLooperManager(mThread.getLooper()); MediaPlayerWrapper wrapper = MediaPlayerWrapperFactory.wrap(mMockContext, mMockController, mThread.getLooper()); wrapper.registerCallback(mTestCbs); // Return null when getting the queue doReturn(null).when(mMockController).getQueue(); // Grab the callbacks the wrapper registered with the controller verify(mMockController).registerCallback(mControllerCbs.capture(), any()); MediaController.Callback controllerCallbacks = mControllerCbs.getValue(); // Update Metadata returned by controller mTestState.setState(PlaybackState.STATE_PLAYING, 1000, 1.0f); doReturn(mTestState.build()).when(mMockController).getPlaybackState(); // Call the callback controllerCallbacks.onPlaybackStateChanged(null); // Assert that the metadata returned by getPlaybackState() is used instead of null verify(mTestCbs, times(1)).mediaUpdatedCallback(mMediaUpdateData.capture()); MediaData data = mMediaUpdateData.getValue(); Assert.assertEquals( "Returned PlaybackState is incorrect", data.state.toString(), mTestState.build().toString()); } @Test public void testNullQueue() { // Create the wrapper object and register the looper with the timeout handler Loading