Make BluetoothAdapter#disable(boolean persist) a @SystemApi am: 8dafa60a2f am: 7db301321d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15960228

Change-Id: Ib97e835bdb2be865f26c1f63d68e25b204e12aa0
This commit is contained in:
Sal Savage
2021-10-01 20:42:39 +00:00
committed by Automerger Merge Worker
3 changed files with 13 additions and 3 deletions

View File

@@ -1937,6 +1937,7 @@ package android.bluetooth {
public final class BluetoothAdapter { 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 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 disableBLE();
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean enableBLE(); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean enableBLE();
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean enableNoAutoConnect(); 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. * 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 * @return true to indicate adapter shutdown has begun, or false on immediate error
* @hide * @hide
*/ */
@UnsupportedAppUsage(trackingBug = 171933273) @SystemApi
@RequiresLegacyBluetoothAdminPermission @RequiresLegacyBluetoothAdminPermission
@RequiresBluetoothConnectPermission @RequiresBluetoothConnectPermission
@RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) @RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public boolean disable(boolean persist) { public boolean disable(boolean persist) {
try { try {

View File

@@ -1154,6 +1154,11 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
public boolean disable(AttributionSource attributionSource, boolean persist) public boolean disable(AttributionSource attributionSource, boolean persist)
throws RemoteException { throws RemoteException {
if (!persist) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
"Need BLUETOOTH_PRIVILEGED permission");
}
final String packageName = attributionSource.getPackageName(); final String packageName = attributionSource.getPackageName();
if (!checkBluetoothPermissions(attributionSource, "disable", true)) { if (!checkBluetoothPermissions(attributionSource, "disable", true)) {
if (DBG) { if (DBG) {