diff --git a/sensors/2.0/default/Sensor.cpp b/sensors/2.0/default/Sensor.cpp index 21c1591d01..d3e3f7e15a 100644 --- a/sensors/2.0/default/Sensor.cpp +++ b/sensors/2.0/default/Sensor.cpp @@ -24,6 +24,7 @@ namespace sensors { namespace V2_0 { namespace implementation { +using ::android::hardware::sensors::V1_0::MetaDataEventType; using ::android::hardware::sensors::V1_0::SensorFlagBits; using ::android::hardware::sensors::V1_0::SensorStatus; @@ -64,6 +65,25 @@ void Sensor::activate(bool enable) { } } +Result Sensor::flush() { + // Only generate a flush complete event if the sensor is enabled and if the sensor is not a + // one-shot sensor. + if (!mIsEnabled || (mSensorInfo.flags & static_cast(SensorFlagBits::ONE_SHOT_MODE))) { + return Result::BAD_VALUE; + } + + // Note: If a sensor supports batching, write all of the currently batched events for the sensor + // to the Event FMQ prior to writing the flush complete event. + Event ev; + ev.sensorHandle = mSensorInfo.sensorHandle; + ev.sensorType = SensorType::ADDITIONAL_INFO; + ev.u.meta.what = MetaDataEventType::META_DATA_FLUSH_COMPLETE; + std::vector evs{ev}; + mCallback->postEvents(evs); + + return Result::OK; +} + void Sensor::startThread(Sensor* sensor) { sensor->run(); } diff --git a/sensors/2.0/default/Sensor.h b/sensors/2.0/default/Sensor.h index e467b56f78..75d9aabb1c 100644 --- a/sensors/2.0/default/Sensor.h +++ b/sensors/2.0/default/Sensor.h @@ -25,6 +25,7 @@ #include using ::android::hardware::sensors::V1_0::Event; +using ::android::hardware::sensors::V1_0::Result; using ::android::hardware::sensors::V1_0::SensorInfo; using ::android::hardware::sensors::V1_0::SensorType; @@ -48,6 +49,7 @@ class Sensor { const SensorInfo& getSensorInfo() const; void batch(int32_t samplingPeriodNs); void activate(bool enable); + Result flush(); protected: void run(); diff --git a/sensors/2.0/default/Sensors.cpp b/sensors/2.0/default/Sensors.cpp index 39c1ded356..cceb7d5c25 100644 --- a/sensors/2.0/default/Sensors.cpp +++ b/sensors/2.0/default/Sensors.cpp @@ -112,9 +112,12 @@ Return Sensors::batch(int32_t sensorHandle, int64_t samplingPeriodNs, return Result::BAD_VALUE; } -Return Sensors::flush(int32_t /* sensorHandle */) { - // TODO implement - return Result{}; +Return Sensors::flush(int32_t sensorHandle) { + auto sensor = mSensors.find(sensorHandle); + if (sensor != mSensors.end()) { + return sensor->second->flush(); + } + return Result::BAD_VALUE; } Return Sensors::injectSensorData(const Event& /* event */) {