audiopolicy: fix preferred device selection
Make sure preferred device selection is taken into account
in getOutputForAttr() even if called twice on the same session:
Force changed flag when adding a SessionRoute even if
the same device is specified.
Also renamed SessionRoute isActive() to isActiveOrChanged() and
hasRouteChanged() to getAndClearRouteChanged() for clarity.
Bug: 69680975
Test: manual
Change-Id: I3f3a659568c4dfc825a788753b0302136fd89871
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index bb00c3f..22bc426 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -1116,7 +1116,7 @@
} else {
newDevice = AUDIO_DEVICE_OUT_REMOTE_SUBMIX;
}
- } else if (mOutputRoutes.hasRouteChanged(session)) {
+ } else if (mOutputRoutes.getAndClearRouteChanged(session)) {
newDevice = getNewOutputDevice(outputDesc, false /*fromCache*/);
checkStrategyRoute(getStrategy(stream), output);
} else {
@@ -1980,7 +1980,7 @@
// Routing?
mInputRoutes.incRouteActivity(session);
- if (audioSession->activeCount() == 1 || mInputRoutes.hasRouteChanged(session)) {
+ if (audioSession->activeCount() == 1 || mInputRoutes.getAndClearRouteChanged(session)) {
// indicate active capture to sound trigger service if starting capture from a mic on
// primary HW module
audio_devices_t device = getNewInputDevice(inputDesc);
@@ -4707,7 +4707,7 @@
for (size_t routeIndex = 0; routeIndex < mOutputRoutes.size(); routeIndex++) {
sp<SessionRoute> route = mOutputRoutes.valueAt(routeIndex);
routing_strategy routeStrategy = getStrategy(route->mStreamType);
- if ((routeStrategy == strategy) && route->isActive() &&
+ if ((routeStrategy == strategy) && route->isActiveOrChanged() &&
(mAvailableOutputDevices.indexOf(route->mDeviceDescriptor) >= 0)) {
return route->mDeviceDescriptor->type();
}
@@ -5139,7 +5139,7 @@
// then select this device.
for (size_t routeIndex = 0; routeIndex < mInputRoutes.size(); routeIndex++) {
sp<SessionRoute> route = mInputRoutes.valueAt(routeIndex);
- if ((inputSource == route->mSource) && route->isActive() &&
+ if ((inputSource == route->mSource) && route->isActiveOrChanged() &&
(mAvailableInputDevices.indexOf(route->mDeviceDescriptor) >= 0)) {
return route->mDeviceDescriptor->type();
}