Block dynamic connection event if sensor not found
A bug in the Sensors HIDL spec marks onDynamicSensorsConnected as oneway
which means that HALs are not blocked on the framework processing that
event. This means the onDynamicSensorsConnected invocation and dynamic
meta event can be received out of order. Blocking processing of the
event gives time for onDynamicSensorsConnected to be invoked so that the
event can be correctly processed.
Bug: 201529167
Test: Connect dynamic sensor and validate that the HAL can deliver the
event and method invocation without any sleeps on the HAL side.
Change-Id: Ie1cad22f26de60a7cecb3c6048280c4919165dbb
diff --git a/services/sensorservice/SensorDevice.h b/services/sensorservice/SensorDevice.h
index 75da7bb..bc8d20f 100644
--- a/services/sensorservice/SensorDevice.h
+++ b/services/sensorservice/SensorDevice.h
@@ -139,6 +139,14 @@
Vector<sensor_t> mSensorList;
std::unordered_map<int32_t, sensor_t*> mConnectedDynamicSensors;
+ // A bug in the Sensors HIDL spec which marks onDynamicSensorsConnected as oneway causes dynamic
+ // meta events and onDynamicSensorsConnected to be received out of order. This mutex + CV are
+ // used to block meta event processing until onDynamicSensorsConnected is received to simplify
+ // HAL implementations.
+ std::mutex mDynamicSensorsMutex;
+ std::condition_variable mDynamicSensorsCv;
+ static constexpr std::chrono::seconds MAX_DYN_SENSOR_WAIT{5};
+
static const nsecs_t MINIMUM_EVENTS_PERIOD = 1000000; // 1000 Hz
mutable Mutex mLock; // protect mActivationCount[].batchParams
// fixed-size array after construction