Transparently map to big image accel as needed

When using SEE and micro-image is enabled, allow big image nanoapps to
receive deep-batched accel data by rerouting their requests for
accelerometer to vendor sensor type 3. This is a custom sensor type
that routes to accelerometer via QMI.

Bug: 79257265
Test: mark all static nanoapps as big image, confirm that SensorWorld
can request accel and get batched delivery in big image, while imu_cal
receives data at a shorter interval in micro-image
Change-Id: Idc38ca9a5a5afaafc89fe04c787c842bbe233a57
diff --git a/platform/shared/chre_api_sensor.cc b/platform/shared/chre_api_sensor.cc
index 13b8e71..d58c774 100644
--- a/platform/shared/chre_api_sensor.cc
+++ b/platform/shared/chre_api_sensor.cc
@@ -31,6 +31,29 @@
 using chre::getSensorTypeFromUnsignedInt;
 
 DLL_EXPORT bool chreSensorFindDefault(uint8_t sensorType, uint32_t *handle) {
+#if defined(CHRE_SLPI_SEE) && defined(CHRE_SLPI_UIMG_ENABLED)
+  // HACK: as SEE does not support software batching in uimg via QCM/uQSockets,
+  // reroute requests for accelerometer from a big image nanoapp to a separate
+  // sensor type internally. Accel is the only always-on sensor used today by
+  // big image nanoapps, and this change allows these requests to transparently
+  // go to a separate sensor implementation that supports uimg batching via
+  // CM/QMI.
+  // TODO(P2-5673a9): work with QC to determine a better long-term solution
+  constexpr uint8_t kBigImageAccelSensorType =
+      (CHRE_SENSOR_TYPE_VENDOR_START + 3);
+  chre::Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
+  if (!nanoapp->isUimgApp()) {
+    if (sensorType == CHRE_SENSOR_TYPE_ACCELEROMETER) {
+      sensorType = kBigImageAccelSensorType;
+    } else if (sensorType == kBigImageAccelSensorType) {
+      // Since we have an accompanying hack in PlatformNanoapp::handleEvent(),
+      // hide the vendor sensor type from big image nanoapps as we're unable to
+      // deliver events for it
+      return false;
+    }
+  }
+#endif  // defined(CHRE_SLPI_SEE) && defined(CHRE_SLPI_UIMG_ENABLED)
+
   SensorType validatedSensorType = getSensorTypeFromUnsignedInt(sensorType);
   return (validatedSensorType != SensorType::Unknown
       && EventLoopManagerSingleton::get()->getSensorRequestManager()
diff --git a/platform/slpi/platform_nanoapp.cc b/platform/slpi/platform_nanoapp.cc
index cb3cb78..20b8196 100644
--- a/platform/slpi/platform_nanoapp.cc
+++ b/platform/slpi/platform_nanoapp.cc
@@ -55,6 +55,21 @@
                                   const void *eventData) {
   if (!isUimgApp()) {
     slpiForceBigImage();
+
+#if defined(CHRE_SLPI_SEE) && defined(CHRE_SLPI_UIMG_ENABLED)
+    // HACK: as SEE does not support software batching in uimg via
+    // QCM/uQSockets, we rewrite requests for accel from big image nanoapps to
+    // vendor type 3 in chreSensorFindDefault(), which is implemented as accel
+    // routed through CM/QMI and supports batching. Rewrite sensor data arriving
+    // on this event type to the vanilla accel event type so that this appears
+    // transparent to the nanoapp.
+    // TODO(P2-5673a9): work with QC to determine a better long-term solution
+    constexpr uint16_t kAccelBigImageEventType =
+        (CHRE_EVENT_SENSOR_DATA_EVENT_BASE + CHRE_SENSOR_TYPE_VENDOR_START + 3);
+    if (eventType == kAccelBigImageEventType) {
+      eventType = CHRE_EVENT_SENSOR_ACCELEROMETER_DATA;
+    }
+#endif  // defined(CHRE_SLPI_SEE) && defined(CHRE_SLPI_UIMG_ENABLED)
   }
 
   mAppInfo->entryPoints.handleEvent(senderInstanceId, eventType, eventData);