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

Commit 50f23f6e authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "APM: avoid adding duplicated audio profile." into udc-qpr-dev

parents c120d093 9b8fecba
Loading
Loading
Loading
Loading
+18 −4
Original line number Diff line number Diff line
@@ -115,9 +115,19 @@ void addProfilesForFormats(AudioProfileVector &audioProfileVector, const FormatV
        profile->setDynamicFormat(true);
        profile->setDynamicChannels(dynamicFormatProfile->isDynamicChannels());
        profile->setDynamicRate(dynamicFormatProfile->isDynamicRate());
        size_t profileIndex = 0;
        for (; profileIndex < audioProfileVector.size(); profileIndex++) {
            if (profile->equals(audioProfileVector.at(profileIndex))) {
                // The dynamic profile is already there
                break;
            }
        }
        if (profileIndex >= audioProfileVector.size()) {
            // Only add when the dynamic profile is not there
            addAudioProfileAndSort(audioProfileVector, profile);
        }
    }
}

void addDynamicAudioProfileAndSort(AudioProfileVector &audioProfileVector,
                                   const sp<AudioProfile> &profileToAdd)
@@ -143,11 +153,15 @@ void addDynamicAudioProfileAndSort(AudioProfileVector &audioProfileVector,
                audioProfileVector, profileToAdd->getChannels(), profileToAdd->getFormat());
        return;
    }
    const bool originalIsDynamicFormat = profileToAdd->isDynamicFormat();
    profileToAdd->setDynamicFormat(true); // set the format as dynamic to allow removal
    // Go through the list of profile to avoid duplicates
    for (size_t profileIndex = 0; profileIndex < audioProfileVector.size(); profileIndex++) {
        const sp<AudioProfile> &profile = audioProfileVector.at(profileIndex);
        if (profile->isValid() && profile == profileToAdd) {
            // Nothing to do
        if (profile->isValid() && profile->equals(profileToAdd)) {
            // The same profile is already there, no need to add.
            // Reset `isDynamicProfile` as original value.
            profileToAdd->setDynamicFormat(originalIsDynamicFormat);
            return;
        }
    }