From 43bc7bccdc3e4ee224d5c22ef8f18b0f2fbeb1e0 Mon Sep 17 00:00:00 2001 From: Erik Staats Date: Thu, 30 Sep 2021 06:50:43 -0700 Subject: [PATCH] dynamic_sensor: Add multi-HAL 2.1 sampling support. Bug: 195964858 Test: Paired a Sony PS4 controller and verified it can be sampled as an accelerometer. The first subscription always returns all 0's, but subsequent subscriptions return proper accel samples. Change-Id: I4bbc4695c988f600a62502f9fccabaa68f42c72b --- .../dynamic_sensor/DynamicSensorsSubHal.cpp | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.cpp b/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.cpp index 4f0cc481..d9e31824 100644 --- a/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.cpp +++ b/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.cpp @@ -35,6 +35,21 @@ using ::android::hardware::Void; namespace android { namespace SensorHalExt { +static Result ResultFromStatus(status_t err) { + switch (err) { + case ::android::OK: + return Result::OK; + case ::android::PERMISSION_DENIED: + return Result::PERMISSION_DENIED; + case ::android::NO_MEMORY: + return Result::NO_MEMORY; + case ::android::BAD_VALUE: + return Result::BAD_VALUE; + default: + return Result::INVALID_OPERATION; + } +} + DynamicSensorsSubHal::DynamicSensorsSubHal() { // initialize dynamic sensor manager mDynamicSensorManager.reset( @@ -49,19 +64,18 @@ Return DynamicSensorsSubHal::setOperationMode(OperationMode mode) { Result::OK : Result::BAD_VALUE); } -Return DynamicSensorsSubHal::activate(int32_t sensor_handle __unused, - bool enabled __unused) { - ALOGE("DynamicSensorsSubHal::activate not supported."); - - return Result::INVALID_OPERATION; +Return DynamicSensorsSubHal::activate(int32_t sensor_handle, + bool enabled) { + int rc = mDynamicSensorManager->activate(sensor_handle, enabled); + return ResultFromStatus(rc); } Return DynamicSensorsSubHal::batch( - int32_t sensor_handle __unused, int64_t sampling_period_ns __unused, - int64_t max_report_latency_ns __unused) { - ALOGE("DynamicSensorsSubHal::batch not supported."); - - return Result::INVALID_OPERATION; + int32_t sensor_handle, int64_t sampling_period_ns, + int64_t max_report_latency_ns) { + int rc = mDynamicSensorManager->batch(sensor_handle, sampling_period_ns, + max_report_latency_ns); + return ResultFromStatus(rc); } Return DynamicSensorsSubHal::flush(int32_t sensor_handle __unused) {