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

Commit 85c2696b authored by Wenyu Zhang's avatar Wenyu Zhang Committed by Android (Google) Code Review
Browse files

Merge "audio: Update output device name for desktop" into main

parents f1005fca 77e62529
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -1409,6 +1409,8 @@
    <string name="media_transfer_this_device_name">This phone</string>
    <!-- Name of the tablet device. [CHAR LIMIT=30] -->
    <string name="media_transfer_this_device_name_tablet">This tablet</string>
    <!-- Name of the internal speaker. [CHAR LIMIT=30] -->
    <string name="media_transfer_this_device_name_desktop">This computer (internal)</string>
    <!-- Name of the default media output of the TV. [CHAR LIMIT=30] -->
    <string name="media_transfer_this_device_name_tv">@string/tv_media_transfer_default</string>
    <!-- Name of the internal mic. [CHAR LIMIT=30] -->
@@ -1639,6 +1641,12 @@
    <!-- Name of the 3.5mm and usb audio device. [CHAR LIMIT=50] -->
    <string name="media_transfer_wired_usb_device_name">Wired headphone</string>

    <!-- Name of the 3.5mm headphone, used in desktop devices. [CHAR LIMIT=50] -->
    <string name="media_transfer_headphone_name">Headphone</string>

    <!-- Name of the usb audio device speaker, used in desktop devices. [CHAR LIMIT=50] -->
    <string name="media_transfer_usb_speaker_name">USB speaker</string>

    <!-- Name of the 3.5mm audio device mic. [CHAR LIMIT=50] -->
    <string name="media_transfer_wired_device_mic_name">Mic jack</string>

+21 −1
Original line number Diff line number Diff line
@@ -72,6 +72,8 @@ public class PhoneMediaDevice extends MediaDevice {
            return context.getString(R.string.media_transfer_this_device_name_tv);
        } else if (isTablet()) {
            return context.getString(R.string.media_transfer_this_device_name_tablet);
        } else if (inputRoutingEnabledAndIsDesktop()) {
            return context.getString(R.string.media_transfer_this_device_name_desktop);
        } else {
            return context.getString(R.string.media_transfer_this_device_name);
        }
@@ -85,10 +87,18 @@ public class PhoneMediaDevice extends MediaDevice {
        switch (routeInfo.getType()) {
            case TYPE_WIRED_HEADSET:
            case TYPE_WIRED_HEADPHONES:
                name =
                        inputRoutingEnabledAndIsDesktop()
                                ? context.getString(R.string.media_transfer_headphone_name)
                                : context.getString(R.string.media_transfer_wired_usb_device_name);
                break;
            case TYPE_USB_DEVICE:
            case TYPE_USB_HEADSET:
            case TYPE_USB_ACCESSORY:
                name = context.getString(R.string.media_transfer_wired_usb_device_name);
                name =
                        inputRoutingEnabledAndIsDesktop()
                                ? context.getString(R.string.media_transfer_usb_speaker_name)
                                : context.getString(R.string.media_transfer_wired_usb_device_name);
                break;
            case TYPE_DOCK:
                name = context.getString(R.string.media_transfer_dock_speaker_device_name);
@@ -139,6 +149,16 @@ public class PhoneMediaDevice extends MediaDevice {
                .contains("tablet");
    }

    static boolean isDesktop() {
        return Arrays.asList(SystemProperties.get("ro.build.characteristics").split(","))
                .contains("desktop");
    }

    static boolean inputRoutingEnabledAndIsDesktop() {
        return com.android.media.flags.Flags.enableAudioInputDeviceRoutingAndVolumeControl()
                && isDesktop();
    }

    // MediaRoute2Info.getType was made public on API 34, but exists since API 30.
    @SuppressWarnings("NewApi")
    @Override
+26 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowSystemProperties;

@RunWith(RobolectricTestRunner.class)
public class PhoneMediaDeviceTest {
@@ -114,6 +115,31 @@ public class PhoneMediaDeviceTest {

        when(mInfo.getType()).thenReturn(TYPE_BUILTIN_SPEAKER);

        assertThat(mPhoneMediaDevice.getName()).isEqualTo(getMediaTransferThisDeviceName(mContext));
    }

    @EnableFlags(Flags.FLAG_ENABLE_AUDIO_INPUT_DEVICE_ROUTING_AND_VOLUME_CONTROL)
    @Test
    public void getName_returnCorrectName_desktop() {
        ShadowSystemProperties.override("ro.build.characteristics", "desktop");

        when(mInfo.getType()).thenReturn(TYPE_WIRED_HEADPHONES);

        assertThat(mPhoneMediaDevice.getName())
                .isEqualTo(mContext.getString(R.string.media_transfer_headphone_name));

        when(mInfo.getType()).thenReturn(TYPE_WIRED_HEADSET);

        assertThat(mPhoneMediaDevice.getName())
                .isEqualTo(mContext.getString(R.string.media_transfer_headphone_name));

        when(mInfo.getType()).thenReturn(TYPE_USB_DEVICE);

        assertThat(mPhoneMediaDevice.getName())
                .isEqualTo(mContext.getString(R.string.media_transfer_usb_speaker_name));

        when(mInfo.getType()).thenReturn(TYPE_BUILTIN_SPEAKER);

        assertThat(mPhoneMediaDevice.getName())
                .isEqualTo(getMediaTransferThisDeviceName(mContext));
    }