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

Commit 5aaffa45 authored by Rocky Fang's avatar Rocky Fang Committed by Android (Google) Code Review
Browse files

Merge "Protect mMicSamplingPeriodBackup by mConnectionLock" into main

parents 9d907f98 4a0de5b4
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;