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

Commit ea938cfb authored by Ricardo Cerqueira's avatar Ricardo Cerqueira Committed by Steve Kondik
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

sensorservice: Set the rate for pre-1.1 HALs _after_ activation

We want to be sure these are applied in the same sequence they
used to be...

Change-Id: Ied2ba08ed3c4bed3a80bac6ab5471fcea9ba2c09
parent 06a1765b
Loading
Loading
Loading
Loading
+15 −7
Original line number Diff line number Diff line
@@ -787,8 +787,10 @@ status_t SensorService::enable(const sp<SensorEventConnection>& connection,
    // Call flush() before calling activate() on the sensor. Wait for a first flush complete
    // event before sending events on this connection. Ignore one-shot sensors which don't
    // support flush(). Also if this sensor isn't already active, don't call flush().
    const SensorDevice& device(SensorDevice::getInstance());
    if (err == NO_ERROR && sensor->getSensor().getReportingMode() != AREPORTING_MODE_ONE_SHOT &&
            rec->getNumConnections() > 1) {
        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 underlying h/w sensor uses an older HAL.
@@ -798,6 +800,7 @@ status_t SensorService::enable(const sp<SensorEventConnection>& connection,
                connection->setFirstFlushPending(handle, false);
            }
        }
    }

    if (err == NO_ERROR) {
        ALOGD_IF(DEBUG_CONNECTIONS, "Calling activate on %d", handle);
@@ -808,6 +811,11 @@ status_t SensorService::enable(const sp<SensorEventConnection>& connection,
        connection->updateLooperRegistration(mLooper);
    }

    if (device.getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_1) {
        // 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) {
        // batch/activate has failed, reset our state.
        cleanupWithoutDisableLocked(connection, handle);