From da270a09f46d300474c8fc47badb8f148dc614f9 Mon Sep 17 00:00:00 2001 From: Ashutosh Joshi Date: Mon, 13 Feb 2017 12:52:14 -0800 Subject: [PATCH] Fix shim layer bugs for Sensors HIDL wrapper. i) Increase the number of default threads to 2. ii) Handle the flush complete event correctly. Bug: 35189074 Bug: 35067266 Test: Test that sensors work in both binderized and passthrough modes. Ensure that camera photosphere works. Change-Id: Ic8dadf03395b4e96092ae962cf790c93d65a1c8d --- sensors/1.0/default/convert.cpp | 10 +++++++++- sensors/1.0/default/service.cpp | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/sensors/1.0/default/convert.cpp b/sensors/1.0/default/convert.cpp index acff6ca7c1..306d3a3bc2 100644 --- a/sensors/1.0/default/convert.cpp +++ b/sensors/1.0/default/convert.cpp @@ -75,6 +75,10 @@ void convertFromSensorEvent(const sensors_event_t &src, Event *dst) { case SensorType::META_DATA: { dst->u.meta.what = (MetaDataEventType)src.meta_data.what; + // Legacy HALs contain the handle reference in the meta data field. + // Copy that over to the handle of the event. In legacy HALs this + // field was expected to be 0. + dst->sensorHandle = src.meta_data.sensor; break; } @@ -212,8 +216,12 @@ void convertToSensorEvent(const Event &src, sensors_event_t *dst) { switch (src.sensorType) { case SensorType::META_DATA: { + // Legacy HALs expect the handle reference in the meta data field. + // Copy it over from the handle of the event. dst->meta_data.what = (int32_t)src.u.meta.what; - dst->meta_data.sensor = dst->sensor; + dst->meta_data.sensor = src.sensorHandle; + // Set the sensor handle to 0 to maintain compatibility. + dst->sensor = 0; break; } diff --git a/sensors/1.0/default/service.cpp b/sensors/1.0/default/service.cpp index 5bcfe4b1f8..65f6d816a1 100644 --- a/sensors/1.0/default/service.cpp +++ b/sensors/1.0/default/service.cpp @@ -23,5 +23,9 @@ using android::hardware::sensors::V1_0::ISensors; using android::hardware::defaultPassthroughServiceImplementation; int main() { - return defaultPassthroughServiceImplementation(); + /* Sensors framework service needs at least two threads. + * One thread blocks on a "poll" + * The second thread is needed for all other HAL methods. + */ + return defaultPassthroughServiceImplementation(2); }