diff options
2 files changed, 76 insertions, 4 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java index 8f8f859d1ada..253629c8d128 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java @@ -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) { @@ -217,6 +219,35 @@ public class BluetoothUtils { } /** + * 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. */ public static IconCompat createIconWithDrawable(Drawable drawable) { diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java index 3a95852c0ba9..2e855145e152 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java @@ -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); + } } |