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
diff --git a/sensors/1.0/default/convert.cpp b/sensors/1.0/default/convert.cpp
index acff6ca..306d3a3 100644
--- a/sensors/1.0/default/convert.cpp
+++ b/sensors/1.0/default/convert.cpp
@@ -75,6 +75,10 @@
         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 @@
   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 5bcfe4b..65f6d81 100644
--- a/sensors/1.0/default/service.cpp
+++ b/sensors/1.0/default/service.cpp
@@ -23,5 +23,9 @@
 using android::hardware::defaultPassthroughServiceImplementation;
 
 int main() {
-    return defaultPassthroughServiceImplementation<ISensors>();
+    /* 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<ISensors>(2);
 }