dynamic_sensor: Add multi-HAL 2.1 flush support.

Bug: 201730055
Test: Verified that flush, batch, and activate sensor VTS tests pass.
Change-Id: I6721d9f8976b3ef9f6af02b2320833025b479ee6
This commit is contained in:
Erik Staats
2021-10-04 15:17:32 -07:00
parent 43bc7bccdc
commit 35964ba076
4 changed files with 17 additions and 12 deletions

View File

@@ -42,6 +42,7 @@ void BaseSensorObject::getUuid(uint8_t* uuid) const {
int BaseSensorObject::flush() {
static const sensors_event_t event = {
.type = SENSOR_TYPE_META_DATA,
.meta_data.what = META_DATA_FLUSH_COMPLETE,
.timestamp = TIMESTAMP_AUTO_FILL // timestamp will be filled at dispatcher
};
generateEvent(event);

View File

@@ -76,7 +76,7 @@ bool DynamicSensorManager::owns(int handle) const {
int DynamicSensorManager::activate(int handle, bool enable) {
if (handle == mHandleRange.first) {
// ignored
mMetaSensorActive = enable;
return 0;
}
@@ -109,13 +109,17 @@ int DynamicSensorManager::setDelay(int handle, nsecs_t sample_period) {
int DynamicSensorManager::flush(int handle) {
if (handle == mHandleRange.first) {
// submit a flush complete here
static const sensors_event_t event = {
.sensor = mHandleRange.first,
.type = SENSOR_TYPE_META_DATA,
.timestamp = TIMESTAMP_AUTO_FILL, // timestamp will be filled at dispatcher
};
submitEvent(nullptr, event);
if (mMetaSensorActive) {
static const sensors_event_t event = {
.sensor = mHandleRange.first,
.type = SENSOR_TYPE_META_DATA,
.meta_data.what = META_DATA_FLUSH_COMPLETE,
.timestamp = TIMESTAMP_AUTO_FILL, // timestamp will be filled at dispatcher
};
submitEvent(nullptr, event);
} else {
return -EINVAL;
}
return 0;
}
return operateSensor(handle, [] (sp<BaseSensorObject> s)->int {return s->flush();});

View File

@@ -111,6 +111,7 @@ private:
// available sensor handle space
const std::pair<int, int> mHandleRange;
sensor_t mMetaSensor;
bool mMetaSensorActive = false;
// immutable pointer to event callback, used in extention mode.
SensorEventCallback * const mCallback;

View File

@@ -78,10 +78,9 @@ Return<Result> DynamicSensorsSubHal::batch(
return ResultFromStatus(rc);
}
Return<Result> DynamicSensorsSubHal::flush(int32_t sensor_handle __unused) {
ALOGE("DynamicSensorsSubHal::flush not supported.");
return Result::INVALID_OPERATION;
Return<Result> DynamicSensorsSubHal::flush(int32_t sensor_handle) {
int rc = mDynamicSensorManager->flush(sensor_handle);
return ResultFromStatus(rc);
}
Return<void> DynamicSensorsSubHal::registerDirectChannel(