Make BluetoothAdapter#disable(boolean persist) a @SystemApi

Bug: 196235708
Test: build, flash car hardware, test basic functionality
Change-Id: I952c3d2ce3b7ec70a384e9a96e172d6ab90c23e8
This commit is contained in:
Sal Savage
2021-09-02 11:52:23 -07:00
parent c0da9473bc
commit 8dafa60a2f
3 changed files with 13 additions and 3 deletions

View File

@@ -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();

View File

@@ -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 {

View File

@@ -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());
}
}