hal: open proxy record2 only when hearing aid is connected

Proxy record2 can be wrongly selected for common afe
proxy session which can cause proxy port mute due to
wrong port selected.
Since proxy record2 is dedicated for hearing aid,only
open proxy record2 when hearing aid is connected.

Change-Id: I1d2bf0ad97c7c0e14fc9e4dc083c21eb04fb4f12
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 9ed29ed..1c14fa6 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -2888,10 +2888,8 @@
 
                     usecase->stream.in->enable_ec_port = false;
 
-                    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) {
+                    if (usecase->id == USECASE_AUDIO_RECORD_AFE_PROXY ||
+                        usecase->id == USECASE_AUDIO_RECORD_AFE_PROXY2) {
                         reassign_device_list(&out_devices, AUDIO_DEVICE_OUT_TELEPHONY_TX, "");
                     } else if (voip_usecase) {
                         assign_devices(&out_devices, &voip_usecase->stream.out->device_list);
@@ -7735,7 +7733,6 @@
     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);
 
@@ -7746,11 +7743,10 @@
     pthread_mutex_lock(&adev->lock);
     ALOGV("%s: in->usecase: %d, device: %x", __func__, in->usecase, get_device_types(&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) {
+    if ((in->usecase == USECASE_AUDIO_RECORD_AFE_PROXY ||
+         in->usecase == USECASE_AUDIO_RECORD_AFE_PROXY2) &&
+         !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
            is on other hal during voice call. */
@@ -8958,6 +8954,9 @@
                 ALOGV("detected USB connect .. disable proxy");
                 adev->allow_afe_proxy_usage = false;
             }
+        } else if (audio_is_hearing_aid_out_device(device) &&
+                   property_get_bool("persist.vendor.audio.ha_proxy.enabled", false)) {
+            adev->ha_proxy_enable = true;
         }
     }
 
@@ -8980,6 +8979,8 @@
                 ALOGV("detected USB disconnect .. enable proxy");
                 adev->allow_afe_proxy_usage = true;
             }
+        } else if (audio_is_hearing_aid_out_device(device)) {
+            adev->ha_proxy_enable = false;
         }
     }
 
@@ -10670,6 +10671,7 @@
     adev->use_old_pspd_mix_ctrl = false;
     adev->adm_routing_changed = false;
     adev->a2dp_started = false;
+    adev->ha_proxy_enable = false;
 
     audio_extn_perf_lock_init();
 
@@ -10844,7 +10846,6 @@
     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)