audio policy: fix crash if output for DAP is not opened
Fix crash in getOutputForAttrInt() if the output corresponding to
the mix returned by AudioPolicyMix is not opened and the device
selected by the mix is not attached.
Before commit c529cf6f, a policy mix without opened output would not
be retuned by AudioPolicyMix.getOutputForAttr(). With direct
output suppoort, this is possible but should be ignored if the device
selected by the policy mix is not attached.
Bug: 155430290
Test: AudioHostTest
Test: AudioServiceHostTest
Test: audiopolicy_tests
Test: manual mirroring and car projection tests
Change-Id: I66be4a3c5fb8b9ae0674c0f1e6e39de7f18ed2fb
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 13e2093..bcf6f38 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -954,7 +954,8 @@
primaryMix->mDeviceAddress,
AUDIO_FORMAT_DEFAULT);
sp<SwAudioOutputDescriptor> policyDesc = primaryMix->getOutput();
- if (policyDesc == nullptr || (policyDesc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT)) {
+ if (deviceDesc != nullptr
+ && (policyDesc == nullptr || (policyDesc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT))) {
audio_io_handle_t newOutput;
status = openDirectOutput(
*stream, session, config,