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

Commit d78f153a authored by Eric Laurent's avatar Eric Laurent
Browse files

audio policy: fix attached devices validation

Consider all supported devices in an io profile and
not only the first one when looking for a match with attached
devices.
Failing to do so would cause the device validation to fail
if supported devices are not declared in a specific order
in the io profile descriptor in audio_policy.conf

Bug: 17532764.
Change-Id: Id27c9192e21de7f075076e17eb8c48e7e42847f6
parent 086c1e3f
Loading
Loading
Loading
Loading
+94 −76
Original line number Diff line number Diff line
@@ -2667,14 +2667,25 @@ AudioPolicyManager::AudioPolicyManager(AudioPolicyClientInterface *clientInterfa
                continue;
            }

            if ((outProfile->mFlags & AUDIO_OUTPUT_FLAG_DIRECT) != 0) {
                continue;
            }
            audio_devices_t profileType = outProfile->mSupportedDevices.types();
            if ((profileType & mDefaultOutputDevice->mDeviceType) != AUDIO_DEVICE_NONE) {
                profileType = mDefaultOutputDevice->mDeviceType;
            } else {
                profileType = outProfile->mSupportedDevices[0]->mDeviceType;
                // chose first device present in mSupportedDevices also part of
                // outputDeviceTypes
                for (size_t k = 0; k  < outProfile->mSupportedDevices.size(); k++) {
                    profileType = outProfile->mSupportedDevices[k]->mDeviceType;
                    if ((profileType & outputDeviceTypes) != 0) {
                        break;
                    }
                }
            }
            if ((profileType & outputDeviceTypes) == 0) {
                continue;
            }
            if ((profileType & outputDeviceTypes) &&
                    ((outProfile->mFlags & AUDIO_OUTPUT_FLAG_DIRECT) == 0)) {
            sp<AudioOutputDescriptor> outputDesc = new AudioOutputDescriptor(outProfile);

            outputDesc->mDevice = profileType;
@@ -2720,7 +2731,6 @@ AudioPolicyManager::AudioPolicyManager(AudioPolicyClientInterface *clientInterfa
                                true);
            }
        }
        }
        // open input streams needed to access attached devices to validate
        // mAvailableInputDevices list
        for (size_t j = 0; j < mHwModules[i]->mInputProfiles.size(); j++)
@@ -2731,9 +2741,18 @@ AudioPolicyManager::AudioPolicyManager(AudioPolicyClientInterface *clientInterfa
                ALOGW("Input profile contains no device on module %s", mHwModules[i]->mName);
                continue;
            }

            audio_devices_t profileType = inProfile->mSupportedDevices[0]->mDeviceType;
            // chose first device present in mSupportedDevices also part of
            // inputDeviceTypes
            audio_devices_t profileType = AUDIO_DEVICE_NONE;
            for (size_t k = 0; k  < inProfile->mSupportedDevices.size(); k++) {
                profileType = inProfile->mSupportedDevices[k]->mDeviceType;
                if (profileType & inputDeviceTypes) {
                    break;
                }
            }
            if ((profileType & inputDeviceTypes) == 0) {
                continue;
            }
            sp<AudioInputDescriptor> inputDesc = new AudioInputDescriptor(inProfile);

            inputDesc->mInputSource = AUDIO_SOURCE_MIC;
@@ -2771,7 +2790,6 @@ AudioPolicyManager::AudioPolicyManager(AudioPolicyClientInterface *clientInterfa
            }
        }
    }
    }
    // make sure all attached devices have been allocated a unique ID
    for (size_t i = 0; i  < mAvailableOutputDevices.size();) {
        if (mAvailableOutputDevices[i]->mId == 0) {