summaryrefslogtreecommitdiff
path: root/packages/SettingsLib
diff options
context:
space:
mode:
authorHugh Chen <hughchen@google.com>2020-11-30 16:13:58 +0800
committerHugh Chen <hughchen@google.com>2020-12-04 06:17:31 +0000
commit99aab3cae7c3d0f4c83c50f76b2f0110bd5badeb (patch)
treed85d1d3f73b4178e605240d675761d6dd55d917f /packages/SettingsLib
parentc905bf06a0b1601c3fc0723f3e8a8bddd6611873 (diff)
Fix pixel buds icon is empty in output switcher
MediaDevice will set a color filter in the bluetooth device icon if the bluetooth device is not a fist pair device. But if apps didn't have permission to get a first pair device icon, MediaDevice will return a default bluetooth icon. In this case MediaDevice will not set the color filter in the icon then it causes the icon to become empty. This CL will use the drawable type to set the color filter instead of checking whether it is a first pair device. Bug: 174279607 Bug: 155822415 Test: make -j42 RunSettingsRoboTests Change-Id: Ic5c348900db3e79e669173ec4ceeaec4d6500e5f Merged-In: Ic5c348900db3e79e669173ec4ceeaec4d6500e5f (cherry picked from commit b4603fd3ffa0710fc9441dd69a97bebe94c12151)
Diffstat (limited to 'packages/SettingsLib')
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/media/BluetoothMediaDevice.java10
-rw-r--r--packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/BluetoothMediaDeviceTest.java14
2 files changed, 19 insertions, 5 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/media/BluetoothMediaDevice.java b/packages/SettingsLib/src/com/android/settingslib/media/BluetoothMediaDevice.java
index 00f94f5c2e64..9d4669a5a37d 100644
--- a/packages/SettingsLib/src/com/android/settingslib/media/BluetoothMediaDevice.java
+++ b/packages/SettingsLib/src/com/android/settingslib/media/BluetoothMediaDevice.java
@@ -18,6 +18,7 @@ package com.android.settingslib.media;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
+import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.media.MediaRoute2Info;
import android.media.MediaRouter2Manager;
@@ -56,8 +57,9 @@ public class BluetoothMediaDevice extends MediaDevice {
@Override
public Drawable getIcon() {
- final Drawable drawable = getIconWithoutBackground();
- if (!isFastPairDevice()) {
+ final Drawable drawable =
+ BluetoothUtils.getBtDrawableWithDescription(mContext, mCachedDevice).first;
+ if (!(drawable instanceof BitmapDrawable)) {
setColorFilter(drawable);
}
return BluetoothUtils.buildAdvancedDrawable(mContext, drawable);
@@ -65,9 +67,7 @@ public class BluetoothMediaDevice extends MediaDevice {
@Override
public Drawable getIconWithoutBackground() {
- return isFastPairDevice()
- ? BluetoothUtils.getBtDrawableWithDescription(mContext, mCachedDevice).first
- : mContext.getDrawable(R.drawable.ic_headphone);
+ return BluetoothUtils.getBtClassDrawableWithDescription(mContext, mCachedDevice).first;
}
@Override
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/BluetoothMediaDeviceTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/BluetoothMediaDeviceTest.java
index 8973d116e438..e887c45083c0 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/BluetoothMediaDeviceTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/BluetoothMediaDeviceTest.java
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
+import android.graphics.drawable.BitmapDrawable;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
@@ -96,4 +97,17 @@ public class BluetoothMediaDeviceTest {
assertThat(mBluetoothMediaDevice.isFastPairDevice()).isFalse();
}
+
+ @Test
+ public void getIcon_isNotFastPairDevice_drawableTypeIsNotBitmapDrawable() {
+ final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class);
+ when(mDevice.getDevice()).thenReturn(bluetoothDevice);
+
+ final String value = "False";
+ final byte[] bytes = value.getBytes();
+ when(bluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET))
+ .thenReturn(bytes);
+
+ assertThat(mBluetoothMediaDevice.getIcon() instanceof BitmapDrawable).isFalse();
+ }
}