summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--android/app/aidl/android/bluetooth/IBluetooth.aidl4
-rw-r--r--android/app/src/com/android/bluetooth/btservice/AdapterService.java38
-rw-r--r--framework/api/system-current.txt2
-rw-r--r--framework/java/android/bluetooth/BluetoothDevice.java35
4 files changed, 51 insertions, 28 deletions
diff --git a/android/app/aidl/android/bluetooth/IBluetooth.aidl b/android/app/aidl/android/bluetooth/IBluetooth.aidl
index b9cf6bca14..bc46353f7c 100644
--- a/android/app/aidl/android/bluetooth/IBluetooth.aidl
+++ b/android/app/aidl/android/bluetooth/IBluetooth.aidl
@@ -100,7 +100,9 @@ interface IBluetooth
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
List<BluetoothDevice> getBondedDevices(in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
- boolean createBond(in BluetoothDevice device, in int transport, in OobData p192Data, in OobData p256Data, in AttributionSource attributionSource);
+ boolean createBond(in BluetoothDevice device, in int transport, in AttributionSource attributionSource);
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
+ boolean createBondOutOfBand(in BluetoothDevice device, in int transport, in OobData p192Data, in OobData p256Data, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
boolean cancelBondProcess(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
diff --git a/android/app/src/com/android/bluetooth/btservice/AdapterService.java b/android/app/src/com/android/bluetooth/btservice/AdapterService.java
index 87f5daad12..eff7a6e132 100644
--- a/android/app/src/com/android/bluetooth/btservice/AdapterService.java
+++ b/android/app/src/com/android/bluetooth/btservice/AdapterService.java
@@ -2551,6 +2551,29 @@ public class AdapterService extends Service {
public boolean createBond(
BluetoothDevice device,
int transport,
+ AttributionSource source) {
+ AdapterService service = getService();
+ if (service == null
+ || !callerIsSystemOrActiveOrManagedUser(service, TAG, "createBond")
+ || !Utils.checkConnectPermissionForDataDelivery(
+ service, source, "AdapterService createBond")) {
+ return false;
+ }
+
+ Log.i(
+ TAG,
+ "createBond:"
+ + (" device=" + device)
+ + (" transport=" + transport)
+ + (" from " + Utils.getUidPidString()));
+ return service.createBond(
+ device, transport, null, null, source.getPackageName());
+ }
+
+ @Override
+ public boolean createBondOutOfBand(
+ BluetoothDevice device,
+ int transport,
OobData remoteP192Data,
OobData remoteP256Data,
AttributionSource source) {
@@ -2562,14 +2585,11 @@ public class AdapterService extends Service {
return false;
}
- // This conditional is required to satisfy permission dependencies
- // since createBond calls createBondOutOfBand with null value passed as data.
- // BluetoothDevice#createBond requires BLUETOOTH_ADMIN only.
- service.enforceBluetoothPrivilegedPermissionIfNeeded(remoteP192Data, remoteP256Data);
+ service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);
Log.i(
TAG,
- "createBond:"
+ "createBondOutOfBand:"
+ (" device=" + device)
+ (" transport=" + transport)
+ (" from " + Utils.getUidPidString()));
@@ -6701,14 +6721,6 @@ public class AdapterService extends Service {
}
}
- @SuppressLint("AndroidFrameworkRequiresPermission")
- private void enforceBluetoothPrivilegedPermissionIfNeeded(
- OobData remoteP192Data, OobData remoteP256Data) {
- if (remoteP192Data != null || remoteP256Data != null) {
- this.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);
- }
- }
-
private final Object mDeviceConfigLock = new Object();
/**
diff --git a/framework/api/system-current.txt b/framework/api/system-current.txt
index 10bdab4b5c..cdb9bf0670 100644
--- a/framework/api/system-current.txt
+++ b/framework/api/system-current.txt
@@ -247,7 +247,7 @@ package android.bluetooth {
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean cancelBondProcess();
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED, android.Manifest.permission.MODIFY_PHONE_STATE}) public int connect();
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean createBond(int);
- method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean createBondOutOfBand(int, @Nullable android.bluetooth.OobData, @Nullable android.bluetooth.OobData);
+ method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean createBondOutOfBand(int, @Nullable android.bluetooth.OobData, @Nullable android.bluetooth.OobData);
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int disconnect();
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}, conditional=true) public boolean fetchUuidsWithSdp(int);
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getActiveAudioDevicePolicy();
diff --git a/framework/java/android/bluetooth/BluetoothDevice.java b/framework/java/android/bluetooth/BluetoothDevice.java
index c7f3b8a052..d5ec86546c 100644
--- a/framework/java/android/bluetooth/BluetoothDevice.java
+++ b/framework/java/android/bluetooth/BluetoothDevice.java
@@ -1950,7 +1950,21 @@ public final class BluetoothDevice implements Parcelable, Attributable {
@RequiresBluetoothConnectPermission
@RequiresPermission(BLUETOOTH_CONNECT)
public boolean createBond(int transport) {
- return createBondInternal(transport, null, null);
+ if (DBG) log("createBond()");
+ final IBluetooth service = getService();
+ if (service == null || !isBluetoothEnabled()) {
+ Log.w(TAG, "BT not enabled, createBond failed");
+ if (DBG) log(Log.getStackTraceString(new Throwable()));
+ } else if (NULL_MAC_ADDRESS.equals(mAddress)) {
+ Log.e(TAG, "Unable to create bond, invalid address " + mAddress);
+ } else {
+ try {
+ return service.createBond(this, transport, mAttributionSource);
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
+ }
+ }
+ return false;
}
/**
@@ -1974,30 +1988,25 @@ public final class BluetoothDevice implements Parcelable, Attributable {
* @hide
*/
@SystemApi
- @RequiresPermission(BLUETOOTH_CONNECT)
+ @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED})
public boolean createBondOutOfBand(
int transport, @Nullable OobData remoteP192Data, @Nullable OobData remoteP256Data) {
+ if (DBG) log("createBondOutOfBand()");
+ final IBluetooth service = getService();
+
if (remoteP192Data == null && remoteP256Data == null) {
throw new IllegalArgumentException(
"One or both arguments for the OOB data types are required to not be null. "
+ " Please use createBond() instead if you do not have OOB data to pass.");
}
- return createBondInternal(transport, remoteP192Data, remoteP256Data);
- }
-
- @RequiresPermission(BLUETOOTH_CONNECT)
- private boolean createBondInternal(
- int transport, @Nullable OobData remoteP192Data, @Nullable OobData remoteP256Data) {
- if (DBG) log("createBondInternal()");
- final IBluetooth service = getService();
if (service == null || !isBluetoothEnabled()) {
- Log.w(TAG, "BT not enabled, createBondInternal failed");
+ Log.w(TAG, "BT not enabled, createBondOutOfBand failed");
if (DBG) log(Log.getStackTraceString(new Throwable()));
} else if (NULL_MAC_ADDRESS.equals(mAddress)) {
- Log.e(TAG, "Unable to create bond, invalid address " + mAddress);
+ Log.e(TAG, "Unable to create bond Out of Band, invalid address " + mAddress);
} else {
try {
- return service.createBond(
+ return service.createBondOutOfBand(
this, transport, remoteP192Data, remoteP256Data, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));