Virtual device sensor support in sensor service.
The virutal device sensors are runtime sensors, using handle range of [0x5F000000, 0x5FFFFFFFF].
As opposed to the HAL dynamic sensors, they do not rely on the existence of a SENSOR_TYPE_DYNAMIC_SENSOR_META. Instead of sensor events representing registration/unregistration of dynamic sensors, they are handled syncronously in the sensor service.
The virtual dynamic sensors are not exposed via the dynamic sensors API. They are provided to SensorManager through a separate JNI call.
Bug: 237278244
Test: atest cts/tests/sensor
Change-Id: I09e5b089d1ae3bed7a25a5454a31aba9cf594a05
diff --git a/services/sensorservice/SensorInterface.cpp b/services/sensorservice/SensorInterface.cpp
index 46f00e8..398cdf9 100644
--- a/services/sensorservice/SensorInterface.cpp
+++ b/services/sensorservice/SensorInterface.cpp
@@ -87,6 +87,42 @@
// ---------------------------------------------------------------------------
+RuntimeSensor::RuntimeSensor(const sensor_t& sensor, sp<StateChangeCallback> callback)
+ : BaseSensor(sensor), mCallback(std::move(callback)) {
+}
+
+status_t RuntimeSensor::activate(void*, bool enabled) {
+ if (enabled != mEnabled) {
+ mEnabled = enabled;
+ mCallback->onStateChanged(mEnabled, mSamplingPeriodNs, mBatchReportLatencyNs);
+ }
+ return OK;
+}
+
+status_t RuntimeSensor::batch(void*, int, int, int64_t samplingPeriodNs,
+ int64_t maxBatchReportLatencyNs) {
+ if (mSamplingPeriodNs != samplingPeriodNs || mBatchReportLatencyNs != maxBatchReportLatencyNs) {
+ mSamplingPeriodNs = samplingPeriodNs;
+ mBatchReportLatencyNs = maxBatchReportLatencyNs;
+ if (mEnabled) {
+ mCallback->onStateChanged(mEnabled, mSamplingPeriodNs, mBatchReportLatencyNs);
+ }
+ }
+ return OK;
+}
+
+status_t RuntimeSensor::setDelay(void*, int, int64_t ns) {
+ if (mSamplingPeriodNs != ns) {
+ mSamplingPeriodNs = ns;
+ if (mEnabled) {
+ mCallback->onStateChanged(mEnabled, mSamplingPeriodNs, mBatchReportLatencyNs);
+ }
+ }
+ return OK;
+}
+
+// ---------------------------------------------------------------------------
+
ProximitySensor::ProximitySensor(const sensor_t& sensor, SensorService& service)
: HardwareSensor(sensor), mSensorService(service) {
}