Merge "Bluetooth: ensure adapter name and address can't be read from 3p apps" into sc-qpr1-dev

This commit is contained in:
Jakub Pawłowski
2021-12-30 14:17:34 +00:00
committed by Android (Google) Code Review
2 changed files with 29 additions and 12 deletions

View File

@@ -6331,6 +6331,27 @@ public final class Settings {
@Readable @Readable
public static final String ALLOW_MOCK_LOCATION = "mock_location"; public static final String ALLOW_MOCK_LOCATION = "mock_location";
/**
* This is used by Bluetooth Manager to store adapter name
* @hide
*/
@Readable(maxTargetSdk = Build.VERSION_CODES.S)
public static final String BLUETOOTH_NAME = "bluetooth_name";
/**
* This is used by Bluetooth Manager to store adapter address
* @hide
*/
@Readable(maxTargetSdk = Build.VERSION_CODES.S)
public static final String BLUETOOTH_ADDRESS = "bluetooth_address";
/**
* This is used by Bluetooth Manager to store whether adapter address is valid
* @hide
*/
@Readable(maxTargetSdk = Build.VERSION_CODES.S)
public static final String BLUETOOTH_ADDR_VALID = "bluetooth_addr_valid";
/** /**
* Setting to indicate that on device captions are enabled. * Setting to indicate that on device captions are enabled.
* *

View File

@@ -110,10 +110,6 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
private static final String BLUETOOTH_PRIVILEGED = private static final String BLUETOOTH_PRIVILEGED =
android.Manifest.permission.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";
private static final String SECURE_SETTINGS_BLUETOOTH_NAME = "bluetooth_name";
private static final int ACTIVE_LOG_MAX_SIZE = 20; private static final int ACTIVE_LOG_MAX_SIZE = 20;
private static final int CRASH_LOG_MAX_SIZE = 100; private static final int CRASH_LOG_MAX_SIZE = 100;
@@ -636,7 +632,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
if (mContext.getResources() if (mContext.getResources()
.getBoolean(com.android.internal.R.bool.config_bluetooth_address_validation) .getBoolean(com.android.internal.R.bool.config_bluetooth_address_validation)
&& Settings.Secure.getIntForUser(mContentResolver, && Settings.Secure.getIntForUser(mContentResolver,
SECURE_SETTINGS_BLUETOOTH_ADDR_VALID, 0, mUserId) Settings.Secure.BLUETOOTH_NAME, 0, mUserId)
== 0) { == 0) {
// if the valid flag is not set, don't load the address and name // if the valid flag is not set, don't load the address and name
if (DBG) { if (DBG) {
@@ -645,9 +641,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
return; return;
} }
mName = Settings.Secure.getStringForUser( mName = Settings.Secure.getStringForUser(
mContentResolver, SECURE_SETTINGS_BLUETOOTH_NAME, mUserId); mContentResolver, Settings.Secure.BLUETOOTH_NAME, mUserId);
mAddress = Settings.Secure.getStringForUser( mAddress = Settings.Secure.getStringForUser(
mContentResolver, SECURE_SETTINGS_BLUETOOTH_ADDRESS, mUserId); mContentResolver, Settings.Secure.BLUETOOTH_ADDRESS, mUserId);
if (DBG) { if (DBG) {
Slog.d(TAG, "Stored bluetooth Name=" + mName + ",Address=" + mAddress); Slog.d(TAG, "Stored bluetooth Name=" + mName + ",Address=" + mAddress);
} }
@@ -661,30 +657,30 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
*/ */
private void storeNameAndAddress(String name, String address) { private void storeNameAndAddress(String name, String address) {
if (name != null) { if (name != null) {
Settings.Secure.putStringForUser(mContentResolver, SECURE_SETTINGS_BLUETOOTH_NAME, name, Settings.Secure.putStringForUser(mContentResolver, Settings.Secure.BLUETOOTH_NAME, name,
mUserId); mUserId);
mName = name; mName = name;
if (DBG) { if (DBG) {
Slog.d(TAG, "Stored Bluetooth name: " + Settings.Secure.getStringForUser( Slog.d(TAG, "Stored Bluetooth name: " + Settings.Secure.getStringForUser(
mContentResolver, SECURE_SETTINGS_BLUETOOTH_NAME, mContentResolver, Settings.Secure.BLUETOOTH_NAME,
mUserId)); mUserId));
} }
} }
if (address != null) { if (address != null) {
Settings.Secure.putStringForUser(mContentResolver, SECURE_SETTINGS_BLUETOOTH_ADDRESS, Settings.Secure.putStringForUser(mContentResolver, Settings.Secure.BLUETOOTH_ADDRESS,
address, mUserId); address, mUserId);
mAddress = address; mAddress = address;
if (DBG) { if (DBG) {
Slog.d(TAG, Slog.d(TAG,
"Stored Bluetoothaddress: " + Settings.Secure.getStringForUser( "Stored Bluetoothaddress: " + Settings.Secure.getStringForUser(
mContentResolver, SECURE_SETTINGS_BLUETOOTH_ADDRESS, mContentResolver, Settings.Secure.BLUETOOTH_ADDRESS,
mUserId)); mUserId));
} }
} }
if ((name != null) && (address != null)) { if ((name != null) && (address != null)) {
Settings.Secure.putIntForUser(mContentResolver, SECURE_SETTINGS_BLUETOOTH_ADDR_VALID, 1, Settings.Secure.putIntForUser(mContentResolver, Settings.Secure.BLUETOOTH_ADDR_VALID, 1,
mUserId); mUserId);
} }
} }