Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2ded7dd4 authored by Scarlett Song's avatar Scarlett Song
Browse files

Health Permissions: Add OP_READ_HEART_RATE

Add OP_READ_HEART_RATE app op for runtime health permission READ_HEART_RATE.

Flag: android.permission.flags.replace_body_sensor_permission_enabled
Bug: 364638912
Bug: 364643245
Bug: 360781841
Test: atest AppOpDefinitionTest
Change-Id: I3355e93051f6068ee88eb93bb95e0b91afcb49dd
parent 0fca6699
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -694,6 +694,7 @@ package android.app {
    field public static final String OPSTR_PROJECT_MEDIA = "android:project_media";
    field @FlaggedApi("android.view.contentprotection.flags.rapid_clear_notifications_by_listener_app_op_enabled") public static final String OPSTR_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER = "android:rapid_clear_notifications_by_listener";
    field public static final String OPSTR_READ_CLIPBOARD = "android:read_clipboard";
    field @FlaggedApi("android.permission.flags.replace_body_sensor_permission_enabled") public static final String OPSTR_READ_HEART_RATE = "android:read_heart_rate";
    field public static final String OPSTR_READ_ICC_SMS = "android:read_icc_sms";
    field public static final String OPSTR_READ_MEDIA_AUDIO = "android:read_media_audio";
    field public static final String OPSTR_READ_MEDIA_IMAGES = "android:read_media_images";
+22 −1
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
import android.database.DatabaseUtils;
import android.health.connect.HealthConnectManager;
import android.health.connect.HealthPermissions;
import android.media.AudioAttributes.AttributeUsage;
import android.media.MediaRouter2;
import android.os.Binder;
@@ -1607,9 +1608,12 @@ public class AppOpsManager {
    public static final int OP_RECEIVE_SENSITIVE_NOTIFICATIONS =
            AppProtoEnums.APP_OP_RECEIVE_SENSITIVE_NOTIFICATIONS;

    /** @hide Access to read heart rate sensor. */
    public static final int OP_READ_HEART_RATE = AppProtoEnums.APP_OP_READ_HEART_RATE;

    /** @hide */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    public static final int _NUM_OP = 149;
    public static final int _NUM_OP = 150;

    /**
     * All app ops represented as strings.
@@ -1762,6 +1766,7 @@ public class AppOpsManager {
            OPSTR_UNARCHIVAL_CONFIRMATION,
            OPSTR_EMERGENCY_LOCATION,
            OPSTR_RECEIVE_SENSITIVE_NOTIFICATIONS,
            OPSTR_READ_HEART_RATE,
    })
    public @interface AppOpString {}

@@ -2499,6 +2504,11 @@ public class AppOpsManager {
    public static final String OPSTR_RECEIVE_SENSITIVE_NOTIFICATIONS =
            "android:receive_sensitive_notifications";

    /** @hide Access to read heart rate sensor. */
    @SystemApi
    @FlaggedApi(Flags.FLAG_REPLACE_BODY_SENSOR_PERMISSION_ENABLED)
    public static final String OPSTR_READ_HEART_RATE = "android:read_heart_rate";

    /** {@link #sAppOpsToNote} not initialized yet for this op */
    private static final byte SHOULD_COLLECT_NOTE_OP_NOT_INITIALIZED = 0;
    /** Should not collect noting of this app-op in {@link #sAppOpsToNote} */
@@ -2572,6 +2582,8 @@ public class AppOpsManager {
            OP_NEARBY_WIFI_DEVICES,
            // Notifications
            OP_POST_NOTIFICATION,
            // Health
            Flags.replaceBodySensorPermissionEnabled() ? OP_READ_HEART_RATE : OP_NONE,
    };

    /**
@@ -2612,6 +2624,7 @@ public class AppOpsManager {
            OP_READ_SYSTEM_GRAMMATICAL_GENDER,
    };

    @SuppressWarnings("FlaggedApi")
    static final AppOpInfo[] sAppOpInfos = new AppOpInfo[]{
        new AppOpInfo.Builder(OP_COARSE_LOCATION, OPSTR_COARSE_LOCATION, "COARSE_LOCATION")
            .setPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION)
@@ -3079,6 +3092,10 @@ public class AppOpsManager {
        new AppOpInfo.Builder(OP_RECEIVE_SENSITIVE_NOTIFICATIONS,
                OPSTR_RECEIVE_SENSITIVE_NOTIFICATIONS, "RECEIVE_SENSITIVE_NOTIFICATIONS")
                .setDefaultMode(MODE_IGNORED).build(),
        new AppOpInfo.Builder(OP_READ_HEART_RATE, OPSTR_READ_HEART_RATE, "READ_HEART_RATE")
            .setPermission(Flags.replaceBodySensorPermissionEnabled() ?
                HealthPermissions.READ_HEART_RATE : null)
            .setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
    };

    // The number of longs needed to form a full bitmask of app ops
@@ -3132,6 +3149,10 @@ public class AppOpsManager {
            }
        }
        for (int op : RUNTIME_PERMISSION_OPS) {
            if (op == OP_NONE) {
                // Skip ops with a disabled feature flag.
                continue;
            }
            if (sAppOpInfos[op].permission != null) {
                sPermToOp.put(sAppOpInfos[op].permission, op);
            }