Make BluetoothAdapter#disable(boolean persist) a @SystemApi
Bug: 196235708
Test: build, flash car hardware, test basic functionality
Change-Id: I952c3d2ce3b7ec70a384e9a96e172d6ab90c23e8
diff --git a/framework/java/android/bluetooth/BluetoothAdapter.java b/framework/java/android/bluetooth/BluetoothAdapter.java
index e9be0ec..9c69903 100644
--- a/framework/java/android/bluetooth/BluetoothAdapter.java
+++ b/framework/java/android/bluetooth/BluetoothAdapter.java
@@ -1245,13 +1245,17 @@
/**
* 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/service/java/com/android/server/bluetooth/BluetoothManagerService.java b/service/java/com/android/server/bluetooth/BluetoothManagerService.java
index d911388..f62935a 100644
--- a/service/java/com/android/server/bluetooth/BluetoothManagerService.java
+++ b/service/java/com/android/server/bluetooth/BluetoothManagerService.java
@@ -1154,6 +1154,11 @@
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 @@
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());
}
}