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

Commit 747472a3 authored by Ricardo Cerqueira's avatar Ricardo Cerqueira
Browse files

sensorservice: Fix init sequence for pre-1.1 API sensor HALs

The sensors API introduced a new flush() method that older binaries
won't have. For those, replace the firstFlush invocation with a
setDelay call since a lot of implementations interpreted that as
the initialization step.
We also don't want any kind of call to flush() to happen when it
isn't there, since it'll either hit a random OEM extension or
a memory address we really don't want to execute.

Change-Id: I26ce923fe385751fed7d1c483a53c074249f0620
parent b245ffb9
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -595,6 +595,8 @@ status_t SensorService::enable(const sp<SensorEventConnection>& connection,
    status_t err = sensor->batch(connection.get(), handle, reservedFlags, samplingPeriodNs,
                                 maxBatchReportLatencyNs);
    if (err == NO_ERROR) {
        const SensorDevice& device(SensorDevice::getInstance());
        if (device.getHalDeviceVersion() >= SENSORS_DEVICE_API_VERSION_1_1) {
            connection->setFirstFlushPending(handle, true);
            status_t err_flush = sensor->flush(connection.get(), handle);
            // Flush may return error if the sensor is not activated or the underlying h/w sensor does
@@ -602,6 +604,10 @@ status_t SensorService::enable(const sp<SensorEventConnection>& connection,
            if (err_flush != NO_ERROR) {
                connection->setFirstFlushPending(handle, false);
            }
        } else {
            // Pre-1.1 sensor HALs had no flush method, and relied on setDelay at init
            sensor->setDelay(connection.get(), handle, samplingPeriodNs);
        }
    }

    if (err == NO_ERROR) {