Add NDK support for new head tracker sensor type
Bug: 210156629
Test: presubmit (definitions only)
Change-Id: Ie93f3a99a3215690ab585b2e248edf096712c8c0
diff --git a/include/android/sensor.h b/include/android/sensor.h
index 9dc6983..45e8afc 100644
--- a/include/android/sensor.h
+++ b/include/android/sensor.h
@@ -256,6 +256,13 @@
* The hinge angle sensor value is returned in degrees.
*/
ASENSOR_TYPE_HINGE_ANGLE = 36,
+ /**
+ * {@link ASENSOR_TYPE_HEAD_TRACKER}
+ * reporting-mode: continuous
+ *
+ * Measures the orientation and rotational velocity of a user's head.
+ */
+ ASENSOR_TYPE_HEAD_TRACKER = 37,
};
/**
@@ -440,6 +447,38 @@
};
} AAdditionalInfoEvent;
+typedef struct AHeadTrackerEvent {
+ /**
+ * The fields rx, ry, rz are an Euler vector (rotation vector, i.e. a vector
+ * whose direction indicates the axis of rotation and magnitude indicates
+ * the angle to rotate around that axis) representing the transform from
+ * the (arbitrary, possibly slowly drifting) reference frame to the
+ * head frame. Expressed in radians. Magnitude of the vector must be
+ * in the range [0, pi], while the value of individual axes are
+ * in the range [-pi, pi].
+ */
+ float rx;
+ float ry;
+ float rz;
+
+ /**
+ * The fields vx, vy, vz are an Euler vector (rotation vector) representing
+ * the angular velocity of the head (relative to itself), in radians per
+ * second. The direction of this vector indicates the axis of rotation, and
+ * the magnitude indicates the rate of rotation.
+ */
+ float vx;
+ float vy;
+ float vz;
+
+ /**
+ * This value changes each time the reference frame is suddenly and
+ * significantly changed, for example if an orientation filter algorithm
+ * used for determining the orientation has had its state reset.
+ */
+ int32_t discontinuity_count;
+} AHeadTrackerEvent;
+
/**
* Information that describes a sensor event, refer to
* <a href="/reference/android/hardware/SensorEvent">SensorEvent</a> for additional
@@ -476,6 +515,7 @@
AHeartRateEvent heart_rate;
ADynamicSensorEvent dynamic_sensor_meta;
AAdditionalInfoEvent additional_info;
+ AHeadTrackerEvent head_tracker;
};
union {
uint64_t data[8];
diff --git a/libs/sensor/Sensor.cpp b/libs/sensor/Sensor.cpp
index 0a49008..e1560c0 100644
--- a/libs/sensor/Sensor.cpp
+++ b/libs/sensor/Sensor.cpp
@@ -276,6 +276,10 @@
mStringType = SENSOR_STRING_TYPE_HINGE_ANGLE;
mFlags |= SENSOR_FLAG_ON_CHANGE_MODE;
break;
+ case SENSOR_TYPE_HEAD_TRACKER:
+ mStringType = SENSOR_STRING_TYPE_HEAD_TRACKER;
+ mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
+ break;
default:
// Only pipe the stringType, requiredPermission and flags for custom sensors.
if (halVersion > SENSORS_DEVICE_API_VERSION_1_0 && hwSensor.stringType) {
diff --git a/services/sensorservice/SensorServiceUtils.cpp b/services/sensorservice/SensorServiceUtils.cpp
index fdd56b3..baa01c9 100644
--- a/services/sensorservice/SensorServiceUtils.cpp
+++ b/services/sensorservice/SensorServiceUtils.cpp
@@ -58,6 +58,9 @@
case SENSOR_TYPE_HINGE_ANGLE:
return 1;
+ case SENSOR_TYPE_HEAD_TRACKER:
+ return 7;
+
default:
return 3;
}