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

Commit 694aa1b5 authored by Jacqueline Bronger's avatar Jacqueline Bronger
Browse files

TV audio output: avoid two TV Defaults

Previously on set top boxes with internal speakers we would have
duplicate namings and icons. Updating namings for both internal speaker
and HDMI and icon for internal speaker based on TV device type.

Bug: 299590878
Test: manual
Test: atest DeviceIconUtilTest
Flag: EXEMPT bugfix

Change-Id: I1beb7bea8504d39060ad6d1b526e2978649bb604
parent e5d7a587
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
<!--
  ~ Copyright (C) 2022 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24"
    android:viewportHeight="24"
    android:tint="?android:attr/textColorPrimary"
    android:autoMirrored="true">
    <path android:fillColor="#FFFFFFFF"
        android:pathData="M14,20.725V18.675Q16.25,18.025 17.625,16.175Q19,14.325 19,11.975Q19,9.625 17.625,7.775Q16.25,5.925 14,5.275V3.225Q17.1,3.925 19.05,6.362Q21,8.8 21,11.975Q21,15.15 19.05,17.587Q17.1,20.025 14,20.725ZM3,15V9H7L12,4V20L7,15ZM14,16V7.95Q15.175,8.5 15.838,9.6Q16.5,10.7 16.5,12Q16.5,13.275 15.838,14.362Q15.175,15.45 14,16ZM10,8.85 L7.85,11H5V13H7.85L10,15.15ZM7.5,12Z"/>
</vector>
 No newline at end of file
+6 −7
Original line number Diff line number Diff line
@@ -1419,7 +1419,7 @@
    <!-- Name of the internal speaker and mic. [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>
    <string name="media_transfer_this_device_name_tv">This TV</string>
    <!-- Name of the dock device. [CHAR LIMIT=30] -->
    <string name="media_transfer_dock_speaker_device_name">Dock speaker</string>
    <!-- Default name of the external device. [CHAR LIMIT=30] -->
@@ -1462,12 +1462,11 @@
    <!-- Media output switcher. Subtitle for devices connected through HDMI EARC if a device name is available. [CHAR LIMIT=NONE] -->
    <string name="tv_media_transfer_earc_subtitle">Connected via eARC</string>

    <!-- TV media output switcher. Title for the default audio output of the device [CHAR LIMIT=NONE] -->
    <string name="tv_media_transfer_default">TV default</string>
    <!-- TV media output switcher. Subtitle for default audio output which is HDMI, e.g. TV dongle [CHAR LIMIT=NONE] -->
    <string name="tv_media_transfer_hdmi">HDMI output</string>
    <!-- TV media output switcher. Subtitle for default audio output which is internal speaker, i.e. panel VTs [CHAR LIMIT=NONE] -->
    <string name="tv_media_transfer_internal_speakers">Internal speakers</string>
    <!-- TV media output switcher. Subtitle for default audio output which is internal speaker [CHAR LIMIT=NONE] -->
    <string name="tv_media_transfer_internal_speakers">Built-in speaker</string>

    <!-- TV media output switcher. Title for default audio output which is HDMI, e.g. TV dongle [CHAR LIMIT=NONE] -->
    <string name="tv_media_transfer_hdmi_title">TV Audio</string>

    <!-- Warning message to tell user is have problem during profile connect, it need to turn off device and back on. [CHAR_LIMIT=NONE] -->
    <string name="profile_connect_timeout_subtext">Problem connecting. Turn device off &amp; back on</string>
+23 −3
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.media.AudioDeviceInfo;
import android.media.AudioManager;
import android.media.MediaRoute2Info;
import android.os.SystemProperties;
import android.util.SparseIntArray;
@@ -116,14 +118,15 @@ public class DeviceIconUtil {

    @SuppressLint("SwitchIntDef")
    @DrawableRes
    private static int getIconResourceIdForTv(@MediaRoute2Info.Type int type) {
    private int getIconResourceIdForTv(@MediaRoute2Info.Type int type) {
        return switch (type) {
            case MediaRoute2Info.TYPE_USB_DEVICE, MediaRoute2Info.TYPE_USB_HEADSET ->
                    R.drawable.ic_headphone;
            case MediaRoute2Info.TYPE_USB_ACCESSORY -> R.drawable.ic_usb;
            case MediaRoute2Info.TYPE_DOCK -> R.drawable.ic_dock_device;
            case MediaRoute2Info.TYPE_HDMI, MediaRoute2Info.TYPE_BUILTIN_SPEAKER ->
                    R.drawable.ic_tv;
            case MediaRoute2Info.TYPE_BUILTIN_SPEAKER ->
                    isPanelTv() ? R.drawable.ic_tv : R.drawable.ic_tv_box_internal_speaker;
            case MediaRoute2Info.TYPE_HDMI -> R.drawable.ic_tv;
            case MediaRoute2Info.TYPE_HDMI_ARC, MediaRoute2Info.TYPE_HDMI_EARC ->
                    R.drawable.ic_hdmi;
            case MediaRoute2Info.TYPE_WIRED_HEADSET, MediaRoute2Info.TYPE_WIRED_HEADPHONES ->
@@ -132,6 +135,23 @@ public class DeviceIconUtil {
        };
    }

    private boolean isPanelTv() {
        if (mContext == null) {
            // This should only happen during testing.
            return true;
        }
        AudioManager audioManager = mContext.getSystemService(AudioManager.class);
        AudioDeviceInfo[] devices = audioManager.getDevices(
                AudioManager.GET_DEVICES_OUTPUTS);
        // If we have an HDMI output (not ARC/eARC) we can assume it's a dongle / set top box.
        for (AudioDeviceInfo device : devices) {
            if (device.getType() == TYPE_HDMI) {
                return false;
            }
        }
        return true;
    }

    static {
        AUDIO_DEVICE_TO_MEDIA_ROUTE_TYPE.put(TYPE_USB_DEVICE, MediaRoute2Info.TYPE_USB_DEVICE);
        AUDIO_DEVICE_TO_MEDIA_ROUTE_TYPE.put(TYPE_USB_HEADSET, MediaRoute2Info.TYPE_USB_HEADSET);
+4 −4
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import static android.media.MediaRoute2Info.TYPE_WIRED_HEADSET;
import static android.media.MediaRoute2Info.TYPE_LINE_DIGITAL;
import static android.media.MediaRoute2Info.TYPE_LINE_ANALOG;
import static android.media.MediaRoute2Info.TYPE_AUX_LINE;

import static com.android.settingslib.media.MediaDevice.SelectionBehavior.SELECTION_BEHAVIOR_TRANSFER;

import android.Manifest;
@@ -40,6 +41,7 @@ import android.hardware.hdmi.HdmiDeviceInfo;
import android.hardware.hdmi.HdmiPortInfo;
import android.media.MediaRoute2Info;
import android.media.RouteListingPreference;
import android.os.Build;
import android.os.SystemProperties;
import android.util.Log;

@@ -72,7 +74,7 @@ public class PhoneMediaDevice extends MediaDevice {
    /** Returns this device name for media transfer. */
    public static @NonNull String getMediaTransferThisDeviceName(@NonNull Context context) {
        if (isTv(context)) {
            return context.getString(R.string.media_transfer_this_device_name_tv);
            return Build.MODEL;
        } else if (isTablet()) {
            return context.getString(R.string.media_transfer_this_device_name_tablet);
        } else if (inputRoutingEnabledAndIsDesktop(context)) {
@@ -110,7 +112,7 @@ public class PhoneMediaDevice extends MediaDevice {
                name = getMediaTransferThisDeviceName(context);
                break;
            case TYPE_HDMI:
                name = context.getString(isTv ? R.string.tv_media_transfer_default :
                name = context.getString(isTv ? R.string.tv_media_transfer_hdmi_title :
                        R.string.media_transfer_external_device_name);
                break;
            case TYPE_HDMI_ARC:
@@ -223,8 +225,6 @@ public class PhoneMediaDevice extends MediaDevice {
        switch (mRouteInfo.getType()) {
            case TYPE_BUILTIN_SPEAKER:
                return mContext.getString(R.string.tv_media_transfer_internal_speakers);
            case TYPE_HDMI:
                return mContext.getString(R.string.tv_media_transfer_hdmi);
            case TYPE_HDMI_ARC:
                if (getHdmiOutDeviceName(mContext) == null) {
                    // Connection type is already part of the title.
+2 −2
Original line number Diff line number Diff line
@@ -173,7 +173,7 @@ public class DeviceIconUtilTest {
    public void getIconResIdFromMediaRouteType_tv_builtinSpeaker_isTv() {
        assertThat(new DeviceIconUtil(/* isTv */ true)
                .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_BUILTIN_SPEAKER))
                .isEqualTo(R.drawable.ic_tv);
                .isAnyOf(R.drawable.ic_tv, R.drawable.ic_tv_box_internal_speaker);
    }

    @Test
@@ -331,7 +331,7 @@ public class DeviceIconUtilTest {
    public void getIconResIdFromAudioDeviceType_tv_builtinSpeaker_isTv() {
        assertThat(new DeviceIconUtil(/* isTv */ true)
                .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER))
                .isEqualTo(R.drawable.ic_tv);
                .isAnyOf(R.drawable.ic_tv, R.drawable.ic_tv_box_internal_speaker);
    }

    @Test