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

Commit 7f25e5f5 authored by Emilian Peev's avatar Emilian Peev
Browse files

Camera: Synchronize access to torch status map

'add-/removeStates()' can modify the torch status map
without holding the necessary 'mTorchStatusMutex'. Any
such modification could theoretically access or
contribute to an inconsistent state of the torch status
map. To avoid any possible data race conditions, always
try to acquire 'mTorchStatusMutex' first.

Bug: 77531948
Test: Camera CTS
Change-Id: Ic135d450d4d32224964eabceb24718e03a439fc3
parent fa33327e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -243,6 +243,7 @@ void CameraService::addStates(const String8 id) {
    }

    if (mFlashlight->hasFlashUnit(id)) {
        Mutex::Autolock al(mTorchStatusMutex);
        mTorchStatusMap.add(id, TorchModeStatus::AVAILABLE_OFF);
    }

@@ -253,6 +254,7 @@ void CameraService::addStates(const String8 id) {
void CameraService::removeStates(const String8 id) {
    updateCameraNumAndIds();
    if (mFlashlight->hasFlashUnit(id)) {
        Mutex::Autolock al(mTorchStatusMutex);
        mTorchStatusMap.removeItem(id);
    }