Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java +43 −6 Original line number Diff line number Diff line Loading @@ -237,14 +237,10 @@ public class BluetoothUtils { * @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"); if (!isAdvancedHeaderEnabled()) { return false; } // The metadata is for Android R if (getBooleanMetaData(bluetoothDevice, BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)) { Log.d(TAG, "isAdvancedDetailsHeader: untetheredHeadset is true"); if (isUntetheredHeadset(bluetoothDevice)) { return true; } // The metadata is for Android S Loading @@ -259,6 +255,47 @@ public class BluetoothUtils { return false; } /** * Check if the Bluetooth device is supports advanced metadata and an untethered headset * * @param bluetoothDevice the BluetoothDevice to get metadata * @return true if it supports advanced metadata and an untethered headset, false otherwise. */ public static boolean isAdvancedUntetheredDevice(@NonNull BluetoothDevice bluetoothDevice) { if (!isAdvancedHeaderEnabled()) { return false; } if (isUntetheredHeadset(bluetoothDevice)) { 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)) { Log.d(TAG, "isAdvancedUntetheredDevice: is untethered device "); return true; } return false; } private static boolean isAdvancedHeaderEnabled() { if (!DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI, BT_ADVANCED_HEADER_ENABLED, true)) { Log.d(TAG, "isAdvancedDetailsHeader: advancedEnabled is false"); return false; } return true; } private static boolean isUntetheredHeadset(@NonNull BluetoothDevice bluetoothDevice) { // The metadata is for Android R if (getBooleanMetaData(bluetoothDevice, BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)) { Log.d(TAG, "isAdvancedDetailsHeader: untetheredHeadset is true"); return true; } return false; } /** * Create an Icon pointing to a drawable. */ Loading packages/SettingsLib/src/com/android/settingslib/media/BluetoothMediaDevice.java +2 −2 Original line number Diff line number Diff line Loading @@ -59,14 +59,14 @@ public class BluetoothMediaDevice extends MediaDevice { @Override public Drawable getIcon() { return BluetoothUtils.isAdvancedDetailsHeader(mCachedDevice.getDevice()) return BluetoothUtils.isAdvancedUntetheredDevice(mCachedDevice.getDevice()) ? mContext.getDrawable(R.drawable.ic_earbuds_advanced) : BluetoothUtils.getBtClassDrawableWithDescription(mContext, mCachedDevice).first; } @Override public Drawable getIconWithoutBackground() { return BluetoothUtils.isAdvancedDetailsHeader(mCachedDevice.getDevice()) return BluetoothUtils.isAdvancedUntetheredDevice(mCachedDevice.getDevice()) ? mContext.getDrawable(R.drawable.ic_earbuds_advanced) : BluetoothUtils.getBtClassDrawableWithDescription(mContext, mCachedDevice).first; } Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java +41 −0 Original line number Diff line number Diff line Loading @@ -205,4 +205,45 @@ public class BluetoothUtilsTest { public void isAdvancedDetailsHeader_noMetadata_returnFalse() { assertThat(BluetoothUtils.isAdvancedDetailsHeader(mBluetoothDevice)).isEqualTo(false); } @Test public void isAdvancedUntetheredDevice_untetheredHeadset_returnTrue() { when(mBluetoothDevice.getMetadata( BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)).thenReturn( BOOL_METADATA.getBytes()); assertThat(BluetoothUtils.isAdvancedUntetheredDevice(mBluetoothDevice)).isEqualTo(true); } @Test public void isAdvancedUntetheredDevice_deviceTypeUntetheredHeadset_returnTrue() { when(mBluetoothDevice.getMetadata( BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn( BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET.getBytes()); assertThat(BluetoothUtils.isAdvancedUntetheredDevice(mBluetoothDevice)).isEqualTo(true); } @Test public void isAdvancedUntetheredDevice_deviceTypeWatch_returnFalse() { when(mBluetoothDevice.getMetadata( BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn( BluetoothDevice.DEVICE_TYPE_WATCH.getBytes()); assertThat(BluetoothUtils.isAdvancedUntetheredDevice(mBluetoothDevice)).isEqualTo(false); } @Test public void isAdvancedUntetheredDevice_deviceTypeDefault_returnFalse() { when(mBluetoothDevice.getMetadata( BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn( BluetoothDevice.DEVICE_TYPE_DEFAULT.getBytes()); assertThat(BluetoothUtils.isAdvancedUntetheredDevice(mBluetoothDevice)).isEqualTo(false); } @Test public void isAdvancedUntetheredDevice_noMetadata_returnFalse() { assertThat(BluetoothUtils.isAdvancedUntetheredDevice(mBluetoothDevice)).isEqualTo(false); } } Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java +43 −6 Original line number Diff line number Diff line Loading @@ -237,14 +237,10 @@ public class BluetoothUtils { * @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"); if (!isAdvancedHeaderEnabled()) { return false; } // The metadata is for Android R if (getBooleanMetaData(bluetoothDevice, BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)) { Log.d(TAG, "isAdvancedDetailsHeader: untetheredHeadset is true"); if (isUntetheredHeadset(bluetoothDevice)) { return true; } // The metadata is for Android S Loading @@ -259,6 +255,47 @@ public class BluetoothUtils { return false; } /** * Check if the Bluetooth device is supports advanced metadata and an untethered headset * * @param bluetoothDevice the BluetoothDevice to get metadata * @return true if it supports advanced metadata and an untethered headset, false otherwise. */ public static boolean isAdvancedUntetheredDevice(@NonNull BluetoothDevice bluetoothDevice) { if (!isAdvancedHeaderEnabled()) { return false; } if (isUntetheredHeadset(bluetoothDevice)) { 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)) { Log.d(TAG, "isAdvancedUntetheredDevice: is untethered device "); return true; } return false; } private static boolean isAdvancedHeaderEnabled() { if (!DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI, BT_ADVANCED_HEADER_ENABLED, true)) { Log.d(TAG, "isAdvancedDetailsHeader: advancedEnabled is false"); return false; } return true; } private static boolean isUntetheredHeadset(@NonNull BluetoothDevice bluetoothDevice) { // The metadata is for Android R if (getBooleanMetaData(bluetoothDevice, BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)) { Log.d(TAG, "isAdvancedDetailsHeader: untetheredHeadset is true"); return true; } return false; } /** * Create an Icon pointing to a drawable. */ Loading
packages/SettingsLib/src/com/android/settingslib/media/BluetoothMediaDevice.java +2 −2 Original line number Diff line number Diff line Loading @@ -59,14 +59,14 @@ public class BluetoothMediaDevice extends MediaDevice { @Override public Drawable getIcon() { return BluetoothUtils.isAdvancedDetailsHeader(mCachedDevice.getDevice()) return BluetoothUtils.isAdvancedUntetheredDevice(mCachedDevice.getDevice()) ? mContext.getDrawable(R.drawable.ic_earbuds_advanced) : BluetoothUtils.getBtClassDrawableWithDescription(mContext, mCachedDevice).first; } @Override public Drawable getIconWithoutBackground() { return BluetoothUtils.isAdvancedDetailsHeader(mCachedDevice.getDevice()) return BluetoothUtils.isAdvancedUntetheredDevice(mCachedDevice.getDevice()) ? mContext.getDrawable(R.drawable.ic_earbuds_advanced) : BluetoothUtils.getBtClassDrawableWithDescription(mContext, mCachedDevice).first; } Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java +41 −0 Original line number Diff line number Diff line Loading @@ -205,4 +205,45 @@ public class BluetoothUtilsTest { public void isAdvancedDetailsHeader_noMetadata_returnFalse() { assertThat(BluetoothUtils.isAdvancedDetailsHeader(mBluetoothDevice)).isEqualTo(false); } @Test public void isAdvancedUntetheredDevice_untetheredHeadset_returnTrue() { when(mBluetoothDevice.getMetadata( BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)).thenReturn( BOOL_METADATA.getBytes()); assertThat(BluetoothUtils.isAdvancedUntetheredDevice(mBluetoothDevice)).isEqualTo(true); } @Test public void isAdvancedUntetheredDevice_deviceTypeUntetheredHeadset_returnTrue() { when(mBluetoothDevice.getMetadata( BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn( BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET.getBytes()); assertThat(BluetoothUtils.isAdvancedUntetheredDevice(mBluetoothDevice)).isEqualTo(true); } @Test public void isAdvancedUntetheredDevice_deviceTypeWatch_returnFalse() { when(mBluetoothDevice.getMetadata( BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn( BluetoothDevice.DEVICE_TYPE_WATCH.getBytes()); assertThat(BluetoothUtils.isAdvancedUntetheredDevice(mBluetoothDevice)).isEqualTo(false); } @Test public void isAdvancedUntetheredDevice_deviceTypeDefault_returnFalse() { when(mBluetoothDevice.getMetadata( BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn( BluetoothDevice.DEVICE_TYPE_DEFAULT.getBytes()); assertThat(BluetoothUtils.isAdvancedUntetheredDevice(mBluetoothDevice)).isEqualTo(false); } @Test public void isAdvancedUntetheredDevice_noMetadata_returnFalse() { assertThat(BluetoothUtils.isAdvancedUntetheredDevice(mBluetoothDevice)).isEqualTo(false); } }