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

Commit dac3abf9 authored by Ajender Reddy's avatar Ajender Reddy
Browse files

audio: update setAudioPatch

avoid duplicate updates from setAudioPatch

Bug: 382421476

Test: m

Change-Id: I1e871b40fd0f75fffc1a835831faedbd4cb3801d
parent b2b0ce95
Loading
Loading
Loading
Loading
+21 −12
Original line number Diff line number Diff line
@@ -1049,6 +1049,23 @@ ndk::ScopedAStatus Module::setAudioPatch(const AudioPatch& in_requested, AudioPa
        return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
    }

    auto& patches = getConfig().patches;
    auto existing = patches.end();
    if (in_requested.id != 0) {
        existing = findById<AudioPatch>(patches, in_requested.id);
        if (existing == patches.end()) {
            LOG(ERROR) << __func__ << ": " << mType << ": not found existing patch id "
                       << in_requested.id;
            return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
        }
        if (in_requested == *existing) {
            LOG(INFO) << __func__ << ": " << mType
                      << ": requested patch has no changes compared to already existing one, id "
                      << in_requested.id;
            return ndk::ScopedAStatus::ok();
        }
    }

    auto& configs = getConfig().portConfigs;
    std::vector<int32_t> missingIds;
    auto sources =
@@ -1088,20 +1105,12 @@ ndk::ScopedAStatus Module::setAudioPatch(const AudioPatch& in_requested, AudioPa
    }
    RETURN_STATUS_IF_ERROR(checkAudioPatchEndpointsMatch(sources, sinks));

    auto& patches = getConfig().patches;
    auto existing = patches.end();
    std::optional<decltype(mPatches)> patchesBackup;
    if (in_requested.id != 0) {
        existing = findById<AudioPatch>(patches, in_requested.id);
    if (existing != patches.end()) {
        patchesBackup = mPatches;
        cleanUpPatch(existing->id);
        } else {
            LOG(ERROR) << __func__ << ": " << mType << ": not found existing patch id "
                       << in_requested.id;
            return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
        }
    }

    // Validate the requested patch.
    for (const auto& [sinkPortId, nonExclusive] : allowedSinkPorts) {
        if (!nonExclusive && mPatches.count(sinkPortId) != 0) {