diff options
author | Yifan Hong <elsk@google.com> | 2017-06-13 18:04:25 -0700 |
---|---|---|
committer | Yifan Hong <elsk@google.com> | 2017-06-13 18:56:07 -0700 |
commit | 80d87ee386be7065817d4d40f2151dec9e0c557c (patch) | |
tree | 2d63602319b8b6e9c87494a1cdf3bfc15c529975 | |
parent | 09034f076e7897732479c8aef6284938aafbfbfe (diff) | |
download | native-80d87ee386be7065817d4d40f2151dec9e0c557c.tar.gz |
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
-rw-r--r-- | services/sensorservice/hidl/SensorManager.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/services/sensorservice/hidl/SensorManager.cpp b/services/sensorservice/hidl/SensorManager.cpp index 004a5c5cae..25a3dc50d2 100644 --- a/services/sensorservice/hidl/SensorManager.cpp +++ b/services/sensorservice/hidl/SensorManager.cpp @@ -143,6 +143,10 @@ sp<::android::Looper> SensorManager::getLooper() { } 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(); |