Loading packages/SystemUI/src/com/android/systemui/media/dialog/MediaSwitchingController.java +8 −1 Original line number Diff line number Diff line Loading @@ -813,8 +813,15 @@ public class MediaSwitchingController } private void attachConnectNewDeviceItemIfNeeded(List<MediaItem> mediaItems) { boolean isSelectedDeviceNotAGroup = getSelectedMediaDevice().size() == 1; if (enableInputRouting()) { // When input routing is enabled, there are expected to be at least 2 total selected // devices: one output device and one input device. isSelectedDeviceNotAGroup = getSelectedMediaDevice().size() <= 2; } // Attach "Connect a device" item only when current output is not remote and not a group if (!isCurrentConnectedDeviceRemote() && getSelectedMediaDevice().size() == 1) { if (!isCurrentConnectedDeviceRemote() && isSelectedDeviceNotAGroup) { mediaItems.add(MediaItem.createPairNewDeviceMediaItem()); } } Loading packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaSwitchingControllerTest.java +62 −0 Original line number Diff line number Diff line Loading @@ -1467,4 +1467,66 @@ public class MediaSwitchingControllerTest extends SysuiTestCase { verify(mInputRouteManager, never()).selectDevice(outputMediaDevice); verify(mLocalMediaManager, atLeastOnce()).connectDevice(outputMediaDevice); } @DisableFlags(Flags.FLAG_ENABLE_AUDIO_INPUT_DEVICE_ROUTING_AND_VOLUME_CONTROL) @Test public void connectDeviceButton_presentAtAllTimesForNonGroupOutputs() { mMediaSwitchingController.start(mCb); reset(mCb); // Mock the selected output device. doReturn(Collections.singletonList(mMediaDevice1)) .when(mLocalMediaManager) .getSelectedMediaDevice(); // Verify that there is initially one "Connect a device" button present. assertThat(getNumberOfConnectDeviceButtons()).isEqualTo(1); // Change the selected device, and verify that there is still one "Connect a device" button // present. doReturn(Collections.singletonList(mMediaDevice2)) .when(mLocalMediaManager) .getSelectedMediaDevice(); mMediaSwitchingController.onDeviceListUpdate(mMediaDevices); assertThat(getNumberOfConnectDeviceButtons()).isEqualTo(1); } @EnableFlags(Flags.FLAG_ENABLE_AUDIO_INPUT_DEVICE_ROUTING_AND_VOLUME_CONTROL) @Test public void connectDeviceButton_presentAtAllTimesForNonGroupOutputs_inputRoutingEnabled() { mMediaSwitchingController.start(mCb); reset(mCb); // Mock the selected output device. doReturn(Collections.singletonList(mMediaDevice1)) .when(mLocalMediaManager) .getSelectedMediaDevice(); // Mock the selected input media device. final MediaDevice selectedInputMediaDevice = mock(MediaDevice.class); doReturn(selectedInputMediaDevice).when(mInputRouteManager).getSelectedInputDevice(); // Verify that there is initially one "Connect a device" button present. assertThat(getNumberOfConnectDeviceButtons()).isEqualTo(1); // Change the selected device, and verify that there is still one "Connect a device" button // present. doReturn(Collections.singletonList(mMediaDevice2)) .when(mLocalMediaManager) .getSelectedMediaDevice(); mMediaSwitchingController.onDeviceListUpdate(mMediaDevices); assertThat(getNumberOfConnectDeviceButtons()).isEqualTo(1); } private int getNumberOfConnectDeviceButtons() { int numberOfConnectDeviceButtons = 0; for (MediaItem item : mMediaSwitchingController.getMediaItemList()) { if (item.getMediaItemType() == MediaItem.MediaItemType.TYPE_PAIR_NEW_DEVICE) { numberOfConnectDeviceButtons++; } } return numberOfConnectDeviceButtons; } } Loading
packages/SystemUI/src/com/android/systemui/media/dialog/MediaSwitchingController.java +8 −1 Original line number Diff line number Diff line Loading @@ -813,8 +813,15 @@ public class MediaSwitchingController } private void attachConnectNewDeviceItemIfNeeded(List<MediaItem> mediaItems) { boolean isSelectedDeviceNotAGroup = getSelectedMediaDevice().size() == 1; if (enableInputRouting()) { // When input routing is enabled, there are expected to be at least 2 total selected // devices: one output device and one input device. isSelectedDeviceNotAGroup = getSelectedMediaDevice().size() <= 2; } // Attach "Connect a device" item only when current output is not remote and not a group if (!isCurrentConnectedDeviceRemote() && getSelectedMediaDevice().size() == 1) { if (!isCurrentConnectedDeviceRemote() && isSelectedDeviceNotAGroup) { mediaItems.add(MediaItem.createPairNewDeviceMediaItem()); } } Loading
packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaSwitchingControllerTest.java +62 −0 Original line number Diff line number Diff line Loading @@ -1467,4 +1467,66 @@ public class MediaSwitchingControllerTest extends SysuiTestCase { verify(mInputRouteManager, never()).selectDevice(outputMediaDevice); verify(mLocalMediaManager, atLeastOnce()).connectDevice(outputMediaDevice); } @DisableFlags(Flags.FLAG_ENABLE_AUDIO_INPUT_DEVICE_ROUTING_AND_VOLUME_CONTROL) @Test public void connectDeviceButton_presentAtAllTimesForNonGroupOutputs() { mMediaSwitchingController.start(mCb); reset(mCb); // Mock the selected output device. doReturn(Collections.singletonList(mMediaDevice1)) .when(mLocalMediaManager) .getSelectedMediaDevice(); // Verify that there is initially one "Connect a device" button present. assertThat(getNumberOfConnectDeviceButtons()).isEqualTo(1); // Change the selected device, and verify that there is still one "Connect a device" button // present. doReturn(Collections.singletonList(mMediaDevice2)) .when(mLocalMediaManager) .getSelectedMediaDevice(); mMediaSwitchingController.onDeviceListUpdate(mMediaDevices); assertThat(getNumberOfConnectDeviceButtons()).isEqualTo(1); } @EnableFlags(Flags.FLAG_ENABLE_AUDIO_INPUT_DEVICE_ROUTING_AND_VOLUME_CONTROL) @Test public void connectDeviceButton_presentAtAllTimesForNonGroupOutputs_inputRoutingEnabled() { mMediaSwitchingController.start(mCb); reset(mCb); // Mock the selected output device. doReturn(Collections.singletonList(mMediaDevice1)) .when(mLocalMediaManager) .getSelectedMediaDevice(); // Mock the selected input media device. final MediaDevice selectedInputMediaDevice = mock(MediaDevice.class); doReturn(selectedInputMediaDevice).when(mInputRouteManager).getSelectedInputDevice(); // Verify that there is initially one "Connect a device" button present. assertThat(getNumberOfConnectDeviceButtons()).isEqualTo(1); // Change the selected device, and verify that there is still one "Connect a device" button // present. doReturn(Collections.singletonList(mMediaDevice2)) .when(mLocalMediaManager) .getSelectedMediaDevice(); mMediaSwitchingController.onDeviceListUpdate(mMediaDevices); assertThat(getNumberOfConnectDeviceButtons()).isEqualTo(1); } private int getNumberOfConnectDeviceButtons() { int numberOfConnectDeviceButtons = 0; for (MediaItem item : mMediaSwitchingController.getMediaItemList()) { if (item.getMediaItemType() == MediaItem.MediaItemType.TYPE_PAIR_NEW_DEVICE) { numberOfConnectDeviceButtons++; } } return numberOfConnectDeviceButtons; } }