audio policy: Fix removing device role when disconnected
Allow to remove a device role for a strategy or capture preset
if the device is not connected.
Test: make
Bug: 265077412
Change-Id: I87f821a987d95e9ea6741c142df9d0a3900adc64
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 6d7ed75..6e255f9 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -3752,11 +3752,12 @@
bool AudioPolicyManager::areAllDevicesSupported(
const AudioDeviceTypeAddrVector& devices,
std::function<bool(audio_devices_t)> predicate,
- const char *context) {
+ const char *context,
+ bool matchAddress) {
for (size_t i = 0; i < devices.size(); i++) {
sp<DeviceDescriptor> devDesc = mHwModules.getDeviceDescriptor(
devices[i].mType, devices[i].getAddress(), String8(),
- AUDIO_FORMAT_DEFAULT, false /*allowToCreate*/, true /*matchAddress*/);
+ AUDIO_FORMAT_DEFAULT, false /*allowToCreate*/, matchAddress);
if (devDesc == nullptr || (predicate != nullptr && !predicate(devices[i].mType))) {
ALOGE("%s: device type %#x address %s not supported or not match predicate",
context, devices[i].mType, devices[i].getAddress());
@@ -3895,7 +3896,8 @@
ALOGV("%s() strategy=%d role=%d %s", __func__, strategy, role,
dumpAudioDeviceTypeAddrVector(devices).c_str());
- if (!areAllDevicesSupported(devices, audio_is_output_device, __func__)) {
+ if (!areAllDevicesSupported(
+ devices, audio_is_output_device, __func__, /*matchAddress*/false)) {
return BAD_VALUE;
}
status_t status = mEngine->removeDevicesRoleForStrategy(strategy, role, devices);
@@ -3995,7 +3997,8 @@
ALOGV("%s() audioSource=%d role=%d devices=%s", __func__, audioSource, role,
dumpAudioDeviceTypeAddrVector(devices).c_str());
- if (!areAllDevicesSupported(devices, audio_call_is_input_device, __func__)) {
+ if (!areAllDevicesSupported(
+ devices, audio_call_is_input_device, __func__, /*matchAddress*/false)) {
return BAD_VALUE;
}