Fix race condition for SensorManager looper.
Before the fix there could be two background threads started for two
loopers. Add a guard to prevent this from happening.
Test: pass
Bug: 62404135
Change-Id: I8230addaaa6b83670d7b83c96809b00fca95d352
diff --git a/services/sensorservice/hidl/SensorManager.cpp b/services/sensorservice/hidl/SensorManager.cpp
index 004a5c5..25a3dc5 100644
--- a/services/sensorservice/hidl/SensorManager.cpp
+++ b/services/sensorservice/hidl/SensorManager.cpp
@@ -143,6 +143,10 @@
}
std::unique_lock<std::mutex> lock(mutex);
+ if (looper != nullptr) {
+ LOG(INFO) << "Another thread has already set the looper, exiting this one.";
+ return;
+ }
looper = Looper::prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS /* opts */);
lock.unlock();