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

Commit 4890fa4d authored by Santiago Seifert's avatar Santiago Seifert
Browse files

Fix Output Switcher "multiple selected routes"

Issue is caused by PhoneMediaDevice choosing its id according
to the type of the route. As a result, having a USB_DEVICE and
an HDMI device connected simultaneously causes a buggy UI.

See linked bug for details.

Flag: ACONFIG com.android.media.flags.enable_audio_policies_device_and_bluetooth_controller TEAMFOOD
Bug: b/319103067
Test: Manually and with atest SettingsLibRoboTests
Change-Id: Icf928948d8fe80773cc36502b6c8aa0a43f35206
parent 315afc8f
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -229,6 +229,17 @@ public class PhoneMediaDevice extends MediaDevice {
    @SuppressWarnings("NewApi")
    @Override
    public String getId() {
        if (com.android.media.flags.Flags.enableAudioPoliciesDeviceAndBluetoothController()) {
            // Note: be careful when removing this flag. Instead of just removing it, you might want
            // to replace it with SDK_INT >= 35. Explanation: The presence of SDK checks in settings
            // lib suggests that a mainline component may depend on this code. Which means removing
            // this "if" (and using always the route info id) could mean a regression on mainline
            // code running on a device that's running API 34 or older. Unfortunately, we cannot
            // check the API level at the moment of writing this code because the API level has not
            // been bumped, yet.
            return mRouteInfo.getId();
        }

        String id;
        switch (mRouteInfo.getType()) {
            case TYPE_WIRED_HEADSET:
+18 −1
Original line number Diff line number Diff line
@@ -31,10 +31,15 @@ import static org.mockito.Mockito.when;

import android.content.Context;
import android.media.MediaRoute2Info;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;

import com.android.media.flags.Flags;
import com.android.settingslib.R;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -45,6 +50,8 @@ import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class PhoneMediaDeviceTest {

    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    @Mock
    private MediaRoute2Info mInfo;

@@ -110,8 +117,18 @@ public class PhoneMediaDeviceTest {
                .isEqualTo(mContext.getString(R.string.media_transfer_this_device_name));
    }

    @EnableFlags(Flags.FLAG_ENABLE_AUDIO_POLICIES_DEVICE_AND_BLUETOOTH_CONTROLLER)
    @Test
    public void getId_whenAdvancedWiredRoutingEnabled_returnCorrectId() {
        String fakeId = "foo";
        when(mInfo.getId()).thenReturn(fakeId);

        assertThat(mPhoneMediaDevice.getId()).isEqualTo(fakeId);
    }

    @DisableFlags(Flags.FLAG_ENABLE_AUDIO_POLICIES_DEVICE_AND_BLUETOOTH_CONTROLLER)
    @Test
    public void getId_returnCorrectId() {
    public void getId_whenAdvancedWiredRoutingDisabled_returnCorrectId() {
        when(mInfo.getType()).thenReturn(TYPE_WIRED_HEADPHONES);

        assertThat(mPhoneMediaDevice.getId())