diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java index 4558a8a3d33ee..fe92e2664eda6 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java @@ -1222,19 +1222,22 @@ public class CachedBluetoothDevice implements Comparable */ public Pair getDrawableWithDescription() { Uri uri = BluetoothUtils.getUriMetaData(mDevice, BluetoothDevice.METADATA_MAIN_ICON); + Pair pair = BluetoothUtils.getBtClassDrawableWithDescription( + mContext, this); + if (BluetoothUtils.isAdvancedDetailsHeader(mDevice) && uri != null) { BitmapDrawable drawable = mDrawableCache.get(uri.toString()); if (drawable != null) { Resources resources = mContext.getResources(); return new Pair<>(new AdaptiveOutlineDrawable( - resources, drawable.getBitmap()), - BluetoothUtils.getBtClassDrawableWithDescription(mContext, this).second); + resources, drawable.getBitmap()), pair.second); } refresh(); } - return BluetoothUtils.getBtRainbowDrawableWithDescription(mContext, this); + return new Pair<>(BluetoothUtils.buildBtRainbowDrawable( + mContext, pair.first, getAddress().hashCode()), pair.second); } void releaseLruCache() { diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java index 38172f7600a68..f523354894158 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java @@ -31,7 +31,9 @@ import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; import android.content.Context; +import android.graphics.drawable.BitmapDrawable; import android.media.AudioManager; +import android.util.LruCache; import com.android.settingslib.R; import com.android.settingslib.testutils.shadow.ShadowBluetoothAdapter; @@ -961,6 +963,10 @@ public class CachedBluetoothDeviceTest { @Test public void getDrawableWithDescription_isAdvancedDevice_returnAdvancedIcon() { + LruCache lruCache = mock(LruCache.class); + mCachedDevice.mDrawableCache = lruCache; + BitmapDrawable drawable = mock(BitmapDrawable.class); + when(lruCache.get("fake_uri")).thenReturn(drawable); when(mDevice.getMetadata(BluetoothDevice.METADATA_MAIN_ICON)) .thenReturn("fake_uri".getBytes()); when(mDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET))