audio policy: fix device address passed when opening HAL streams
Commit fe231127 caused a regression where the device address is
not passed properly to audio HAL by openInputStream() or
openOutputStream(). The address must be read from available
device descriptors, not supported devices in profiles which do not
have the current device address for removable devices.
Bug: 70321528
Test: audio smoke tests,CTS AudioRecordTest
Change-Id: I83211a31f86391b80c3c244b436a2e36923ccea0
diff --git a/services/audiopolicy/common/managerdefinitions/src/AudioInputDescriptor.cpp b/services/audiopolicy/common/managerdefinitions/src/AudioInputDescriptor.cpp
index 624e688..8eadc11 100644
--- a/services/audiopolicy/common/managerdefinitions/src/AudioInputDescriptor.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/AudioInputDescriptor.cpp
@@ -206,24 +206,16 @@
lConfig = *config;
}
- String8 lAddress = address;
- if (lAddress == "") {
- const DeviceVector& supportedDevices = mProfile->getSupportedDevices();
- const DeviceVector& devicesForType = supportedDevices.getDevicesFromType(device);
- lAddress = devicesForType.size() > 0 ? devicesForType.itemAt(0)->mAddress
- : String8("");
- }
-
mDevice = device;
ALOGV("opening input for device %08x address %s profile %p name %s",
- mDevice, lAddress.string(), mProfile.get(), mProfile->getName().string());
+ mDevice, address.string(), mProfile.get(), mProfile->getName().string());
status_t status = mClientInterface->openInput(mProfile->getModuleHandle(),
input,
&lConfig,
&mDevice,
- lAddress,
+ address,
source,
flags);
LOG_ALWAYS_FATAL_IF(mDevice != device,
diff --git a/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp b/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp
index f96c5bc..dc407a6 100644
--- a/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp
@@ -398,14 +398,6 @@
lConfig = *config;
}
- String8 lAddress = address;
- if (lAddress == "") {
- const DeviceVector& supportedDevices = mProfile->getSupportedDevices();
- const DeviceVector& devicesForType = supportedDevices.getDevicesFromType(device);
- lAddress = devicesForType.size() > 0 ? devicesForType.itemAt(0)->mAddress
- : String8("");
- }
-
mDevice = device;
// if the selected profile is offloaded and no offload info was specified,
// create a default one
@@ -425,13 +417,13 @@
mFlags = (audio_output_flags_t)(mFlags | flags);
ALOGV("opening output for device %08x address %s profile %p name %s",
- mDevice, lAddress.string(), mProfile.get(), mProfile->getName().string());
+ mDevice, address.string(), mProfile.get(), mProfile->getName().string());
status_t status = mClientInterface->openOutput(mProfile->getModuleHandle(),
output,
&lConfig,
&mDevice,
- lAddress,
+ address,
&mLatency,
mFlags);
LOG_ALWAYS_FATAL_IF(mDevice != device,
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index ad24439..46e758e 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -918,7 +918,12 @@
}
outputDesc = new SwAudioOutputDescriptor(profile, mpClientInterface);
- status = outputDesc->open(config, device, String8(""), stream, flags, &output);
+
+ DeviceVector outputDevices = mAvailableOutputDevices.getDevicesFromType(device);
+ String8 address = outputDevices.size() > 0 ? outputDevices.itemAt(0)->mAddress
+ : String8("");
+
+ status = outputDesc->open(config, device, address, stream, flags, &output);
// only accept an output with the requested parameters
if (status != NO_ERROR ||
@@ -1678,6 +1683,12 @@
lConfig.channel_mask = profileChannelMask;
lConfig.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 = inputDesc->open(&lConfig, device, address,
halInputSource, profileFlags, &input);
@@ -3588,10 +3599,17 @@
sp<AudioInputDescriptor> inputDesc =
new AudioInputDescriptor(inProfile, mpClientInterface);
+ DeviceVector inputDevices = mAvailableInputDevices.getDevicesFromType(profileType);
+ // the inputs vector must be of size >= 1, but we don't want to crash here
+ String8 address = inputDevices.size() > 0 ? inputDevices.itemAt(0)->mAddress
+ : String8("");
+ ALOGV(" for input device 0x%x using address %s", profileType, address.string());
+ ALOGE_IF(inputDevices.size() == 0, "Input device list is empty!");
+
audio_io_handle_t input = AUDIO_IO_HANDLE_NONE;
status_t status = inputDesc->open(nullptr,
profileType,
- String8(""),
+ address,
AUDIO_SOURCE_MIC,
AUDIO_INPUT_FLAG_NONE,
&input);