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.h b/services/sensorservice/SensorInterface.h
index 5704359..5ee5e12 100644
--- a/services/sensorservice/SensorInterface.h
+++ b/services/sensorservice/SensorInterface.h
@@ -104,6 +104,32 @@
 
 // ---------------------------------------------------------------------------
 
+class RuntimeSensor : public BaseSensor {
+public:
+    static constexpr int DEFAULT_DEVICE_ID = 0;
+
+    class StateChangeCallback : public virtual RefBase {
+      public:
+        virtual void onStateChanged(bool enabled, int64_t samplingPeriodNs,
+                                    int64_t batchReportLatencyNs) = 0;
+    };
+    RuntimeSensor(const sensor_t& sensor, sp<StateChangeCallback> callback);
+    virtual status_t activate(void* ident, bool enabled) override;
+    virtual status_t batch(void* ident, int handle, int flags, int64_t samplingPeriodNs,
+                           int64_t maxBatchReportLatencyNs) override;
+    virtual status_t setDelay(void* ident, int handle, int64_t ns) override;
+    virtual bool process(sensors_event_t*, const sensors_event_t&) { return false; }
+    virtual bool isVirtual() const override { return false; }
+
+private:
+    bool mEnabled = false;
+    int64_t mSamplingPeriodNs = 0;
+    int64_t mBatchReportLatencyNs = 0;
+    sp<StateChangeCallback> mCallback;
+};
+
+// ---------------------------------------------------------------------------
+
 class ProximitySensor : public HardwareSensor {
 public:
     explicit ProximitySensor(const sensor_t& sensor, SensorService& service);