From 6fb4059944727a552b6fbc4cc08c63f7820be59a Mon Sep 17 00:00:00 2001 From: Tim Peng Date: Tue, 7 Apr 2020 11:54:26 +0800 Subject: [PATCH] Transferring to a cast device should not close the output switcher -Close panel only when on pause and stop -Transfer device would set the play state to "STATE_NONE" -Add test case Bug: 152632226 Test: make -j42 RunSettingsRoboTests Change-Id: Ibf6ce1454b1d5bf3facc07abec15b8735029f2cf --- .../android/settings/panel/MediaOutputPanel.java | 4 +++- .../settings/panel/MediaOutputPanelTest.java | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/panel/MediaOutputPanel.java b/src/com/android/settings/panel/MediaOutputPanel.java index f528cea4f5a..56ed6fbe8ce 100644 --- a/src/com/android/settings/panel/MediaOutputPanel.java +++ b/src/com/android/settings/panel/MediaOutputPanel.java @@ -259,7 +259,9 @@ public class MediaOutputPanel implements PanelContent, LocalMediaManager.DeviceC @Override public void onPlaybackStateChanged(PlaybackState state) { - if (mCallback != null && state.getState() != PlaybackState.STATE_PLAYING) { + final int playState = state.getState(); + if (mCallback != null && (playState == PlaybackState.STATE_STOPPED + || playState == PlaybackState.STATE_PAUSED)) { mCallback.forceClose(); } } diff --git a/tests/robotests/src/com/android/settings/panel/MediaOutputPanelTest.java b/tests/robotests/src/com/android/settings/panel/MediaOutputPanelTest.java index 0f30c200bf1..e0b926b8a68 100644 --- a/tests/robotests/src/com/android/settings/panel/MediaOutputPanelTest.java +++ b/tests/robotests/src/com/android/settings/panel/MediaOutputPanelTest.java @@ -295,4 +295,19 @@ public class MediaOutputPanelTest { verify(mCallback).forceClose(); } + + @Test + public void onPlaybackStateChanged_stateFromPlayingToPaused_verifyCallForceClose() { + mPanel.onStart(); + verify(mMediaController).registerCallback(mControllerCbs.capture()); + final MediaController.Callback controllerCallbacks = mControllerCbs.getValue(); + when(mPlaybackState.getState()).thenReturn(PlaybackState.STATE_PLAYING); + controllerCallbacks.onPlaybackStateChanged(mPlaybackState); + verify(mCallback, never()).forceClose(); + + when(mPlaybackState.getState()).thenReturn(PlaybackState.STATE_PAUSED); + controllerCallbacks.onPlaybackStateChanged(mPlaybackState); + + verify(mCallback).forceClose(); + } }