hal: Fix WFD and voice call over USB concurrency

- If WFD framework occupies the AFE proxy, it may result unintended
  behavior while starting voice call over USB.
- Audio is always routed to the USB audio device when connected,
  even if WFD is connected. So no need to allow afe proxy port
  usage by WFD framework.
- Disallow the afe proxy port usage by external modules when
  AUDIO_DEVICE_OUT_USB_DEVICE is connected.

CRs-Fixed: 998488

Change-Id: I889be7f477ae3f7ad46757592a46f3d0e8eb41e2
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 2489471..65b1ab6 100755
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -3528,6 +3528,16 @@
         if (val & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
             ALOGV("cache new edid");
             platform_cache_edid(adev->platform);
+        } else if (val & AUDIO_DEVICE_OUT_USB_DEVICE) {
+            /*
+             * Do not allow AFE proxy port usage by WFD source when USB headset is connected.
+             * Per AudioPolicyManager, USB device is higher priority than WFD.
+             * For Voice call over USB headset, voice call audio is routed to AFE proxy ports.
+             * If WFD use case occupies AFE proxy, it may result unintended behavior while
+             * starting voice call on USB
+             */
+            ALOGV("detected USB connect .. disable proxy");
+            adev->allow_afe_proxy_usage = false;
         }
     }
 
@@ -3537,6 +3547,9 @@
         if (val & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
             ALOGV("invalidate cached edid");
             platform_invalidate_edid(adev->platform);
+        } else if (val & AUDIO_DEVICE_OUT_USB_DEVICE) {
+            ALOGV("detected USB disconnect .. enable proxy");
+            adev->allow_afe_proxy_usage = true;
         }
     }
 
@@ -3961,6 +3974,7 @@
     adev->out_device = AUDIO_DEVICE_NONE;
     adev->bluetooth_nrec = true;
     adev->acdb_settings = TTY_MODE_OFF;
+    adev->allow_afe_proxy_usage = true;
     /* adev->cur_hdmi_channels = 0;  by calloc() */
     adev->snd_dev_ref_cnt = calloc(SND_DEVICE_MAX, sizeof(int));
     voice_init(adev);