diff --git a/audio/core/all-versions/vts/functional/6.0/Generators.cpp b/audio/core/all-versions/vts/functional/6.0/Generators.cpp index 6b4dbc17af..e3b98c909f 100644 --- a/audio/core/all-versions/vts/functional/6.0/Generators.cpp +++ b/audio/core/all-versions/vts/functional/6.0/Generators.cpp @@ -36,9 +36,14 @@ using namespace ::android::hardware::audio::CPP_VERSION; std::vector generateOutputDeviceConfigParameters(bool oneProfilePerDevice) { std::vector result; for (const auto& device : getDeviceParameters()) { - auto module = - getCachedPolicyConfig().getModuleFromName(std::get(device)); + const std::string moduleName = std::get(device); + auto module = getCachedPolicyConfig().getModuleFromName(moduleName); for (const auto& ioProfile : module->getOutputProfiles()) { + if (getCachedPolicyConfig() + .getAttachedSinkDeviceForMixPort(moduleName, ioProfile->getName()) + .empty()) { + continue; // no attached device + } for (const auto& profile : ioProfile->getAudioProfiles()) { const auto& channels = profile->getChannels(); const auto& sampleRates = profile->getSampleRates(); @@ -94,9 +99,14 @@ const std::vector& getOutputDeviceSingleConfigParameters( std::vector generateInputDeviceConfigParameters(bool oneProfilePerDevice) { std::vector result; for (const auto& device : getDeviceParameters()) { - auto module = - getCachedPolicyConfig().getModuleFromName(std::get(device)); + const std::string moduleName = std::get(device); + auto module = getCachedPolicyConfig().getModuleFromName(moduleName); for (const auto& ioProfile : module->getInputProfiles()) { + if (getCachedPolicyConfig() + .getAttachedSourceDeviceForMixPort(moduleName, ioProfile->getName()) + .empty()) { + continue; // no attached device + } for (const auto& profile : ioProfile->getAudioProfiles()) { const auto& channels = profile->getChannels(); const auto& sampleRates = profile->getSampleRates(); diff --git a/audio/core/all-versions/vts/functional/7.0/AudioPrimaryHidlHalTest.cpp b/audio/core/all-versions/vts/functional/7.0/AudioPrimaryHidlHalTest.cpp index 0cc6a5b964..27598012fe 100644 --- a/audio/core/all-versions/vts/functional/7.0/AudioPrimaryHidlHalTest.cpp +++ b/audio/core/all-versions/vts/functional/7.0/AudioPrimaryHidlHalTest.cpp @@ -499,18 +499,10 @@ static const std::vector& getOutputDevicePcmOnlyConfigPar return xsd::isLinearPcm(std::get(cfg).base.format) // MMAP NOIRQ and HW A/V Sync profiles use special writing protocols. && - std::find_if(flags.begin(), flags.end(), - [](const auto& flag) { - return flag == toString(xsd::AudioInOutFlag:: - AUDIO_OUTPUT_FLAG_MMAP_NOIRQ) || - flag == toString(xsd::AudioInOutFlag:: - AUDIO_OUTPUT_FLAG_HW_AV_SYNC); - }) == flags.end() && - !getCachedPolicyConfig() - .getAttachedSinkDeviceForMixPort( - std::get(std::get(cfg)), - std::get(cfg)) - .empty(); + std::find_if(flags.begin(), flags.end(), [](const auto& flag) { + return flag == toString(xsd::AudioInOutFlag::AUDIO_OUTPUT_FLAG_MMAP_NOIRQ) || + flag == toString(xsd::AudioInOutFlag::AUDIO_OUTPUT_FLAG_HW_AV_SYNC); + }) == flags.end(); }); return pcmParams; }(); @@ -677,20 +669,13 @@ static const std::vector& getInputDevicePcmOnlyConfigPara // reading h/w hotword might require Soundtrigger to be active. && std::find_if( - flags.begin(), flags.end(), - [](const auto& flag) { + flags.begin(), flags.end(), [](const auto& flag) { return flag == toString( xsd::AudioInOutFlag:: AUDIO_INPUT_FLAG_MMAP_NOIRQ) || flag == toString(xsd::AudioInOutFlag:: AUDIO_INPUT_FLAG_HW_HOTWORD); - }) == flags.end() && - !getCachedPolicyConfig() - .getAttachedSourceDeviceForMixPort( - std::get( - std::get(cfg)), - std::get(cfg)) - .empty(); + }) == flags.end(); }); return pcmParams; }(); diff --git a/audio/core/all-versions/vts/functional/7.0/Generators.cpp b/audio/core/all-versions/vts/functional/7.0/Generators.cpp index 8c92cbd161..42bf1d341d 100644 --- a/audio/core/all-versions/vts/functional/7.0/Generators.cpp +++ b/audio/core/all-versions/vts/functional/7.0/Generators.cpp @@ -95,11 +95,16 @@ static AudioOffloadInfo generateOffloadInfo(const AudioConfigBase& base) { std::vector generateOutputDeviceConfigParameters(bool oneProfilePerDevice) { std::vector result; for (const auto& device : getDeviceParameters()) { - auto module = - getCachedPolicyConfig().getModuleFromName(std::get(device)); + const std::string moduleName = std::get(device); + auto module = getCachedPolicyConfig().getModuleFromName(moduleName); if (!module || !module->getFirstMixPorts()) break; for (const auto& mixPort : module->getFirstMixPorts()->getMixPort()) { if (mixPort.getRole() != xsd::Role::source) continue; // not an output profile + if (getCachedPolicyConfig() + .getAttachedSinkDeviceForMixPort(moduleName, mixPort.getName()) + .empty()) { + continue; // no attached device + } auto [flags, isOffload] = generateOutFlags(mixPort); for (const auto& profile : mixPort.getProfile()) { if (!profile.hasFormat() || !profile.hasSamplingRates() || @@ -223,11 +228,16 @@ const std::vector& getOutputDeviceInvalidConfigParameters std::vector generateInputDeviceConfigParameters(bool oneProfilePerDevice) { std::vector result; for (const auto& device : getDeviceParameters()) { - auto module = - getCachedPolicyConfig().getModuleFromName(std::get(device)); + const std::string moduleName = std::get(device); + auto module = getCachedPolicyConfig().getModuleFromName(moduleName); if (!module || !module->getFirstMixPorts()) break; for (const auto& mixPort : module->getFirstMixPorts()->getMixPort()) { if (mixPort.getRole() != xsd::Role::sink) continue; // not an input profile + if (getCachedPolicyConfig() + .getAttachedSourceDeviceForMixPort(moduleName, mixPort.getName()) + .empty()) { + continue; // no attached device + } std::vector flags; if (mixPort.hasFlags()) { std::transform(mixPort.getFlags().begin(), mixPort.getFlags().end(), diff --git a/audio/core/all-versions/vts/functional/Android.bp b/audio/core/all-versions/vts/functional/Android.bp index b99ed4319e..b280d7c3ae 100644 --- a/audio/core/all-versions/vts/functional/Android.bp +++ b/audio/core/all-versions/vts/functional/Android.bp @@ -217,6 +217,7 @@ cc_test { data: [ "tests/apm_config_no_vx.xml", "tests/apm_config_with_vx.xml", + "tests/apm_config_b_205808571_6_0.xml", ], test_config: "tests/HalAudioV6_0GeneratorTest.xml", } @@ -246,6 +247,7 @@ cc_test { "tests/apm_config_no_vx_7_0.xml", "tests/apm_config_with_vx_7_0.xml", "tests/apm_config_b_204314749_7_0.xml", + "tests/apm_config_b_205808571_7_0.xml", ], test_config: "tests/HalAudioV7_0GeneratorTest.xml", } diff --git a/audio/core/all-versions/vts/functional/PolicyConfig.h b/audio/core/all-versions/vts/functional/PolicyConfig.h index a94041c427..171d03f42a 100644 --- a/audio/core/all-versions/vts/functional/PolicyConfig.h +++ b/audio/core/all-versions/vts/functional/PolicyConfig.h @@ -76,6 +76,16 @@ class PolicyConfig : private PolicyConfigData, public android::AudioPolicyConfig const std::set& getModulesWithDevicesNames() const { return mModulesWithDevicesNames; } + std::string getAttachedSinkDeviceForMixPort(const std::string& moduleName, + const std::string& mixPortName) const { + return findAttachedDevice(getAttachedDevices(moduleName), + getSinkDevicesForMixPort(moduleName, mixPortName)); + } + std::string getAttachedSourceDeviceForMixPort(const std::string& moduleName, + const std::string& mixPortName) const { + return findAttachedDevice(getAttachedDevices(moduleName), + getSourceDevicesForMixPort(moduleName, mixPortName)); + } bool haveInputProfilesInModule(const std::string& name) const { auto module = getModuleFromName(name); return module && !module->getInputProfiles().empty(); @@ -92,6 +102,8 @@ class PolicyConfig : private PolicyConfigData, public android::AudioPolicyConfig for (const auto& module : hwModules) { if (module->getDeclaredDevices().indexOf(device) >= 0) { mModulesWithDevicesNames.insert(module->getName()); + mAttachedDevicesPerModule[module->getName()].push_back( + device->getTagName()); break; } } @@ -100,16 +112,64 @@ class PolicyConfig : private PolicyConfigData, public android::AudioPolicyConfig for (const auto& module : hwModules) { if (module->getDeclaredDevices().indexOf(device) >= 0) { mModulesWithDevicesNames.insert(module->getName()); + mAttachedDevicesPerModule[module->getName()].push_back( + device->getTagName()); break; } } } } } + std::string findAttachedDevice(const std::vector& attachedDevices, + const std::set& possibleDevices) const { + for (const auto& device : attachedDevices) { + if (possibleDevices.count(device)) return device; + } + return {}; + } + std::vector getAttachedDevices(const std::string& moduleName) const { + if (auto iter = mAttachedDevicesPerModule.find(moduleName); + iter != mAttachedDevicesPerModule.end()) { + return iter->second; + } + return {}; + } + std::set getSinkDevicesForMixPort(const std::string& moduleName, + const std::string& mixPortName) const { + std::set result; + auto module = getModuleFromName(moduleName); + if (module != nullptr) { + for (const auto& route : module->getRoutes()) { + for (const auto& source : route->getSources()) { + if (source->getTagName() == mixPortName) { + result.insert(route->getSink()->getTagName()); + } + } + } + } + return result; + } + std::set getSourceDevicesForMixPort(const std::string& moduleName, + const std::string& mixPortName) const { + std::set result; + auto module = getModuleFromName(moduleName); + if (module != nullptr) { + for (const auto& route : module->getRoutes()) { + if (route->getSink()->getTagName() == mixPortName) { + const auto& sources = route->getSources(); + std::transform(sources.begin(), sources.end(), + std::inserter(result, result.end()), + [](const auto& source) { return source->getTagName(); }); + } + } + } + return result; + } const std::string mConfigFileName; status_t mStatus = android::NO_INIT; std::string mFilePath; sp mPrimaryModule = nullptr; std::set mModulesWithDevicesNames; + std::map> mAttachedDevicesPerModule; }; diff --git a/audio/core/all-versions/vts/functional/tests/HalAudioV6_0GeneratorTest.xml b/audio/core/all-versions/vts/functional/tests/HalAudioV6_0GeneratorTest.xml index 0c85a05838..0230447ec6 100644 --- a/audio/core/all-versions/vts/functional/tests/HalAudioV6_0GeneratorTest.xml +++ b/audio/core/all-versions/vts/functional/tests/HalAudioV6_0GeneratorTest.xml @@ -24,6 +24,7 @@