Fix deadlock on SensorService
If mLock is held by SensorService::threadLoop(), and a new call
from SensorEventConnection comes in to e.g. enable/disable a sensor,
this thread must wait for the mLock to be released. However, if this
thread holds mConnectionLock in SensorEventConnection, and SensorService
invokes SensorEventConnection.sendEvent, the system will come into a
deadlock because both threads are waiting for each other.
To avoid this situation unlock SensotEventConnection's mConnectionLock
while going out of scope.
Also create separate mutexes for modifying mSensorInfo and
mSensorInfoBackup for better separation.
Bug: 153188258
Test: 1) Run sensor logger and enable sensor, put app in background.
2) Open a_sns_test and start streaming sensor samples
3) Open app again and verify no system ANR, sensor samples
continue to be received on app.
Change-Id: If137f39918a8b1148dcc00f1b1d82b4454bb5c7b
diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp
index 92c27b1..29df825 100644
--- a/services/sensorservice/SensorService.cpp
+++ b/services/sensorservice/SensorService.cpp
@@ -316,6 +316,9 @@
conn->setSensorAccess(hasAccess);
}
}
+
+ // Lock the mutex again for clean shutdown
+ mLock.lock();
}
const Sensor& SensorService::registerSensor(SensorInterface* s, bool isDebug, bool isVirtual) {