Update to modern Bluetooth permissions.

The Settings app offers several Bluetooth intents, and they need to
be updated to enforce the new "Nearby devices" runtime permission
model, since the old BLUETOOTH and BLUETOOTH_ADMIN permissions have
been deprecated.

Bug: 191174082
Test: TH
Change-Id: I0d812f486bc3dadc517d5b04d3082d4f56f60ef4
This commit is contained in:
Jeff Sharkey
2021-06-22 19:58:58 -06:00
parent 34961821f4
commit 7025a83f39
6 changed files with 12 additions and 13 deletions

View File

@@ -17,8 +17,7 @@
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />
@@ -2222,7 +2221,7 @@
<activity android:name=".bluetooth.RequestPermissionActivity"
android:excludeFromRecents="true"
android:permission="android.permission.BLUETOOTH"
android:permission="android.permission.BLUETOOTH_CONNECT"
android:exported="true"
android:theme="@style/Theme.BluetoothPermission">
<intent-filter android:priority="1">
@@ -2265,7 +2264,7 @@
<activity android:name=".bluetooth.RequestPermissionHelperActivity"
android:label="@string/bluetooth_pairing_request"
android:excludeFromRecents="true"
android:permission="android.permission.BLUETOOTH"
android:permission="android.permission.BLUETOOTH_CONNECT"
android:theme="@*android:style/Theme.DeviceDefault.Dialog.Alert.DayNight">
</activity>
@@ -2280,7 +2279,7 @@
<receiver android:name=".bluetooth.BluetoothPermissionRequest"
android:exported="true"
android:permission="android.permission.BLUETOOTH_ADMIN">
android:permission="android.permission.BLUETOOTH_CONNECT">
<intent-filter>
<action android:name="android.bluetooth.device.action.CONNECTION_ACCESS_REQUEST" />
<action android:name="android.bluetooth.device.action.CONNECTION_ACCESS_CANCEL" />
@@ -2290,7 +2289,7 @@
<activity android:name=".bluetooth.BluetoothPermissionActivity"
android:label="@string/bluetooth_connection_permission_request"
android:excludeFromRecents="true"
android:permission="android.permission.BLUETOOTH_ADMIN"
android:permission="android.permission.BLUETOOTH_CONNECT"
android:exported="true"
android:theme="@android:style/Theme.DeviceDefault.Light.Dialog.Alert">
<intent-filter android:priority="1">
@@ -3545,7 +3544,7 @@
<activity android:name="Settings$BluetoothDeviceDetailActivity"
android:label="@string/device_details_title"
android:exported="true"
android:permission="android.permission.BLUETOOTH_ADMIN">
android:permission="android.permission.BLUETOOTH_CONNECT">
<intent-filter android:priority="1">
<action android:name="com.android.settings.BLUETOOTH_DEVICE_DETAIL_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
@@ -3750,7 +3749,7 @@
<receiver
android:name=".media.BluetoothPairingReceiver"
android:exported="true"
android:permission="android.permission.BLUETOOTH_ADMIN">
android:permission="android.permission.BLUETOOTH_CONNECT">
<intent-filter>
<action android:name="com.android.settings.action.LAUNCH_BLUETOOTH_PAIRING"/>
</intent-filter>/>

View File

@@ -221,7 +221,7 @@ public class BluetoothPermissionActivity extends AlertActivity implements
intent.putExtra(BluetoothDevice.EXTRA_ALWAYS_ALLOWED, always);
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
intent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, mRequestType);
sendBroadcast(intent, android.Manifest.permission.BLUETOOTH_ADMIN);
sendBroadcast(intent, android.Manifest.permission.BLUETOOTH_CONNECT);
}
public void onClick(DialogInterface dialog, int which) {

View File

@@ -293,6 +293,6 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {
: BluetoothDevice.CONNECTION_ACCESS_NO);
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
intent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, mRequestType);
mContext.sendBroadcast(intent, android.Manifest.permission.BLUETOOTH_ADMIN);
mContext.sendBroadcast(intent, android.Manifest.permission.BLUETOOTH_CONNECT);
}
}

View File

@@ -212,6 +212,6 @@ public final class DevicePickerFragment extends DeviceListPreferenceFragment {
}
}
mContext.sendBroadcast(intent, Manifest.permission.BLUETOOTH_ADMIN);
mContext.sendBroadcast(intent, Manifest.permission.BLUETOOTH_CONNECT);
}
}

View File

@@ -53,6 +53,6 @@ public class BluetoothPermissionActivityTest {
mActivity.sendReplyIntentToReceiver(true, true);
verify(mContext).sendBroadcast(intentCaptor.capture(),
eq("android.permission.BLUETOOTH_ADMIN"));
eq("android.permission.BLUETOOTH_CONNECT"));
}
}

View File

@@ -82,7 +82,7 @@ public class DevicePickerFragmentTest {
mFragment.onDeviceBondStateChanged(cachedDevice, BluetoothDevice.BOND_BONDED);
verify(mContext).sendBroadcast(intentCaptor.capture(),
eq("android.permission.BLUETOOTH_ADMIN"));
eq("android.permission.BLUETOOTH_CONNECT"));
assertThat(intentCaptor.getValue().getComponent().getPackageName())
.isEqualTo(mFragment.mLaunchPackage);
}