pal: handling for SCO when DEVICE_NONE routing comes while dev is disconnected

If a stream is active on SCO and playback has ended, APM will send routing=0.
Stream will be closed in PAL after standby time. If SCO device gets disconnected,
this stream will not receive new routing and stream will remain with SCO for the
time being. If SCO device gets connected again with different config in the
meantime and capture stream tries to start ABR path, it will lead to error due to
config mismatch.

Added handling to route SCO streams to Speaker during ReleaseAudiPatch when SCO
device is disconnected.

Change-Id: I59d0b785054c5761b97ecd768877c09010385391
diff --git a/stream/src/Stream.cpp b/stream/src/Stream.cpp
index 355d35e..60fac2c 100644
--- a/stream/src/Stream.cpp
+++ b/stream/src/Stream.cpp
@@ -1373,6 +1373,7 @@
     int32_t connectCount = 0, disconnectCount = 0;
     bool isNewDeviceA2dp = false;
     bool isCurDeviceA2dp = false;
+    bool isCurDeviceSco = false;
     bool isCurrentDeviceProxyOut = false;
     bool isCurrentDeviceDpOut = false;
     bool matchFound = false;
@@ -1425,6 +1426,11 @@
             curBtDevId = curDevId;
         }
 
+        if (curDevId == PAL_DEVICE_OUT_BLUETOOTH_SCO) {
+            isCurDeviceSco = true;
+            curBtDevId = curDevId;
+        }
+
         if (curDevId == PAL_DEVICE_OUT_PROXY)
             isCurrentDeviceProxyOut = true;
 
@@ -1497,11 +1503,19 @@
          * But the audioflinger continues to write data until standby time
          * (3sec). As BT is turned off, the write gets blocked.
          * Avoid this by routing audio to speaker until standby.
+         *
+         * If a stream is active on SCO and playback has ended, APM will send
+         * routing=0. Stream will be closed in PAL after standby time. If SCO
+         * device gets disconnected, this stream will not receive new routing
+         * and stream will remain with SCO for the time being. If SCO device
+         * gets connected again with different config in the meantime and
+         * capture stream tries to start ABR path, it will lead to error due to
+         * config mismatch. Added OUT_SCO device handling to resolve this.
          */
         // This assumes that PAL_DEVICE_NONE comes as single device
         if ((newDevices[i].id == PAL_DEVICE_NONE) &&
-            (((isCurDeviceA2dp == true) && (!rm->isDeviceReady(curBtDevId))) ||
-             (isCurrentDeviceProxyOut) || (isCurrentDeviceDpOut))) {
+            ((isCurrentDeviceProxyOut) || (isCurrentDeviceDpOut) ||
+             ((isCurDeviceA2dp || isCurDeviceSco) && (!rm->isDeviceReady(curBtDevId))))) {
             newDevices[i].id = PAL_DEVICE_OUT_SPEAKER;
 
             if (rm->getDeviceConfig(&newDevices[i], mStreamAttr)) {