Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 65402ae1 authored by Alex Shabalin's avatar Alex Shabalin
Browse files

Don't add input devices to the list of selected devices.

The Output Switcher has logic that determines the UI behavior based on
the count of selected devices. For example, a group playback UI is
rendered when there are more than one **output** media devices selected.
Adding **input** devices to the list breaks this logic.

Bug: 422288043
Test: atest MediaSwitchingControllerTest
Flag: com.android.media.flags.enable_audio_input_device_routing_and_volume_control
Change-Id: Id5eeb8b26827bb8de41e61e54ae1b7f3143c64b4
parent 156b0ed8
Loading
Loading
Loading
Loading
+1 −17
Original line number Diff line number Diff line
@@ -650,11 +650,6 @@ public class MediaSwitchingController
    @Nullable
    MediaItem getConnectNewDeviceItem() {
        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
        return (!isCurrentConnectedDeviceRemote() && isSelectedDeviceNotAGroup)
@@ -779,20 +774,9 @@ public class MediaSwitchingController
    }

    public List<MediaDevice> getSelectedMediaDevice() {
        if (!enableInputRouting()) {
        return mLocalMediaManager.getSelectedMediaDevice();
    }

        // Add selected input device if input routing is supported.
        List<MediaDevice> selectedDevices =
                new ArrayList<>(mLocalMediaManager.getSelectedMediaDevice());
        MediaDevice selectedInputDevice = mInputRouteManager.getSelectedInputDevice();
        if (selectedInputDevice != null) {
            selectedDevices.add(selectedInputDevice);
        }
        return selectedDevices;
    }

    List<MediaDevice> getDeselectableMediaDevice() {
        return mLocalMediaManager.getDeselectableMediaDevice();
    }
+1 −36
Original line number Diff line number Diff line
@@ -1388,7 +1388,6 @@ public class MediaSwitchingControllerTest extends SysuiTestCase {
        verify(mCallback).dismissDialog();
    }

    @EnableFlags(Flags.FLAG_ENABLE_AUDIO_INPUT_DEVICE_ROUTING_AND_VOLUME_CONTROL)
    @Test
    public void getSelectedMediaDevice() {
        // Mock MediaDevice since none of the output media device constructor is publicly available
@@ -1398,13 +1397,9 @@ public class MediaSwitchingControllerTest extends SysuiTestCase {
                .when(mLocalMediaManager)
                .getSelectedMediaDevice();

        // Mock selected input media device.
        final MediaDevice selectedInputMediaDevice = mock(MediaDevice.class);
        doReturn(selectedInputMediaDevice).when(mInputRouteManager).getSelectedInputDevice();

        List<MediaDevice> selectedMediaDevices = mMediaSwitchingController.getSelectedMediaDevice();
        assertThat(selectedMediaDevices)
                .containsExactly(selectedOutputMediaDevice, selectedInputMediaDevice);
                .containsExactly(selectedOutputMediaDevice);
    }

    @EnableFlags(Flags.FLAG_ENABLE_AUDIO_INPUT_DEVICE_ROUTING_AND_VOLUME_CONTROL)
@@ -1508,36 +1503,6 @@ public class MediaSwitchingControllerTest extends SysuiTestCase {
                mMediaSwitchingController.getMediaItemList())).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(
                mMediaSwitchingController.getMediaItemList())).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(
                mMediaSwitchingController.getMediaItemList())).isEqualTo(1);
    }

    @Test
    public void selectedDevicesAddedInSameOrder() {
        when(mLocalMediaManager.isPreferenceRouteListingExist()).thenReturn(true);