Merge "hal: fix compiler warnings which are now treated as errors"
diff --git a/hal/audio_extn/audio_extn.c b/hal/audio_extn/audio_extn.c
index db91b51..200cbeb 100644
--- a/hal/audio_extn/audio_extn.c
+++ b/hal/audio_extn/audio_extn.c
@@ -553,7 +553,7 @@
 
 #ifndef AFE_PROXY_ENABLED
 #define audio_extn_set_afe_proxy_parameters(adev, parms)  (0)
-#define audio_extn_get_afe_proxy_parameters(query, reply) (0)
+#define audio_extn_get_afe_proxy_parameters(adev, query, reply) (0)
 #else
 static int32_t afe_proxy_set_channel_mapping(struct audio_device *adev,
                                                      int channel_count)
@@ -667,23 +667,25 @@
     }
 }
 
-int audio_extn_get_afe_proxy_parameters(struct str_parms *query,
+int audio_extn_get_afe_proxy_parameters(const struct audio_device *adev,
+                                        struct str_parms *query,
                                         struct str_parms *reply)
 {
-    int ret, val;
+    int ret, val = 0;
     char value[32]={0};
     char *str = NULL;
 
     ret = str_parms_get_str(query, AUDIO_PARAMETER_CAN_OPEN_PROXY, value,
                             sizeof(value));
     if (ret >= 0) {
-        if (audio_extn_usb_is_proxy_inuse())
+        if (audio_extn_usb_is_proxy_inuse() ||
+            !adev->allow_afe_proxy_usage)
             val = 0;
         else
             val = 1;
         str_parms_add_int(reply, AUDIO_PARAMETER_CAN_OPEN_PROXY, val);
     }
-
+    ALOGV("%s: called ... can_use_proxy %d", __func__, val);
     return 0;
 }
 
@@ -775,7 +777,7 @@
                               struct str_parms *reply)
 {
     char *kv_pairs = NULL;
-    audio_extn_get_afe_proxy_parameters(query, reply);
+    audio_extn_get_afe_proxy_parameters(adev, query, reply);
     audio_extn_get_fluence_parameters(adev, query, reply);
     audio_extn_ssr_get_parameters(adev, query, reply);
     get_active_offload_usecases(adev, query, reply);
diff --git a/hal/audio_extn/utils.c b/hal/audio_extn/utils.c
index 846f88f..8eb557e 100644
--- a/hal/audio_extn/utils.c
+++ b/hal/audio_extn/utils.c
@@ -627,9 +627,6 @@
                     usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
          }
 
-         if (!audio_extn_is_hifi_audio_enabled())
-             usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
-
          sample_rate = usecase->stream.out->app_type_cfg.sample_rate;
 
          property_get("audio.playback.mch.downsample",value,"");
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 4840bf1..d10bc18 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -3508,6 +3508,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;
         }
     }
 
@@ -3517,6 +3527,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;
         }
     }
 
@@ -3939,6 +3952,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);
diff --git a/hal/audio_hw.h b/hal/audio_hw.h
index a7d4483..e13415d 100644
--- a/hal/audio_hw.h
+++ b/hal/audio_hw.h
@@ -323,6 +323,7 @@
     unsigned int cur_hdmi_channels;
     unsigned int cur_wfd_channels;
     bool bt_wb_speech_enabled;
+    bool allow_afe_proxy_usage;
 
     int snd_card;
     unsigned int cur_codec_backend_samplerate;