diff options
| author | 2024-08-26 22:05:27 +0000 | |
|---|---|---|
| committer | 2024-09-17 23:06:17 +0000 | |
| commit | 4a0de5b41e6e4dabf0af4b8f59a9a78fb7d0b3f9 (patch) | |
| tree | 4a536bcd9519aff88168c1136f0dc1474e7b8774 | |
| parent | c69b08521f8325504d675a419e083eb01549d95a (diff) | |
Protect mMicSamplingPeriodBackup by mConnectionLock
Test: Presubmit
Fixes: 357599979
Flag: EXEMPT bug fix
Change-Id: I705579eef8cc5fe371f3e57d0e16e8df1acfc3c5
| -rw-r--r-- | services/sensorservice/Android.bp | 1 | ||||
| -rw-r--r-- | services/sensorservice/SensorEventConnection.cpp | 5 | ||||
| -rw-r--r-- | services/sensorservice/SensorEventConnection.h | 3 |
3 files changed, 8 insertions, 1 deletions
diff --git a/services/sensorservice/Android.bp b/services/sensorservice/Android.bp index f4b0265afb..7b2596adca 100644 --- a/services/sensorservice/Android.bp +++ b/services/sensorservice/Android.bp @@ -52,6 +52,7 @@ cc_library { "-Wall", "-Werror", "-Wextra", + "-Wthread-safety", "-fvisibility=hidden", ], diff --git a/services/sensorservice/SensorEventConnection.cpp b/services/sensorservice/SensorEventConnection.cpp index f56642b77c..0d00642688 100644 --- a/services/sensorservice/SensorEventConnection.cpp +++ b/services/sensorservice/SensorEventConnection.cpp @@ -711,14 +711,17 @@ status_t SensorService::SensorEventConnection::enableDisable( if (err == OK && isSensorCapped) { if ((requestedSamplingPeriodNs >= SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS) || !isRateCappedBasedOnPermission()) { + Mutex::Autolock _l(mConnectionLock); mMicSamplingPeriodBackup[handle] = requestedSamplingPeriodNs; } else { + Mutex::Autolock _l(mConnectionLock); mMicSamplingPeriodBackup[handle] = SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS; } } } else { err = mService->disable(this, handle); + Mutex::Autolock _l(mConnectionLock); mMicSamplingPeriodBackup.erase(handle); } return err; @@ -750,8 +753,10 @@ status_t SensorService::SensorEventConnection::setEventRate(int handle, nsecs_t if (ret == OK && isSensorCapped) { if ((requestedSamplingPeriodNs >= SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS) || !isRateCappedBasedOnPermission()) { + Mutex::Autolock _l(mConnectionLock); mMicSamplingPeriodBackup[handle] = requestedSamplingPeriodNs; } else { + Mutex::Autolock _l(mConnectionLock); mMicSamplingPeriodBackup[handle] = SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS; } } diff --git a/services/sensorservice/SensorEventConnection.h b/services/sensorservice/SensorEventConnection.h index 6a98a40686..bb8733dc3a 100644 --- a/services/sensorservice/SensorEventConnection.h +++ b/services/sensorservice/SensorEventConnection.h @@ -199,7 +199,8 @@ private: // valid mapping for sensors that require a permission in order to reduce the lookup time. std::unordered_map<int32_t, int32_t> mHandleToAppOp; // Mapping of sensor handles to its rate before being capped by the mic toggle. - std::unordered_map<int, nsecs_t> mMicSamplingPeriodBackup; + std::unordered_map<int, nsecs_t> mMicSamplingPeriodBackup + GUARDED_BY(mConnectionLock); userid_t mUserId; std::optional<bool> mIsRateCappedBasedOnPermission; |