hal: ensure voip tx update base on the rx path

Voip does not use primary output in rx path. When voip
rx device change, voip tx path is not updated accordingly.

Fix it by selecting voip tx device base on the rx path,
otherwise base on primary output device.

CRs-Fixed: 2289517
Change-Id: Ic078eb057be40dd4338ade70f541bb056c19dfca
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index 3d9a7e0..e5cb9b4 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -4655,6 +4655,16 @@
               (mode == AUDIO_MODE_IN_COMMUNICATION)) {
         if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
             in_device = AUDIO_DEVICE_IN_BACK_MIC;
+        else if (out_device & AUDIO_DEVICE_OUT_EARPIECE)
+            in_device = AUDIO_DEVICE_IN_BUILTIN_MIC;
+        else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET)
+            in_device = AUDIO_DEVICE_IN_WIRED_HEADSET;
+        else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE)
+             in_device = AUDIO_DEVICE_IN_USB_DEVICE;
+
+        in_device = ((out_device == AUDIO_DEVICE_NONE) ?
+                      AUDIO_DEVICE_IN_BUILTIN_MIC : in_device) & ~AUDIO_DEVICE_BIT_IN;
+
         if (adev->active_input) {
             snd_device = get_snd_device_for_voice_comm(my_data, out_device, in_device);
         }