summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Sal Savage <salsavage@google.com> 2021-09-02 11:52:23 -0700
committer Sal Savage <salsavage@google.com> 2021-10-01 18:17:37 +0000
commit8dafa60a2fcf8beec61b5ddbc7729b861865b05c (patch)
tree0a5cd002b20c80701dbe621abeb87d0b0d6ec013
parentc0da9473bc94db68c20e4ea27ebfdcbefc1cc54b (diff)
Make BluetoothAdapter#disable(boolean persist) a @SystemApi
Bug: 196235708 Test: build, flash car hardware, test basic functionality Change-Id: I952c3d2ce3b7ec70a384e9a96e172d6ab90c23e8
-rw-r--r--core/api/system-current.txt1
-rw-r--r--core/java/android/bluetooth/BluetoothAdapter.java8
-rw-r--r--services/core/java/com/android/server/BluetoothManagerService.java7
3 files changed, 13 insertions, 3 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index ba7903b6c7b6..6b170bcf14db 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -1937,6 +1937,7 @@ package android.bluetooth {
public final class BluetoothAdapter {
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean addOnMetadataChangedListener(@NonNull android.bluetooth.BluetoothDevice, @NonNull java.util.concurrent.Executor, @NonNull android.bluetooth.BluetoothAdapter.OnMetadataChangedListener);
+ method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean disable(boolean);
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean disableBLE();
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean enableBLE();
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean enableNoAutoConnect();
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java
index e9be0ecd2044..9c69903d5995 100644
--- a/core/java/android/bluetooth/BluetoothAdapter.java
+++ b/core/java/android/bluetooth/BluetoothAdapter.java
@@ -1245,13 +1245,17 @@ public final class BluetoothAdapter {
/**
* Turn off the local Bluetooth adapter and don't persist the setting.
*
+ * @param persist Indicate whether the off state should be persisted following the next reboot
* @return true to indicate adapter shutdown has begun, or false on immediate error
* @hide
*/
- @UnsupportedAppUsage(trackingBug = 171933273)
+ @SystemApi
@RequiresLegacyBluetoothAdminPermission
@RequiresBluetoothConnectPermission
- @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
+ @RequiresPermission(allOf = {
+ android.Manifest.permission.BLUETOOTH_CONNECT,
+ android.Manifest.permission.BLUETOOTH_PRIVILEGED,
+ })
public boolean disable(boolean persist) {
try {
diff --git a/services/core/java/com/android/server/BluetoothManagerService.java b/services/core/java/com/android/server/BluetoothManagerService.java
index d911388de3e6..f62935ab1b13 100644
--- a/services/core/java/com/android/server/BluetoothManagerService.java
+++ b/services/core/java/com/android/server/BluetoothManagerService.java
@@ -1154,6 +1154,11 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
public boolean disable(AttributionSource attributionSource, boolean persist)
throws RemoteException {
+ if (!persist) {
+ mContext.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
+ "Need BLUETOOTH_PRIVILEGED permission");
+ }
+
final String packageName = attributionSource.getPackageName();
if (!checkBluetoothPermissions(attributionSource, "disable", true)) {
if (DBG) {
@@ -2599,7 +2604,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
intent.putExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE, prevState);
intent.putExtra(BluetoothAdapter.EXTRA_STATE, newState);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
- mContext.sendBroadcastAsUser(intent, UserHandle.ALL, null,
+ mContext.sendBroadcastAsUser(intent, UserHandle.ALL, null,
getTempAllowlistBroadcastOptions());
}
}