From 626ffc2010c51cb22f63cc3306c88be9f01204bc Mon Sep 17 00:00:00 2001 From: Rahul Sabnis Date: Fri, 29 Jan 2021 12:38:13 -0800 Subject: [PATCH] Skips the consent pairing dialog for recently associated CDM app and device combos because they have already been shown the CDM prompt which implicitly provides consent to bond. Tag: #feature Bug: 172006481 Test: Manual Change-Id: I541b720c6b8b6e55be10e04f202e0a58cf33715f --- core/api/system-current.txt | 1 + .../android/bluetooth/BluetoothAdapter.java | 2 +- .../android/bluetooth/BluetoothDevice.java | 28 ++++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index bfdce373a47e2..42bc39ce9e6d0 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -1849,6 +1849,7 @@ package android.bluetooth { } public final class BluetoothDevice implements android.os.Parcelable { + method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean canBondWithoutDialog(); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean cancelBondProcess(); method @Nullable @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public byte[] getMetadata(int); method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public int getSimAccessPermission(); diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java index ea7e5ea7c802a..ec46da0dcf0eb 100644 --- a/core/java/android/bluetooth/BluetoothAdapter.java +++ b/core/java/android/bluetooth/BluetoothAdapter.java @@ -1654,7 +1654,7 @@ public final class BluetoothAdapter { mContext = context; } - private String getOpPackageName() { + String getOpPackageName() { // Workaround for legacy API for getting a BluetoothAdapter not // passing a context if (mContext != null) { diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java index 3b8dec7bf9556..e7661dbad749e 100644 --- a/core/java/android/bluetooth/BluetoothDevice.java +++ b/core/java/android/bluetooth/BluetoothDevice.java @@ -1236,7 +1236,8 @@ public final class BluetoothDevice implements Parcelable { return false; } try { - return service.createBond(this, transport, oobData); + BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); + return service.createBond(this, transport, oobData, adapter.getOpPackageName()); } catch (RemoteException e) { Log.e(TAG, "", e); } @@ -1393,6 +1394,31 @@ public final class BluetoothDevice implements Parcelable { return BOND_NONE; } + /** + * Checks whether this bluetooth device is associated with CDM and meets the criteria to skip + * the bluetooth pairing dialog because it has been already consented by the CDM prompt. + * + * @return true if we can bond without the dialog, false otherwise + * + * @hide + */ + @SystemApi + @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED) + public boolean canBondWithoutDialog() { + final IBluetooth service = sService; + if (service == null) { + Log.e(TAG, "BT not enabled. Cannot check if we can skip pairing dialog"); + return false; + } + try { + if (DBG) Log.d(TAG, "canBondWithoutDialog, device: " + this); + return service.canBondWithoutDialog(this); + } catch (RemoteException e) { + Log.e(TAG, "", e); + } + return false; + } + /** * Returns whether there is an open connection to this device. *