Use new api to get bluetooth device icon

This CL use CachedBluetoothDevice#getDrawableWithDescription()
to get bluetooth device icon.

Bug: 178255374
Test: make RunSettingsRoboTests -j56

Change-Id: I45c273e2dd782029da7a3a2724cbca3762cc2d9c
This commit is contained in:
Hugh Chen
2021-04-16 22:15:52 +08:00
parent 976c6ac56d
commit 3cf4c3f3a5
2 changed files with 16 additions and 11 deletions

View File

@@ -176,17 +176,9 @@ public final class BluetoothDevicePreference extends GearPreference {
} }
void onPreferenceAttributesChanged() { void onPreferenceAttributesChanged() {
ThreadUtils.postOnBackgroundThread(() -> { Pair<Drawable, String> pair = mCachedDevice.getDrawableWithDescription();
final Pair<Drawable, String> pair =
BluetoothUtils.getBtRainbowDrawableWithDescription(getContext(), mCachedDevice);
ThreadUtils.postOnMainThread(() -> {
if (pair.first != null) {
setIcon(pair.first); setIcon(pair.first);
contentDescription = pair.second; contentDescription = pair.second;
}
});
});
/* /*
* The preference framework takes care of making sure the value has * 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.bluetooth.BluetoothDevice;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.UserManager; import android.os.UserManager;
import android.util.Pair;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent; 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 String MAC_ADDRESS_4 = "07:52:C7:0B:D8:3C";
private static final Comparator<BluetoothDevicePreference> COMPARATOR = private static final Comparator<BluetoothDevicePreference> COMPARATOR =
Comparator.naturalOrder(); Comparator.naturalOrder();
private static final String FAKE_DESCRIPTION = "fake_description";
private Context mContext; private Context mContext;
@Mock @Mock
@@ -73,6 +76,8 @@ public class BluetoothDevicePreferenceTest {
private CachedBluetoothDevice mCachedDevice2; private CachedBluetoothDevice mCachedDevice2;
@Mock @Mock
private CachedBluetoothDevice mCachedDevice3; private CachedBluetoothDevice mCachedDevice3;
@Mock
private Drawable mDrawable;
private FakeFeatureFactory mFakeFeatureFactory; private FakeFeatureFactory mFakeFeatureFactory;
private MetricsFeatureProvider mMetricsFeatureProvider; private MetricsFeatureProvider mMetricsFeatureProvider;
@@ -87,9 +92,17 @@ public class BluetoothDevicePreferenceTest {
mFakeFeatureFactory = FakeFeatureFactory.setupForTest(); mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider(); mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider();
when(mCachedBluetoothDevice.getAddress()).thenReturn(MAC_ADDRESS); when(mCachedBluetoothDevice.getAddress()).thenReturn(MAC_ADDRESS);
when(mCachedBluetoothDevice.getDrawableWithDescription())
.thenReturn(new Pair<>(mDrawable, FAKE_DESCRIPTION));
when(mCachedDevice1.getAddress()).thenReturn(MAC_ADDRESS_2); 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.getAddress()).thenReturn(MAC_ADDRESS_3);
when(mCachedDevice2.getDrawableWithDescription())
.thenReturn(new Pair<>(mDrawable, FAKE_DESCRIPTION));
when(mCachedDevice3.getAddress()).thenReturn(MAC_ADDRESS_4); when(mCachedDevice3.getAddress()).thenReturn(MAC_ADDRESS_4);
when(mCachedDevice3.getDrawableWithDescription())
.thenReturn(new Pair<>(mDrawable, FAKE_DESCRIPTION));
mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
SHOW_DEVICES_WITHOUT_NAMES, BluetoothDevicePreference.SortType.TYPE_DEFAULT); SHOW_DEVICES_WITHOUT_NAMES, BluetoothDevicePreference.SortType.TYPE_DEFAULT);
} }