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

Commit db832e69 authored by Santiago Seifert's avatar Santiago Seifert Committed by Android (Google) Code Review
Browse files

Merge changes Icf928948,I05a1f851 into main

* changes:
  Fix Output Switcher "multiple selected routes"
  Prepare MOControllerTest for change in PhoneMediaDevice id assignment
parents 83b4fe61 4890fa4d
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())
+24 −0
Original line number Diff line number Diff line
@@ -414,6 +414,18 @@ public class MediaOutputControllerTest extends SysuiTestCase {

    @Test
    public void onDeviceListUpdate_verifyDeviceListCallback() {
        // This test relies on mMediaOutputController.start being called while the selected device
        // list has exactly one item, and that item's id is:
        // - Different from both ids in mMediaDevices.
        // - Different from the id of the route published by the device under test (usually the
        //   built-in speakers).
        // So mock the selected device to respect these two preconditions.
        MediaDevice mockSelectedMediaDevice = Mockito.mock(MediaDevice.class);
        when(mockSelectedMediaDevice.getId()).thenReturn(TEST_DEVICE_3_ID);
        doReturn(List.of(mockSelectedMediaDevice))
                .when(mLocalMediaManager)
                .getSelectedMediaDevice();

        mMediaOutputController.start(mCb);
        reset(mCb);

@@ -434,6 +446,18 @@ public class MediaOutputControllerTest extends SysuiTestCase {

    @Test
    public void advanced_onDeviceListUpdateWithConnectedDeviceRemote_verifyItemSize() {
        // This test relies on mMediaOutputController.start being called while the selected device
        // list has exactly one item, and that item's id is:
        // - Different from both ids in mMediaDevices.
        // - Different from the id of the route published by the device under test (usually the
        //   built-in speakers).
        // So mock the selected device to respect these two preconditions.
        MediaDevice mockSelectedMediaDevice = Mockito.mock(MediaDevice.class);
        when(mockSelectedMediaDevice.getId()).thenReturn(TEST_DEVICE_3_ID);
        doReturn(List.of(mockSelectedMediaDevice))
                .when(mLocalMediaManager)
                .getSelectedMediaDevice();

        when(mMediaDevice1.getFeatures()).thenReturn(
                ImmutableList.of(MediaRoute2Info.FEATURE_REMOTE_PLAYBACK));
        when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(mMediaDevice1);