hal: Do not force mono for VoIP Rx with stock configuration

HAL forces mono configuration for VoIP. This is due to VoIP
topology being configured as mono. However, pure AOSP
targets support VoIP with stereo configuration. HAL forcing
mono would lead to mismatched configuration. Correct this by
forcing mono only on vendor enhanced targets.

Change-Id: Icc63e14469ef67b5d916cebdba56a45910dcf28d
diff --git a/hal/audio_extn/audio_extn.h b/hal/audio_extn/audio_extn.h
index 043ce48..3a317e3 100644
--- a/hal/audio_extn/audio_extn.h
+++ b/hal/audio_extn/audio_extn.h
@@ -800,6 +800,7 @@
 int audio_extn_utils_get_sample_rate_from_string(const char *);
 int audio_extn_utils_get_channels_from_string(const char *);
 void audio_extn_utils_release_snd_device(snd_device_t snd_device);
+int audio_extn_utils_is_vendor_enhanced_fwk();
 
 #ifdef DS2_DOLBY_DAP_ENABLED
 #define LIB_DS2_DAP_HAL "vendor/lib/libhwdaphal.so"
diff --git a/hal/audio_extn/audio_feature_manager.c b/hal/audio_extn/audio_feature_manager.c
index 2de5af3..441071d 100644
--- a/hal/audio_extn/audio_feature_manager.c
+++ b/hal/audio_extn/audio_feature_manager.c
@@ -42,47 +42,17 @@
 #include "voice_extn.h"
 #include "audio_feature_manager.h"
 
-#ifdef __LP64__
-#define VNDK_FWK_LIB_PATH "/vendor/lib64/libqti_vndfwk_detect.so"
-#else
-#define VNDK_FWK_LIB_PATH "/vendor/lib/libqti_vndfwk_detect.so"
-#endif
-
 AHalValues* confValues = NULL;
-static void *vndk_fwk_lib_handle = NULL;
-
-typedef int (*vndk_fwk_isVendorEnhancedFwk_t)();
-static vndk_fwk_isVendorEnhancedFwk_t vndk_fwk_isVendorEnhancedFwk;
 
 void audio_feature_manager_init()
 {
     ALOGD("%s: Enter", __func__);
-    int is_running_with_enhanced_fwk = 0;
 
-    //dlopen lib
-    vndk_fwk_lib_handle = dlopen(VNDK_FWK_LIB_PATH, RTLD_NOW);
-    if (vndk_fwk_lib_handle != NULL) {
-        vndk_fwk_isVendorEnhancedFwk = (vndk_fwk_isVendorEnhancedFwk_t)
-                    dlsym(vndk_fwk_lib_handle, "isRunningWithVendorEnhancedFramework");
-        if (vndk_fwk_isVendorEnhancedFwk == NULL) {
-            ALOGW("%s: VNDK_FWK_LIB not found, defaulting to enhanced_fwk configuration",
-                                                                            __func__);
-            is_running_with_enhanced_fwk = 1;
-        } else {
-            is_running_with_enhanced_fwk = vndk_fwk_isVendorEnhancedFwk();
-        }
-    }
-
-    ALOGD("%s: vndk_fwk_isVendorEnhancedFwk=%d", __func__, is_running_with_enhanced_fwk);
+    int is_running_with_enhanced_fwk = audio_extn_utils_is_vendor_enhanced_fwk();
     audio_extn_ahal_config_helper_init(is_running_with_enhanced_fwk);
     audio_extn_get_feature_values(&confValues);
     audio_extn_feature_init(is_running_with_enhanced_fwk);
     voice_extn_feature_init(is_running_with_enhanced_fwk);
-
-    if (vndk_fwk_lib_handle != NULL) {
-        dlclose(vndk_fwk_lib_handle);
-        vndk_fwk_lib_handle = NULL;
-    }
 }
 
 bool audio_feature_manager_is_feature_enabled(audio_ext_feature feature)
diff --git a/hal/audio_extn/utils.c b/hal/audio_extn/utils.c
index b06276e..af89a8a 100644
--- a/hal/audio_extn/utils.c
+++ b/hal/audio_extn/utils.c
@@ -108,6 +108,16 @@
 #define MAX_CHANNELS_SUPPORTED 8
 #endif
 
+#ifdef __LP64__
+#define VNDK_FWK_LIB_PATH "/vendor/lib64/libqti_vndfwk_detect.so"
+#else
+#define VNDK_FWK_LIB_PATH "/vendor/lib/libqti_vndfwk_detect.so"
+#endif
+
+static void *vndk_fwk_lib_handle = NULL;
+typedef int (*vndk_fwk_isVendorEnhancedFwk_t)();
+static vndk_fwk_isVendorEnhancedFwk_t vndk_fwk_isVendorEnhancedFwk;
+
 typedef struct {
     const char *id_string;
     const int value;
@@ -2752,3 +2762,31 @@
     return mixer_ctl_set_array(ctl, gain_cfg,
                                sizeof(gain_cfg)/sizeof(gain_cfg[0]));
 }
+
+int audio_extn_utils_is_vendor_enhanced_fwk()
+{
+    static int is_running_with_enhanced_fwk = -EINVAL;
+
+    if (is_running_with_enhanced_fwk == -EINVAL) {
+        vndk_fwk_lib_handle = dlopen(VNDK_FWK_LIB_PATH, RTLD_NOW);
+        if (vndk_fwk_lib_handle != NULL) {
+            vndk_fwk_isVendorEnhancedFwk = (vndk_fwk_isVendorEnhancedFwk_t)
+                        dlsym(vndk_fwk_lib_handle, "isRunningWithVendorEnhancedFramework");
+            if (vndk_fwk_isVendorEnhancedFwk == NULL) {
+                ALOGW("%s: dlsym failed, defaulting to enhanced_fwk configuration",
+                       __func__);
+                is_running_with_enhanced_fwk = 1;
+            } else {
+                is_running_with_enhanced_fwk = vndk_fwk_isVendorEnhancedFwk();
+            }
+            dlclose(vndk_fwk_lib_handle);
+            vndk_fwk_lib_handle = NULL;
+        } else {
+            ALOGW("%s: VNDK_FWK_LIB not found, setting stock configuration", __func__);
+            is_running_with_enhanced_fwk = 0;
+        }
+        ALOGV("%s: vndk_fwk_isVendorEnhancedFwk=%d", __func__, is_running_with_enhanced_fwk);
+    }
+
+    return is_running_with_enhanced_fwk;
+}
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 2343603..89b3dbe 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -5288,7 +5288,9 @@
                      __func__, frames, frame_size, bytes_to_write);
 
             if (out->usecase == USECASE_INCALL_MUSIC_UPLINK ||
-                out->usecase == USECASE_INCALL_MUSIC_UPLINK2) {
+                out->usecase == USECASE_INCALL_MUSIC_UPLINK2 ||
+                (out->usecase == USECASE_AUDIO_PLAYBACK_VOIP &&
+                 !audio_extn_utils_is_vendor_enhanced_fwk())) {
                 size_t channel_count = audio_channel_count_from_out_mask(out->channel_mask);
                 int16_t *src = (int16_t *)buffer;
                 int16_t *dst = (int16_t *)buffer;
@@ -6933,7 +6935,8 @@
         if (!voice_extn_is_compress_voip_supported()) {
             if (out->sample_rate == 8000 || out->sample_rate == 16000 ||
              out->sample_rate == 32000 || out->sample_rate == 48000) {
-                out->channel_mask = AUDIO_CHANNEL_OUT_MONO;
+                out->channel_mask = audio_extn_utils_is_vendor_enhanced_fwk() ?
+                                        AUDIO_CHANNEL_OUT_MONO : AUDIO_CHANNEL_OUT_STEREO;
                 out->usecase = USECASE_AUDIO_PLAYBACK_VOIP;
                 out->format = AUDIO_FORMAT_PCM_16_BIT;