From 11ab8b2042acb1fa126fef2a81d7674538b59e44 Mon Sep 17 00:00:00 2001 From: Jay Thomas Sullivan Date: Mon, 8 Mar 2021 03:34:45 +0000 Subject: [PATCH 1/5] Define new NEARBY_DEVICES permission group This defines a new Android permission group named NEARBY_DEVICES, which is displayed to the user as "Nearby Bluetooth Devices". This also defines two new permissions: - BLUETOOTH_SCAN - BLUETOOTH_CONNECT The BLUETOOTH_SCAN permission is a new dangerous permission which will henceforth be used by applications that wish to be allowed to scan for or pair with Bluetooth devices. The BLUETOOTH_CONNECT permission, likewise, is used to connect to and communicate with already-paired devices. (As of this commit, these permissions are not yet used, and the corresponding AppOps are not yet mapped, so these changes do not yet have any effect.) Bug: 181813006 Test: manual Change-Id: I05c82ae05813189a5ec41656a15c6f4fc770ca57 --- core/api/current.txt | 3 +++ core/res/AndroidManifest.xml | 24 ++++++++++++++++++++++++ core/res/res/values/strings.xml | 13 +++++++++++++ 3 files changed, 40 insertions(+) diff --git a/core/api/current.txt b/core/api/current.txt index 001e960d2867f..e895813714022 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -55,7 +55,9 @@ package android { field public static final String BIND_WALLPAPER = "android.permission.BIND_WALLPAPER"; field public static final String BLUETOOTH = "android.permission.BLUETOOTH"; field public static final String BLUETOOTH_ADMIN = "android.permission.BLUETOOTH_ADMIN"; + field public static final String BLUETOOTH_CONNECT = "android.permission.BLUETOOTH_CONNECT"; field public static final String BLUETOOTH_PRIVILEGED = "android.permission.BLUETOOTH_PRIVILEGED"; + field public static final String BLUETOOTH_SCAN = "android.permission.BLUETOOTH_SCAN"; field public static final String BODY_SENSORS = "android.permission.BODY_SENSORS"; field public static final String BROADCAST_PACKAGE_REMOVED = "android.permission.BROADCAST_PACKAGE_REMOVED"; field public static final String BROADCAST_SMS = "android.permission.BROADCAST_SMS"; @@ -194,6 +196,7 @@ package android { field public static final String CONTACTS = "android.permission-group.CONTACTS"; field public static final String LOCATION = "android.permission-group.LOCATION"; field public static final String MICROPHONE = "android.permission-group.MICROPHONE"; + field public static final String NEARBY_DEVICES = "android.permission-group.NEARBY_DEVICES"; field public static final String PHONE = "android.permission-group.PHONE"; field public static final String SENSORS = "android.permission-group.SENSORS"; field public static final String SMS = "android.permission-group.SMS"; diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 29fa70de43a2c..480e1dee976a1 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -1388,6 +1388,14 @@ android:backgroundPermission="android.permission.BACKGROUND_CAMERA" android:protectionLevel="dangerous|instant" /> + + + + + + + + take pictures and record video + + Nearby Bluetooth Devices + + discover and connect to nearby Bluetooth devices + Call logs @@ -1471,6 +1476,14 @@ Allows the app to view the configuration of the Bluetooth on the phone, and to make and accept connections with paired devices. + + discover and pair nearby Bluetooth devices + + Allows the app to discover and pair nearby Bluetooth devices + + connect to paired Bluetooth devices + + Allows the app to connect to paired Bluetooth devices Preferred NFC Payment Service Information From 4452bbd06550baaa141b1ccb9a850a165d30fab3 Mon Sep 17 00:00:00 2001 From: Jay Thomas Sullivan Date: Wed, 10 Mar 2021 21:51:22 +0000 Subject: [PATCH 2/5] Split new NEARBY_DEVICES permissions This creates a "split permission" from: - BLUETOOTH to BLUETOOTH_SCAN and BLUETOOTH_CONNECT, and - BLUETOOTH_ADMIN to BLUETOOTH_SCAN and BLUETOOTH_CONNECT ...for apps targetting SDK<31. What this means is that any apps that use either the BLUETOOTH or the BLUETOOTH_ADMIN permission, and target SDK<31, will automatically be be granted the BLUETOOTH_SCAN and BLUETOOTH_CONNECT permissions. Bug: 181813006 Test: manual Change-Id: I92a974203fd51e87747e740273a21ba399a81cd0 --- data/etc/platform.xml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/data/etc/platform.xml b/data/etc/platform.xml index 27bf4ef4c84dc..8da4a37e44cda 100644 --- a/data/etc/platform.xml +++ b/data/etc/platform.xml @@ -224,7 +224,22 @@ targetSdk="29"> - + + + + + + + + + + + + From 1e8d1a62e064665eede0c1cbb3676c1142f76082 Mon Sep 17 00:00:00 2001 From: Jay Thomas Sullivan Date: Thu, 18 Mar 2021 10:38:34 -0400 Subject: [PATCH 3/5] Add BLUETOOTH_SCAN and BLUETOOTH_CONNECT app ops This adds a new BLUETOOTH_CONNECT app op, and recycles an old, unused BLUETOOTH_SCAN app op. Bug: 181813006 Test: manual Change-Id: Ie6a3c37532a52675c47a38f13af558932fe0763d --- core/java/android/app/AppOpsManager.java | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java index 27b19bcd31a13..a6aa28effe001 100644 --- a/core/java/android/app/AppOpsManager.java +++ b/core/java/android/app/AppOpsManager.java @@ -1073,6 +1073,8 @@ public class AppOpsManager { /** @hide */ @UnsupportedAppUsage public static final int OP_BLUETOOTH_SCAN = AppProtoEnums.APP_OP_BLUETOOTH_SCAN; + /** @hide */ + public static final int OP_BLUETOOTH_CONNECT = AppProtoEnums.APP_OP_BLUETOOTH_CONNECT; /** @hide Use the BiometricPrompt/BiometricManager APIs. */ public static final int OP_USE_BIOMETRIC = AppProtoEnums.APP_OP_USE_BIOMETRIC; /** @hide Physical activity recognition. */ @@ -1221,7 +1223,7 @@ public class AppOpsManager { /** @hide */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) - public static final int _NUM_OP = 111; + public static final int _NUM_OP = 112; /** Access to coarse location information. */ public static final String OPSTR_COARSE_LOCATION = "android:coarse_location"; @@ -1465,6 +1467,8 @@ public class AppOpsManager { public static final String OPSTR_START_FOREGROUND = "android:start_foreground"; /** @hide */ public static final String OPSTR_BLUETOOTH_SCAN = "android:bluetooth_scan"; + /** @hide */ + public static final String OPSTR_BLUETOOTH_CONNECT = "android:bluetooth_connect"; /** @hide Use the BiometricPrompt/BiometricManager APIs. */ public static final String OPSTR_USE_BIOMETRIC = "android:use_biometric"; @@ -1696,6 +1700,9 @@ public class AppOpsManager { OP_WRITE_MEDIA_VIDEO, OP_READ_MEDIA_IMAGES, OP_WRITE_MEDIA_IMAGES, + // Nearby devices + OP_BLUETOOTH_SCAN, + OP_BLUETOOTH_CONNECT, // APPOP PERMISSIONS OP_ACCESS_NOTIFICATIONS, @@ -1801,7 +1808,7 @@ public class AppOpsManager { OP_ACCEPT_HANDOVER, // ACCEPT_HANDOVER OP_MANAGE_IPSEC_TUNNELS, // MANAGE_IPSEC_HANDOVERS OP_START_FOREGROUND, // START_FOREGROUND - OP_COARSE_LOCATION, // BLUETOOTH_SCAN + OP_BLUETOOTH_SCAN, // BLUETOOTH_SCAN OP_USE_BIOMETRIC, // BIOMETRIC OP_ACTIVITY_RECOGNITION, // ACTIVITY_RECOGNITION OP_SMS_FINANCIAL_TRANSACTIONS, // SMS_FINANCIAL_TRANSACTIONS @@ -1835,6 +1842,7 @@ public class AppOpsManager { OP_FINE_LOCATION, // OP_FINE_LOCATION_SOURCE OP_COARSE_LOCATION, // OP_COARSE_LOCATION_SOURCE OP_MANAGE_MEDIA, // MANAGE_MEDIA + OP_BLUETOOTH_CONNECT, // OP_BLUETOOTH_CONNECT }; /** @@ -1952,6 +1960,7 @@ public class AppOpsManager { OPSTR_FINE_LOCATION_SOURCE, OPSTR_COARSE_LOCATION_SOURCE, OPSTR_MANAGE_MEDIA, + OPSTR_BLUETOOTH_CONNECT, }; /** @@ -2070,6 +2079,7 @@ public class AppOpsManager { "FINE_LOCATION_SOURCE", "COARSE_LOCATION_SOURCE", "MANAGE_MEDIA", + "BLUETOOTH_CONNECT", }; /** @@ -2155,7 +2165,7 @@ public class AppOpsManager { Manifest.permission.ACCEPT_HANDOVER, Manifest.permission.MANAGE_IPSEC_TUNNELS, Manifest.permission.FOREGROUND_SERVICE, - null, // no permission for OP_BLUETOOTH_SCAN + Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.USE_BIOMETRIC, Manifest.permission.ACTIVITY_RECOGNITION, Manifest.permission.SMS_FINANCIAL_TRANSACTIONS, @@ -2189,6 +2199,7 @@ public class AppOpsManager { null, // no permission for OP_ACCESS_FINE_LOCATION_SOURCE, null, // no permission for OP_ACCESS_COARSE_LOCATION_SOURCE, Manifest.permission.MANAGE_MEDIA, + Manifest.permission.BLUETOOTH_CONNECT, }; /** @@ -2308,6 +2319,7 @@ public class AppOpsManager { null, // ACCESS_FINE_LOCATION_SOURCE null, // ACCESS_COARSE_LOCATION_SOURCE null, // MANAGE_MEDIA + null, // BLUETOOTH_CONNECT }; /** @@ -2426,6 +2438,7 @@ public class AppOpsManager { null, // ACCESS_FINE_LOCATION_SOURCE null, // ACCESS_COARSE_LOCATION_SOURCE null, // MANAGE_MEDIA + null, // BLUETOOTH_CONNECT }; /** @@ -2543,6 +2556,7 @@ public class AppOpsManager { AppOpsManager.MODE_ALLOWED, // ACCESS_FINE_LOCATION_SOURCE AppOpsManager.MODE_ALLOWED, // ACCESS_COARSE_LOCATION_SOURCE AppOpsManager.MODE_DEFAULT, // MANAGE_MEDIA + AppOpsManager.MODE_ALLOWED, // BLUETOOTH_CONNECT }; /** @@ -2664,6 +2678,7 @@ public class AppOpsManager { false, // ACCESS_FINE_LOCATION_SOURCE false, // ACCESS_COARSE_LOCATION_SOURCE false, // MANAGE_MEDIA + false, // BLUETOOTH_CONNECT }; /** From aaf8de42d14c5ba2d20ba981fd39cec7c5967535 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Mon, 22 Mar 2021 12:45:54 -0600 Subject: [PATCH 4/5] Default grants for "Nearby devices" permission. The location stack can interact with nearby devices to better resolve the device's location, so grant access by default. The companion device app needs to interact with nearby devices as part of configuring them. Bug: 181813006 Test: atest CtsPermission2TestCases Test: atest CtsPermission3TestCases Test: atest CtsStatsdAtomHostTestCases Change-Id: Ib0d740b1e5928a55ca7a1e454ed19d3b96b52444 --- .../pm/permission/DefaultPermissionGrantPolicy.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java b/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java index 27bf8a13766a3..f0d54b4c06174 100644 --- a/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java +++ b/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java @@ -206,6 +206,12 @@ final class DefaultPermissionGrantPolicy { STORAGE_PERMISSIONS.add(Manifest.permission.ACCESS_MEDIA_LOCATION); } + private static final Set NEARBY_DEVICES_PERMISSIONS = new ArraySet<>(); + static { + NEARBY_DEVICES_PERMISSIONS.add(Manifest.permission.BLUETOOTH_CONNECT); + NEARBY_DEVICES_PERMISSIONS.add(Manifest.permission.BLUETOOTH_SCAN); + } + private static final int MSG_READ_DEFAULT_PERMISSION_EXCEPTIONS = 1; private static final String ACTION_TRACK = "com.android.fitness.TRACK"; @@ -733,14 +739,15 @@ final class DefaultPermissionGrantPolicy { PHONE_PERMISSIONS, SMS_PERMISSIONS, CAMERA_PERMISSIONS, SENSORS_PERMISSIONS, STORAGE_PERMISSIONS); grantSystemFixedPermissionsToSystemPackage(pm, packageName, userId, - ALWAYS_LOCATION_PERMISSIONS, ACTIVITY_RECOGNITION_PERMISSIONS); + ALWAYS_LOCATION_PERMISSIONS, NEARBY_DEVICES_PERMISSIONS, + ACTIVITY_RECOGNITION_PERMISSIONS); } } if (locationExtraPackageNames != null) { // Also grant location and activity recognition permission to location extra packages. for (String packageName : locationExtraPackageNames) { grantPermissionsToSystemPackage(pm, packageName, userId, - ALWAYS_LOCATION_PERMISSIONS); + ALWAYS_LOCATION_PERMISSIONS, NEARBY_DEVICES_PERMISSIONS); grantSystemFixedPermissionsToSystemPackage(pm, packageName, userId, ACTIVITY_RECOGNITION_PERMISSIONS); } @@ -809,7 +816,7 @@ final class DefaultPermissionGrantPolicy { // Companion devices grantSystemFixedPermissionsToSystemPackage(pm, CompanionDeviceManager.COMPANION_DEVICE_DISCOVERY_PACKAGE_NAME, userId, - ALWAYS_LOCATION_PERMISSIONS); + ALWAYS_LOCATION_PERMISSIONS, NEARBY_DEVICES_PERMISSIONS); // Ringtone Picker grantSystemFixedPermissionsToSystemPackage(pm, From 7b14b87647323371a8f29d38accbcd8fc2373331 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Mon, 22 Mar 2021 15:34:02 -0600 Subject: [PATCH 5/5] Request new Bluetooth runtime permissions. An upcoming platform change is introducing a new "Nearby devices" runtime permission which contains the new BLUETOOTH_CONNECT and BLUETOOTH_SCAN permissions. We have logic in place to use to translate the older BLUETOOTH and BLUETOOTH_ADMIN permissions into these new runtime permissions, but modern apps will need to pivot to requesting them directly as part of targeting Android S. This change requests both the old and new permissions to avoid breakage while the new permission enforcement is being phased in. Bug: 181813006 Test: atest CtsPermission2TestCases Test: atest CtsPermission3TestCases Test: atest CtsStatsdAtomHostTestCases Change-Id: I39f45e7d22d132d44c84017cd98e6d9e98533c7f --- core/tests/bluetoothtests/AndroidManifest.xml | 2 ++ core/tests/coretests/AndroidManifest.xml | 2 ++ .../test-apps/ExternalLocAllPermsTestApp/AndroidManifest.xml | 2 ++ .../test-apps/ExternalSharedPermsBT/AndroidManifest.xml | 3 +++ media/packages/BluetoothMidiService/AndroidManifest.xml | 3 +++ media/tests/ScoAudioTest/AndroidManifest.xml | 3 +++ packages/CompanionDeviceManager/AndroidManifest.xml | 2 ++ packages/Shell/AndroidManifest.xml | 3 +++ packages/SystemUI/AndroidManifest.xml | 2 ++ services/tests/servicestests/AndroidManifest.xml | 3 +++ tests/UsesFeature2Test/AndroidManifest.xml | 3 +++ 11 files changed, 28 insertions(+) diff --git a/core/tests/bluetoothtests/AndroidManifest.xml b/core/tests/bluetoothtests/AndroidManifest.xml index 6849a90f50107..f8c69ac17bb03 100644 --- a/core/tests/bluetoothtests/AndroidManifest.xml +++ b/core/tests/bluetoothtests/AndroidManifest.xml @@ -20,6 +20,8 @@ + + diff --git a/core/tests/coretests/AndroidManifest.xml b/core/tests/coretests/AndroidManifest.xml index f31233b29cd03..408624a6f1b47 100644 --- a/core/tests/coretests/AndroidManifest.xml +++ b/core/tests/coretests/AndroidManifest.xml @@ -44,6 +44,8 @@ + + diff --git a/core/tests/hosttests/test-apps/ExternalLocAllPermsTestApp/AndroidManifest.xml b/core/tests/hosttests/test-apps/ExternalLocAllPermsTestApp/AndroidManifest.xml index 0898faeb70805..b3b34ef93ebed 100644 --- a/core/tests/hosttests/test-apps/ExternalLocAllPermsTestApp/AndroidManifest.xml +++ b/core/tests/hosttests/test-apps/ExternalLocAllPermsTestApp/AndroidManifest.xml @@ -32,6 +32,8 @@ + + diff --git a/core/tests/hosttests/test-apps/ExternalSharedPermsBT/AndroidManifest.xml b/core/tests/hosttests/test-apps/ExternalSharedPermsBT/AndroidManifest.xml index 98f7177992e2f..42d94071400d8 100644 --- a/core/tests/hosttests/test-apps/ExternalSharedPermsBT/AndroidManifest.xml +++ b/core/tests/hosttests/test-apps/ExternalSharedPermsBT/AndroidManifest.xml @@ -21,6 +21,9 @@ android:sharedUserId="com.android.framework.externalsharedpermstestapp"> + + + diff --git a/media/packages/BluetoothMidiService/AndroidManifest.xml b/media/packages/BluetoothMidiService/AndroidManifest.xml index fc96fd926e2de..3794ccddb48f9 100644 --- a/media/packages/BluetoothMidiService/AndroidManifest.xml +++ b/media/packages/BluetoothMidiService/AndroidManifest.xml @@ -27,6 +27,9 @@ + + + + + + + + diff --git a/packages/Shell/AndroidManifest.xml b/packages/Shell/AndroidManifest.xml index 2b4fef0c9ba7a..90f77e737036d 100644 --- a/packages/Shell/AndroidManifest.xml +++ b/packages/Shell/AndroidManifest.xml @@ -45,6 +45,9 @@ + + + diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml index 3904201d2ee8e..4135bbe3e86d8 100644 --- a/packages/SystemUI/AndroidManifest.xml +++ b/packages/SystemUI/AndroidManifest.xml @@ -62,6 +62,8 @@ + + diff --git a/services/tests/servicestests/AndroidManifest.xml b/services/tests/servicestests/AndroidManifest.xml index b9aa554aa0acc..5761958ea89da 100644 --- a/services/tests/servicestests/AndroidManifest.xml +++ b/services/tests/servicestests/AndroidManifest.xml @@ -74,6 +74,9 @@ + + + diff --git a/tests/UsesFeature2Test/AndroidManifest.xml b/tests/UsesFeature2Test/AndroidManifest.xml index 8caf4a1588672..1f1a909582980 100644 --- a/tests/UsesFeature2Test/AndroidManifest.xml +++ b/tests/UsesFeature2Test/AndroidManifest.xml @@ -22,6 +22,9 @@ + + +