summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Justin Lannin <jlannin@google.com> 2024-11-06 07:25:00 +0000
committer Justin Lannin <jlannin@google.com> 2024-11-08 01:18:02 +0000
commit0980aa8675918ac2c18acca4668db683a93c65be (patch)
treebe548728af2e638db989d8a16b0db5089f8f2760
parent52683c69b2beb487108bb5bd846546f4bb513544 (diff)
ASM: Add required AppOp lookup to custom sensors for all permissions.
Previously, we only made an AppOp lookup if the custom sensor used BODY_SENSORS. We are deprecating BODY_SENSORS in favor of READ_HEART_RATE and other granular health permissions. This CL ensures the correct AppOp is used if the custom sensor uses these other permissions. In the spirit of flagging, we guard the expanded AppOp lookup behind the replace_body_sensor_permission_enabled flag. However, it's worth noting that any permission with an existing AppOp would now be used (not just READ_HEART_RATE). Bug: 377576685 Change-Id: Ia16663795479ee49d5b5a82cd5b304b6dd6a26f1 Flag: android.permission.flags.replace_body_sensor_permission_enabled
-rw-r--r--libs/sensor/Sensor.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/libs/sensor/Sensor.cpp b/libs/sensor/Sensor.cpp
index eddd568fb5..797efbe5df 100644
--- a/libs/sensor/Sensor.cpp
+++ b/libs/sensor/Sensor.cpp
@@ -306,7 +306,18 @@ Sensor::Sensor(struct sensor_t const& hwSensor, const uuid_t& uuid, int halVersi
}
if (halVersion > SENSORS_DEVICE_API_VERSION_1_0 && hwSensor.requiredPermission) {
mRequiredPermission = hwSensor.requiredPermission;
- if (!strcmp(mRequiredPermission, SENSOR_PERMISSION_BODY_SENSORS)) {
+ bool requiresBodySensorPermission =
+ !strcmp(mRequiredPermission, SENSOR_PERMISSION_BODY_SENSORS);
+ if (android::permission::flags::replace_body_sensor_permission_enabled()) {
+ if (requiresBodySensorPermission) {
+ ALOGE("Sensor %s using deprecated Body Sensor permission", mName.c_str());
+ }
+
+ AppOpsManager appOps;
+ // Lookup to see if an AppOp exists for the permission. If none
+ // does, the default value of -1 is used.
+ mRequiredAppOp = appOps.permissionToOpCode(String16(mRequiredPermission));
+ } else if (requiresBodySensorPermission) {
AppOpsManager appOps;
mRequiredAppOp = appOps.permissionToOpCode(String16(SENSOR_PERMISSION_BODY_SENSORS));
}