audio: fix no sound in rigntone case with a2dp and speaker path
am: 9baad39099

Change-Id: Iba063c6f7f4efcaf4c076cf3bbd8274d069a3ca0
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 977ba10..0a12cff 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -1367,7 +1367,10 @@
          out_snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP) &&
         (!audio_extn_a2dp_is_ready())) {
         ALOGW("%s: A2DP profile is not ready, routing to speaker only", __func__);
-        out_snd_device = SND_DEVICE_OUT_SPEAKER;
+        if (out_snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP)
+            out_snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
+        else
+            out_snd_device = SND_DEVICE_OUT_SPEAKER;
     }
 
     if (out_snd_device != SND_DEVICE_NONE &&
@@ -2026,7 +2029,7 @@
 
     if (out->devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
         if (!audio_extn_a2dp_is_ready()) {
-            if (out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
+            if (out->devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
                 a2dp_combo = true;
             } else {
                 if (!(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)) {
@@ -2073,7 +2076,10 @@
             check_a2dp_restore_l(adev, out, false);
         } else {
             audio_devices_t dev = out->devices;
-            out->devices = AUDIO_DEVICE_OUT_SPEAKER;
+            if (dev & AUDIO_DEVICE_OUT_SPEAKER_SAFE)
+                out->devices = AUDIO_DEVICE_OUT_SPEAKER_SAFE;
+            else
+                out->devices = AUDIO_DEVICE_OUT_SPEAKER;
             select_devices(adev, out->usecase);
             out->devices = dev;
         }
@@ -2545,7 +2551,7 @@
          */
         if (val & AUDIO_DEVICE_OUT_ALL_A2DP) {
             if (!audio_extn_a2dp_is_ready()) {
-                if (val & AUDIO_DEVICE_OUT_SPEAKER) {
+                if (val & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
                     //combo usecase just by pass a2dp
                     ALOGW("%s: A2DP profile is not ready,routing to speaker only", __func__);
                     bypass_a2dp = true;
@@ -2625,7 +2631,10 @@
                 if (!bypass_a2dp) {
                     select_devices(adev, out->usecase);
                 } else {
-                    out->devices = AUDIO_DEVICE_OUT_SPEAKER;
+                    if (new_dev & AUDIO_DEVICE_OUT_SPEAKER_SAFE)
+                        out->devices = AUDIO_DEVICE_OUT_SPEAKER_SAFE;
+                    else
+                        out->devices = AUDIO_DEVICE_OUT_SPEAKER;
                     select_devices(adev, out->usecase);
                     out->devices = new_dev;
                 }
@@ -2953,7 +2962,7 @@
 
     if ((out->devices & AUDIO_DEVICE_OUT_ALL_A2DP) &&
         (audio_extn_a2dp_is_suspended())) {
-        if (!(out->devices & AUDIO_DEVICE_OUT_SPEAKER)) {
+        if (!(out->devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
             if (!(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)) {
                 ret = -EIO;
                 goto exit;