From f41a5cd6b66d579d3235c2e9b1a29870a7bd2017 Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Wed, 24 Aug 2022 15:42:39 -0400 Subject: [PATCH 1/2] APM: Optionally force-load audio policy for system-side bt audio HAL Required to support our system-side bt audio implementation, i.e. `sysbta`. Co-authored-by: Pierre-Hugues Husson Change-Id: I279fff541a531f922f3fa55b8f14d00237db59ff Signed-off-by: Nishant Kumar --- .../managerdefinitions/src/Serializer.cpp | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp b/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp index d446e9667b..f5233f2a42 100644 --- a/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp +++ b/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -890,6 +891,30 @@ status_t PolicySerializer::deserialize(const char *configFile, AudioPolicyConfig if (status != NO_ERROR) { return status; } + + // Remove modules called bluetooth, bluetooth_qti or a2dp, and inject our own + if (property_get_bool("persist.bluetooth.system_audio_hal.enabled", false)) { + for (auto it = modules.begin(); it != modules.end(); it++) { + const char *name = (*it)->getName(); + if (strcmp(name, "a2dp") == 0 || + strcmp(name, "a2dpsink") == 0 || + strcmp(name, "bluetooth") == 0 || + strcmp(name, "bluetooth_qti") == 0) { + + ALOGE("Removed module %s\n", name); + it = modules.erase(it); + } + if (it == modules.end()) break; + } + const char* a2dpFileName = "/system/etc/sysbta_audio_policy_configuration.xml"; + if (version == "7.0") + a2dpFileName = "/system/etc/sysbta_audio_policy_configuration_7_0.xml"; + auto doc = make_xmlUnique(xmlParseFile(a2dpFileName)); + xmlNodePtr root = xmlDocGetRootElement(doc.get()); + auto maybeA2dpModule = deserialize(root, config); + modules.add(std::get<1>(maybeA2dpModule)); + } + config->setHwModules(modules); // Global Configuration -- GitLab From 82043c1f5a162e6ba367b4bca0ce49dd769c7ac3 Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Thu, 25 Aug 2022 13:30:29 -0400 Subject: [PATCH 2/2] APM: Remove A2DP audio ports from the primary HAL These ports defined in the primary HAL are intended for A2DP offloading, however they do not work in general on GSIs, and will interfere with sysbta, the system-side generic bluetooth audio implementation. Remove them as we parse the policy XML. Co-authored-by: Pierre-Hugues Husson Change-Id: I3305594a17285da113167b419543543f0ef71122 Signed-off-by: Nishant Kumar --- .../managerdefinitions/src/Serializer.cpp | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp b/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp index f5233f2a42..6630d06f6d 100644 --- a/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp +++ b/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -334,11 +335,8 @@ status_t PolicySerializer::deserializeCollection(const xmlNode *cur, Trait::collectionTag); return status; } - } else if (mIgnoreVendorExtensions && std::get(maybeElement) == NO_INIT) { - // Skip a vendor extension element. - } else { - return BAD_VALUE; } + // Ignore elements that failed to parse, e.g. routes with invalid sinks } } if (!xmlStrcmp(cur->name, reinterpret_cast(Trait::tag))) { @@ -679,6 +677,7 @@ std::variant PolicySerializer::deserialize PolicySerializer::deserializetype(); + if (type == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP + || type == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES + || type == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER) { + ALOGE("Erasing A2DP device port %s", port->getTagName().c_str()); + iter = devicePorts.erase(iter); + } else { + iter++; + } + } + } module->setDeclaredDevices(devicePorts); RouteTraits::Collection routes; -- GitLab