diff options
| author | 2023-11-03 09:52:33 +0000 | |
|---|---|---|
| committer | 2023-11-03 09:52:33 +0000 | |
| commit | 5ea095ca58eac7f5ae1011793f054ac2bebd81f8 (patch) | |
| tree | 3a9a1770781f73a11f4d20e4888fd6ad0d204688 | |
| parent | 56fcc173dcbc7795a845c1da1c627348fb1d0fd4 (diff) | |
| parent | a40517dcbe884f052c10735ae1d44c97f5e5c8d2 (diff) | |
Merge "Adjust PhoneMediaDevice icons and (sub)titles (TV)" into main
9 files changed, 478 insertions, 69 deletions
diff --git a/packages/SettingsLib/res/drawable/ic_hdmi.xml b/packages/SettingsLib/res/drawable/ic_hdmi.xml new file mode 100644 index 000000000000..c7a553bddb8c --- /dev/null +++ b/packages/SettingsLib/res/drawable/ic_hdmi.xml @@ -0,0 +1,26 @@ +<!-- + ~ Copyright (C) 2023 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="48dp" + android:height="48dp" + android:viewportWidth="960" + android:viewportHeight="960" + android:tint="?attr/colorControlNormal"> + <path + android:fillColor="@android:color/white" + android:pathData="M320,880L320,760L200,521L200,280L240,280L240,140Q240,117 258.5,98.5Q277,80 300,80L660,80Q683,80 701.5,98.5Q720,117 720,140L720,280L760,280L760,521L640,760L640,880L320,880ZM300,280L398,280L398,198L432,198L432,280L528,280L528,198L562,198L562,280L660,280L660,140Q660,140 660,140Q660,140 660,140L300,140Q300,140 300,140Q300,140 300,140L300,280ZM378,743L378,743L582,743L582,743L582,743L378,743L378,743ZM378,743L582,743L700,504L700,340L260,340L260,504L378,743Z"/> +</vector> diff --git a/packages/SettingsLib/res/drawable/ic_tv.xml b/packages/SettingsLib/res/drawable/ic_tv.xml new file mode 100644 index 000000000000..87abaf42bd65 --- /dev/null +++ b/packages/SettingsLib/res/drawable/ic_tv.xml @@ -0,0 +1,26 @@ +<!-- + ~ Copyright (C) 2023 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="960" + android:viewportHeight="960" + android:tint="?attr/colorControlNormal"> + <path + android:fillColor="@android:color/white" + android:pathData="M320,840L320,760L160,760Q127,760 103.5,736.5Q80,713 80,680L80,200Q80,167 103.5,143.5Q127,120 160,120L800,120Q833,120 856.5,143.5Q880,167 880,200L880,680Q880,713 856.5,736.5Q833,760 800,760L640,760L640,840L320,840ZM160,680L800,680Q800,680 800,680Q800,680 800,680L800,200Q800,200 800,200Q800,200 800,200L160,200Q160,200 160,200Q160,200 160,200L160,680Q160,680 160,680Q160,680 160,680ZM160,680Q160,680 160,680Q160,680 160,680L160,200Q160,200 160,200Q160,200 160,200L160,200Q160,200 160,200Q160,200 160,200L160,680Q160,680 160,680Q160,680 160,680L160,680Z"/> +</vector>
\ No newline at end of file diff --git a/packages/SettingsLib/res/drawable/ic_usb.xml b/packages/SettingsLib/res/drawable/ic_usb.xml new file mode 100644 index 000000000000..b5f15eae3855 --- /dev/null +++ b/packages/SettingsLib/res/drawable/ic_usb.xml @@ -0,0 +1,26 @@ +<!-- + ~ Copyright (C) 2023 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="48dp" + android:height="48dp" + android:viewportWidth="960" + android:viewportHeight="960" + android:tint="?attr/colorControlNormal"> + <path + android:fillColor="@android:color/white" + android:pathData="M480,880Q448,880 428,860Q408,840 408,808Q408,786 419,768Q430,750 450,739L450,628L302,628Q278,628 260,610Q242,592 242,568L242,459Q222,450 211,432.39Q200,414.78 200,392.28Q200,360 220,340Q240,320 272,320Q304,320 324,340Q344,360 344,392.41Q344,415 333,432.5Q322,450 302,459L302,568Q302,568 302,568Q302,568 302,568L450,568L450,228L370,228L480,79L590,228L510,228L510,568L658,568Q658,568 658,568Q658,568 658,568L658,464L616,464L616,320L760,320L760,464L718,464L718,568Q718,592 700,610Q682,628 658,628L510,628L510,739Q529.95,749.65 540.97,768.83Q552,788 552,808Q552,840 532,860Q512,880 480,880Z"/> +</vector>
\ No newline at end of file diff --git a/packages/SettingsLib/res/drawable/ic_wired_device.xml b/packages/SettingsLib/res/drawable/ic_wired_device.xml new file mode 100644 index 000000000000..7964c9f08d7e --- /dev/null +++ b/packages/SettingsLib/res/drawable/ic_wired_device.xml @@ -0,0 +1,25 @@ +<!-- + Copyright (C) 2020 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="48dp" + android:height="48dp" + android:viewportWidth="960" + android:viewportHeight="960" + android:tint="?attr/colorControlNormal"> + <path + android:fillColor="@android:color/white" + android:pathData="M123,920L123,750Q89,737 64.5,707.5Q40,678 40,643L40,245L123,245L123,70Q123,56 131,48Q139,40 153,40Q167,40 175,48Q183,56 183,70L183,245L266,245L266,643Q266,678 242,707.5Q218,737 183,750L183,920L123,920ZM450,920L450,750Q416,737 391.5,707.5Q367,678 367,643L367,245L450,245L450,70Q450,56 458,48Q466,40 480,40Q494,40 502,48Q510,56 510,70L510,245L593,245L593,643Q593,678 569,707.5Q545,737 510,750L510,920L450,920ZM777,920L777,750Q743,737 718.5,707.5Q694,678 694,643L694,245L777,245L777,70Q777,56 785,48Q793,40 807,40Q821,40 829,48Q837,56 837,70L837,245L920,245L920,643Q920,678 895.5,707.5Q871,737 837,750L837,920L777,920ZM100,489L206,489L206,305L100,305L100,489ZM427,489L533,489L533,305L427,305L427,489ZM754,489L860,489L860,305L754,305L754,489ZM153,489L153,489L153,489L153,489L153,489ZM480,489L480,489L480,489L480,489L480,489ZM807,489L807,489L807,489L807,489L807,489ZM100,489L100,489L206,489L206,489L100,489ZM427,489L427,489L533,489L533,489L427,489ZM754,489L754,489L860,489L860,489L754,489Z"/> +</vector>
\ No newline at end of file diff --git a/packages/SettingsLib/res/values/strings.xml b/packages/SettingsLib/res/values/strings.xml index 96029c813528..1a5acf650cb4 100644 --- a/packages/SettingsLib/res/values/strings.xml +++ b/packages/SettingsLib/res/values/strings.xml @@ -1334,6 +1334,8 @@ <string name="media_transfer_this_device_name" product="default">This phone</string> <!-- Name of the tablet device. [CHAR LIMIT=30] --> <string name="media_transfer_this_device_name" product="tablet">This tablet</string> + <!-- Name of the default media output of the TV. [CHAR LIMIT=30] --> + <string name="media_transfer_this_device_name" product="tv">@string/tv_media_transfer_default</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] --> @@ -1357,6 +1359,26 @@ <!-- Sub status indicates the device does not support the current media track. [CHAR LIMIT=NONE] --> <string name="media_output_status_track_unsupported">Can\’t play this media here</string> + <!-- Media output switcher. Default subtitle for any output option that is connected if no more information is known [CHAR LIMIT=NONE] --> + <string name="tv_media_transfer_connected">Connected</string> + + <!-- TV media output switcher. Title for devices connected through HDMI ARC if no device name is available. [CHAR LIMIT=NONE] --> + <string name="tv_media_transfer_arc_fallback_title">HDMI ARC</string> + <!-- TV media output switcher. Title for devices connected through HDMI EARC if no device name is available. [CHAR LIMIT=NONE] --> + <string name="tv_media_transfer_earc_fallback_title">HDMI eARC</string> + + <!-- TV media output switcher. Subtitle for devices connected through HDMI ARC if a device name is available. [CHAR LIMIT=NONE] --> + <string name="tv_media_transfer_arc_subtitle">Connected via ARC</string> + <!-- 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> + <!-- 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 & back on</string> diff --git a/packages/SettingsLib/src/com/android/settingslib/media/DeviceIconUtil.java b/packages/SettingsLib/src/com/android/settingslib/media/DeviceIconUtil.java index 2a2841745fa0..cf224dc3be5f 100644 --- a/packages/SettingsLib/src/com/android/settingslib/media/DeviceIconUtil.java +++ b/packages/SettingsLib/src/com/android/settingslib/media/DeviceIconUtil.java @@ -18,11 +18,13 @@ package com.android.settingslib.media; import android.annotation.DrawableRes; import android.content.Context; +import android.content.pm.PackageManager; import android.graphics.drawable.Drawable; import android.media.AudioDeviceInfo; import android.media.MediaRoute2Info; import com.android.settingslib.R; +import com.android.settingslib.media.flags.Flags; import java.util.Arrays; import java.util.HashMap; @@ -31,16 +33,25 @@ import java.util.Map; /** A util class to get the appropriate icon for different device types. */ public class DeviceIconUtil { + + // A default icon to use if the type is not present in the map. + @DrawableRes private static final int DEFAULT_ICON = R.drawable.ic_smartphone; + @DrawableRes private static final int DEFAULT_ICON_TV = R.drawable.ic_media_speaker_device; + // A map from a @AudioDeviceInfo.AudioDeviceType to full device information. private final Map<Integer, Device> mAudioDeviceTypeToIconMap = new HashMap<>(); // A map from a @MediaRoute2Info.Type to full device information. private final Map<Integer, Device> mMediaRouteTypeToIconMap = new HashMap<>(); - // A default icon to use if the type is not present in the map. - @DrawableRes private static final int DEFAULT_ICON = R.drawable.ic_smartphone; - public DeviceIconUtil() { - List<Device> deviceList = - Arrays.asList( + private final boolean mIsTv; + + public DeviceIconUtil(Context context) { + this(context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)); + } + + public DeviceIconUtil(boolean isTv) { + mIsTv = isTv && Flags.enableTvMediaOutputDialog(); + List<Device> deviceList = Arrays.asList( new Device( AudioDeviceInfo.TYPE_USB_DEVICE, MediaRoute2Info.TYPE_USB_DEVICE, @@ -52,7 +63,7 @@ public class DeviceIconUtil { new Device( AudioDeviceInfo.TYPE_USB_ACCESSORY, MediaRoute2Info.TYPE_USB_ACCESSORY, - R.drawable.ic_headphone), + mIsTv ? R.drawable.ic_usb : R.drawable.ic_headphone), new Device( AudioDeviceInfo.TYPE_DOCK, MediaRoute2Info.TYPE_DOCK, @@ -60,29 +71,27 @@ public class DeviceIconUtil { new Device( AudioDeviceInfo.TYPE_HDMI, MediaRoute2Info.TYPE_HDMI, - R.drawable.ic_headphone), - // TODO: b/306359110 - Put proper iconography for HDMI_ARC type. + mIsTv ? R.drawable.ic_tv : R.drawable.ic_headphone), new Device( AudioDeviceInfo.TYPE_HDMI_ARC, MediaRoute2Info.TYPE_HDMI_ARC, - R.drawable.ic_headphone), - // TODO: b/306359110 - Put proper iconography for HDMI_EARC type. + mIsTv ? R.drawable.ic_hdmi : R.drawable.ic_headphone), new Device( AudioDeviceInfo.TYPE_HDMI_EARC, MediaRoute2Info.TYPE_HDMI_EARC, - R.drawable.ic_headphone), + mIsTv ? R.drawable.ic_hdmi : R.drawable.ic_headphone), new Device( AudioDeviceInfo.TYPE_WIRED_HEADSET, MediaRoute2Info.TYPE_WIRED_HEADSET, - R.drawable.ic_headphone), + mIsTv ? R.drawable.ic_wired_device : R.drawable.ic_headphone), new Device( AudioDeviceInfo.TYPE_WIRED_HEADPHONES, MediaRoute2Info.TYPE_WIRED_HEADPHONES, - R.drawable.ic_headphone), + mIsTv ? R.drawable.ic_wired_device : R.drawable.ic_headphone), new Device( AudioDeviceInfo.TYPE_BUILTIN_SPEAKER, MediaRoute2Info.TYPE_BUILTIN_SPEAKER, - R.drawable.ic_smartphone)); + mIsTv ? R.drawable.ic_tv : R.drawable.ic_smartphone)); for (int i = 0; i < deviceList.size(); i++) { Device device = deviceList.get(i); mAudioDeviceTypeToIconMap.put(device.mAudioDeviceType, device); @@ -90,6 +99,10 @@ public class DeviceIconUtil { } } + private int getDefaultIcon() { + return mIsTv ? DEFAULT_ICON_TV : DEFAULT_ICON; + } + /** Returns a drawable for an icon representing the given audioDeviceType. */ public Drawable getIconFromAudioDeviceType( @AudioDeviceInfo.AudioDeviceType int audioDeviceType, Context context) { @@ -103,7 +116,7 @@ public class DeviceIconUtil { if (mAudioDeviceTypeToIconMap.containsKey(audioDeviceType)) { return mAudioDeviceTypeToIconMap.get(audioDeviceType).mIconDrawableRes; } - return DEFAULT_ICON; + return getDefaultIcon(); } /** Returns a drawable res ID for an icon representing the given mediaRouteType. */ @@ -113,7 +126,7 @@ public class DeviceIconUtil { if (mMediaRouteTypeToIconMap.containsKey(mediaRouteType)) { return mMediaRouteTypeToIconMap.get(mediaRouteType).mIconDrawableRes; } - return DEFAULT_ICON; + return getDefaultIcon(); } private static class Device { diff --git a/packages/SettingsLib/src/com/android/settingslib/media/PhoneMediaDevice.java b/packages/SettingsLib/src/com/android/settingslib/media/PhoneMediaDevice.java index c44f66e99d00..80eeab56cc45 100644 --- a/packages/SettingsLib/src/com/android/settingslib/media/PhoneMediaDevice.java +++ b/packages/SettingsLib/src/com/android/settingslib/media/PhoneMediaDevice.java @@ -28,15 +28,24 @@ import static android.media.MediaRoute2Info.TYPE_WIRED_HEADSET; import static com.android.settingslib.media.MediaDevice.SelectionBehavior.SELECTION_BEHAVIOR_TRANSFER; +import android.Manifest; import android.annotation.NonNull; import android.content.Context; +import android.content.pm.PackageManager; import android.graphics.drawable.Drawable; +import android.hardware.hdmi.HdmiControlManager; +import android.hardware.hdmi.HdmiDeviceInfo; +import android.hardware.hdmi.HdmiPortInfo; import android.media.MediaRoute2Info; import android.media.RouteListingPreference; +import android.util.Log; import androidx.annotation.VisibleForTesting; import com.android.settingslib.R; +import com.android.settingslib.media.flags.Flags; + +import java.util.List; /** * PhoneMediaDevice extends MediaDevice to represents Phone device. @@ -58,6 +67,7 @@ public class PhoneMediaDevice extends MediaDevice { public static String getSystemRouteNameFromType( @NonNull Context context, @NonNull MediaRoute2Info routeInfo) { CharSequence name; + boolean isTv = isTv(context); switch (routeInfo.getType()) { case TYPE_WIRED_HEADSET: case TYPE_WIRED_HEADPHONES: @@ -73,9 +83,32 @@ public class PhoneMediaDevice extends MediaDevice { name = context.getString(R.string.media_transfer_this_device_name); break; case TYPE_HDMI: + name = context.getString(isTv ? R.string.tv_media_transfer_default : + R.string.media_transfer_external_device_name); + break; case TYPE_HDMI_ARC: + if (isTv) { + String deviceName = getHdmiOutDeviceName(context); + if (deviceName != null) { + name = deviceName; + } else { + name = context.getString(R.string.tv_media_transfer_arc_fallback_title); + } + } else { + name = context.getString(R.string.media_transfer_external_device_name); + } + break; case TYPE_HDMI_EARC: - name = context.getString(R.string.media_transfer_external_device_name); + if (isTv) { + String deviceName = getHdmiOutDeviceName(context); + if (deviceName != null) { + name = deviceName; + } else { + name = context.getString(R.string.tv_media_transfer_arc_fallback_title); + } + } else { + name = context.getString(R.string.media_transfer_external_device_name); + } break; default: name = context.getString(R.string.media_transfer_default_device_name); @@ -94,10 +127,15 @@ public class PhoneMediaDevice extends MediaDevice { String packageName, RouteListingPreference.Item item) { super(context, info, packageName, item); - mDeviceIconUtil = new DeviceIconUtil(); + mDeviceIconUtil = new DeviceIconUtil(mContext); initDeviceRecord(); } + static boolean isTv(Context context) { + return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK) + && Flags.enableTvMediaOutputDialog(); + } + // MediaRoute2Info.getType was made public on API 34, but exists since API 30. @SuppressWarnings("NewApi") @Override @@ -111,9 +149,64 @@ public class PhoneMediaDevice extends MediaDevice { return SELECTION_BEHAVIOR_TRANSFER; } + private static String getHdmiOutDeviceName(Context context) { + HdmiControlManager hdmiControlManager; + if (context.checkCallingOrSelfPermission(Manifest.permission.HDMI_CEC) + == PackageManager.PERMISSION_GRANTED) { + hdmiControlManager = context.getSystemService(HdmiControlManager.class); + } else { + Log.w(TAG, "Could not get HDMI device name, android.permission.HDMI_CEC denied"); + return null; + } + + HdmiPortInfo hdmiOutputPortInfo = null; + for (HdmiPortInfo hdmiPortInfo : hdmiControlManager.getPortInfo()) { + if (hdmiPortInfo.getType() == HdmiPortInfo.PORT_OUTPUT) { + hdmiOutputPortInfo = hdmiPortInfo; + break; + } + } + if (hdmiOutputPortInfo == null) { + return null; + } + List<HdmiDeviceInfo> connectedDevices = hdmiControlManager.getConnectedDevices(); + for (HdmiDeviceInfo deviceInfo : connectedDevices) { + if (deviceInfo.getPortId() == hdmiOutputPortInfo.getId()) { + String deviceName = deviceInfo.getDisplayName(); + if (deviceName != null && !deviceName.isEmpty()) { + return deviceName; + } + } + } + return null; + } + @Override public String getSummary() { - return mSummary; + if (!isTv(mContext)) { + return mSummary; + } + 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. + return mContext.getString(R.string.tv_media_transfer_connected); + } + return mContext.getString(R.string.tv_media_transfer_arc_subtitle); + case TYPE_HDMI_EARC: + if (getHdmiOutDeviceName(mContext) == null) { + // Connection type is already part of the title. + return mContext.getString(R.string.tv_media_transfer_connected); + } + return mContext.getString(R.string.tv_media_transfer_earc_subtitle); + default: + return null; + } + } @Override diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/DeviceIconUtilTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/DeviceIconUtilTest.java index 72dfc1733275..5669276a0424 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/DeviceIconUtilTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/DeviceIconUtilTest.java @@ -20,131 +20,309 @@ import static com.google.common.truth.Truth.assertThat; import android.media.AudioDeviceInfo; import android.media.MediaRoute2Info; +import android.platform.test.flag.junit.SetFlagsRule; import com.android.settingslib.R; +import com.android.settingslib.media.flags.Flags; +import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; @RunWith(RobolectricTestRunner.class) public class DeviceIconUtilTest { - private final DeviceIconUtil mDeviceIconUtil = new DeviceIconUtil(); + + @Rule + public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); + + @Before + public void setup() { + mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_TV_MEDIA_OUTPUT_DIALOG); + } @Test public void getIconResIdFromMediaRouteType_usbDevice_isHeadphone() { - assertThat(mDeviceIconUtil.getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_USB_DEVICE)) - .isEqualTo(R.drawable.ic_headphone); + assertThat(new DeviceIconUtil(/* isTv */ false) + .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_USB_DEVICE)) + .isEqualTo(R.drawable.ic_headphone); + assertThat(new DeviceIconUtil(/* isTv */ true) + .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_USB_DEVICE)) + .isEqualTo(R.drawable.ic_headphone); } @Test public void getIconResIdFromMediaRouteType_usbHeadset_isHeadphone() { - assertThat(mDeviceIconUtil.getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_USB_HEADSET)) - .isEqualTo(R.drawable.ic_headphone); + assertThat(new DeviceIconUtil(/* isTv */ false) + .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_USB_HEADSET)) + .isEqualTo(R.drawable.ic_headphone); + assertThat(new DeviceIconUtil(/* isTv */ true) + .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_USB_HEADSET)) + .isEqualTo(R.drawable.ic_headphone); } @Test public void getIconResIdFromMediaRouteType_usbAccessory_isHeadphone() { - assertThat( - mDeviceIconUtil.getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_USB_ACCESSORY)) - .isEqualTo(R.drawable.ic_headphone); + assertThat(new DeviceIconUtil(/* isTv */ false) + .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_USB_ACCESSORY)) + .isEqualTo(R.drawable.ic_headphone); + } + + @Test + public void getIconResIdFromMediaRouteType_tv_usbAccessory_isUsb() { + assertThat(new DeviceIconUtil(/* isTv */ true) + .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_USB_ACCESSORY)) + .isEqualTo(R.drawable.ic_usb); + } + + @Test + public void getIconResIdFromMediaRouteType_dock_isDock() { + assertThat(new DeviceIconUtil(/* isTv */ false) + .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_DOCK)) + .isEqualTo(R.drawable.ic_dock_device); + assertThat(new DeviceIconUtil(/* isTv */ true) + .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_DOCK)) + .isEqualTo(R.drawable.ic_dock_device); + } + + @Test + public void getIconResIdFromMediaRouteType_hdmi() { + assertThat(new DeviceIconUtil(/* isTv */ false) + .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_HDMI)) + .isEqualTo(R.drawable.ic_headphone); + } + + @Test + public void getIconResIdFromMediaRouteType_tv_hdmi_isTv() { + assertThat(new DeviceIconUtil(/* isTv */ true) + .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_HDMI)) + .isEqualTo(R.drawable.ic_tv); + } + + @Test + public void getIconResIdFromMediaRouteType_hdmiArc_isHeadphone() { + assertThat(new DeviceIconUtil(/* isTv */ false) + .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_HDMI_ARC)) + .isEqualTo(R.drawable.ic_headphone); + } + + @Test + public void getIconResIdFromMediaRouteType_tv_hdmiArc_isHdmi() { + assertThat(new DeviceIconUtil(/* isTv */ true) + .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_HDMI_ARC)) + .isEqualTo(R.drawable.ic_hdmi); } @Test - public void getIconResIdFromMediaRouteType_dock_isHeadphone() { - assertThat(mDeviceIconUtil.getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_DOCK)) - .isEqualTo(R.drawable.ic_headphone); + public void getIconResIdFromMediaRouteType_hdmiEarc_isHeadphone() { + assertThat(new DeviceIconUtil(/* isTv */ false) + .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_HDMI_EARC)) + .isEqualTo(R.drawable.ic_headphone); } @Test - public void getIconResIdFromMediaRouteType_hdmi_isHeadphone() { - assertThat(mDeviceIconUtil.getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_HDMI)) - .isEqualTo(R.drawable.ic_headphone); + public void getIconResIdFromMediaRouteType_tv_hdmiEarc_isHdmi() { + assertThat(new DeviceIconUtil(/* isTv */ true) + .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_HDMI_EARC)) + .isEqualTo(R.drawable.ic_hdmi); } @Test public void getIconResIdFromMediaRouteType_wiredHeadset_isHeadphone() { - assertThat( - mDeviceIconUtil.getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_WIRED_HEADSET)) - .isEqualTo(R.drawable.ic_headphone); + assertThat(new DeviceIconUtil(/* isTv */ false) + .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_WIRED_HEADSET)) + .isEqualTo(R.drawable.ic_headphone); + } + + @Test + public void getIconResIdFromMediaRouteType_tv_wiredHeadset_isWiredDevice() { + assertThat(new DeviceIconUtil(/* isTv */ true) + .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_WIRED_HEADSET)) + .isEqualTo(R.drawable.ic_wired_device); } @Test public void getIconResIdFromMediaRouteType_wiredHeadphones_isHeadphone() { - assertThat( - mDeviceIconUtil.getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_WIRED_HEADPHONES)) - .isEqualTo(R.drawable.ic_headphone); + assertThat(new DeviceIconUtil(/* isTv */ false) + .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_WIRED_HEADPHONES)) + .isEqualTo(R.drawable.ic_headphone); + } + + @Test + public void getIconResIdFromMediaRouteType_tv_wiredHeadphones_isWiredDevice() { + assertThat(new DeviceIconUtil(/* isTv */ true) + .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_WIRED_HEADPHONES)) + .isEqualTo(R.drawable.ic_wired_device); } @Test public void getIconResIdFromMediaRouteType_builtinSpeaker_isSmartphone() { - assertThat( - mDeviceIconUtil.getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_BUILTIN_SPEAKER)) - .isEqualTo(R.drawable.ic_smartphone); + assertThat(new DeviceIconUtil(/* isTv */ false) + .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_BUILTIN_SPEAKER)) + .isEqualTo(R.drawable.ic_smartphone); + } + + @Test + public void getIconResIdFromMediaRouteType_tv_builtinSpeaker_isTv() { + assertThat(new DeviceIconUtil(/* isTv */ true) + .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_BUILTIN_SPEAKER)) + .isEqualTo(R.drawable.ic_tv); } @Test public void getIconResIdFromMediaRouteType_unsupportedType_isSmartphone() { - assertThat(mDeviceIconUtil.getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_UNKNOWN)) - .isEqualTo(R.drawable.ic_smartphone); + assertThat(new DeviceIconUtil(/* isTv */ false) + .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_UNKNOWN)) + .isEqualTo(R.drawable.ic_smartphone); + } + + @Test + public void getIconResIdFromMediaRouteType_tv_unsupportedType_isSpeaker() { + assertThat(new DeviceIconUtil(/* isTv */ true) + .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_UNKNOWN)) + .isEqualTo(R.drawable.ic_media_speaker_device); } @Test public void getIconResIdFromAudioDeviceType_usbDevice_isHeadphone() { - assertThat(mDeviceIconUtil.getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_USB_DEVICE)) - .isEqualTo(R.drawable.ic_headphone); + assertThat(new DeviceIconUtil(/* isTv */ false) + .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_USB_DEVICE)) + .isEqualTo(R.drawable.ic_headphone); + assertThat(new DeviceIconUtil(/* isTv */ true) + .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_USB_DEVICE)) + .isEqualTo(R.drawable.ic_headphone); } @Test public void getIconResIdFromAudioDeviceType_usbHeadset_isHeadphone() { - assertThat( - mDeviceIconUtil.getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_USB_HEADSET)) - .isEqualTo(R.drawable.ic_headphone); + assertThat(new DeviceIconUtil(/* isTv */ false) + .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_USB_HEADSET)) + .isEqualTo(R.drawable.ic_headphone); + assertThat(new DeviceIconUtil(/* isTv */ true) + .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_USB_HEADSET)) + .isEqualTo(R.drawable.ic_headphone); } @Test public void getIconResIdFromAudioDeviceType_usbAccessory_isHeadphone() { - assertThat( - mDeviceIconUtil.getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_USB_ACCESSORY)) - .isEqualTo(R.drawable.ic_headphone); + assertThat(new DeviceIconUtil(/* isTv */ false) + .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_USB_ACCESSORY)) + .isEqualTo(R.drawable.ic_headphone); + } + + @Test + public void getIconResIdFromAudioDeviceType_tv_usbAccessory_isUsb() { + assertThat(new DeviceIconUtil(/* isTv */ true) + .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_USB_ACCESSORY)) + .isEqualTo(R.drawable.ic_usb); } @Test - public void getIconResIdFromAudioDeviceType_dock_isHeadphone() { - assertThat(mDeviceIconUtil.getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_DOCK)) - .isEqualTo(R.drawable.ic_headphone); + public void getIconResIdFromAudioDeviceType_dock_isDock() { + assertThat(new DeviceIconUtil(/* isTv */ false) + .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_DOCK)) + .isEqualTo(R.drawable.ic_dock_device); + assertThat(new DeviceIconUtil(/* isTv */ true) + .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_DOCK)) + .isEqualTo(R.drawable.ic_dock_device); } @Test public void getIconResIdFromAudioDeviceType_hdmi_isHeadphone() { - assertThat(mDeviceIconUtil.getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_HDMI)) - .isEqualTo(R.drawable.ic_headphone); + assertThat(new DeviceIconUtil(/* isTv */ false) + .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_HDMI)) + .isEqualTo(R.drawable.ic_headphone); + } + + @Test + public void getIconResIdFromAudioDeviceType_tv_hdmi_isTv() { + assertThat(new DeviceIconUtil(/* isTv */ true) + .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_HDMI)) + .isEqualTo(R.drawable.ic_tv); + } + + @Test + public void getIconResIdFromAudioDeviceType_hdmiArc_isHeadphone() { + assertThat(new DeviceIconUtil(/* isTv */ false) + .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_HDMI_ARC)) + .isEqualTo(R.drawable.ic_headphone); + } + + @Test + public void getIconResIdFromAudioDeviceType_hdmiArc_isHdmi() { + assertThat(new DeviceIconUtil(/* isTv */ true) + .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_HDMI_ARC)) + .isEqualTo(R.drawable.ic_hdmi); + } + + @Test + public void getIconResIdFromAudioDeviceType_hdmiEarc_isHeadphone() { + assertThat(new DeviceIconUtil(/* isTv */ false) + .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_HDMI_EARC)) + .isEqualTo(R.drawable.ic_headphone); + } + + @Test + public void getIconResIdFromAudioDeviceType_tv_hdmiEarc() { + assertThat(new DeviceIconUtil(/* isTv */ true) + .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_HDMI_EARC)) + .isEqualTo(R.drawable.ic_hdmi); } @Test public void getIconResIdFromAudioDeviceType_wiredHeadset_isHeadphone() { - assertThat( - mDeviceIconUtil.getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_WIRED_HEADSET)) - .isEqualTo(R.drawable.ic_headphone); + assertThat(new DeviceIconUtil(/* isTv */ false) + .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_WIRED_HEADSET)) + .isEqualTo(R.drawable.ic_headphone); + } + + @Test + public void getIconResIdFromAudioDeviceType_tv_wiredHeadset_isWiredDevice() { + assertThat(new DeviceIconUtil(/* isTv */ true) + .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_WIRED_HEADSET)) + .isEqualTo(R.drawable.ic_wired_device); } @Test public void getIconResIdFromAudioDeviceType_wiredHeadphones_isHeadphone() { - assertThat( - mDeviceIconUtil.getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_WIRED_HEADPHONES)) - .isEqualTo(R.drawable.ic_headphone); + assertThat(new DeviceIconUtil(/* isTv */ false) + .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_WIRED_HEADPHONES)) + .isEqualTo(R.drawable.ic_headphone); + } + + @Test + public void getIconResIdFromAudioDeviceType_tv_wiredHeadphones_isWiredDevice() { + assertThat(new DeviceIconUtil(/* isTv */ true) + .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_WIRED_HEADPHONES)) + .isEqualTo(R.drawable.ic_wired_device); } @Test public void getIconResIdFromAudioDeviceType_builtinSpeaker_isSmartphone() { - assertThat( - mDeviceIconUtil.getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER)) - .isEqualTo(R.drawable.ic_smartphone); + assertThat(new DeviceIconUtil(/* isTv */ false) + .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER)) + .isEqualTo(R.drawable.ic_smartphone); + } + + @Test + public void getIconResIdFromAudioDeviceType_tv_builtinSpeaker_isTv() { + assertThat(new DeviceIconUtil(/* isTv */ true) + .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER)) + .isEqualTo(R.drawable.ic_tv); } @Test public void getIconResIdFromAudioDeviceType_unsupportedType_isSmartphone() { - assertThat(mDeviceIconUtil.getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_UNKNOWN)) - .isEqualTo(R.drawable.ic_smartphone); + assertThat(new DeviceIconUtil(/* isTv */ false) + .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_UNKNOWN)) + .isEqualTo(R.drawable.ic_smartphone); + } + + @Test + public void getIconResIdFromAudioDeviceType_tv_unsupportedType_isSpeaker() { + assertThat(new DeviceIconUtil(/* isTv */ true) + .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_UNKNOWN)) + .isEqualTo(R.drawable.ic_media_speaker_device); } } diff --git a/packages/SystemUI/src/com/android/systemui/media/muteawait/MediaMuteAwaitConnectionManagerFactory.kt b/packages/SystemUI/src/com/android/systemui/media/muteawait/MediaMuteAwaitConnectionManagerFactory.kt index 97ec654a627b..6e3b7b865cb0 100644 --- a/packages/SystemUI/src/com/android/systemui/media/muteawait/MediaMuteAwaitConnectionManagerFactory.kt +++ b/packages/SystemUI/src/com/android/systemui/media/muteawait/MediaMuteAwaitConnectionManagerFactory.kt @@ -31,7 +31,7 @@ class MediaMuteAwaitConnectionManagerFactory @Inject constructor( private val logger: MediaMuteAwaitLogger, @Main private val mainExecutor: Executor ) { - private val deviceIconUtil = DeviceIconUtil() + private val deviceIconUtil = DeviceIconUtil(context) /** Creates a [MediaMuteAwaitConnectionManager]. */ fun create(localMediaManager: LocalMediaManager): MediaMuteAwaitConnectionManager { |