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

Commit 32be1ae7 authored by Jeremy Wu's avatar Jeremy Wu
Browse files

MediaRoute: update mock to contain addr

This CL updates the mock to create the audio device with address, and
ensure that the address is empty string rather null due to that being
the default and to comply with existing non-null annotations.

Bug: 419589719
Test: run presubmit with `if (flag)` -> `if (true || flag)`
Flag: com.android.media.flags.enable_device_address_as_identifier_in_media_router_2
Change-Id: I1b71a7e0104dddc8e82cc53f0dd62dc5d7376fc6
parent eda00f7b
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -413,6 +413,8 @@ import java.util.concurrent.CopyOnWriteArrayList;
     *
     * @param selectedDeviceAttributesType The {@link AudioDeviceInfo#getType() type} that
     *     corresponds to the currently selected route.
     * @param selectedDeviceAttributesAddr The {@link AudioDeviceInfo#getAddress() address} that
     *     corresponds to the currently selected route.
     * @param audioDeviceInfos The available audio outputs as obtained from {@link
     *     AudioManager#getDevices}.
     * @param availableBluetoothRoutes The available bluetooth routes as obtained from {@link
+16 −10
Original line number Diff line number Diff line
@@ -78,10 +78,10 @@ public class AudioManagerRouteControllerTest {

    private static final AudioDeviceInfo FAKE_AUDIO_DEVICE_INFO_BUILTIN_SPEAKER =
            createAudioDeviceInfo(
                    AudioSystem.DEVICE_OUT_SPEAKER, "name_builtin", /* address= */ null);
                    AudioSystem.DEVICE_OUT_SPEAKER, "name_builtin", /* address= */ "");
    private static final AudioDeviceInfo FAKE_AUDIO_DEVICE_INFO_WIRED_HEADSET =
            createAudioDeviceInfo(
                    AudioSystem.DEVICE_OUT_WIRED_HEADSET, "name_wired_hs", /* address= */ null);
                    AudioSystem.DEVICE_OUT_WIRED_HEADSET, "name_wired_hs", /* address= */ "");
    private static final AudioDeviceInfo FAKE_AUDIO_DEVICE_INFO_WIRED_HEADSET_WITH_ADDRESS =
            createAudioDeviceInfo(
                    AudioSystem.DEVICE_OUT_WIRED_HEADSET,
@@ -93,13 +93,13 @@ public class AudioManagerRouteControllerTest {

    private static final AudioDeviceInfo FAKE_AUDIO_DEVICE_BUILTIN_EARPIECE =
            createAudioDeviceInfo(
                    AudioSystem.DEVICE_OUT_EARPIECE, /* name= */ null, /* address= */ null);
                    AudioSystem.DEVICE_OUT_EARPIECE, /* name= */ "", /* address= */ "");

    private static final AudioDeviceInfo FAKE_AUDIO_DEVICE_NO_NAME =
            createAudioDeviceInfo(
                    AudioSystem.DEVICE_OUT_DGTL_DOCK_HEADSET,
                    /* name= */ null,
                    /* address= */ null);
                    /* name= */ "",
                    /* address= */ "");

    private Instrumentation mInstrumentation;
    private AudioDeviceInfo mSelectedAudioDeviceInfo;
@@ -246,7 +246,8 @@ public class AudioManagerRouteControllerTest {
        verify(mMockAudioManager, Mockito.timeout(ASYNC_CALL_TIMEOUTS_MS))
                .setPreferredDeviceForStrategy(
                        mMediaAudioProductStrategy,
                        createAudioDeviceAttribute(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER));
                        createAudioDeviceAttribute(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER,
                                                   /* address= */ ""));

        MediaRoute2Info wiredHeadsetRoute =
                getAvailableRouteWithType(MediaRoute2Info.TYPE_WIRED_HEADSET);
@@ -254,7 +255,8 @@ public class AudioManagerRouteControllerTest {
        verify(mMockAudioManager, Mockito.timeout(ASYNC_CALL_TIMEOUTS_MS))
                .setPreferredDeviceForStrategy(
                        mMediaAudioProductStrategy,
                        createAudioDeviceAttribute(AudioDeviceInfo.TYPE_WIRED_HEADSET));
                        createAudioDeviceAttribute(AudioDeviceInfo.TYPE_WIRED_HEADSET,
                                                   /* address= */ ""));
    }

    @Test
@@ -393,18 +395,22 @@ public class AudioManagerRouteControllerTest {
    }

    private void updateMockAudioManagerState() {
        int selectedDeviceAttributesType = mSelectedAudioDeviceInfo.getType();
        String selectedDeviceAttributesAddr = mSelectedAudioDeviceInfo.getAddress();
        when(mMockAudioManager.getDevicesForAttributes(ATTRIBUTES_MEDIA))
                .thenReturn(
                        List.of(createAudioDeviceAttribute(mSelectedAudioDeviceInfo.getType())));
                        List.of(createAudioDeviceAttribute(selectedDeviceAttributesType,
                                                           selectedDeviceAttributesAddr)));
        when(mMockAudioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS))
                .thenReturn(mAvailableAudioDeviceInfos.toArray(new AudioDeviceInfo[0]));
    }

    private static AudioDeviceAttributes createAudioDeviceAttribute(
            @AudioDeviceInfo.AudioDeviceType int type) {
            @AudioDeviceInfo.AudioDeviceType int type,
            @NonNull String address) {
        // Address is unused.
        return new AudioDeviceAttributes(
                AudioDeviceAttributes.ROLE_OUTPUT, type, /* address= */ "");
                AudioDeviceAttributes.ROLE_OUTPUT, type, address);
    }

    private static AudioDeviceInfo createAudioDeviceInfo(