Add tristate permission support for body sensor permission

Currently only states supported for body sensor permissions are allow
and deny. This change adds support for allowing the permission only
while the app is in foreground by adding a new permission only for
background. This structure is similar to the current state for location
permissions.

BYPASS_INCLUSIVE_LANGUAGE_REASON=Referring to an existing method failing
the inclusive language check.

Test: Manual atest
Change-Id: I8fcab6c0c884b79291586f64fd221e40982bc4c5
Bug: 208305481
This commit is contained in:
varun
2021-11-29 05:07:08 +00:00
parent 5505530a4b
commit 4379a4cb56
6 changed files with 31 additions and 3 deletions

View File

@@ -61,6 +61,7 @@ package android {
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 BODY_SENSORS_BACKGROUND = "android.permission.BODY_SENSORS_BACKGROUND";
field public static final String BROADCAST_PACKAGE_REMOVED = "android.permission.BROADCAST_PACKAGE_REMOVED";
field public static final String BROADCAST_SMS = "android.permission.BROADCAST_SMS";
field public static final String BROADCAST_STICKY = "android.permission.BROADCAST_STICKY";

View File

@@ -1481,8 +1481,26 @@
android:permissionGroup="android.permission-group.UNDEFINED"
android:label="@string/permlab_bodySensors"
android:description="@string/permdesc_bodySensors"
android:backgroundPermission="android.permission.BODY_SENSORS_BACKGROUND"
android:protectionLevel="dangerous" />
<!-- Allows an application to access data from sensors that the user uses to measure what is
happening inside their body, such as heart rate. If you're requesting this permission, you
must also request {@link #BODY_SENSORS}. Requesting this permission by itself doesn't give
you Body sensors access.
<p>Protection level: dangerous
<p> This is a hard restricted permission which cannot be held by an app until
the installer on record whitelists the permission. For more details see
{@link android.content.pm.PackageInstaller.SessionParams#setWhitelistedRestrictedPermissions(Set)}.
-->
<permission android:name="android.permission.BODY_SENSORS_BACKGROUND"
android:permissionGroup="android.permission-group.UNDEFINED"
android:label="@string/permlab_bodySensors_background"
android:description="@string/permdesc_bodySensors_background"
android:protectionLevel="dangerous"
android:permissionFlags="hardRestricted" />
<!-- Allows an app to use fingerprint hardware.
<p>Protection level: normal
@deprecated Applications should request {@link

View File

@@ -1237,8 +1237,11 @@
<string name="permlab_bodySensors">access body sensors (like heart rate monitors)
</string>
<!-- Description of the body sensors permission, listed so the user can decide whether to allow the application to access data from body sensors. [CHAR LIMIT=NONE] -->
<string name="permdesc_bodySensors" product="default">Allows the app to access data from sensors
that monitor your physical condition, such as your heart rate.</string>
<string name="permdesc_bodySensors" product="default">Access to data from body sensors such as heart rate, temperature, blood oxygen percentage, etc.</string>
<!-- Title of the background body sensors permission, listed so the user can decide whether to allow the application to access body sensor data in the background. [CHAR LIMIT=80] -->
<string name="permlab_bodySensors_background">access body sensors (like heart rate monitors) while in the background</string>
<!-- Description of the background body sensors permission, listed so the user can decide whether to allow the application to access data from body sensors in the background. [CHAR LIMIT=NONE] -->
<string name="permdesc_bodySensors_background" product="default">Access to data from body sensors such as heart rate, temperature, blood oxygen percentage, etc. while in the background.</string>
<!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
<string name="permlab_readCalendar">Read calendar events and details</string>

View File

@@ -222,6 +222,10 @@
targetSdk="29">
<new-permission name="android.permission.ACCESS_BACKGROUND_LOCATION" />
</split-permission>
<split-permission name="android.permission.BODY_SENSORS"
targetSdk="33">
<new-permission name="android.permission.BODY_SENSORS_BACKGROUND" />
</split-permission>
<split-permission name="android.permission.READ_EXTERNAL_STORAGE"
targetSdk="29">
<new-permission name="android.permission.ACCESS_MEDIA_LOCATION" />

View File

@@ -198,6 +198,7 @@ final class DefaultPermissionGrantPolicy {
private static final Set<String> SENSORS_PERMISSIONS = new ArraySet<>();
static {
SENSORS_PERMISSIONS.add(Manifest.permission.BODY_SENSORS);
SENSORS_PERMISSIONS.add(Manifest.permission.BODY_SENSORS_BACKGROUND);
}
private static final Set<String> STORAGE_PERMISSIONS = new ArraySet<>();

View File

@@ -5914,7 +5914,8 @@ public class PermissionManagerService extends IPermissionManager.Stub {
if (op < 0) {
// Bg location is one-off runtime modifier permission and has no app op
if (sPlatformPermissions.contains(permission)
&& !Manifest.permission.ACCESS_BACKGROUND_LOCATION.equals(permission)) {
&& !Manifest.permission.ACCESS_BACKGROUND_LOCATION.equals(permission)
&& !Manifest.permission.BODY_SENSORS_BACKGROUND.equals(permission)) {
Slog.wtf(LOG_TAG, "Platform runtime permission " + permission
+ " with no app op defined!");
}