Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4a0de5b4 authored by Rocky Fang's avatar Rocky Fang
Browse files

Protect mMicSamplingPeriodBackup by mConnectionLock

Test: Presubmit
Fixes: 357599979
Flag: EXEMPT bug fix
Change-Id: I705579eef8cc5fe371f3e57d0e16e8df1acfc3c5
parent c69b0852
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ cc_library {
        "-Wall",
        "-Werror",
        "-Wextra",
        "-Wthread-safety",
        "-fvisibility=hidden",
    ],

+5 −0
Original line number Diff line number Diff line
@@ -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;
        }
    }
+2 −1
Original line number Diff line number Diff line
@@ -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;