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

Commit 0422f138 authored by Shunkai Yao's avatar Shunkai Yao Committed by Android (Google) Code Review
Browse files

Merge changes I5501e12e,Ia1de5676 into main

* changes:
  AudioFlinger: getEffectThread_l return with first thread
  AudioFlinger: validate effect before access to avoid crash
parents 51270e4d 0bc6456e
Loading
Loading
Loading
Loading
+14 −19
Original line number Diff line number Diff line
@@ -2171,30 +2171,24 @@ sp<IAfThreadBase> AudioFlinger::getEffectThread_l(audio_session_t sessionId,
    sp<IAfThreadBase> thread;

    for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
        if (mPlaybackThreads.valueAt(i)->getEffect(sessionId, effectId) != 0) {
            ALOG_ASSERT(thread == 0);
        thread = mPlaybackThreads.valueAt(i);
        }
    }
    if (thread != nullptr) {
        if (thread->getEffect(sessionId, effectId) != 0) {
            return thread;
        }
    }
    for (size_t i = 0; i < mRecordThreads.size(); i++) {
        if (mRecordThreads.valueAt(i)->getEffect(sessionId, effectId) != 0) {
            ALOG_ASSERT(thread == 0);
        thread = mRecordThreads.valueAt(i);
        }
    }
    if (thread != nullptr) {
        if (thread->getEffect(sessionId, effectId) != 0) {
            return thread;
        }
    }
    for (size_t i = 0; i < mMmapThreads.size(); i++) {
        if (mMmapThreads.valueAt(i)->getEffect(sessionId, effectId) != 0) {
            ALOG_ASSERT(thread == 0);
        thread = mMmapThreads.valueAt(i);
        if (thread->getEffect(sessionId, effectId) != 0) {
            return thread;
        }
    }
    return thread;
    return nullptr;
}

// ----------------------------------------------------------------------------
@@ -4390,9 +4384,10 @@ void AudioFlinger::setEffectSuspended(int effectId,
        return;
    }
    audio_utils::lock_guard _sl(thread->mutex());
    sp<IAfEffectModule> effect = thread->getEffect_l(sessionId, effectId);
    if (const auto& effect = thread->getEffect_l(sessionId, effectId)) {
        thread->setEffectSuspended_l(&effect->desc().type, suspended, sessionId);
    }
}


// moveEffectChain_ll must be called with the AudioFlinger::mutex()