Merge "Show advanced device icon in Connected devices list by new metadata" into sc-dev
This commit is contained in:
@@ -13,11 +13,14 @@ import android.graphics.Canvas;
|
|||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.provider.DeviceConfig;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
import androidx.annotation.DrawableRes;
|
import androidx.annotation.DrawableRes;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.core.graphics.drawable.IconCompat;
|
import androidx.core.graphics.drawable.IconCompat;
|
||||||
|
|
||||||
import com.android.settingslib.R;
|
import com.android.settingslib.R;
|
||||||
@@ -34,6 +37,7 @@ public class BluetoothUtils {
|
|||||||
public static final boolean D = true; // regular logging
|
public static final boolean D = true; // regular logging
|
||||||
|
|
||||||
public static final int META_INT_ERROR = -1;
|
public static final int META_INT_ERROR = -1;
|
||||||
|
public static final String BT_ADVANCED_HEADER_ENABLED = "bt_advanced_header_enabled";
|
||||||
|
|
||||||
private static ErrorListener sErrorListener;
|
private static ErrorListener sErrorListener;
|
||||||
|
|
||||||
@@ -178,14 +182,12 @@ public class BluetoothUtils {
|
|||||||
final Pair<Drawable, String> pair = BluetoothUtils.getBtClassDrawableWithDescription(
|
final Pair<Drawable, String> pair = BluetoothUtils.getBtClassDrawableWithDescription(
|
||||||
context, cachedDevice);
|
context, cachedDevice);
|
||||||
final BluetoothDevice bluetoothDevice = cachedDevice.getDevice();
|
final BluetoothDevice bluetoothDevice = cachedDevice.getDevice();
|
||||||
final boolean untetheredHeadset = getBooleanMetaData(
|
|
||||||
bluetoothDevice, BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET);
|
|
||||||
final int iconSize = context.getResources().getDimensionPixelSize(
|
final int iconSize = context.getResources().getDimensionPixelSize(
|
||||||
R.dimen.bt_nearby_icon_size);
|
R.dimen.bt_nearby_icon_size);
|
||||||
final Resources resources = context.getResources();
|
final Resources resources = context.getResources();
|
||||||
|
|
||||||
// Deal with untethered headset
|
// Deal with advanced device icon
|
||||||
if (untetheredHeadset) {
|
if (isAdvancedDetailsHeader(bluetoothDevice)) {
|
||||||
final Uri iconUri = getUriMetaData(bluetoothDevice,
|
final Uri iconUri = getUriMetaData(bluetoothDevice,
|
||||||
BluetoothDevice.METADATA_MAIN_ICON);
|
BluetoothDevice.METADATA_MAIN_ICON);
|
||||||
if (iconUri != null) {
|
if (iconUri != null) {
|
||||||
@@ -216,6 +218,35 @@ public class BluetoothUtils {
|
|||||||
return new Pair<>(pair.first, pair.second);
|
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.
|
* Create an Icon pointing to a drawable.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -150,4 +150,45 @@ public class BluetoothUtilsTest {
|
|||||||
assertThat(BluetoothUtils.getUriMetaData(mBluetoothDevice,
|
assertThat(BluetoothUtils.getUriMetaData(mBluetoothDevice,
|
||||||
BluetoothDevice.METADATA_MAIN_ICON)).isNull();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user