[Sound Panel] Fix bugs for sound panel slice

1. notify item change when slice live data has update
2. keep showing Output Switcher slice when media state is in "Pause"
   state

Bug: 247043239
Bug: 238715094
Bug: 204165377
Test: verified on device
Change-Id: Ic56a70f2f2835231519e2fccf0d2e649d41b106e
This commit is contained in:
shaoweishen
2022-08-18 03:52:05 +00:00
committed by Shaowei Shen
parent 062b18c736
commit 66098febbc
4 changed files with 71 additions and 15 deletions

View File

@@ -66,7 +66,18 @@ public class MediaOutputUtilsTest {
@Test
public void getActiveLocalMediaController_localMediaPlaying_returnController() {
initPlayback();
initPlayback(PlaybackState.STATE_PLAYING);
when(mMediaController.getPlaybackInfo()).thenReturn(mPlaybackInfo);
when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState);
assertThat(MediaOutputUtils.getActiveLocalMediaController(mMediaSessionManager)).isEqualTo(
mMediaController);
}
@Test
public void getActiveLocalMediaController_localMediaPause_returnController() {
initPlayback(PlaybackState.STATE_PAUSED);
when(mMediaController.getPlaybackInfo()).thenReturn(mPlaybackInfo);
when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState);
@@ -113,6 +124,44 @@ public class MediaOutputUtilsTest {
assertThat(MediaOutputUtils.getActiveLocalMediaController(mMediaSessionManager)).isNull();
}
@Test
public void getActiveLocalMediaController_localMediaNone_returnNull() {
mPlaybackInfo = new MediaController.PlaybackInfo(
MediaController.PlaybackInfo.PLAYBACK_TYPE_LOCAL,
VolumeProvider.VOLUME_CONTROL_ABSOLUTE,
100,
10,
new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).build(),
null);
mPlaybackState = new PlaybackState.Builder()
.setState(PlaybackState.STATE_NONE, 0, 1)
.build();
when(mMediaController.getPlaybackInfo()).thenReturn(mPlaybackInfo);
when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState);
assertThat(MediaOutputUtils.getActiveLocalMediaController(mMediaSessionManager)).isNull();
}
@Test
public void getActiveLocalMediaController_localMediaError_returnNull() {
mPlaybackInfo = new MediaController.PlaybackInfo(
MediaController.PlaybackInfo.PLAYBACK_TYPE_LOCAL,
VolumeProvider.VOLUME_CONTROL_ABSOLUTE,
100,
10,
new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).build(),
null);
mPlaybackState = new PlaybackState.Builder()
.setState(PlaybackState.STATE_ERROR, 0, 1)
.build();
when(mMediaController.getPlaybackInfo()).thenReturn(mPlaybackInfo);
when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState);
assertThat(MediaOutputUtils.getActiveLocalMediaController(mMediaSessionManager)).isNull();
}
@Test
public void getActiveLocalMediaController_bothHaveRemoteMediaAndLocalMedia_returnNull() {
mMediaControllers.clear();
@@ -130,7 +179,7 @@ public class MediaOutputUtilsTest {
mMediaControllers.add(remoteMediaController);
mMediaControllers.add(mMediaController);
initPlayback();
initPlayback(PlaybackState.STATE_PLAYING);
when(mMediaController.getPlaybackInfo()).thenReturn(mPlaybackInfo);
when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState);
@@ -155,7 +204,7 @@ public class MediaOutputUtilsTest {
final MediaController remoteMediaController = mock(MediaController.class);
mMediaControllers.add(remoteMediaController);
initPlayback();
initPlayback(PlaybackState.STATE_PLAYING);
when(mMediaController.getPlaybackInfo()).thenReturn(mPlaybackInfo);
when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState);
@@ -165,7 +214,7 @@ public class MediaOutputUtilsTest {
assertThat(MediaOutputUtils.getActiveLocalMediaController(mMediaSessionManager)).isNull();
}
private void initPlayback() {
private void initPlayback(int playbackState) {
mPlaybackInfo = new MediaController.PlaybackInfo(
MediaController.PlaybackInfo.PLAYBACK_TYPE_LOCAL,
VolumeProvider.VOLUME_CONTROL_ABSOLUTE,
@@ -174,7 +223,7 @@ public class MediaOutputUtilsTest {
new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).build(),
null);
mPlaybackState = new PlaybackState.Builder()
.setState(PlaybackState.STATE_PLAYING, 0, 1)
.setState(playbackState, 0, 1)
.build();
}
}