From c77679141d48c6fb593a1b23f5a985f2330f5820 Mon Sep 17 00:00:00 2001 From: Ricardo Cerqueira Date: Sun, 15 Dec 2013 18:12:17 +0000 Subject: 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 --- services/sensorservice/SensorService.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'services') diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp index 40b21a9..313011a 100644 --- a/services/sensorservice/SensorService.cpp +++ b/services/sensorservice/SensorService.cpp @@ -915,15 +915,18 @@ status_t SensorService::enable(const sp& 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) { - 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. - if (err_flush == NO_ERROR) { - rec->addPendingFlushConnection(connection.get()); - } else { - connection->setFirstFlushPending(handle, false); + 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. + if (err_flush == NO_ERROR) { + rec->addPendingFlushConnection(connection.get()); + } else { + connection->setFirstFlushPending(handle, false); + } } } @@ -949,6 +952,11 @@ status_t SensorService::enable(const sp& connection, mNextSensorRegIndex = (mNextSensorRegIndex + 1) % SENSOR_REGISTRATIONS_BUF_SIZE; } + 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); -- cgit v1.1