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
This commit is contained in:
Erik Staats 2021-09-30 06:50:43 -07:00
parent 7b29add5f7
commit 43bc7bccdc

View file

@ -35,6 +35,21 @@ using ::android::hardware::Void;
namespace android { namespace android {
namespace SensorHalExt { 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() { DynamicSensorsSubHal::DynamicSensorsSubHal() {
// initialize dynamic sensor manager // initialize dynamic sensor manager
mDynamicSensorManager.reset( mDynamicSensorManager.reset(
@ -49,19 +64,18 @@ Return<Result> DynamicSensorsSubHal::setOperationMode(OperationMode mode) {
Result::OK : Result::BAD_VALUE); Result::OK : Result::BAD_VALUE);
} }
Return<Result> DynamicSensorsSubHal::activate(int32_t sensor_handle __unused, Return<Result> DynamicSensorsSubHal::activate(int32_t sensor_handle,
bool enabled __unused) { bool enabled) {
ALOGE("DynamicSensorsSubHal::activate not supported."); int rc = mDynamicSensorManager->activate(sensor_handle, enabled);
return ResultFromStatus(rc);
return Result::INVALID_OPERATION;
} }
Return<Result> DynamicSensorsSubHal::batch( Return<Result> DynamicSensorsSubHal::batch(
int32_t sensor_handle __unused, int64_t sampling_period_ns __unused, int32_t sensor_handle, int64_t sampling_period_ns,
int64_t max_report_latency_ns __unused) { int64_t max_report_latency_ns) {
ALOGE("DynamicSensorsSubHal::batch not supported."); int rc = mDynamicSensorManager->batch(sensor_handle, sampling_period_ns,
max_report_latency_ns);
return Result::INVALID_OPERATION; return ResultFromStatus(rc);
} }
Return<Result> DynamicSensorsSubHal::flush(int32_t sensor_handle __unused) { Return<Result> DynamicSensorsSubHal::flush(int32_t sensor_handle __unused) {