Merge "Introduce isDeviceClassMatched() to align BluetoothClass comparison" am: 75117f499c am: 3143d81f97

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2372630

Change-Id: I42be4eb4b00eabfab9588c0c6149f8579931cc16
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
William Escande
2023-01-05 07:02:43 +00:00
committed by Automerger Merge Worker
2 changed files with 16 additions and 5 deletions

View File

@@ -278,6 +278,18 @@ public class BluetoothUtils {
return false; return false;
} }
/**
* Check if a device class matches with a defined BluetoothClass device.
*
* @param device Must be one of the public constants in {@link BluetoothClass.Device}
* @return true if device class matches, false otherwise.
*/
public static boolean isDeviceClassMatched(@NonNull BluetoothDevice bluetoothDevice,
int device) {
return bluetoothDevice.getBluetoothClass() != null
&& bluetoothDevice.getBluetoothClass().getDeviceClass() == device;
}
private static boolean isAdvancedHeaderEnabled() { private static boolean isAdvancedHeaderEnabled() {
if (!DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI, BT_ADVANCED_HEADER_ENABLED, if (!DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI, BT_ADVANCED_HEADER_ENABLED,
true)) { true)) {

View File

@@ -1026,12 +1026,11 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
if (BluetoothUuid.containsAnyUuid(uuids, PbapServerProfile.PBAB_CLIENT_UUIDS)) { if (BluetoothUuid.containsAnyUuid(uuids, PbapServerProfile.PBAB_CLIENT_UUIDS)) {
// The pairing dialog now warns of phone-book access for paired devices. // The pairing dialog now warns of phone-book access for paired devices.
// No separate prompt is displayed after pairing. // No separate prompt is displayed after pairing.
final BluetoothClass bluetoothClass = mDevice.getBluetoothClass();
if (mDevice.getPhonebookAccessPermission() == BluetoothDevice.ACCESS_UNKNOWN) { if (mDevice.getPhonebookAccessPermission() == BluetoothDevice.ACCESS_UNKNOWN) {
if (bluetoothClass != null && (bluetoothClass.getDeviceClass() if (BluetoothUtils.isDeviceClassMatched(mDevice,
== BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE)
|| bluetoothClass.getDeviceClass() || BluetoothUtils.isDeviceClassMatched(mDevice,
== BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET)) { BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET)) {
EventLog.writeEvent(0x534e4554, "138529441", -1, ""); EventLog.writeEvent(0x534e4554, "138529441", -1, "");
} }
} }