audiopolicy: fix routing of exclusive preferred device

In call music played on remote is called an "exclusive" preferred
device. It may not be propagated to other client that may play locally.
The client of the exclusive preferred device is not routed as the
exclusive preferred device are ignored from findPreferredDevice helper.

This CL fixes the routing

Bug: 130284799
Test: AudioPolicyEmulatorTests --gtest_filter=FilteringExpliciRoutingTest*

Change-Id: Iec7e14cb170d0f67c8c0b231f8219c133d7d2185
Signed-off-by: François Gaffie <francois.gaffie@renault.com>
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 80393ca..af29f87 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -1641,7 +1641,14 @@
     outputDesc->setClientActive(client, true);
 
     if (client->hasPreferredDevice(true)) {
-        devices = getNewOutputDevices(outputDesc, false /*fromCache*/);
+        if (outputDesc->clientsList(true /*activeOnly*/).size() == 1 &&
+                client->isPreferredDeviceForExclusiveUse()) {
+            // Preferred device may be exclusive, use only if no other active clients on this output
+            devices = DeviceVector(
+                        mAvailableOutputDevices.getDeviceFromId(client->preferredDeviceId()));
+        } else {
+            devices = getNewOutputDevices(outputDesc, false /*fromCache*/);
+        }
         if (devices != outputDesc->devices()) {
             checkStrategyRoute(clientStrategy, outputDesc->mIoHandle);
         }