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
This commit is contained in:
Ricardo Cerqueira 2013-12-15 18:12:17 +00:00 committed by Steve Kondik
parent 5b6a10373e
commit c77679141d
1 changed files with 15 additions and 7 deletions

View File

@ -915,15 +915,18 @@ 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) {
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<SensorEventConnection>& 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);