audio: Add support for DSDS for incall music feature

Add support for incall-music-uplink2 usecase to enable Dual Sim
Dual Standby (DSDS) voice scenarios

Change-Id: I66947e2b505be170492d5265e91ad9cf557627cf
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 7d8103b..6d24335 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -3370,8 +3370,10 @@
         audio_low_latency_hint_end();
     }
 
-    if (out->usecase == USECASE_INCALL_MUSIC_UPLINK)
+    if (out->usecase == USECASE_INCALL_MUSIC_UPLINK ||
+        out->usecase == USECASE_INCALL_MUSIC_UPLINK2) {
         voice_set_device_mute_flag(adev, false);
+    }
 
     /* 1. Get and set stream specific mixer controls */
     disable_audio_route(adev, uc_info);
@@ -3508,6 +3510,16 @@
         goto error_config;
     }
 
+    //Update incall music usecase to reflect correct voice session
+    if (out->flags & AUDIO_OUTPUT_FLAG_INCALL_MUSIC) {
+        ret = voice_extn_check_and_set_incall_music_usecase(adev, out);
+        if (ret != 0) {
+            ALOGE("%s: Incall music delivery usecase cannot be set error:%d",
+                __func__, ret);
+            goto error_config;
+        }
+    }
+
     if (out->devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
         if (!audio_extn_a2dp_source_is_ready()) {
             if (out->devices &
@@ -3607,8 +3619,10 @@
          select_devices(adev, out->usecase);
     }
 
-    if (out->usecase == USECASE_INCALL_MUSIC_UPLINK)
+    if (out->usecase == USECASE_INCALL_MUSIC_UPLINK ||
+        out->usecase == USECASE_INCALL_MUSIC_UPLINK2) {
         voice_set_device_mute_flag(adev, true);
+    }
 
     if (audio_extn_ext_hw_plugin_usecase_start(adev->ext_hw_plugin, uc_info))
         ALOGE("%s: failed to start ext hw plugin", __func__);
diff --git a/hal/msm8974/platform.h b/hal/msm8974/platform.h
index 13f85e6..c0e2634 100644
--- a/hal/msm8974/platform.h
+++ b/hal/msm8974/platform.h
@@ -456,6 +456,10 @@
 #define INCALL_MUSIC_UPLINK2_PCM_DEVICE 16
 #elif PLATFORM_APQ8084
 #define INCALL_MUSIC_UPLINK2_PCM_DEVICE 34
+#elif PLATFORM_MSMNILE
+#define INCALL_MUSIC_UPLINK2_PCM_DEVICE 27
+#elif PLATFORM_KONA
+#define INCALL_MUSIC_UPLINK2_PCM_DEVICE 23
 #else
 #define INCALL_MUSIC_UPLINK2_PCM_DEVICE 35
 #endif
diff --git a/hal/voice_extn/voice_extn.c b/hal/voice_extn/voice_extn.c
index 473edc2..d278742 100644
--- a/hal/voice_extn/voice_extn.c
+++ b/hal/voice_extn/voice_extn.c
@@ -684,7 +684,16 @@
                                                   struct stream_out *out)
 {
     if(voice_extn_incall_music_enabled) {
-        out->usecase = USECASE_INCALL_MUSIC_UPLINK;
+        uint32_t session_id = get_session_id_with_state(adev, CALL_ACTIVE);
+        if (session_id == VOICEMMODE1_VSID) {
+            out->usecase = USECASE_INCALL_MUSIC_UPLINK;
+        } else if (session_id == VOICEMMODE2_VSID) {
+            out->usecase = USECASE_INCALL_MUSIC_UPLINK2;
+        } else {
+            ALOGE("%s: Invalid session id %x", __func__, session_id);
+            out->usecase = USECASE_INCALL_MUSIC_UPLINK;
+        }
+
         out->config = pcm_config_incall_music;
         //FIXME: add support for MONO stream configuration when audioflinger mixer supports it
         out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_STEREO;