Support REPLAY_DATA_INJECTION mode

For test builds only, allow an app to inject sensor data and have that
data forwarded to all active clients of the sensors framework. This
allows replay frameworks to be built for advanced testing of system
behavior.

Bug: 262573975
Test: Run on prod/test builds and verify it only works on the latter
Test: Verify all modes continue to work as expected
Change-Id: I9e9fcb76cbd7ab4bc8eddffc71d60981f50517f4
diff --git a/services/sensorservice/SensorEventConnection.cpp b/services/sensorservice/SensorEventConnection.cpp
index 82d0295..a3a62a1 100644
--- a/services/sensorservice/SensorEventConnection.cpp
+++ b/services/sensorservice/SensorEventConnection.cpp
@@ -850,6 +850,11 @@
                     // Unregister call backs.
                     return 0;
                 }
+                if (!mService->isWhiteListedPackage(mPackageName)) {
+                    ALOGE("App not allowed to inject data, dropping event"
+                          "package=%s uid=%d", mPackageName.string(), mUid);
+                    return 0;
+                }
                 sensors_event_t sensor_event;
                 memcpy(&sensor_event, buf, sizeof(sensors_event_t));
                 std::shared_ptr<SensorInterface> si =