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

Commit b98ff1b0 authored by Robert Wu's avatar Robert Wu
Browse files

APM: Valid sr and ch shouldn't be overriden

Valid sample rates and channels are overriden when open fails.
The fix is to check if they are within the set.

Bug: 287528103
Change-Id: I1f064b83226247d09d1d84f3cf80793c81e488e2
Test: OboeTester Test Input/Output
parent cac2af69
Loading
Loading
Loading
Loading
+18 −8
Original line number Diff line number Diff line
@@ -1325,10 +1325,15 @@ status_t AudioPolicyManager::getOutputForAttrInt(
        AudioProfileVector profiles;
        status_t ret = getProfilesForDevices(outputDevices, profiles, *flags, false /*isInput*/);
        if (ret == NO_ERROR && !profiles.empty()) {
            config->channel_mask = profiles[0]->getChannels().empty() ? config->channel_mask
                    : *profiles[0]->getChannels().begin();
            config->sample_rate = profiles[0]->getSampleRates().empty() ? config->sample_rate
                    : *profiles[0]->getSampleRates().begin();
            const auto channels = profiles[0]->getChannels();
            if (!channels.empty() && (channels.find(config->channel_mask) == channels.end())) {
                config->channel_mask = *channels.begin();
            }
            const auto sampleRates = profiles[0]->getSampleRates();
            if (!sampleRates.empty() &&
                    (sampleRates.find(config->sample_rate) == sampleRates.end())) {
                config->sample_rate = *sampleRates.begin();
            }
            config->format = profiles[0]->getFormat();
        }
        return INVALID_OPERATION;
@@ -2774,10 +2779,15 @@ status_t AudioPolicyManager::getInputForAttr(const audio_attributes_t *attr,
        status_t ret = getProfilesForDevices(
                DeviceVector(device), profiles, flags, true /*isInput*/);
        if (ret == NO_ERROR && !profiles.empty()) {
            config->channel_mask = profiles[0]->getChannels().empty() ? config->channel_mask
                    : *profiles[0]->getChannels().begin();
            config->sample_rate = profiles[0]->getSampleRates().empty() ? config->sample_rate
                    : *profiles[0]->getSampleRates().begin();
            const auto channels = profiles[0]->getChannels();
            if (!channels.empty() && (channels.find(config->channel_mask) == channels.end())) {
                config->channel_mask = *channels.begin();
            }
            const auto sampleRates = profiles[0]->getSampleRates();
            if (!sampleRates.empty() &&
                    (sampleRates.find(config->sample_rate) == sampleRates.end())) {
                config->sample_rate = *sampleRates.begin();
            }
            config->format = profiles[0]->getFormat();
        }
        goto error;