From caaf4d4bd4fcc3fd59a2185b69ba0d77fe2e66c6 Mon Sep 17 00:00:00 2001 From: Pierre-Hugues Husson Date: Mon, 5 Aug 2019 18:09:50 +0200 Subject: [PATCH 5/5] Fix BT in-call on CAF devices See https://github.com/phhusson/treble_experimentations/issues/374 In Qualcomm's BSP audio_policy_configuration.xml, one route is missing, from primary output and telephony to BT SCO. Add it if we detect telephony and bt sco, but no such route. Change-Id: Ifea0f88276ec9a0811f3cb1973c4b06f2c82077b --- .../managerdefinitions/src/Serializer.cpp | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp b/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp index c4474cf1c2..c1df8f278b 100644 --- a/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp +++ b/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp @@ -676,6 +676,98 @@ std::variant PolicySerializer::deserialize primary input mix + // But Telephony Rx => BT SCO Headset route is missing + // When we detect such case, add the missing route + + // If we have: + // + // + // + // And no + + // Add: + // + bool foundBtScoHeadsetDevice = false; + for(const auto& device: devicePorts) { + if(device->getTagName() == "BT SCO Headset") { + foundBtScoHeadsetDevice = true; + break; + } + } + if(!foundBtScoHeadsetDevice) { + ALOGE("No BT SCO Headset device found, don't patch policy"); + return; + } + + bool foundTelephony = false; + bool foundBtScoInput = false; + bool foundScoHeadsetRoute = false; + for(const auto& route: routes) { + ALOGE("Looking at route %d\n", route->getType()); + if(route->getType() != AUDIO_ROUTE_MIX) + continue; + auto sink = route->getSink(); + ALOGE("... With sink %s\n", sink->getTagName().c_str()); + if(sink->getTagName() == "Telephony Tx") { + foundTelephony = true; + continue; + } + if(sink->getTagName() == "BT SCO Headset") { + foundScoHeadsetRoute = true; + break; + } + for(const auto& source: route->getSources()) { + ALOGE("... With source %s\n", source->getTagName().c_str()); + if(source->getTagName() == "BT SCO Headset Mic") { + foundBtScoInput = true; + break; + } + } + } + //The route we want to add is already there + ALOGE("Done looking for existing routes"); + if(foundScoHeadsetRoute) + return; + + ALOGE("No existing route found... %d %d", foundTelephony ? 1 : 0, foundBtScoInput ? 1 : 0); + //We couldn't find the routes we assume are required for the function we want to add + if(!foundTelephony || !foundBtScoInput) + return; + ALOGE("Adding our own."); + + // Add: + // + AudioRoute *newRoute = new AudioRoute(AUDIO_ROUTE_MIX); + + auto sink = ctx->findPortByTagName("BT SCO Headset"); + ALOGE("Got sink %p\n", sink.get()); + newRoute->setSink(sink); + + Vector> sources; + for(const auto& sourceName: { + "primary output", + "deep_buffer", + "compressed_offload", + "Telephony Rx" + }) { + auto source = ctx->findPortByTagName(sourceName); + ALOGE("Got source %p\n", source.get()); + if (source.get() != nullptr) { + sources.add(source); + source->addRoute(newRoute); + } + } + + newRoute->setSources(sources); + + sink->addRoute(newRoute); + + auto ret = routes.add(newRoute); + ALOGE("route add returned %zd", ret); +} + template<> std::variant PolicySerializer::deserialize( const xmlNode *cur, ModuleTraits::PtrSerializingCtx ctx) @@ -743,6 +835,7 @@ std::variant PolicySerializer::deserializesetRoutes(routes); for (const xmlNode *children = cur->xmlChildrenNode; children != NULL; -- 2.44.0