Loading src/com/android/settings/media/MediaOutputUtils.java +3 −1 Original line number Diff line number Diff line Loading @@ -64,7 +64,9 @@ public class MediaOutputUtils { + ", play back type : " + pi.getPlaybackType() + ", play back state : " + playbackState.getState()); } if (playbackState.getState() != PlaybackState.STATE_PLAYING) { if (playbackState.getState() == PlaybackState.STATE_STOPPED || playbackState.getState() == PlaybackState.STATE_NONE || playbackState.getState() == PlaybackState.STATE_ERROR) { // do nothing continue; } Loading src/com/android/settings/panel/PanelFragment.java +7 −1 Original line number Diff line number Diff line Loading @@ -60,6 +60,7 @@ import com.android.settingslib.utils.ThreadUtils; import com.google.android.setupdesign.DividerItemDecoration; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; Loading Loading @@ -339,8 +340,13 @@ public class PanelFragment extends Fragment { mSliceLiveData.put(uri, sliceLiveData); sliceLiveData.observe(getViewLifecycleOwner(), slice -> { // If the Slice has already loaded, do nothing. // If the Slice has already loaded, refresh list with slice data. if (mPanelSlicesLoaderCountdownLatch.isSliceLoaded(uri)) { if (mAdapter != null) { int itemIndex = (new ArrayList<>(mSliceLiveData.keySet())).indexOf(uri); mAdapter.notifyItemChanged(itemIndex); } return; } Loading src/com/android/settings/panel/PanelSlicesAdapter.java +7 −8 Original line number Diff line number Diff line Loading @@ -84,7 +84,7 @@ public class PanelSlicesAdapter @Override public void onBindViewHolder(@NonNull SliceRowViewHolder sliceRowViewHolder, int position) { sliceRowViewHolder.onBind(mSliceLiveData.get(position), position); sliceRowViewHolder.onBind(mSliceLiveData.get(position).getValue()); } /** Loading Loading @@ -132,15 +132,14 @@ public class PanelSlicesAdapter /** * Called when the view is displayed. */ public void onBind(LiveData<Slice> sliceLiveData, int position) { sliceLiveData.observe(mPanelFragment.getViewLifecycleOwner(), sliceView); // Do not show the divider above media devices switcher slice per request final Slice slice = sliceLiveData.getValue(); public void onBind(Slice slice) { // Hides slice which reports with error hint or not contain any slice sub-item. if (slice == null || !isValidSlice(slice)) { sliceView.setVisibility(View.GONE); return; } else { sliceView.setSlice(slice); sliceView.setVisibility(View.VISIBLE); } // Add divider for the end icon Loading @@ -154,7 +153,7 @@ public class PanelSlicesAdapter .action(0 /* attribution */, SettingsEnums.ACTION_PANEL_INTERACTION, mMetricsCategory, sliceLiveData.getValue().getUri().getLastPathSegment() slice.getUri().getLastPathSegment() /* log key */, eventInfo.actionType /* value */); }) Loading tests/robotests/src/com/android/settings/media/MediaOutputUtilsTest.java +54 −5 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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(); Loading @@ -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); Loading @@ -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); Loading @@ -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, Loading @@ -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(); } } Loading
src/com/android/settings/media/MediaOutputUtils.java +3 −1 Original line number Diff line number Diff line Loading @@ -64,7 +64,9 @@ public class MediaOutputUtils { + ", play back type : " + pi.getPlaybackType() + ", play back state : " + playbackState.getState()); } if (playbackState.getState() != PlaybackState.STATE_PLAYING) { if (playbackState.getState() == PlaybackState.STATE_STOPPED || playbackState.getState() == PlaybackState.STATE_NONE || playbackState.getState() == PlaybackState.STATE_ERROR) { // do nothing continue; } Loading
src/com/android/settings/panel/PanelFragment.java +7 −1 Original line number Diff line number Diff line Loading @@ -60,6 +60,7 @@ import com.android.settingslib.utils.ThreadUtils; import com.google.android.setupdesign.DividerItemDecoration; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; Loading Loading @@ -339,8 +340,13 @@ public class PanelFragment extends Fragment { mSliceLiveData.put(uri, sliceLiveData); sliceLiveData.observe(getViewLifecycleOwner(), slice -> { // If the Slice has already loaded, do nothing. // If the Slice has already loaded, refresh list with slice data. if (mPanelSlicesLoaderCountdownLatch.isSliceLoaded(uri)) { if (mAdapter != null) { int itemIndex = (new ArrayList<>(mSliceLiveData.keySet())).indexOf(uri); mAdapter.notifyItemChanged(itemIndex); } return; } Loading
src/com/android/settings/panel/PanelSlicesAdapter.java +7 −8 Original line number Diff line number Diff line Loading @@ -84,7 +84,7 @@ public class PanelSlicesAdapter @Override public void onBindViewHolder(@NonNull SliceRowViewHolder sliceRowViewHolder, int position) { sliceRowViewHolder.onBind(mSliceLiveData.get(position), position); sliceRowViewHolder.onBind(mSliceLiveData.get(position).getValue()); } /** Loading Loading @@ -132,15 +132,14 @@ public class PanelSlicesAdapter /** * Called when the view is displayed. */ public void onBind(LiveData<Slice> sliceLiveData, int position) { sliceLiveData.observe(mPanelFragment.getViewLifecycleOwner(), sliceView); // Do not show the divider above media devices switcher slice per request final Slice slice = sliceLiveData.getValue(); public void onBind(Slice slice) { // Hides slice which reports with error hint or not contain any slice sub-item. if (slice == null || !isValidSlice(slice)) { sliceView.setVisibility(View.GONE); return; } else { sliceView.setSlice(slice); sliceView.setVisibility(View.VISIBLE); } // Add divider for the end icon Loading @@ -154,7 +153,7 @@ public class PanelSlicesAdapter .action(0 /* attribution */, SettingsEnums.ACTION_PANEL_INTERACTION, mMetricsCategory, sliceLiveData.getValue().getUri().getLastPathSegment() slice.getUri().getLastPathSegment() /* log key */, eventInfo.actionType /* value */); }) Loading
tests/robotests/src/com/android/settings/media/MediaOutputUtilsTest.java +54 −5 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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(); Loading @@ -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); Loading @@ -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); Loading @@ -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, Loading @@ -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(); } }