Default flush implementation for Sensors 2.0

Bug: 111070257
Test: Builds, passes corresponding VTS tests
Change-Id: I5b46232ffb0dd2c85bccd9dad34dd04d29a5677d
This commit is contained in:
Brian Stack
2018-10-29 11:51:46 -07:00
parent 76a428e985
commit e4f74c77b1
3 changed files with 28 additions and 3 deletions

View File

@@ -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<uint32_t>(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<Event> evs{ev};
mCallback->postEvents(evs);
return Result::OK;
}
void Sensor::startThread(Sensor* sensor) {
sensor->run();
}

View File

@@ -25,6 +25,7 @@
#include <vector>
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();

View File

@@ -112,9 +112,12 @@ Return<Result> Sensors::batch(int32_t sensorHandle, int64_t samplingPeriodNs,
return Result::BAD_VALUE;
}
Return<Result> Sensors::flush(int32_t /* sensorHandle */) {
// TODO implement
return Result{};
Return<Result> Sensors::flush(int32_t sensorHandle) {
auto sensor = mSensors.find(sensorHandle);
if (sensor != mSensors.end()) {
return sensor->second->flush();
}
return Result::BAD_VALUE;
}
Return<Result> Sensors::injectSensorData(const Event& /* event */) {