Loading services/sensorservice/SensorDevice.cpp +12 −8 Original line number Diff line number Diff line Loading @@ -429,16 +429,20 @@ void SensorDevice::onDynamicSensorsConnected(const std::vector<sensor_t>& dynami } void SensorDevice::onDynamicSensorsDisconnected( const std::vector<int32_t>& dynamicSensorHandlesRemoved) { if (sensorservice_flags::sensor_device_on_dynamic_sensor_disconnected()) { for (auto handle : dynamicSensorHandlesRemoved) { const std::vector<int32_t>& /*dynamicSensorHandlesRemoved*/) { // This function is currently a no-op has removing data in mConnectedDynamicSensors here will // cause a race condition between when this callback is invoked and when the dynamic sensor meta // event is processed by polling. The clean up should only happen after processing the meta // event. See the call stack of cleanupDisconnectedDynamicSensor. } void SensorDevice::cleanupDisconnectedDynamicSensor(int handle) { std::lock_guard<std::mutex> lock(mDynamicSensorsMutex); auto it = mConnectedDynamicSensors.find(handle); if (it != mConnectedDynamicSensors.end()) { mConnectedDynamicSensors.erase(it); } } } } void SensorDevice::writeWakeLockHandled(uint32_t count) { if (mHalWrapper != nullptr && mHalWrapper->supportsMessageQueues()) { Loading services/sensorservice/SensorDevice.h +8 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,14 @@ public: std::vector<int32_t> getDynamicSensorHandles(); void handleDynamicSensorConnection(int handle, bool connected); /** * Removes handle from connected dynamic sensor list. Note that this method must be called after * SensorService has done using sensor data. * * @param handle of the disconnected dynamic sensor. */ void cleanupDisconnectedDynamicSensor(int handle); status_t initCheck() const; int getHalDeviceVersion() const; Loading services/sensorservice/SensorService.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -1273,6 +1273,7 @@ bool SensorService::threadLoop() { } else { int handle = mSensorEventBuffer[i].dynamic_sensor_meta.handle; disconnectDynamicSensor(handle, activeConnections); device.cleanupDisconnectedDynamicSensor(handle); } } } Loading Loading
services/sensorservice/SensorDevice.cpp +12 −8 Original line number Diff line number Diff line Loading @@ -429,16 +429,20 @@ void SensorDevice::onDynamicSensorsConnected(const std::vector<sensor_t>& dynami } void SensorDevice::onDynamicSensorsDisconnected( const std::vector<int32_t>& dynamicSensorHandlesRemoved) { if (sensorservice_flags::sensor_device_on_dynamic_sensor_disconnected()) { for (auto handle : dynamicSensorHandlesRemoved) { const std::vector<int32_t>& /*dynamicSensorHandlesRemoved*/) { // This function is currently a no-op has removing data in mConnectedDynamicSensors here will // cause a race condition between when this callback is invoked and when the dynamic sensor meta // event is processed by polling. The clean up should only happen after processing the meta // event. See the call stack of cleanupDisconnectedDynamicSensor. } void SensorDevice::cleanupDisconnectedDynamicSensor(int handle) { std::lock_guard<std::mutex> lock(mDynamicSensorsMutex); auto it = mConnectedDynamicSensors.find(handle); if (it != mConnectedDynamicSensors.end()) { mConnectedDynamicSensors.erase(it); } } } } void SensorDevice::writeWakeLockHandled(uint32_t count) { if (mHalWrapper != nullptr && mHalWrapper->supportsMessageQueues()) { Loading
services/sensorservice/SensorDevice.h +8 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,14 @@ public: std::vector<int32_t> getDynamicSensorHandles(); void handleDynamicSensorConnection(int handle, bool connected); /** * Removes handle from connected dynamic sensor list. Note that this method must be called after * SensorService has done using sensor data. * * @param handle of the disconnected dynamic sensor. */ void cleanupDisconnectedDynamicSensor(int handle); status_t initCheck() const; int getHalDeviceVersion() const; Loading
services/sensorservice/SensorService.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -1273,6 +1273,7 @@ bool SensorService::threadLoop() { } else { int handle = mSensorEventBuffer[i].dynamic_sensor_meta.handle; disconnectDynamicSensor(handle, activeConnections); device.cleanupDisconnectedDynamicSensor(handle); } } } Loading