audio policy: always provide a valid device address when opening a stream
Treble audio HAL mandates that a valid device address is passed when
opening an output or input stream and teh device type requires and
address.
Bug: 37905534
Test: USB capture at various sampling rates. Audio playback and capture regression
Change-Id: I12f2128120b1bbe8530e8c2428e3e2cba1ba1535
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index e3a23f9..aaa6134 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -1007,11 +1007,14 @@
if (offloadInfo != NULL) {
config.offload_info = *offloadInfo;
}
+ DeviceVector outputDevices = mAvailableOutputDevices.getDevicesFromType(device);
+ String8 address = outputDevices.size() > 0 ? outputDevices.itemAt(0)->mAddress
+ : String8("");
status = mpClientInterface->openOutput(profile->getModuleHandle(),
&output,
&config,
&outputDesc->mDevice,
- String8(""),
+ address,
&outputDesc->mLatency,
outputDesc->mFlags);
@@ -1699,6 +1702,12 @@
config.channel_mask = profileChannelMask;
config.format = profileFormat;
+ if (address == "") {
+ DeviceVector inputDevices = mAvailableInputDevices.getDevicesFromType(device);
+ // the inputs vector must be of size 1, but we don't want to crash here
+ address = inputDevices.size() > 0 ? inputDevices.itemAt(0)->mAddress : String8("");
+ }
+
status_t status = mpClientInterface->openInput(profile->getModuleHandle(),
&input,
&config,