Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5f1de538 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Default flush implementation for Sensors 2.0"

parents ca9a156f e4f74c77
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -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();
}
+2 −0
Original line number Diff line number Diff line
@@ -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();
+6 −3
Original line number Diff line number Diff line
@@ -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 */) {