Merge "Fix anr when open connected devices" into sc-dev am: 94c64def14

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14702758

Change-Id: Ibe2f13a6899788699a70a5b2f8c173620fd8e138
This commit is contained in:
TreeHugger Robot
2021-05-25 12:08:16 +00:00
committed by Automerger Merge Worker
2 changed files with 12 additions and 3 deletions

View File

@@ -1222,19 +1222,22 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
*/ */
public Pair<Drawable, String> getDrawableWithDescription() { public Pair<Drawable, String> getDrawableWithDescription() {
Uri uri = BluetoothUtils.getUriMetaData(mDevice, BluetoothDevice.METADATA_MAIN_ICON); Uri uri = BluetoothUtils.getUriMetaData(mDevice, BluetoothDevice.METADATA_MAIN_ICON);
Pair<Drawable, String> pair = BluetoothUtils.getBtClassDrawableWithDescription(
mContext, this);
if (BluetoothUtils.isAdvancedDetailsHeader(mDevice) && uri != null) { if (BluetoothUtils.isAdvancedDetailsHeader(mDevice) && uri != null) {
BitmapDrawable drawable = mDrawableCache.get(uri.toString()); BitmapDrawable drawable = mDrawableCache.get(uri.toString());
if (drawable != null) { if (drawable != null) {
Resources resources = mContext.getResources(); Resources resources = mContext.getResources();
return new Pair<>(new AdaptiveOutlineDrawable( return new Pair<>(new AdaptiveOutlineDrawable(
resources, drawable.getBitmap()), resources, drawable.getBitmap()), pair.second);
BluetoothUtils.getBtClassDrawableWithDescription(mContext, this).second);
} }
refresh(); refresh();
} }
return BluetoothUtils.getBtRainbowDrawableWithDescription(mContext, this); return new Pair<>(BluetoothUtils.buildBtRainbowDrawable(
mContext, pair.first, getAddress().hashCode()), pair.second);
} }
void releaseLruCache() { void releaseLruCache() {

View File

@@ -31,7 +31,9 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothProfile;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.media.AudioManager; import android.media.AudioManager;
import android.util.LruCache;
import com.android.settingslib.R; import com.android.settingslib.R;
import com.android.settingslib.testutils.shadow.ShadowBluetoothAdapter; import com.android.settingslib.testutils.shadow.ShadowBluetoothAdapter;
@@ -961,6 +963,10 @@ public class CachedBluetoothDeviceTest {
@Test @Test
public void getDrawableWithDescription_isAdvancedDevice_returnAdvancedIcon() { 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)) when(mDevice.getMetadata(BluetoothDevice.METADATA_MAIN_ICON))
.thenReturn("fake_uri".getBytes()); .thenReturn("fake_uri".getBytes());
when(mDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)) when(mDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET))