hal: Fix in call music stream muted issue when mic is muted

Fix in-call music stream mute issue when mic is muted within
dialer app. Issue is caused due to mute applied on mixed
voice stream containing both Voice Tx and incall music stream.
Solution is to apply mute on voice device as and when mic is
muted and incall music usecase is active. Mute cannot be
always applied on device as comfort noise can only be applied
after Mute in Voice stream topology.

Change-Id: I5f3eefdc78590b74beb9c2031139c1da2e41bd1e
Test: manual.
Bug: 70800193
diff --git a/hal/voice.c b/hal/voice.c
index f456ce1..96a4238 100644
--- a/hal/voice.c
+++ b/hal/voice.c
@@ -170,6 +170,7 @@
     uc_info->devices = adev->current_call_output ->devices;
     uc_info->in_snd_device = SND_DEVICE_NONE;
     uc_info->out_snd_device = SND_DEVICE_NONE;
+    adev->use_voice_device_mute = false;
 
     list_add_tail(&adev->usecase_list, &uc_info->list);
 
@@ -356,11 +357,19 @@
 int voice_set_mic_mute(struct audio_device *adev, bool state)
 {
     int err = 0;
+    struct audio_usecase *usecase = NULL;
 
     adev->voice.mic_mute = state;
     if (adev->mode == AUDIO_MODE_IN_CALL ||
-        adev->mode == AUDIO_MODE_IN_COMMUNICATION)
-        err = platform_set_mic_mute(adev->platform, state);
+        adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
+        /* Use device mute if incall music delivery usecase is in progress */
+        if (adev->use_voice_device_mute)
+            err = platform_set_device_mute(adev->platform, state, "tx");
+        else
+            err = platform_set_mic_mute(adev->platform, state);
+        ALOGV("%s: voice mute status=%d, use_voice_device_mute_flag=%d",
+            __func__, state, adev->use_voice_device_mute);
+    }
 
     return err;
 }
@@ -370,6 +379,25 @@
     return adev->voice.mic_mute;
 }
 
+// Following function is called when incall music uplink usecase is
+// created or destroyed while mic is muted. If incall music uplink
+// usecase is active, apply voice device mute to mute only voice Tx
+// path and not the mixed voice Tx + inncall-music path. Revert to
+// voice stream mute once incall music uplink usecase is inactive
+void voice_set_device_mute_flag (struct audio_device *adev, bool state)
+{
+    if (adev->voice.mic_mute) {
+        if (state) {
+            platform_set_device_mute(adev->platform, true, "tx");
+            platform_set_mic_mute(adev->platform, false);
+        } else {
+            platform_set_mic_mute(adev->platform, true);
+            platform_set_device_mute(adev->platform, false, "tx");
+        }
+    }
+    adev->use_voice_device_mute = state;
+}
+
 int voice_set_volume(struct audio_device *adev, float volume)
 {
     int vol, err = 0;
@@ -516,6 +544,8 @@
     adev->voice.volume = 1.0f;
     adev->voice.mic_mute = false;
     adev->voice.in_call = false;
+    adev->use_voice_device_mute = false;
+
     for (i = 0; i < MAX_VOICE_SESSIONS; i++) {
         adev->voice.session[i].pcm_rx = NULL;
         adev->voice.session[i].pcm_tx = NULL;