hal: add new proxy usecase for hearding aid

Add a dedicated proxy usecase for hearing aid.

Change-Id: Iacc828f23393e3b44e9eefed89bbb365240a9813
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 9b8f29d..2a33f9e 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -383,6 +383,7 @@
 
     [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = "afe-proxy-playback",
     [USECASE_AUDIO_RECORD_AFE_PROXY] = "afe-proxy-record",
+    [USECASE_AUDIO_RECORD_AFE_PROXY2] = "afe-proxy-record2",
     [USECASE_AUDIO_PLAYBACK_SILENCE] = "silence-playback",
 
     /* Transcode loopback cases */
@@ -880,6 +881,7 @@
 static inline bool is_mmap_usecase(audio_usecase_t uc_id)
 {
     return (uc_id == USECASE_AUDIO_RECORD_AFE_PROXY) ||
+           (uc_id == USECASE_AUDIO_RECORD_AFE_PROXY2) ||
            (uc_id == USECASE_AUDIO_PLAYBACK_AFE_PROXY);
 }
 
@@ -2707,7 +2709,10 @@
 
                     usecase->stream.in->enable_ec_port = false;
 
-                    if (usecase->id == USECASE_AUDIO_RECORD_AFE_PROXY) {
+                    bool is_ha_usecase = adev->ha_proxy_enable ?
+                        usecase->id == USECASE_AUDIO_RECORD_AFE_PROXY2 :
+                        usecase->id == USECASE_AUDIO_RECORD_AFE_PROXY;
+                    if (is_ha_usecase) {
                         reassign_device_list(&out_devices, AUDIO_DEVICE_OUT_TELEPHONY_TX, "");
                     } else if (voip_usecase) {
                         assign_devices(&out_devices, &voip_usecase->stream.out->device_list);
@@ -3117,7 +3122,8 @@
         unsigned int flags = PCM_IN | PCM_MONOTONIC;
         unsigned int pcm_open_retry_count = 0;
 
-        if (in->usecase == USECASE_AUDIO_RECORD_AFE_PROXY) {
+        if ((in->usecase == USECASE_AUDIO_RECORD_AFE_PROXY) ||
+             (in->usecase == USECASE_AUDIO_RECORD_AFE_PROXY2)) {
             flags |= PCM_MMAP | PCM_NOIRQ;
             pcm_open_retry_count = PROXY_OPEN_RETRY_COUNT;
         } else if (in->realtime) {
@@ -6921,7 +6927,8 @@
      */
     if ((ret == 0 && voice_get_mic_mute(adev) &&
          !voice_is_in_call_rec_stream(in) &&
-         in->usecase != USECASE_AUDIO_RECORD_AFE_PROXY) ||
+         (in->usecase != USECASE_AUDIO_RECORD_AFE_PROXY &&
+          in->usecase != USECASE_AUDIO_RECORD_AFE_PROXY2)) ||
         (adev->num_va_sessions &&
          in->source != AUDIO_SOURCE_VOICE_RECOGNITION &&
          property_get_bool("persist.vendor.audio.va_concurrency_mute_enabled",
@@ -7396,6 +7403,7 @@
     struct stream_in *in = (struct stream_in *)stream;
     struct audio_device *adev = in->dev;
     struct listnode devices;
+    bool is_ha_usecase = false;
 
     list_init(&devices);
 
@@ -7406,8 +7414,10 @@
     pthread_mutex_lock(&adev->lock);
     ALOGV("%s: in->usecase: %d, device: %x", __func__, in->usecase, get_device_types(&devices));
 
-    if (in->usecase == USECASE_AUDIO_RECORD_AFE_PROXY
-            && !list_empty(&devices)
+    is_ha_usecase = adev->ha_proxy_enable ?
+        in->usecase == USECASE_AUDIO_RECORD_AFE_PROXY2 :
+        in->usecase == USECASE_AUDIO_RECORD_AFE_PROXY;
+    if (is_ha_usecase && !list_empty(&devices)
             && adev->voice_tx_output != NULL) {
         /* Use the rx device from afe-proxy record to route voice call because
            there is no routing if tx device is on primary hal and rx device
@@ -9235,6 +9245,10 @@
         }
 
         in->usecase = USECASE_AUDIO_RECORD_AFE_PROXY;
+        if (adev->ha_proxy_enable &&
+            is_single_device_type_equal(&in->device_list,
+                                        AUDIO_DEVICE_IN_TELEPHONY_RX))
+            in->usecase = USECASE_AUDIO_RECORD_AFE_PROXY2;
         in->config = pcm_config_afe_proxy_record;
         in->config.rate = config->sample_rate;
         in->af_period_multiplier = 1;
@@ -10427,6 +10441,7 @@
     audio_extn_qdsp_init(adev->platform);
 
     adev->multi_offload_enable = property_get_bool("vendor.audio.offload.multiple.enabled", false);
+    adev->ha_proxy_enable = property_get_bool("persist.vendor.audio.ha_proxy.enabled", false);
     pthread_mutex_unlock(&adev_init_lock);
 
     if (adev->adm_init)
diff --git a/hal/audio_hw.h b/hal/audio_hw.h
index ce82145..f7c010d 100644
--- a/hal/audio_hw.h
+++ b/hal/audio_hw.h
@@ -213,6 +213,7 @@
 
     USECASE_AUDIO_PLAYBACK_AFE_PROXY,
     USECASE_AUDIO_RECORD_AFE_PROXY,
+    USECASE_AUDIO_RECORD_AFE_PROXY2,
     USECASE_AUDIO_DSM_FEEDBACK,
 
     USECASE_AUDIO_PLAYBACK_SILENCE,
@@ -717,6 +718,7 @@
     struct listnode audio_patch_record_list;
     Hashmap *patch_map;
     Hashmap *io_streams_map;
+    bool ha_proxy_enable;
 };
 
 struct audio_patch_record {
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index ed23aca..e38285c 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -459,6 +459,8 @@
                                           AFE_PROXY_RECORD_PCM_DEVICE},
     [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
                                         AFE_PROXY_RECORD_PCM_DEVICE},
+    [USECASE_AUDIO_RECORD_AFE_PROXY2] = {AFE_PROXY_RECORD2_PCM_DEVICE,
+                                        AFE_PROXY_RECORD2_PCM_DEVICE},
     [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
     [USECASE_AUDIO_PLAYBACK_SILENCE] = {MULTIMEDIA9_PCM_DEVICE, -1},
     [USECASE_AUDIO_TRANSCODE_LOOPBACK_RX] = {TRANSCODE_LOOPBACK_RX_DEV_ID, -1},
@@ -1301,6 +1303,7 @@
     {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
     {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
     {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
+    {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY2)},
     {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
     {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_SILENCE)},
     {TO_NAME_INDEX(USECASE_AUDIO_EC_REF_LOOPBACK)},
diff --git a/hal/msm8974/platform.h b/hal/msm8974/platform.h
index be138c0..6b2a671 100644
--- a/hal/msm8974/platform.h
+++ b/hal/msm8974/platform.h
@@ -612,6 +612,7 @@
 
 #define AFE_PROXY_PLAYBACK_PCM_DEVICE 7
 #define AFE_PROXY_RECORD_PCM_DEVICE 8
+#define AFE_PROXY_RECORD2_PCM_DEVICE 40
 
 #ifdef PLATFORM_MSM8x26
 #ifdef EXTERNAL_BT_SUPPORTED