Merge "Show advanced device icon in Connected devices list by new metadata" into sc-dev

This commit is contained in:
tim peng
2021-03-29 04:23:01 +00:00
committed by Android (Google) Code Review
2 changed files with 76 additions and 4 deletions

View File

@@ -13,11 +13,14 @@ import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.provider.DeviceConfig;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.core.graphics.drawable.IconCompat;
import com.android.settingslib.R;
@@ -34,6 +37,7 @@ public class BluetoothUtils {
public static final boolean D = true; // regular logging
public static final int META_INT_ERROR = -1;
public static final String BT_ADVANCED_HEADER_ENABLED = "bt_advanced_header_enabled";
private static ErrorListener sErrorListener;
@@ -178,14 +182,12 @@ public class BluetoothUtils {
final Pair<Drawable, String> pair = BluetoothUtils.getBtClassDrawableWithDescription(
context, cachedDevice);
final BluetoothDevice bluetoothDevice = cachedDevice.getDevice();
final boolean untetheredHeadset = getBooleanMetaData(
bluetoothDevice, BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET);
final int iconSize = context.getResources().getDimensionPixelSize(
R.dimen.bt_nearby_icon_size);
final Resources resources = context.getResources();
// Deal with untethered headset
if (untetheredHeadset) {
// Deal with advanced device icon
if (isAdvancedDetailsHeader(bluetoothDevice)) {
final Uri iconUri = getUriMetaData(bluetoothDevice,
BluetoothDevice.METADATA_MAIN_ICON);
if (iconUri != null) {
@@ -216,6 +218,35 @@ public class BluetoothUtils {
return new Pair<>(pair.first, pair.second);
}
/**
* Check if the Bluetooth device supports advanced metadata
*
* @param bluetoothDevice the BluetoothDevice to get metadata
* @return true if it supports advanced metadata, false otherwise.
*/
public static boolean isAdvancedDetailsHeader(@NonNull BluetoothDevice bluetoothDevice) {
if (!DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI, BT_ADVANCED_HEADER_ENABLED,
true)) {
Log.d(TAG, "isAdvancedDetailsHeader: advancedEnabled is false");
return false;
}
// The metadata is for Android R
if (getBooleanMetaData(bluetoothDevice, BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)) {
Log.d(TAG, "isAdvancedDetailsHeader: untetheredHeadset is true");
return true;
}
// The metadata is for Android S
String deviceType = getStringMetaData(bluetoothDevice,
BluetoothDevice.METADATA_DEVICE_TYPE);
if (TextUtils.equals(deviceType, BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET)
|| TextUtils.equals(deviceType, BluetoothDevice.DEVICE_TYPE_WATCH)
|| TextUtils.equals(deviceType, BluetoothDevice.DEVICE_TYPE_DEFAULT)) {
Log.d(TAG, "isAdvancedDetailsHeader: deviceType is " + deviceType);
return true;
}
return false;
}
/**
* Create an Icon pointing to a drawable.
*/

View File

@@ -150,4 +150,45 @@ public class BluetoothUtilsTest {
assertThat(BluetoothUtils.getUriMetaData(mBluetoothDevice,
BluetoothDevice.METADATA_MAIN_ICON)).isNull();
}
@Test
public void isAdvancedDetailsHeader_untetheredHeadset_returnTrue() {
when(mBluetoothDevice.getMetadata(
BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)).thenReturn(
BOOL_METADATA.getBytes());
assertThat(BluetoothUtils.isAdvancedDetailsHeader(mBluetoothDevice)).isEqualTo(true);
}
@Test
public void isAdvancedDetailsHeader_deviceTypeUntetheredHeadset_returnTrue() {
when(mBluetoothDevice.getMetadata(
BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn(
BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET.getBytes());
assertThat(BluetoothUtils.isAdvancedDetailsHeader(mBluetoothDevice)).isEqualTo(true);
}
@Test
public void isAdvancedDetailsHeader_deviceTypeWatch_returnTrue() {
when(mBluetoothDevice.getMetadata(
BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn(
BluetoothDevice.DEVICE_TYPE_WATCH.getBytes());
assertThat(BluetoothUtils.isAdvancedDetailsHeader(mBluetoothDevice)).isEqualTo(true);
}
@Test
public void isAdvancedDetailsHeader_deviceTypeDefault_returnTrue() {
when(mBluetoothDevice.getMetadata(
BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn(
BluetoothDevice.DEVICE_TYPE_DEFAULT.getBytes());
assertThat(BluetoothUtils.isAdvancedDetailsHeader(mBluetoothDevice)).isEqualTo(true);
}
@Test
public void isAdvancedDetailsHeader_noMetadata_returnFalse() {
assertThat(BluetoothUtils.isAdvancedDetailsHeader(mBluetoothDevice)).isEqualTo(false);
}
}