Loading src/com/android/settings/media/MediaOutputUtils.java +9 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,9 @@ import androidx.annotation.Nullable; import com.android.settings.sound.MediaOutputPreferenceController; import java.util.ArrayList; import java.util.List; /** * Utilities that can be shared between {@link MediaOutputIndicatorWorker} and * {@link MediaOutputPreferenceController}. Loading @@ -43,6 +46,7 @@ public class MediaOutputUtils { MediaSessionManager mediaSessionManager) { MediaController localController = null; final List<String> remoteMediaSessionLists = new ArrayList<>(); for (MediaController controller : mediaSessionManager.getActiveSessions(null)) { final MediaController.PlaybackInfo pi = controller.getPlaybackInfo(); if (pi == null) { Loading @@ -69,10 +73,14 @@ public class MediaOutputUtils { controller.getPackageName())) { localController = null; } if (!remoteMediaSessionLists.contains(controller.getPackageName())) { remoteMediaSessionLists.add(controller.getPackageName()); } continue; } if (pi.getPlaybackType() == MediaController.PlaybackInfo.PLAYBACK_TYPE_LOCAL) { if (localController == null) { if (localController == null && !remoteMediaSessionLists.contains(controller.getPackageName())) { localController = controller; } } Loading tests/robotests/src/com/android/settings/media/MediaOutputUtilsTest.java +27 −0 Original line number Diff line number Diff line Loading @@ -115,6 +115,33 @@ public class MediaOutputUtilsTest { @Test public void getActiveLocalMediaController_bothHaveRemoteMediaAndLocalMedia_returnNull() { mMediaControllers.clear(); final MediaController.PlaybackInfo playbackInfo = new MediaController.PlaybackInfo( MediaController.PlaybackInfo.PLAYBACK_TYPE_REMOTE, VolumeProvider.VOLUME_CONTROL_ABSOLUTE, 100, 10, new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).build(), null); final PlaybackState playbackState = new PlaybackState.Builder() .setState(PlaybackState.STATE_PLAYING, 0, 1) .build(); final MediaController remoteMediaController = mock(MediaController.class); mMediaControllers.add(remoteMediaController); mMediaControllers.add(mMediaController); initPlayback(); when(mMediaController.getPlaybackInfo()).thenReturn(mPlaybackInfo); when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState); when(remoteMediaController.getPlaybackInfo()).thenReturn(playbackInfo); when(remoteMediaController.getPlaybackState()).thenReturn(playbackState); assertThat(MediaOutputUtils.getActiveLocalMediaController(mMediaSessionManager)).isNull(); } @Test public void getActiveLocalMediaController_bothHaveLocalMediaAndRemoteMedia_returnNull() { final MediaController.PlaybackInfo playbackInfo = new MediaController.PlaybackInfo( MediaController.PlaybackInfo.PLAYBACK_TYPE_REMOTE, VolumeProvider.VOLUME_CONTROL_ABSOLUTE, Loading Loading
src/com/android/settings/media/MediaOutputUtils.java +9 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,9 @@ import androidx.annotation.Nullable; import com.android.settings.sound.MediaOutputPreferenceController; import java.util.ArrayList; import java.util.List; /** * Utilities that can be shared between {@link MediaOutputIndicatorWorker} and * {@link MediaOutputPreferenceController}. Loading @@ -43,6 +46,7 @@ public class MediaOutputUtils { MediaSessionManager mediaSessionManager) { MediaController localController = null; final List<String> remoteMediaSessionLists = new ArrayList<>(); for (MediaController controller : mediaSessionManager.getActiveSessions(null)) { final MediaController.PlaybackInfo pi = controller.getPlaybackInfo(); if (pi == null) { Loading @@ -69,10 +73,14 @@ public class MediaOutputUtils { controller.getPackageName())) { localController = null; } if (!remoteMediaSessionLists.contains(controller.getPackageName())) { remoteMediaSessionLists.add(controller.getPackageName()); } continue; } if (pi.getPlaybackType() == MediaController.PlaybackInfo.PLAYBACK_TYPE_LOCAL) { if (localController == null) { if (localController == null && !remoteMediaSessionLists.contains(controller.getPackageName())) { localController = controller; } } Loading
tests/robotests/src/com/android/settings/media/MediaOutputUtilsTest.java +27 −0 Original line number Diff line number Diff line Loading @@ -115,6 +115,33 @@ public class MediaOutputUtilsTest { @Test public void getActiveLocalMediaController_bothHaveRemoteMediaAndLocalMedia_returnNull() { mMediaControllers.clear(); final MediaController.PlaybackInfo playbackInfo = new MediaController.PlaybackInfo( MediaController.PlaybackInfo.PLAYBACK_TYPE_REMOTE, VolumeProvider.VOLUME_CONTROL_ABSOLUTE, 100, 10, new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).build(), null); final PlaybackState playbackState = new PlaybackState.Builder() .setState(PlaybackState.STATE_PLAYING, 0, 1) .build(); final MediaController remoteMediaController = mock(MediaController.class); mMediaControllers.add(remoteMediaController); mMediaControllers.add(mMediaController); initPlayback(); when(mMediaController.getPlaybackInfo()).thenReturn(mPlaybackInfo); when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState); when(remoteMediaController.getPlaybackInfo()).thenReturn(playbackInfo); when(remoteMediaController.getPlaybackState()).thenReturn(playbackState); assertThat(MediaOutputUtils.getActiveLocalMediaController(mMediaSessionManager)).isNull(); } @Test public void getActiveLocalMediaController_bothHaveLocalMediaAndRemoteMedia_returnNull() { final MediaController.PlaybackInfo playbackInfo = new MediaController.PlaybackInfo( MediaController.PlaybackInfo.PLAYBACK_TYPE_REMOTE, VolumeProvider.VOLUME_CONTROL_ABSOLUTE, Loading