From ee291365417b741a2a30844cd0d42514c77ae02e Mon Sep 17 00:00:00 2001 From: Alice Kuo Date: Fri, 13 Aug 2021 00:17:17 +0800 Subject: [PATCH] Add a system api to fetch uuids by the specific transport The functionality is similar with fetchUuidsWithSdp which uses TRANSPORT_AUTO. Bt stack depends on the devie type and address type to do sdp or gatt service discovery. Add an api to specific the transport. It would be fexible to handle the dual mode device. Tag: #feature Bug: 197195548 Test: atest BluetoothInstrumentationTests Test: Take two headphone to test the dual mode behavior Change-Id: I32c8dde68969e0bdc42e4e898c43a4f2c1d3379a Merged-In: I32c8dde68969e0bdc42e4e898c43a4f2c1d3379a --- core/api/system-current.txt | 1 + .../android/bluetooth/BluetoothDevice.java | 27 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index aa528ba007263..a0e6146893459 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -1510,6 +1510,7 @@ package android.bluetooth { public final class BluetoothDevice implements android.os.Parcelable { method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean cancelBondProcess(); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean createBondOutOfBand(int, @Nullable android.bluetooth.OobData, @Nullable android.bluetooth.OobData); + method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean fetchUuidsWithSdp(int); method @Nullable @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public byte[] getMetadata(int); method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public int getSimAccessPermission(); method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public boolean isConnected(); diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java index 0969ec2269b19..38fb90d9c4a75 100644 --- a/core/java/android/bluetooth/BluetoothDevice.java +++ b/core/java/android/bluetooth/BluetoothDevice.java @@ -1622,13 +1622,38 @@ public final class BluetoothDevice implements Parcelable { */ @RequiresPermission(Manifest.permission.BLUETOOTH) public boolean fetchUuidsWithSdp() { + return fetchUuidsWithSdp(TRANSPORT_AUTO); + } + + /** + * Perform a service discovery on the remote device to get the UUIDs supported with the + * specific transport. + * + *

This API is asynchronous and {@link #ACTION_UUID} intent is sent, + * with the UUIDs supported by the remote end. If there is an error + * in getting the SDP or GATT records or if the process takes a long time, or the device + * is bonding and we have its UUIDs cached, {@link #ACTION_UUID} intent is sent with the + * UUIDs that is currently present in the cache. Clients should use the {@link #getUuids} + * to get UUIDs if service discovery is not to be performed. If there is an ongoing bonding + * process, service discovery or device inquiry, the request will be queued. + * + * @param transport - provide type of transport (e.g. LE or Classic). + * @return False if the check fails, True if the process of initiating an ACL connection + * to the remote device was started or cached UUIDs will be broadcast with the specific + * transport. + * + * @hide + */ + @SystemApi + @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED) + public boolean fetchUuidsWithSdp(@Transport int transport) { final IBluetooth service = sService; if (service == null || !isBluetoothEnabled()) { Log.e(TAG, "BT not enabled. Cannot fetchUuidsWithSdp"); return false; } try { - return service.fetchRemoteUuids(this); + return service.fetchRemoteUuids(this, transport); } catch (RemoteException e) { Log.e(TAG, "", e); }