Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java +17 −0 Original line number Diff line number Diff line Loading @@ -73,6 +73,10 @@ public class BluetoothUtils { private static final Set<Integer> SA_PROFILES = ImmutableSet.of( BluetoothProfile.A2DP, BluetoothProfile.LE_AUDIO, BluetoothProfile.HEARING_AID); private static final List<Integer> BLUETOOTH_DEVICE_CLASS_HEADSET = List.of( BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES, BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET); private static final String TEMP_BOND_TYPE = "TEMP_BOND_TYPE"; private static final String TEMP_BOND_DEVICE_METADATA_VALUE = "le_audio_sharing"; Loading Loading @@ -390,6 +394,19 @@ public class BluetoothUtils { return false; } /** Checks whether the bluetooth device is a headset. */ public static boolean isHeadset(@NonNull BluetoothDevice bluetoothDevice) { String deviceType = BluetoothUtils.getStringMetaData( bluetoothDevice, BluetoothDevice.METADATA_DEVICE_TYPE); if (!TextUtils.isEmpty(deviceType)) { return BluetoothDevice.DEVICE_TYPE_HEADSET.equals(deviceType) || BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET.equals(deviceType); } BluetoothClass btClass = bluetoothDevice.getBluetoothClass(); return btClass != null && BLUETOOTH_DEVICE_CLASS_HEADSET.contains(btClass.getDeviceClass()); } /** Create an Icon pointing to a drawable. */ public static IconCompat createIconWithDrawable(Drawable drawable) { Bitmap bitmap; Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java +35 −1 Original line number Diff line number Diff line Loading @@ -80,7 +80,9 @@ public class BluetoothUtilsTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) private CachedBluetoothDevice mCachedBluetoothDevice; @Mock private BluetoothDevice mBluetoothDevice; @Mock(answer = Answers.RETURNS_DEEP_STUBS) private BluetoothDevice mBluetoothDevice; @Mock private AudioManager mAudioManager; @Mock private PackageManager mPackageManager; @Mock private LeAudioProfile mA2dpProfile; Loading Loading @@ -398,6 +400,38 @@ public class BluetoothUtilsTest { assertThat(BluetoothUtils.isAdvancedUntetheredDevice(mBluetoothDevice)).isFalse(); } @Test public void isHeadset_metadataMatched_returnTrue() { when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_DEVICE_TYPE)) .thenReturn(BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET.getBytes()); assertThat(BluetoothUtils.isHeadset(mBluetoothDevice)).isTrue(); } @Test public void isHeadset_metadataNotMatched_returnFalse() { when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_DEVICE_TYPE)) .thenReturn(BluetoothDevice.DEVICE_TYPE_CARKIT.getBytes()); assertThat(BluetoothUtils.isHeadset(mBluetoothDevice)).isFalse(); } @Test public void isHeadset_btClassMatched_returnTrue() { when(mBluetoothDevice.getBluetoothClass().getDeviceClass()) .thenReturn(BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES); assertThat(BluetoothUtils.isHeadset(mBluetoothDevice)).isTrue(); } @Test public void isHeadset_btClassNotMatched_returnFalse() { when(mBluetoothDevice.getBluetoothClass().getDeviceClass()) .thenReturn(BluetoothClass.Device.AUDIO_VIDEO_LOUDSPEAKER); assertThat(BluetoothUtils.isHeadset(mBluetoothDevice)).isFalse(); } @Test public void isAvailableMediaBluetoothDevice_isConnectedLeAudioDevice_returnTrue() { when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true); Loading Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java +17 −0 Original line number Diff line number Diff line Loading @@ -73,6 +73,10 @@ public class BluetoothUtils { private static final Set<Integer> SA_PROFILES = ImmutableSet.of( BluetoothProfile.A2DP, BluetoothProfile.LE_AUDIO, BluetoothProfile.HEARING_AID); private static final List<Integer> BLUETOOTH_DEVICE_CLASS_HEADSET = List.of( BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES, BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET); private static final String TEMP_BOND_TYPE = "TEMP_BOND_TYPE"; private static final String TEMP_BOND_DEVICE_METADATA_VALUE = "le_audio_sharing"; Loading Loading @@ -390,6 +394,19 @@ public class BluetoothUtils { return false; } /** Checks whether the bluetooth device is a headset. */ public static boolean isHeadset(@NonNull BluetoothDevice bluetoothDevice) { String deviceType = BluetoothUtils.getStringMetaData( bluetoothDevice, BluetoothDevice.METADATA_DEVICE_TYPE); if (!TextUtils.isEmpty(deviceType)) { return BluetoothDevice.DEVICE_TYPE_HEADSET.equals(deviceType) || BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET.equals(deviceType); } BluetoothClass btClass = bluetoothDevice.getBluetoothClass(); return btClass != null && BLUETOOTH_DEVICE_CLASS_HEADSET.contains(btClass.getDeviceClass()); } /** Create an Icon pointing to a drawable. */ public static IconCompat createIconWithDrawable(Drawable drawable) { Bitmap bitmap; Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java +35 −1 Original line number Diff line number Diff line Loading @@ -80,7 +80,9 @@ public class BluetoothUtilsTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) private CachedBluetoothDevice mCachedBluetoothDevice; @Mock private BluetoothDevice mBluetoothDevice; @Mock(answer = Answers.RETURNS_DEEP_STUBS) private BluetoothDevice mBluetoothDevice; @Mock private AudioManager mAudioManager; @Mock private PackageManager mPackageManager; @Mock private LeAudioProfile mA2dpProfile; Loading Loading @@ -398,6 +400,38 @@ public class BluetoothUtilsTest { assertThat(BluetoothUtils.isAdvancedUntetheredDevice(mBluetoothDevice)).isFalse(); } @Test public void isHeadset_metadataMatched_returnTrue() { when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_DEVICE_TYPE)) .thenReturn(BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET.getBytes()); assertThat(BluetoothUtils.isHeadset(mBluetoothDevice)).isTrue(); } @Test public void isHeadset_metadataNotMatched_returnFalse() { when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_DEVICE_TYPE)) .thenReturn(BluetoothDevice.DEVICE_TYPE_CARKIT.getBytes()); assertThat(BluetoothUtils.isHeadset(mBluetoothDevice)).isFalse(); } @Test public void isHeadset_btClassMatched_returnTrue() { when(mBluetoothDevice.getBluetoothClass().getDeviceClass()) .thenReturn(BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES); assertThat(BluetoothUtils.isHeadset(mBluetoothDevice)).isTrue(); } @Test public void isHeadset_btClassNotMatched_returnFalse() { when(mBluetoothDevice.getBluetoothClass().getDeviceClass()) .thenReturn(BluetoothClass.Device.AUDIO_VIDEO_LOUDSPEAKER); assertThat(BluetoothUtils.isHeadset(mBluetoothDevice)).isFalse(); } @Test public void isAvailableMediaBluetoothDevice_isConnectedLeAudioDevice_returnTrue() { when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true); Loading