From 3b7232c1abf51629975f90c85bad26b72290b3ec Mon Sep 17 00:00:00 2001 From: Chen Chen Date: Thu, 23 Jul 2020 14:38:32 -0700 Subject: [PATCH] BluetoothManagerService: enforce BLUETOOTH_PRIVILEGED for onFactoryReset Bug: 159061926 Test: Try app_debug.apk in the bug, and make sure Bluetooth won't be turned off by the app Change-Id: I7d7e684be7908fc95f4f87528fb0ba7e5ace9f4a --- .../java/com/android/server/BluetoothManagerService.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/services/core/java/com/android/server/BluetoothManagerService.java b/services/core/java/com/android/server/BluetoothManagerService.java index 0d4efed25da34..8c38b66dd44ed 100644 --- a/services/core/java/com/android/server/BluetoothManagerService.java +++ b/services/core/java/com/android/server/BluetoothManagerService.java @@ -95,6 +95,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub { private static final String BLUETOOTH_ADMIN_PERM = android.Manifest.permission.BLUETOOTH_ADMIN; private static final String BLUETOOTH_PERM = android.Manifest.permission.BLUETOOTH; + private static final String BLUETOOTH_PRIVILEGED = + android.Manifest.permission.BLUETOOTH_PRIVILEGED; private static final String SECURE_SETTINGS_BLUETOOTH_ADDR_VALID = "bluetooth_addr_valid"; private static final String SECURE_SETTINGS_BLUETOOTH_ADDRESS = "bluetooth_address"; @@ -279,6 +281,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub { }; public boolean onFactoryReset() { + mContext.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, + "Need BLUETOOTH_PRIVILEGED permission"); + // Wait for stable state if bluetooth is temporary state. int state = getState(); if (state == BluetoothAdapter.STATE_BLE_TURNING_ON