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

Commit 77e62529 authored by wenyu zhang's avatar wenyu zhang
Browse files

audio: Update output device name for desktop

Currently, both 3.5mm and USB headphone are named "Wired headphone". For desktop devices, this CL renames 3.5mm headphone as "Headphone" and USB headphone as "USB speaker".

For the device built-in speaker, this CL renames "This phone" to "This computer (internal)".

Change-Id: I6294a9968741b734c49c0511800b3be5bac8f575
Bug: b/355684672, b/357122624
Test: atest PhoneMediaDeviceTest
Flag: com.android.media.flags.enable_audio_input_device_routing_and_volume_control
parent ada98fa1
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));
    }