Skip to content

Commit 0980aa8

Browse files
author
Justin Lannin
committed
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
1 parent 52683c6 commit 0980aa8

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

libs/sensor/Sensor.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,18 @@ Sensor::Sensor(struct sensor_t const& hwSensor, const uuid_t& uuid, int halVersi
306306
}
307307
if (halVersion > SENSORS_DEVICE_API_VERSION_1_0 && hwSensor.requiredPermission) {
308308
mRequiredPermission = hwSensor.requiredPermission;
309-
if (!strcmp(mRequiredPermission, SENSOR_PERMISSION_BODY_SENSORS)) {
309+
bool requiresBodySensorPermission =
310+
!strcmp(mRequiredPermission, SENSOR_PERMISSION_BODY_SENSORS);
311+
if (android::permission::flags::replace_body_sensor_permission_enabled()) {
312+
if (requiresBodySensorPermission) {
313+
ALOGE("Sensor %s using deprecated Body Sensor permission", mName.c_str());
314+
}
315+
316+
AppOpsManager appOps;
317+
// Lookup to see if an AppOp exists for the permission. If none
318+
// does, the default value of -1 is used.
319+
mRequiredAppOp = appOps.permissionToOpCode(String16(mRequiredPermission));
320+
} else if (requiresBodySensorPermission) {
310321
AppOpsManager appOps;
311322
mRequiredAppOp = appOps.permissionToOpCode(String16(SENSOR_PERMISSION_BODY_SENSORS));
312323
}

0 commit comments

Comments
 (0)