Merge "audio: config: Enable Conditional flag"
diff --git a/configs/sdm670/audio_platform_info_intcodec.xml b/configs/sdm670/audio_platform_info_intcodec.xml
index 94f3853..b249102 100644
--- a/configs/sdm670/audio_platform_info_intcodec.xml
+++ b/configs/sdm670/audio_platform_info_intcodec.xml
@@ -197,7 +197,11 @@
         <device name="SND_DEVICE_IN_SPEAKER_QMIC_NS" interface="INT3_MI2S_TX"/>
         <device name="SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS" interface="INT3_MI2S_TX"/>
         <device name="SND_DEVICE_IN_THREE_MIC" interface="INT3_MI2S_TX"/>
+        <device name="SND_DEVICE_IN_HANDSET_TMIC_FLUENCE_PRO" interface="INT3_MI2S_TX"/>
         <device name="SND_DEVICE_IN_HANDSET_TMIC" interface="INT3_MI2S_TX"/>
+        <device name="SND_DEVICE_IN_HANDSET_TMIC_AEC" interface="INT3_MI2S_TX"/>
+        <device name="SND_DEVICE_IN_HANDSET_TMIC_NS" interface="INT3_MI2S_TX"/>
+        <device name="SND_DEVICE_IN_HANDSET_TMIC_AEC_NS" interface="INT3_MI2S_TX"/>
         <device name="SND_DEVICE_IN_VOICE_REC_TMIC" interface="INT3_MI2S_TX"/>
         <device name="SND_DEVICE_IN_UNPROCESSED_MIC" interface="INT3_MI2S_TX"/>
         <device name="SND_DEVICE_IN_UNPROCESSED_STEREO_MIC" interface="INT3_MI2S_TX"/>
diff --git a/configs/sdm670/sdm670.mk b/configs/sdm670/sdm670.mk
index def9497..d34ff01 100644
--- a/configs/sdm670/sdm670.mk
+++ b/configs/sdm670/sdm670.mk
@@ -139,7 +139,8 @@
 ro.vendor.audio.sdk.fluencetype=none\
 persist.vendor.audio.fluence.voicecall=true\
 persist.vendor.audio.fluence.voicerec=false\
-persist.vendor.audio.fluence.speaker=true
+persist.vendor.audio.fluence.speaker=true\
+persist.vendor.audio.fluence.tmic.enabled=false
 
 ##speaker protection v3 switch and ADSP AFE API version
 PRODUCT_PROPERTY_OVERRIDES += \
diff --git a/hal/acdb.c b/hal/acdb.c
index cbb96bd..182e513 100644
--- a/hal/acdb.c
+++ b/hal/acdb.c
@@ -143,10 +143,12 @@
         if (my_data->acdb_handle)
             dlclose(my_data->acdb_handle);
 
-        struct listnode *node;
-        struct meta_key_list *key_info;
-        list_for_each(node, &my_data->acdb_meta_key_list) {
+        struct listnode *node = NULL;
+        struct meta_key_list *key_info = NULL;
+        struct listnode *tempnode = NULL;
+        list_for_each_safe(node, tempnode, &my_data->acdb_meta_key_list) {
             key_info = node_to_item(node, struct meta_key_list, list);
+            list_remove(node);
             free(key_info);
         }
         free(my_data);
diff --git a/hal/audio_extn/spkr_protection.c b/hal/audio_extn/spkr_protection.c
index ea4d856..589a391 100644
--- a/hal/audio_extn/spkr_protection.c
+++ b/hal/audio_extn/spkr_protection.c
@@ -70,8 +70,8 @@
 #define MIN_RESISTANCE_LOOKUP (3.2)
 #define MAX_RESISTANCE_LOOKUP (8)
 #define SPV3_LOOKUP_TABLE_ROWS (49)
-/* default limiter threshold is 0dB */
-#define DEFAULT_LIMITER_TH (0x0)
+/* default limiter threshold is 0dB(0x7FFFFFF in natural value) */
+#define DEFAULT_LIMITER_TH (0x07FFFFFF)
 #define AFE_API_VERSION_SUPPORT_SPV3 (0x2)
 enum spv3_boost_max_state {
     BOOST_NO_MAX_STATE,
@@ -275,15 +275,15 @@
 
 /* 3.2ohm : 0.1ohm : 8ohm lookup table */
 static int spv3_limiter_th_q27_table[SPV3_LOOKUP_TABLE_ROWS] = {
-    -526133494, -508685189, -491236884, -473788580, -457682452, -441576325,
-    -426812375, -410706248, -395942298, -382520525, -367756575, -354334802,
-    -340913029, -327491256, -315411661, -301989888, -289910292, -277830697,
-    -265751101, -255013683, -242934088, -232196669, -221459251, -210721833,
-    -199984415, -190589174, -179851756, -170456515, -159719096, -150323855,
-    -140928614, -131533373, -122138132, -114085069, -104689828, -95294587,
-    -87241523,  -79188460,  -69793219,  -61740155,  -53687091,  -45634028,
-    -37580964,  -29527900,  -22817014,  -14763950,  -6710886,   0,
-    0
+    85469248, 86758070, 88066327, 89394311, 90637910, 91898809,
+    93070036, 94364769, 95567425, 96674043, 97906130, 99039829,
+    100186656, 101346763, 102402340, 103588104, 104667026, 105757185,
+    106858699, 107847451, 108970736, 109979029, 110996653, 112023692,
+    113060235, 113975074, 115029672, 115960448, 117033416, 117980405,
+    118935056, 119897432, 120867596, 121705410, 122690202, 123682964,
+    124540293, 125403565, 126418282, 127294571, 128176935, 129065415,
+    129960054, 130860894, 131616362, 132528683, 133447328, 134217728,
+    134217728
 };
 static struct speaker_prot_session handle;
 static int vi_feed_no_channels;
diff --git a/hal/audio_hw.h b/hal/audio_hw.h
index c5ee848..7885b97 100644
--- a/hal/audio_hw.h
+++ b/hal/audio_hw.h
@@ -64,6 +64,9 @@
 #define ANC_FLAG	     0x00000001
 #define DMIC_FLAG            0x00000002
 #define QMIC_FLAG            0x00000004
+/* Include TMIC Flag after existing QMIC flag to avoid backward compatibility
+ * issues since they are bit masked */
+#define TMIC_FLAG            0x00000008
 #define TTY_MODE_OFF         0x00000010
 #define TTY_MODE_FULL        0x00000020
 #define TTY_MODE_VCO         0x00000040
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index 56d9aec..c31a8d8 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -6777,7 +6777,7 @@
          *sample_rate = stream_sr;
 
      if (snd_device == SND_DEVICE_OUT_HDMI)
-         *sample_rate = platform_get_supported_sampling_rate_on_hdmi(stream_sr);
+         *sample_rate = platform_get_supported_copp_sampling_rate(stream_sr);
 
      ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
 , *sample_rate);
@@ -7882,7 +7882,7 @@
     return MAX_CODEC_BACKENDS;
 }
 
-int platform_get_supported_sampling_rate_on_hdmi(uint32_t stream_sr)
+int platform_get_supported_copp_sampling_rate(uint32_t stream_sr)
 {
     int sample_rate;
     switch (stream_sr){
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index f2625bc..4a6ba5b 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -525,7 +525,11 @@
     [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = "quad-mic",
     [SND_DEVICE_IN_VOICE_REC_QMIC_FLUENCE] = "quad-mic",
     [SND_DEVICE_IN_THREE_MIC] = "three-mic",
+    [SND_DEVICE_IN_HANDSET_TMIC_FLUENCE_PRO] = "three-mic",
     [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
+    [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
+    [SND_DEVICE_IN_HANDSET_TMIC_NS] = "three-mic",
+    [SND_DEVICE_IN_HANDSET_TMIC_AEC_NS] = "three-mic",
     [SND_DEVICE_IN_VOICE_REC_TMIC] = "three-mic",
     [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
     [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
@@ -684,7 +688,11 @@
     [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = 129,
     [SND_DEVICE_IN_VOICE_REC_QMIC_FLUENCE] = 125,
     [SND_DEVICE_IN_THREE_MIC] = 46, /* for APSS Surround Sound Recording */
-    [SND_DEVICE_IN_HANDSET_TMIC] = 125, /* for 3mic recording with fluence */
+    [SND_DEVICE_IN_HANDSET_TMIC_FLUENCE_PRO] = 125,
+    [SND_DEVICE_IN_HANDSET_TMIC] = 153,
+    [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 154,
+    [SND_DEVICE_IN_HANDSET_TMIC_NS] = 155,
+    [SND_DEVICE_IN_HANDSET_TMIC_AEC_NS] = 156,
     [SND_DEVICE_IN_VOICE_REC_TMIC] = 125,
     [SND_DEVICE_IN_UNPROCESSED_MIC] = 143,
     [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 144,
@@ -827,7 +835,11 @@
     {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)},
     {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_QMIC_FLUENCE)},
     {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_FLUENCE_PRO)},
     {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_NS)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC_NS)},
     {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_TMIC)},
     {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
     {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
@@ -1507,7 +1519,11 @@
     hw_interface_table[SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
     hw_interface_table[SND_DEVICE_IN_VOICE_REC_QMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
     hw_interface_table[SND_DEVICE_IN_THREE_MIC] = strdup("SLIMBUS_0_TX");
+    hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_FLUENCE_PRO] = strdup("SLIMBUS_0_TX");
     hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC] = strdup("SLIMBUS_0_TX");
+    hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC] = strdup("SLIMBUS_0_TX");
+    hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_NS] = strdup("SLIMBUS_0_TX");
+    hw_interface_table[SND_DEVICE_IN_HANDSET_TMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
     hw_interface_table[SND_DEVICE_IN_VOICE_REC_TMIC] = strdup("SLIMBUS_0_TX");
     hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
     hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
@@ -2051,8 +2067,16 @@
     property_get("ro.vendor.audio.sdk.fluencetype", my_data->fluence_cap, "");
     if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro"))) {
         my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
+
+        if (property_get_bool("persist.vendor.audio.fluence.tmic.enabled",false)) {
+            my_data->fluence_type |= FLUENCE_TRI_MIC;
+        }
     } else if (!strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
         my_data->fluence_type = FLUENCE_DUAL_MIC;
+
+        if (property_get_bool("persist.vendor.audio.fluence.tmic.enabled",false)) {
+            my_data->fluence_type |= FLUENCE_TRI_MIC;
+        }
     } else {
         my_data->fluence_type = FLUENCE_NONE;
     }
@@ -3927,7 +3951,11 @@
             } else
                 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
         } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
-            if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
+            if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
+                (my_data->source_mic_type & SOURCE_THREE_MIC)) {
+                snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC_NS;
+                adev->acdb_settings |= TMIC_FLAG;
+            } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
                 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
                 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
                 adev->acdb_settings |= DMIC_FLAG;
@@ -3967,7 +3995,11 @@
             } else
                 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
         } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
-            if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
+            if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
+                (my_data->source_mic_type & SOURCE_THREE_MIC)) {
+                snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC_NS;
+                adev->acdb_settings |= TMIC_FLAG;
+            } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
                 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
                 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
                 adev->acdb_settings |= DMIC_FLAG;
@@ -3997,7 +4029,11 @@
             } else
                 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
         } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
-            if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
+            if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
+                (my_data->source_mic_type & SOURCE_THREE_MIC)) {
+                snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
+                adev->acdb_settings |= TMIC_FLAG;
+            } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
                 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
                 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
                 adev->acdb_settings |= DMIC_FLAG;
@@ -4027,7 +4063,11 @@
             } else
                 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
         } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
-            if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
+            if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
+                (my_data->source_mic_type & SOURCE_THREE_MIC)) {
+                snd_device = SND_DEVICE_IN_HANDSET_TMIC_NS;
+                adev->acdb_settings |= TMIC_FLAG;
+            } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
                 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
                 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
                 adev->acdb_settings |= DMIC_FLAG;
@@ -4143,8 +4183,14 @@
                 if (audio_extn_hfp_is_active(adev))
                     platform_set_echo_reference(adev, true, out_device);
             } else {
-                snd_device = SND_DEVICE_IN_VOICE_DMIC;
-                adev->acdb_settings |= DMIC_FLAG;
+                if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
+                    (my_data->source_mic_type & SOURCE_THREE_MIC)) {
+                    snd_device = SND_DEVICE_IN_HANDSET_TMIC;
+                    adev->acdb_settings |= TMIC_FLAG;
+                } else { /* for FLUENCE_DUAL_MIC and SOURCE_DUAL_MIC */
+                    snd_device = SND_DEVICE_IN_VOICE_DMIC;
+                    adev->acdb_settings |= DMIC_FLAG;
+                }
             }
         } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
             snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
@@ -4315,6 +4361,9 @@
                     platform_set_echo_reference(adev, true, out_device);
                 } else if ((my_data->fluence_type & FLUENCE_QUAD_MIC) &&
                     (my_data->source_mic_type & SOURCE_THREE_MIC)) {
+                    snd_device = SND_DEVICE_IN_HANDSET_TMIC_FLUENCE_PRO;
+                } else if ((my_data->fluence_type & FLUENCE_TRI_MIC) &&
+                           (my_data->source_mic_type & SOURCE_THREE_MIC)) {
                     snd_device = SND_DEVICE_IN_HANDSET_TMIC;
                 } else if ((my_data->fluence_type & FLUENCE_DUAL_MIC) &&
                     (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
@@ -6876,8 +6925,9 @@
      } else
          *sample_rate = stream_sr;
 
-    if (snd_device == SND_DEVICE_OUT_HDMI)
-        *sample_rate = platform_get_supported_sampling_rate_on_hdmi(stream_sr);
+    if ((snd_device == SND_DEVICE_OUT_HDMI) || (snd_device == SND_DEVICE_OUT_DISPLAY_PORT) ||
+                  (snd_device == SND_DEVICE_OUT_USB_HEADSET))
+        *sample_rate = platform_get_supported_copp_sampling_rate(stream_sr);
 
      ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr, *sample_rate);
 
@@ -7687,7 +7737,7 @@
 
     return MAX_CODEC_BACKENDS;
 }
-int platform_get_supported_sampling_rate_on_hdmi(uint32_t stream_sr)
+int platform_get_supported_copp_sampling_rate(uint32_t stream_sr)
 {
     int sample_rate;
     switch (stream_sr){
diff --git a/hal/msm8974/platform.h b/hal/msm8974/platform.h
index db86cdc..c2fb810 100644
--- a/hal/msm8974/platform.h
+++ b/hal/msm8974/platform.h
@@ -24,8 +24,9 @@
 enum {
     FLUENCE_NONE,
     FLUENCE_DUAL_MIC = 0x1,
-    FLUENCE_QUAD_MIC = 0x2,
-    FLUENCE_HEX_MIC = 0x4,
+    FLUENCE_TRI_MIC = 0x2,
+    FLUENCE_QUAD_MIC = 0x4,
+    FLUENCE_HEX_MIC = 0x8,
 };
 
 enum {
@@ -217,7 +218,11 @@
     SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS,
     SND_DEVICE_IN_VOICE_REC_QMIC_FLUENCE,
     SND_DEVICE_IN_THREE_MIC,
+    SND_DEVICE_IN_HANDSET_TMIC_FLUENCE_PRO,
     SND_DEVICE_IN_HANDSET_TMIC,
+    SND_DEVICE_IN_HANDSET_TMIC_AEC,
+    SND_DEVICE_IN_HANDSET_TMIC_NS,
+    SND_DEVICE_IN_HANDSET_TMIC_AEC_NS,
     SND_DEVICE_IN_VOICE_REC_TMIC,
     SND_DEVICE_IN_UNPROCESSED_MIC,
     SND_DEVICE_IN_UNPROCESSED_STEREO_MIC,
diff --git a/hal/platform_api.h b/hal/platform_api.h
index 0674761..e72c6e9 100644
--- a/hal/platform_api.h
+++ b/hal/platform_api.h
@@ -184,7 +184,7 @@
 
 int platform_set_channel_allocation(void *platform, int channel_alloc);
 int platform_get_edid_info(void *platform);
-int platform_get_supported_sampling_rate_on_hdmi(uint32_t stream_sr);
+int platform_get_supported_copp_sampling_rate(uint32_t stream_sr);
 int platform_set_channel_map(void *platform, int ch_count, char *ch_map,
                              int snd_id);
 int platform_set_stream_channel_map(void *platform, audio_channel_mask_t channel_mask,
diff --git a/qahw/Android.mk b/qahw/Android.mk
index c7df9e3..0b782f0 100644
--- a/qahw/Android.mk
+++ b/qahw/Android.mk
@@ -27,6 +27,7 @@
 LOCAL_COPY_HEADERS      += inc/qahw_effect_api.h
 
 LOCAL_PRELINK_MODULE    := false
+LOCAL_VENDOR_MODULE     := true
 
 include $(BUILD_SHARED_LIBRARY)
 
diff --git a/qahw/inc/qahw_effect_api.h b/qahw/inc/qahw_effect_api.h
index de53cd3..dbd61e2 100644
--- a/qahw/inc/qahw_effect_api.h
+++ b/qahw/inc/qahw_effect_api.h
@@ -31,8 +31,6 @@
 
 #include <system/audio.h>
 
-#include "qahw.h"
-
 __BEGIN_DECLS
 
 #define QAHW_EFFECT_API_VERSION_0_0 QAHW_MAKE_API_VERSION(0, 0)
diff --git a/qahw/src/qahw_effect.c b/qahw/src/qahw_effect.c
index cf7b3fd..2eff79f 100644
--- a/qahw/src/qahw_effect.c
+++ b/qahw/src/qahw_effect.c
@@ -38,6 +38,7 @@
 #include <hardware/audio_effect.h>
 #include <stdlib.h>
 
+#include "qahw.h"
 #include "qahw_effect_api.h"
 
 // The current effect API version.
diff --git a/qahw_api/Android.mk b/qahw_api/Android.mk
index ba402ba..fa4e6cb 100644
--- a/qahw_api/Android.mk
+++ b/qahw_api/Android.mk
@@ -34,6 +34,7 @@
 LOCAL_COPY_HEADERS      += inc/qahw_effect_visualizer.h
 
 LOCAL_PRELINK_MODULE    := false
+LOCAL_VENDOR_MODULE     := true
 
 include $(BUILD_SHARED_LIBRARY)
 
diff --git a/qahw_api/Makefile.am b/qahw_api/Makefile.am
index 5892bb9..38506b8 100644
--- a/qahw_api/Makefile.am
+++ b/qahw_api/Makefile.am
@@ -22,8 +22,8 @@
 libqahw_la_CPPFLAGS += -std=c++11 -DHAVE_PTHREADS -DHAVE_ANDROID_OS
 libqahw_la_CPPFLAGS += -DDEBUG_REFS_CALLSTACK_ENABLED=0
 libqahw_la_CPPFLAGS += -DNDEBUG
-libqahw_la_LDFLAGS   = -ltinyalsa -lhardware -lexpat -lcutils -llog -ldl -lbinder -shared -avoid-version -llog -lcutils -lpthread -lutils
+libqahw_la_LDFLAGS   = -ltinyalsa -lhardware -lexpat -lcutils -llog -ldl -shared -avoid-version -lpthread -lutils
 if QTI_AUDIO_SERVER_ENABLED
 AM_CPPFLAGS += -DQTI_AUDIO_SERVER_ENABLED
-libqahw_la_LDFLAGS +=  -lqtiaudioserver
+libqahw_la_LDFLAGS +=  -lqtiaudioserver -lbinder
 endif
diff --git a/qahw_api/test/Android.mk b/qahw_api/test/Android.mk
index ec4e698..06e8a5a 100644
--- a/qahw_api/test/Android.mk
+++ b/qahw_api/test/Android.mk
@@ -20,10 +20,10 @@
     libutils \
     libcutils
 
-LOCAL_LDLIBS := -lpthread
 LOCAL_32_BIT_ONLY := true
 
 LOCAL_C_INCLUDES += $(hal-play-inc)
+LOCAL_VENDOR_MODULE := true
 
 include $(BUILD_EXECUTABLE)
 
@@ -43,4 +43,6 @@
 hal-rec-inc     = $(TARGET_OUT_HEADERS)/mm-audio/qahw_api/inc
 
 LOCAL_C_INCLUDES += $(hal-rec-inc)
+LOCAL_VENDOR_MODULE := true
+
 include $(BUILD_EXECUTABLE)
diff --git a/qahw_api/test/qahw_effect_test.c b/qahw_api/test/qahw_effect_test.c
index bc249f3..9ea362f 100644
--- a/qahw_api/test/qahw_effect_test.c
+++ b/qahw_api/test/qahw_effect_test.c
@@ -34,6 +34,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <errno.h>
+#include <signal.h>
 
 #include "qahw_api.h"
 #include "qahw_defs.h"
@@ -111,6 +112,12 @@
 #define NUM_EQ_BANDS 5
 const uint16_t qahw_equalizer_band_freqs[NUM_EQ_BANDS] = {60, 230, 910, 3600, 14000}; /* frequencies in HZ */
 
+/* Handler to handle input command_thread_func signal */
+void stop_effect_command_thread_handler(int signal __unused)
+{
+   pthread_exit(NULL);
+}
+
 /* THREAD BODY OF BASSBOOST */
 void *bassboost_thread_func(void* data) {
     thread_data_t            *thr_ctxt = (thread_data_t *)data;
@@ -489,6 +496,12 @@
     qahw_effect_param_t *param = (qahw_effect_param_t *)buf32;
     qahw_effect_param_t *param_2 = (qahw_effect_param_t *)buf32_2;
 
+    /* Register the SIGUSR1 to close this thread properly
+       as it is waiting for input in while loop */
+    if (signal(SIGUSR1, stop_effect_command_thread_handler) == SIG_ERR) {
+        fprintf(stderr, "Failed to register SIGUSR1:%d\n",errno);
+    }
+
     while(!thr_ctxt->exit) {
         if (fgets(cmd_str, sizeof(cmd_str), stdin) == NULL) {
             fprintf(stderr, "read error\n");
diff --git a/qahw_api/test/qahw_multi_record_test.c b/qahw_api/test/qahw_multi_record_test.c
index d618101..2e0a396 100644
--- a/qahw_api/test/qahw_multi_record_test.c
+++ b/qahw_api/test/qahw_multi_record_test.c
@@ -588,7 +588,7 @@
     printf("                                               For mono channel 16kHz rate for 30seconds\n\n");
 }
 
-static void qti_audio_server_death_notify_cb(void *ctxt) {
+static void qti_audio_server_death_notify_cb(void *ctxt __unused) {
     fprintf(log_file, "qas died\n");
     fprintf(stderr, "qas died\n");
     stop_record = true;
@@ -769,7 +769,7 @@
     /* set global setparams entered by user.
      * Also other global setparams can be concatenated if required.
      */
-    if (params[0].kvpairs != NULL) {
+    if (params[0].kvpairs[0] != 0) {
         size_t len;
         len = strcspn(params[0].kvpairs, ",");
         while (len < strlen(params[0].kvpairs)) {
diff --git a/qahw_api/test/qahw_playback_test.c b/qahw_api/test/qahw_playback_test.c
index fceff8b..2469b3c 100644
--- a/qahw_api/test/qahw_playback_test.c
+++ b/qahw_api/test/qahw_playback_test.c
@@ -854,10 +854,12 @@
         // destory effect command thread
         params->cmd_data.exit = true;
         usleep(100000);  // give a chance for thread to exit gracefully
-        rc = pthread_cancel(params->cmd_data.cmd_thread);
+
+        //Send signal for input command_thread_func to stop
+        rc = pthread_kill(params->cmd_data.cmd_thread, SIGUSR1);
         if (rc != 0) {
-            fprintf(log_file, "Fail to cancel thread!\n");
-            fprintf(stderr, "Fail to cancel thread!\n");
+            fprintf(log_file, "Fail to kill effect command thread!\n");
+            fprintf(stderr, "Fail to kill effect command thread!\n");
         }
         rc = pthread_join(params->cmd_data.cmd_thread, NULL);
         if (rc < 0) {
@@ -1197,7 +1199,7 @@
 int tigger_event(qahw_stream_handle_t* out_handle)
 {
     qahw_param_payload payload;
-    struct event_data event_payload = {0};
+    struct event_data event_payload = {0, 0, 0, 0, 0, 0, 0};
     int ret = 0;
 
     event_payload.num_events = 1;
diff --git a/qahw_api/test/qahw_playback_test.h b/qahw_api/test/qahw_playback_test.h
index 3ec8f25..b643c1d 100644
--- a/qahw_api/test/qahw_playback_test.h
+++ b/qahw_api/test/qahw_playback_test.h
@@ -159,8 +159,12 @@
 #define is_qap_session_active(argc, argv, kvp_string)                    (0)
 #define get_play_list(fp, stream_param, num_of_streams, kvp_str)         (0)
 #define check_for_playlist(kvp_string)                                   (0)
-#define start_playback_through_qap(kvp_string, num_of_streams,\
-                                         qap_out_hal_handle_t)           (0)
+inline int start_playback_through_qap(char * kvp_string __unused,
+                                      int num_of_streams __unused,
+                                      qahw_module_handle_t *qap_out_hal_handle_t __unused)
+{
+    return 0;
+}
 #define start_playback_through_qap_playlist(cmd_kvp_str, num_of_streams,\
                    kvp_string, stream_param, qap_wrapper_session_active,\
                    qap_out_hal_handle_t)                                 (0)