diff --git a/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.cpp b/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.cpp index df636a3b..2db58842 100644 --- a/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.cpp +++ b/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.cpp @@ -16,16 +16,30 @@ #include "DynamicSensorsSubHal.h" +#include #include #include using ::android::hardware::sensors::V1_0::Result; +using ::android::hardware::sensors::V2_1::SensorInfo; +using ::android::hardware::sensors::V2_1::SensorType; template using Return = ::android::hardware::Return; using ::android::hardware::Void; namespace android { namespace SensorHalExt { +DynamicSensorsSubHal::DynamicSensorsSubHal() { + // initialize dynamic sensor manager + int32_t base = property_get_int32("sensor.dynamic_sensor_hal.handle_base", + kDynamicHandleBase); + int32_t count = property_get_int32("sensor.dynamic_sensor_hal.handle_count", + kMaxDynamicHandleCount); + mDynamicSensorManager.reset( + DynamicSensorManager::createInstance(base, count, + nullptr /* callback */)); +} + // ISensors. Return DynamicSensorsSubHal::setOperationMode(OperationMode mode) { return (mode == static_cast(SENSOR_HAL_NORMAL_MODE) ? @@ -77,9 +91,32 @@ Return DynamicSensorsSubHal::configDirectReport( } Return DynamicSensorsSubHal::getSensorsList_2_1( - getSensorsList_2_1_cb callback __unused) { + getSensorsList_2_1_cb callback) { + const sensor_t& sensor_info = mDynamicSensorManager->getDynamicMetaSensor(); + std::vector sensors; + ALOGD("DynamicSensorsSubHal::getSensorsList_2_1 invoked."); + // get the dynamic sensor info + sensors.resize(1); + sensors[0].sensorHandle = sensor_info.handle; + sensors[0].name = sensor_info.name; + sensors[0].vendor = sensor_info.vendor; + sensors[0].version = 1; + sensors[0].type = static_cast(sensor_info.type); + sensors[0].typeAsString = sensor_info.stringType; + sensors[0].maxRange = sensor_info.maxRange; + sensors[0].resolution = sensor_info.resolution; + sensors[0].power = sensor_info.power; + sensors[0].minDelay = sensor_info.minDelay; + sensors[0].fifoReservedEventCount = sensor_info.fifoReservedEventCount; + sensors[0].fifoMaxEventCount = sensor_info.fifoMaxEventCount; + sensors[0].requiredPermission = sensor_info.requiredPermission; + sensors[0].maxDelay = sensor_info.maxDelay; + sensors[0].flags = sensor_info.flags; + + callback(sensors); + return Void(); } diff --git a/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.h b/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.h index 36ed9f5a..ab5d2999 100644 --- a/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.h +++ b/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.h @@ -17,6 +17,8 @@ #ifndef ANDROID_SENSORHAL_EXT_DYNAMIC_SENSORS_SUB_HAL_H #define ANDROID_SENSORHAL_EXT_DYNAMIC_SENSORS_SUB_HAL_H +#include "DynamicSensorManager.h" + #include namespace android { @@ -37,6 +39,8 @@ class DynamicSensorsSubHal : using SharedMemInfo = ::android::hardware::sensors::V1_0::SharedMemInfo; public: + DynamicSensorsSubHal(); + // ISensors. Return setOperationMode(OperationMode mode) override; Return activate(int32_t sensor_handle, bool enabled) override; @@ -60,6 +64,14 @@ public: const std::string getName() override { return "Dynamic-SubHAL"; } Return initialize( const sp& hal_proxy_callback) override; + +private: + static constexpr int32_t kDynamicHandleBase = 0; + static constexpr int32_t kDynamicHandleEnd = 0x1000000; + static constexpr int32_t kMaxDynamicHandleCount = kDynamicHandleEnd - + kDynamicHandleBase; + + std::unique_ptr mDynamicSensorManager; }; } // namespace SensorHalExt