Merge "Use new api to get bluetooth device icon" into sc-dev am: 3bcd6bade2

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/14250087

Change-Id: I3117ad137ab35309182236f6ffe408960f5074e5
This commit is contained in:
TreeHugger Robot
2021-04-23 12:04:36 +00:00
committed by Automerger Merge Worker
2 changed files with 16 additions and 11 deletions

View File

@@ -176,17 +176,9 @@ public final class BluetoothDevicePreference extends GearPreference {
}
void onPreferenceAttributesChanged() {
ThreadUtils.postOnBackgroundThread(() -> {
final Pair<Drawable, String> pair =
BluetoothUtils.getBtRainbowDrawableWithDescription(getContext(), mCachedDevice);
ThreadUtils.postOnMainThread(() -> {
if (pair.first != null) {
setIcon(pair.first);
contentDescription = pair.second;
}
});
});
Pair<Drawable, String> pair = mCachedDevice.getDrawableWithDescription();
setIcon(pair.first);
contentDescription = pair.second;
/*
* The preference framework takes care of making sure the value has

View File

@@ -28,7 +28,9 @@ import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.UserManager;
import android.util.Pair;
import android.view.ContextThemeWrapper;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
@@ -63,6 +65,7 @@ public class BluetoothDevicePreferenceTest {
private static final String MAC_ADDRESS_4 = "07:52:C7:0B:D8:3C";
private static final Comparator<BluetoothDevicePreference> COMPARATOR =
Comparator.naturalOrder();
private static final String FAKE_DESCRIPTION = "fake_description";
private Context mContext;
@Mock
@@ -73,6 +76,8 @@ public class BluetoothDevicePreferenceTest {
private CachedBluetoothDevice mCachedDevice2;
@Mock
private CachedBluetoothDevice mCachedDevice3;
@Mock
private Drawable mDrawable;
private FakeFeatureFactory mFakeFeatureFactory;
private MetricsFeatureProvider mMetricsFeatureProvider;
@@ -87,9 +92,17 @@ public class BluetoothDevicePreferenceTest {
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider();
when(mCachedBluetoothDevice.getAddress()).thenReturn(MAC_ADDRESS);
when(mCachedBluetoothDevice.getDrawableWithDescription())
.thenReturn(new Pair<>(mDrawable, FAKE_DESCRIPTION));
when(mCachedDevice1.getAddress()).thenReturn(MAC_ADDRESS_2);
when(mCachedDevice1.getDrawableWithDescription())
.thenReturn(new Pair<>(mDrawable, FAKE_DESCRIPTION));
when(mCachedDevice2.getAddress()).thenReturn(MAC_ADDRESS_3);
when(mCachedDevice2.getDrawableWithDescription())
.thenReturn(new Pair<>(mDrawable, FAKE_DESCRIPTION));
when(mCachedDevice3.getAddress()).thenReturn(MAC_ADDRESS_4);
when(mCachedDevice3.getDrawableWithDescription())
.thenReturn(new Pair<>(mDrawable, FAKE_DESCRIPTION));
mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
SHOW_DEVICES_WITHOUT_NAMES, BluetoothDevicePreference.SortType.TYPE_DEFAULT);
}