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

Commit 870f6d61 authored by Vlad Popa's avatar Vlad Popa
Browse files

Fix possible deadlock in MelReporter

Test: cf_x86_64_phone-userdebug should cover this path
Bug: 263462151
Change-Id: Ib97f1568fa0f12f3af318705ec9ba9523a16a971
parent 002efea6
Loading
Loading
Loading
Loading
+3 −18
Original line number Diff line number Diff line
@@ -60,8 +60,6 @@ bool AudioFlinger::MelReporter::activateHalSoundDoseComputation(const std::strin
        return false;
    }

    std::lock_guard _l(mLock);
    mUseHalSoundDoseInterface = true;
    stopInternalMelComputation();
    return true;
}
@@ -77,12 +75,6 @@ void AudioFlinger::MelReporter::activateInternalSoundDoseComputation() {
    }

    mSoundDoseManager->setHalSoundDoseInterface(nullptr);

    for (const auto& activePatches : mActiveMelPatches) {
        for (const auto& deviceId : activePatches.second.deviceHandles) {
            startMelComputationForNewPatch(activePatches.second.streamHandle, deviceId);
        }
    }
}

void AudioFlinger::MelReporter::onFirstRef() {
@@ -205,16 +197,9 @@ sp<media::ISoundDose> AudioFlinger::MelReporter::getSoundDoseInterface(

void AudioFlinger::MelReporter::stopInternalMelComputation() {
    ALOGV("%s", __func__);
    std::unordered_map<audio_patch_handle_t, ActiveMelPatch> activePatchesCopy;
    {
    std::lock_guard _l(mLock);
        activePatchesCopy = mActiveMelPatches;
    mActiveMelPatches.clear();
    }

    for (const auto& activePatch : activePatchesCopy) {
        stopInternalMelComputationForStream(activePatch.second.streamHandle);
    }
    mUseHalSoundDoseInterface = true;
}

void AudioFlinger::MelReporter::stopInternalMelComputationForStream(audio_io_handle_t streamId) {