Merge "configs: reduce the gain of headset mic for QRD device"
diff --git a/configs/kona/mixer_paths_qrd.xml b/configs/kona/mixer_paths_qrd.xml
index 70f047d..eec42d2 100644
--- a/configs/kona/mixer_paths_qrd.xml
+++ b/configs/kona/mixer_paths_qrd.xml
@@ -2280,7 +2280,7 @@
     </path>
 
     <path name="speaker-protected">
-        <ctl name="WSA_AIF_VI Mixer WSA_SPKR_VI_1" value="1" />
+        <ctl name="WSA_AIF_VI Mixer WSA_SPKR_VI_2" value="1" />
         <ctl name="WSA_CDC_DMA_0 TX Format" value="PACKED_16B" />
         <path name="speaker" />
         <ctl name="VI_FEED_TX Channels" value="One" />
@@ -2288,7 +2288,7 @@
     </path>
 
     <path name="voice-speaker-protected">
-        <ctl name="WSA_AIF_VI Mixer WSA_SPKR_VI_1" value="1" />
+        <ctl name="WSA_AIF_VI Mixer WSA_SPKR_VI_2" value="1" />
         <ctl name="WSA_CDC_DMA_0 TX Format" value="PACKED_16B" />
         <path name="speaker-mono" />
         <ctl name="VI_FEED_TX Channels" value="One" />
diff --git a/configs/lito/audio_configs.xml b/configs/lito/audio_configs.xml
new file mode 100644
index 0000000..bcc617d
--- /dev/null
+++ b/configs/lito/audio_configs.xml
@@ -0,0 +1,114 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+Copyright (c) 2019, The Linux Foundation. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above
+      copyright notice, this list of conditions and the following
+      disclaimer in the documentation and/or other materials provided
+      with the distribution.
+    * Neither the name of The Linux Foundation nor the names of its
+      contributors may be used to endorse or promote products derived
+      from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+-->
+<configs>
+        <!-- APM Configs -->
+        <property name="audio.deep_buffer.media" value="true"/>
+        <property name="audio.offload.disable" value="false"/>
+        <property name="audio.offload.min.duration.secs" value="60"/>
+        <property name="audio.offload.video" value="true"/>
+        <property name="persist.vendor.audio.sva.conc.enabled" value="false"/>
+        <property name="persist.vendor.audio.va_concurrency_enabled" value="false"/>
+        <property name="vendor.audio.av.streaming.offload.enable" value="false"/>
+        <property name="vendor.audio.offload.track.enable" value="true"/>
+        <property name="vendor.audio.offload.multiple.enabled" value="false"/>
+        <property name="vendor.audio.rec.playback.conc.disabled" value="false"/>
+        <property name="vendor.voice.conc.fallbackpath" value=""/>
+        <property name="vendor.voice.dsd.playback.conc.disabled" value="true"/>
+        <property name="vendor.voice.path.for.pcm.voip" value="true"/>
+        <property name="vendor.voice.playback.conc.disabled" value="false"/>
+        <property name="vendor.voice.record.conc.disabled" value="false"/>
+        <property name="vendor.voice.voip.conc.disabled" value="false"/>
+        <flag name="audio_extn_formats_enabled" value="true" />
+        <flag name="audio_extn_hdmi_spk_enabled" value="true" />
+        <flag name="use_xml_audio_policy_conf" value="true" />
+        <flag name="voice_concurrency" value="false" />
+
+        <!-- AV Configs -->
+        <property name="vendor.audio.use.sw.alac.decoder" value="true"/>
+        <property name="vendor.audio.use.sw.ape.decoder" value="true"/>
+        <property name="vendor.audio.use.sw.mpegh.decoder" value="false"/>
+        <property name="vendor.audio.flac.sw.decoder.24bit" value="true"/>
+        <property name="vendor.audio.hw.aac.encoder" value="true"/>
+        <flag name="aac_adts_offload_enabled" value="true" />
+        <flag name="alac_offload_enabled" value="true" />
+        <flag name="ape_offload_enabled" value="true" />
+        <flag name="flac_offload_enabled" value="true" />
+        <flag name="pcm_offload_enabled_16" value="true" />
+        <flag name="pcm_offload_enabled_24" value="true" />
+        <flag name="qti_flac_decoder" value="true" />
+        <flag name="vorbis_offload_enabled" value="true" />
+        <flag name="wma_offload_enabled" value="true" />
+
+        <!-- AHAL Configs -->
+        <flag name="a2dp_offload_enabled" value="true" />
+        <flag name="anc_headset_enabled" value="true" />
+        <flag name="audiosphere_enabled" value="true" />
+        <flag name="audio_zoom_enabled" value="false" />
+        <flag name="battery_listener_enabled" value="true" />
+        <flag name="compress_capture_enabled" value="false" />
+        <flag name="compress_in_enabled" value="true" />
+        <flag name="compress_metadata_needed" value="true" />
+        <flag name="concurrent_capture_enabled" value="true" />
+        <flag name="custom_stereo_enabled" value="true" />
+        <flag name="display_port_enabled" value="true" />
+        <flag name="dsm_feedback_enabled" value="false" />
+        <flag name="dynamic_ecns_enabled" value="true" />
+        <flag name="ext_hw_plugin_enabled" value="true" />
+        <flag name="ext_qdsp_enabled" value="false" />
+        <flag name="ext_spkr_enabled" value="false" />
+        <flag name="ext_spkr_tfa_enabled" value="false" />
+        <flag name="fluence_enabled" value="true" />
+        <flag name="hdmi_edid_enabled" value="true" />
+        <flag name="hdmi_passthrough_enabled" value="true" />
+        <flag name="hfp_enabled" value="true" />
+        <flag name="hifi_audio_enabled" value="false" />
+        <flag name="hwdep_cal_enabled" value="false" />
+        <flag name="incall_music_enabled" value="true" />
+        <flag name="keep_alive_enabled" value="true" />
+        <flag name="kpi_optimize_enabled" value="true" />
+        <flag name="maxx_audio_enabled" value="false" />
+        <flag name="receiver_aided_stereo" value="true" />
+        <flag name="snd_monitor_enabled" value="true" />
+        <flag name="source_track_enabled" value="true" />
+        <flag name="spkr_prot_enabled" value="true" />
+        <flag name="ssrec_enabled" value="true" />
+        <flag name="usb_offload_burst_mode" value="true" />
+        <flag name="usb_offload_enabled" value="true" />
+        <flag name="usb_offload_sidetone_vol_enabled" value="false" />
+        <flag name="use_deep_buffer_as_primary_output" value="false" />
+        <flag name="vbat_enabled" value="true" />
+        <flag name="wsa_enabled" value="false" />
+
+        <!-- Common configs between APM and AHAL -->
+        <flag name="afe_proxy_enabled" value="true" />
+        <flag name="compress_voip_enabled" value="false" />
+        <flag name="fm_power_opt" value="true" />
+        <flag name="record_play_concurrency" value="false" />
+</configs>
diff --git a/configs/lito/audio_configs_stock.xml b/configs/lito/audio_configs_stock.xml
new file mode 100644
index 0000000..e26ef14
--- /dev/null
+++ b/configs/lito/audio_configs_stock.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+Copyright (c) 2019, The Linux Foundation. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above
+      copyright notice, this list of conditions and the following
+      disclaimer in the documentation and/or other materials provided
+      with the distribution.
+    * Neither the name of The Linux Foundation nor the names of its
+      contributors may be used to endorse or promote products derived
+      from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+-->
+<configs>
+        <!-- AHAL Configs -->
+        <flag name="a2dp_offload_enabled" value="true" />
+        <flag name="afe_proxy_enabled" value="false" />
+        <flag name="anc_headset_enabled" value="false" />
+        <flag name="audio_zoom_enabled" value="false" />
+        <flag name="audiosphere_enabled" value="false" />
+        <flag name="battery_listener_enabled" value="false" />
+        <flag name="compress_capture_enabled" value="false" />
+        <flag name="compress_in_enabled" value="false" />
+        <flag name="compress_metadata_needed" value="false" />
+        <flag name="compress_voip_enabled" value="false" />
+        <flag name="concurrent_capture_enabled" value="true" />
+        <flag name="custom_stereo_enabled" value="false" />
+        <flag name="display_port_enabled" value="false" />
+        <flag name="dsm_feedback_enabled" value="false" />
+        <flag name="dynamic_ecns_enabled" value="false" />
+        <flag name="ext_hw_plugin_enabled" value="false" />
+        <flag name="ext_qdsp_enabled" value="true" />
+        <flag name="ext_spkr_enabled" value="true" />
+        <flag name="ext_spkr_tfa_enabled" value="false" />
+        <flag name="fluence_enabled" value="false" />
+        <flag name="fm_power_opt" value="false" />
+        <flag name="hdmi_edid_enabled" value="false" />
+        <flag name="hdmi_passthrough_enabled" value="false" />
+        <flag name="hfp_enabled" value="true" />
+        <flag name="hifi_audio_enabled" value="false" />
+        <flag name="hwdep_cal_enabled" value="true" />
+        <flag name="incall_music_enabled" value="true" />
+        <flag name="keep_alive_enabled" value="false" />
+        <flag name="kpi_optimize_enabled" value="false" />
+        <flag name="receiver_aided_stereo" value="false" />
+        <flag name="record_play_concurrency" value="false" />
+        <flag name="snd_monitor_enabled" value="true" />
+        <flag name="source_track_enabled" value="false" />
+        <flag name="spkr_prot_enabled" value="true" />
+        <flag name="ssrec_enabled" value="false" />
+        <flag name="usb_offload_burst_mode" value="false" />
+        <flag name="usb_offload_enabled" value="true" />
+        <flag name="usb_offload_sidetone_vol_enabled" value="false" />
+        <flag name="use_deep_buffer_as_primary_output" value="false" />
+        <flag name="vbat_enabled" value="false" />
+        <flag name="wsa_enabled" value="false" />
+</configs>
diff --git a/configs/lito/audio_io_policy.conf b/configs/lito/audio_io_policy.conf
index 350fe11..7e00464 100644
--- a/configs/lito/audio_io_policy.conf
+++ b/configs/lito/audio_io_policy.conf
@@ -84,16 +84,22 @@
 }
 
 inputs {
+  record_16bit {
+    formats AUDIO_FORMAT_PCM_16_BIT
+    sampling_rates 8000|16000|32000|44100|48000|88200|96000|176400|192000
+    bit_width 16
+    app_type 69938
+  }
   record_24bit {
     formats AUDIO_FORMAT_PCM_24_BIT_PACKED|AUDIO_FORMAT_PCM_24_BIT
     sampling_rates 44100|48000|88200|96000|176400|192000
     bit_width 24
-    app_type 69938
+    app_type 69948
   }
   record_32bit {
     formats AUDIO_FORMAT_PCM_32_BIT|AUDIO_FORMAT_PCM_FLOAT
     sampling_rates 44100|48000|88200|96000|176400|192000
     bit_width 32
-    app_type 69938
+    app_type 69949
   }
 }
diff --git a/configs/lito/audio_policy_configuration.xml b/configs/lito/audio_policy_configuration.xml
index f98f9d2..50920b3 100644
--- a/configs/lito/audio_policy_configuration.xml
+++ b/configs/lito/audio_policy_configuration.xml
@@ -262,15 +262,18 @@
                     <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                              samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_MONO,AUDIO_CHANNEL_OUT_STEREO"/>
                 </devicePort>
-                <devicePort tagName="BT A2DP Out" type="AUDIO_DEVICE_OUT_BLUETOOTH_A2DP" role="sink">
+                <devicePort tagName="BT A2DP Out" type="AUDIO_DEVICE_OUT_BLUETOOTH_A2DP" role="sink"
+                            encodedFormats="AUDIO_FORMAT_SBC AUDIO_FORMAT_AAC AUDIO_FORMAT_APTX AUDIO_FORMAT_APTX_HD AUDIO_FORMAT_LDAC AUDIO_FORMAT_CELT AUDIO_FORMAT_APTX_ADAPTIVE">
                     <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                              samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
                 </devicePort>
-                <devicePort tagName="BT A2DP Headphones" type="AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES" role="sink">
+                <devicePort tagName="BT A2DP Headphones" type="AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES" role="sink"
+                            encodedFormats="AUDIO_FORMAT_SBC AUDIO_FORMAT_AAC AUDIO_FORMAT_APTX AUDIO_FORMAT_APTX_HD AUDIO_FORMAT_LDAC AUDIO_FORMAT_CELT AUDIO_FORMAT_APTX_ADAPTIVE">
                     <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                              samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
                 </devicePort>
-                <devicePort tagName="BT A2DP Speaker" type="AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER" role="sink">
+                <devicePort tagName="BT A2DP Speaker" type="AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER" role="sink"
+                            encodedFormats="AUDIO_FORMAT_SBC AUDIO_FORMAT_AAC AUDIO_FORMAT_APTX AUDIO_FORMAT_APTX_HD AUDIO_FORMAT_LDAC AUDIO_FORMAT_CELT AUDIO_FORMAT_APTX_ADAPTIVE">
                     <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                              samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
                 </devicePort>
diff --git a/configs/lito/lito.mk b/configs/lito/lito.mk
index f307de9..096c6de 100644
--- a/configs/lito/lito.mk
+++ b/configs/lito/lito.mk
@@ -1,12 +1,22 @@
 #BOARD_USES_GENERIC_AUDIO := true
 #
 #AUDIO_FEATURE_FLAGS
+ifeq ($(TARGET_USES_QMAA_OVERRIDE_AUDIO), false)
+ifeq ($(TARGET_USES_QMAA),true)
+AUDIO_USE_STUB_HAL := true
+endif
+endif
+
+ifneq ($(AUDIO_USE_STUB_HAL), true)
 BOARD_USES_ALSA_AUDIO := true
 TARGET_USES_AOSP_FOR_AUDIO := false
 
 ifneq ($(TARGET_USES_AOSP_FOR_AUDIO), true)
 USE_CUSTOM_AUDIO_POLICY := 1
+AUDIO_FEATURE_QSSI_COMPLIANCE := false
 AUDIO_FEATURE_ENABLED_COMPRESS_CAPTURE := false
+AUDIO_FEATURE_ENABLED_COMPRESS_INPUT := true
+AUDIO_FEATURE_ENABLED_CONCURRENT_CAPTURE := true
 AUDIO_FEATURE_ENABLED_COMPRESS_VOIP := false
 AUDIO_FEATURE_ENABLED_DYNAMIC_ECNS := true
 AUDIO_FEATURE_ENABLED_EXTN_FORMATS := true
@@ -30,18 +40,18 @@
 MM_AUDIO_ENABLED_SAFX := true
 AUDIO_FEATURE_ENABLED_HW_ACCELERATED_EFFECTS := false
 AUDIO_FEATURE_ENABLED_AUDIOSPHERE := true
-AUDIO_FEATURE_ENABLED_USB_TUNNEL_AUDIO := true
-AUDIO_FEATURE_ENABLED_SPLIT_A2DP := true
+AUDIO_FEATURE_ENABLED_USB_TUNNEL := true
+AUDIO_FEATURE_ENABLED_A2DP_OFFLOAD := true
 AUDIO_FEATURE_ENABLED_3D_AUDIO := true
+AUDIO_FEATURE_ENABLED_AHAL_EXT := true
 DOLBY_ENABLE := false
 endif
 
-USE_XML_AUDIO_POLICY_CONF := 1
 AUDIO_FEATURE_ENABLED_DLKM := true
 BOARD_SUPPORTS_SOUND_TRIGGER := true
 BOARD_SUPPORTS_GCS := false
 AUDIO_FEATURE_ENABLED_INSTANCE_ID := true
-AUDIO_USE_LL_AS_PRIMARY_OUTPUT := true
+AUDIO_USE_DEEP_AS_PRIMARY_OUTPUT := false
 AUDIO_FEATURE_ENABLED_VBAT_MONITOR := true
 AUDIO_FEATURE_ENABLED_ANC_HEADSET := true
 AUDIO_FEATURE_ENABLED_CUSTOMSTEREO := true
@@ -86,8 +96,11 @@
     vendor/qcom/opensource/audio-hal/primary-hal/configs/lito/audio_platform_info_intcodec.xml:$(TARGET_COPY_OUT_VENDOR)/etc/audio_platform_info_intcodec.xml \
     vendor/qcom/opensource/audio-hal/primary-hal/configs/lito/sound_trigger_mixer_paths.xml:$(TARGET_COPY_OUT_VENDOR)/etc/sound_trigger_mixer_paths.xml \
     vendor/qcom/opensource/audio-hal/primary-hal/configs/lito/sound_trigger_mixer_paths_qrd.xml:$(TARGET_COPY_OUT_VENDOR)/etc/sound_trigger_mixer_paths_qrd.xml \
-    vendor/qcom/opensource/audio-hal/primary-hal/configs/lito/mixer_paths_mtp.xml:$(TARGET_COPY_OUT_VENDOR)/etc/mixer_paths_mtp.xml \
+    vendor/qcom/opensource/audio-hal/primary-hal/configs/lito/mixer_paths.xml:$(TARGET_COPY_OUT_VENDOR)/etc/mixer_paths.xml \
     vendor/qcom/opensource/audio-hal/primary-hal/configs/lito/mixer_paths_qrd.xml:$(TARGET_COPY_OUT_VENDOR)/etc/mixer_paths_qrd.xml \
+    vendor/qcom/opensource/audio-hal/primary-hal/configs/lito/audio_configs.xml:$(TARGET_COPY_OUT_VENDOR)/etc/audio_configs.xml \
+    vendor/qcom/opensource/audio-hal/primary-hal/configs/lito/audio_configs_stock.xml:$(TARGET_COPY_OUT_VENDOR)/etc/audio_configs_stock.xml \
+    frameworks/native/data/etc/android.hardware.audio.pro.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.audio.pro.xml
 
 #XML Audio configuration files
 ifneq ($(TARGET_USES_AOSP_FOR_AUDIO), true)
@@ -118,6 +131,11 @@
 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 += \
+persist.vendor.audio.spv3.enable=true\
+persist.vendor.audio.avs.afe_api_version=2
+
 #disable tunnel encoding
 PRODUCT_PROPERTY_OVERRIDES += \
 vendor.audio.tunnel.encode=false
@@ -187,6 +205,18 @@
 PRODUCT_PROPERTY_OVERRIDES += \
 persist.vendor.bt.a2dp_offload_cap=sbc-aptx-aptxtws-aptxhd-aac-ldac
 
+# A2DP offload support
+PRODUCT_PROPERTY_OVERRIDES += \
+ro.bluetooth.a2dp_offload.supported=true
+
+# Disable A2DP offload
+PRODUCT_PROPERTY_OVERRIDES += \
+persist.bluetooth.a2dp_offload.disabled=false
+
+# A2DP offload DSP supported encoder list
+PRODUCT_PROPERTY_OVERRIDES += \
+persist.bluetooth.a2dp_offload.cap=sbc-aac-aptx-aptxhd-ldac
+
 #enable software decoders for ALAC and APE
 PRODUCT_PROPERTY_OVERRIDES += \
 vendor.audio.use.sw.alac.decoder=true
@@ -221,10 +251,29 @@
 PRODUCT_PROPERTY_OVERRIDES += \
 vendor.audio.adm.buffering.ms=2
 
+#enable headset calibration
+PRODUCT_PROPERTY_OVERRIDES += \
+audio.volume.headset.gain.depcal=true
+
+#enable dualmic fluence for voice communication
+PRODUCT_PROPERTY_OVERRIDES += \
+persist.audio.fluence.voicecomm=true
+endif
+
+USE_XML_AUDIO_POLICY_CONF := 1
+
 #enable keytone FR
 PRODUCT_PROPERTY_OVERRIDES += \
 vendor.audio.hal.output.suspend.supported=true
 
+#Enable AAudio MMAP/NOIRQ data path
+#2 is AAUDIO_POLICY_AUTO so it will try MMAP then fallback to Legacy path
+PRODUCT_PROPERTY_OVERRIDES += aaudio.mmap_policy=2
+#Allow EXCLUSIVE then fall back to SHARED.
+PRODUCT_PROPERTY_OVERRIDES += aaudio.mmap_exclusive_policy=2
+PRODUCT_PROPERTY_OVERRIDES += aaudio.hw_burst_min_usec=2000
+
+
 #enable mirror-link feature
 PRODUCT_PROPERTY_OVERRIDES += \
 vendor.audio.enable.mirrorlink=false
@@ -248,4 +297,14 @@
     android.hardware.audio.common@4.0-util \
     android.hardware.audio@4.0-impl \
     android.hardware.audio.effect@4.0 \
-    android.hardware.audio.effect@4.0-impl
+    android.hardware.audio.effect@4.0-impl \
+    vendor.qti.hardware.audiohalext@1.0 \
+    vendor.qti.hardware.audiohalext@1.0-impl \
+    vendor.qti.hardware.audiohalext-utils
+
+PRODUCT_PACKAGES_ENG += \
+    VoicePrintTest \
+    VoicePrintDemo
+
+PRODUCT_PACKAGES_DEBUG += \
+    AudioSettings
diff --git a/configs/msm8998/audio_configs.xml b/configs/msm8998/audio_configs.xml
new file mode 100644
index 0000000..4b0159d
--- /dev/null
+++ b/configs/msm8998/audio_configs.xml
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+Copyright (c) 2019, The Linux Foundation. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above
+      copyright notice, this list of conditions and the following
+      disclaimer in the documentation and/or other materials provided
+      with the distribution.
+    * Neither the name of The Linux Foundation nor the names of its
+      contributors may be used to endorse or promote products derived
+      from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+-->
+<configs>
+        <!-- APM Configs -->
+        <property name="audio.deep_buffer.media" value="true"/>
+        <property name="audio.offload.disable" value="false"/>
+        <property name="audio.offload.min.duration.secs" value="60"/>
+        <property name="audio.offload.video" value="true"/>
+        <property name="persist.vendor.audio.sva.conc.enabled" value="false"/>
+        <property name="persist.vendor.audio.va_concurrency_enabled" value="false"/>
+        <property name="vendor.audio.av.streaming.offload.enable" value="false"/>
+        <property name="vendor.audio.offload.track.enable" value="true"/>
+        <property name="vendor.audio.offload.multiple.enabled" value="false"/>
+        <property name="vendor.audio.rec.playback.conc.disabled" value="false"/>
+        <property name="vendor.voice.conc.fallbackpath" value=""/>
+        <property name="vendor.voice.dsd.playback.conc.disabled" value="true"/>
+        <property name="vendor.voice.path.for.pcm.voip" value="true"/>
+        <property name="vendor.voice.playback.conc.disabled" value="false"/>
+        <property name="vendor.voice.record.conc.disabled" value="false"/>
+        <property name="vendor.voice.voip.conc.disabled" value="false"/>
+        <flag name="audio_extn_formats_enabled" value="true" />
+        <flag name="audio_extn_hdmi_spk_enabled" value="true" />
+        <flag name="use_xml_audio_policy_conf" value="true" />
+        <flag name="voice_concurrency" value="false" />
+
+        <!-- AV Configs -->
+        <property name="vendor.audio.use.sw.alac.decoder" value="true"/>
+        <property name="vendor.audio.use.sw.ape.decoder" value="true"/>
+        <property name="vendor.audio.use.sw.mpegh.decoder" value="false"/>
+        <property name="vendor.audio.flac.sw.decoder.24bit" value="true"/>
+        <property name="vendor.audio.hw.aac.encoder" value="true"/>
+        <flag name="aac_adts_offload_enabled" value="true" />
+        <flag name="alac_offload_enabled" value="true" />
+        <flag name="ape_offload_enabled" value="true" />
+        <flag name="flac_offload_enabled" value="true" />
+        <flag name="pcm_offload_enabled_16" value="true" />
+        <flag name="pcm_offload_enabled_24" value="true" />
+        <flag name="qti_flac_decoder" value="true" />
+        <flag name="vorbis_offload_enabled" value="true" />
+        <flag name="wma_offload_enabled" value="true" />
+
+        <!-- AHAL Configs -->
+        <flag name="a2dp_offload_enabled" value="true" />
+        <flag name="anc_headset_enabled" value="true" />
+        <flag name="audiosphere_enabled" value="true" />
+        <flag name="battery_listener_enabled" value="false" />
+        <flag name="compress_capture_enabled" value="false" />
+        <flag name="compress_in_enabled" value="false" />
+        <flag name="compress_metadata_needed" value="true" />
+        <flag name="concurrent_capture_enabled" value="false" />
+        <flag name="custom_stereo_enabled" value="true" />
+        <flag name="display_port_enabled" value="true" />
+        <flag name="dsm_feedback_enabled" value="false" />
+        <flag name="dynamic_ecns_enabled" value="false" />
+        <flag name="ext_hw_plugin_enabled" value="false" />
+        <flag name="ext_qdsp_enabled" value="false" />
+        <flag name="ext_spkr_enabled" value="false" />
+        <flag name="ext_spkr_tfa_enabled" value="false" />
+        <flag name="fluence_enabled" value="true" />
+        <flag name="hdmi_edid_enabled" value="true" />
+        <flag name="hdmi_passthrough_enabled" value="true" />
+        <flag name="hfp_enabled" value="true" />
+        <flag name="hifi_audio_enabled" value="false" />
+        <flag name="hwdep_cal_enabled" value="false" />
+        <flag name="incall_music_enabled" value="false" />
+        <flag name="keep_alive_enabled" value="false" />
+        <flag name="kpi_optimize_enabled" value="true" />
+        <flag name="maxx_audio_enabled" value="false" />
+        <flag name="receiver_aided_stereo" value="true" />
+        <flag name="snd_monitor_enabled" value="true" />
+        <flag name="source_track_enabled" value="true" />
+        <flag name="spkr_prot_enabled" value="true" />
+        <flag name="ssrec_enabled" value="true" />
+        <flag name="usb_offload_burst_mode" value="false" />
+        <flag name="usb_offload_enabled" value="true" />
+        <flag name="usb_offload_sidetone_vol_enabled" value="false" />
+        <flag name="use_deep_buffer_as_primary_output" value="false" />
+        <flag name="vbat_enabled" value="true" />
+        <flag name="wsa_enabled" value="false" />
+
+        <!-- Common configs between APM and AHAL -->
+        <flag name="afe_proxy_enabled" value="true" />
+        <flag name="compress_voip_enabled" value="false" />
+        <flag name="fm_power_opt" value="true" />
+        <flag name="record_play_concurrency" value="false" />
+</configs>
diff --git a/configs/msm8998/msm8998.mk b/configs/msm8998/msm8998.mk
index 6c8333c..013e636 100644
--- a/configs/msm8998/msm8998.mk
+++ b/configs/msm8998/msm8998.mk
@@ -34,6 +34,7 @@
 AUDIO_FEATURE_ENABLED_VOICE_PRINT := false
 USE_LEGACY_AUDIO_DAEMON := false
 USE_LEGACY_AUDIO_MEASUREMENT := false
+AUDIO_FEATURE_ENABLED_AHAL_EXT := false
 DOLBY_ENABLE := false
 endif
 
@@ -97,7 +98,8 @@
     vendor/qcom/opensource/audio-hal/primary-hal/configs/msm8998/sound_trigger_mixer_paths_wcd9340.xml:$(TARGET_COPY_OUT_VENDOR)/etc/sound_trigger_mixer_paths_wcd9340.xml \
     vendor/qcom/opensource/audio-hal/primary-hal/configs/msm8998/sound_trigger_platform_info.xml:$(TARGET_COPY_OUT_VENDOR)/etc/sound_trigger_platform_info.xml \
     vendor/qcom/opensource/audio-hal/primary-hal/configs/msm8998/graphite_ipc_platform_info.xml:$(TARGET_COPY_OUT_VENDOR)/etc/graphite_ipc_platform_info.xml \
-    vendor/qcom/opensource/audio-hal/primary-hal/configs/msm8998/audio_platform_info.xml:$(TARGET_COPY_OUT_VENDOR)/etc/audio_platform_info.xml
+    vendor/qcom/opensource/audio-hal/primary-hal/configs/msm8998/audio_platform_info.xml:$(TARGET_COPY_OUT_VENDOR)/etc/audio_platform_info.xml \
+    vendor/qcom/opensource/audio-hal/primary-hal/configs/msm8998/audio_configs.xml:$(TARGET_COPY_OUT_VENDOR)/etc/audio_configs.xml
 
 #XML Audio configuration files
 ifeq ($(USE_XML_AUDIO_POLICY_CONF), 1)
diff --git a/configs/msmnile/mixer_paths_tavil.xml b/configs/msmnile/mixer_paths_tavil.xml
index b101e3a..c8e22e8 100644
--- a/configs/msmnile/mixer_paths_tavil.xml
+++ b/configs/msmnile/mixer_paths_tavil.xml
@@ -466,6 +466,7 @@
     <ctl name="RX INT8_1 MIX1 INP0" value="ZERO" />
     <ctl name="RX INT8_1 MIX1 INP1" value="ZERO" />
     <ctl name="RX INT8_1 MIX1 INP2" value="ZERO" />
+    <ctl name="RX INT7 MIX2 INP" value="ZERO" />
     <ctl name="RX INT0_2 MUX" value="ZERO" />
     <ctl name="RX INT1_2 MUX" value="ZERO" />
     <ctl name="RX INT2_2 MUX" value="ZERO" />
diff --git a/hal/acdb.c b/hal/acdb.c
index 9b43303..d2b2b94 100644
--- a/hal/acdb.c
+++ b/hal/acdb.c
@@ -182,13 +182,13 @@
 
     /* Get Sound card name */
     snd_card_name = mixer_get_name(mixer);
+    snd_card_name = platform_get_snd_card_name_for_acdb_loader(snd_card_name);
     if (!snd_card_name) {
-        ALOGE("failed to allocate memory for snd_card_name");
+        ALOGE("failed to get snd_card_name");
         result = -1;
         goto cleanup;
     }
 
-    snd_card_name = platform_get_snd_card_name_for_acdb_loader(snd_card_name);
     int key = 0;
     struct listnode *node = NULL;
     struct meta_key_list *key_info = NULL;
diff --git a/hal/audio_extn/a2dp.c b/hal/audio_extn/a2dp.c
index c9ab383..0d58df6 100644
--- a/hal/audio_extn/a2dp.c
+++ b/hal/audio_extn/a2dp.c
@@ -2678,7 +2678,7 @@
                     goto param_handled;
                 list_for_each(node, &a2dp.adev->usecase_list) {
                     uc_info = node_to_item(node, struct audio_usecase, list);
-                    if (uc_info->type == PCM_PLAYBACK &&
+                    if (uc_info->stream.out && uc_info->type == PCM_PLAYBACK &&
                          (uc_info->stream.out->devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
                         pthread_mutex_unlock(&a2dp.adev->lock);
                         fp_check_a2dp_restore(a2dp.adev, uc_info->stream.out, false);
@@ -2719,7 +2719,7 @@
                 }
                 list_for_each(node, &a2dp.adev->usecase_list) {
                     uc_info = node_to_item(node, struct audio_usecase, list);
-                    if (uc_info->type == PCM_PLAYBACK &&
+                    if (uc_info->stream.out && uc_info->type == PCM_PLAYBACK &&
                          (uc_info->stream.out->devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
                         pthread_mutex_unlock(&a2dp.adev->lock);
                         fp_check_a2dp_restore(a2dp.adev, uc_info->stream.out, true);
diff --git a/hal/audio_extn/audio_extn.c b/hal/audio_extn/audio_extn.c
index 58de600..3d6cd4a 100644
--- a/hal/audio_extn/audio_extn.c
+++ b/hal/audio_extn/audio_extn.c
@@ -823,7 +823,7 @@
         // Refresh device selection for anc playback
         list_for_each(node, &adev->usecase_list) {
             usecase = node_to_item(node, struct audio_usecase, list);
-            if (usecase->type != PCM_CAPTURE) {
+            if (usecase->stream.out && usecase->type != PCM_CAPTURE) {
                 if (usecase->stream.out->devices == \
                     AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
                     usecase->stream.out->devices ==  \
diff --git a/hal/audio_extn/dolby.c b/hal/audio_extn/dolby.c
index 906c234..335cfbd 100644
--- a/hal/audio_extn/dolby.c
+++ b/hal/audio_extn/dolby.c
@@ -245,7 +245,7 @@
 
     list_for_each(node, &adev->usecase_list) {
         usecase = node_to_item(node, struct audio_usecase, list);
-        if ((usecase->type == PCM_PLAYBACK) &&
+        if (usecase->stream.out && (usecase->type == PCM_PLAYBACK) &&
             (usecase->devices & ddp_dev) &&
             (usecase->stream.out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) &&
             ((usecase->stream.out->format == AUDIO_FORMAT_AC3) ||
@@ -263,7 +263,7 @@
     struct audio_usecase *usecase;
     list_for_each(node, &adev->usecase_list) {
         usecase = node_to_item(node, struct audio_usecase, list);
-        if ((usecase->type == PCM_PLAYBACK) &&
+        if (usecase->stream.out && (usecase->type == PCM_PLAYBACK) &&
             (usecase->devices & AUDIO_DEVICE_OUT_ALL) &&
             (usecase->stream.out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) &&
             ((usecase->stream.out->format == AUDIO_FORMAT_AC3) ||
diff --git a/hal/audio_extn/dts_eagle.c b/hal/audio_extn/dts_eagle.c
index 3771a9d..be7bab1 100644
--- a/hal/audio_extn/dts_eagle.c
+++ b/hal/audio_extn/dts_eagle.c
@@ -112,7 +112,7 @@
         list_for_each(node, &adev->usecase_list) {
             usecase = node_to_item(node, struct audio_usecase, list);
             /* set/get eagle params for offload usecases only */
-            if ((usecase->type == PCM_PLAYBACK) && is_offload_usecase(usecase->id)) {
+            if (usecase->stream.out && (usecase->type == PCM_PLAYBACK) && is_offload_usecase(usecase->id)) {
                 tret = do_DTS_Eagle_params_stream(usecase->stream.out, t, get);
                 if (tret < 0)
                     ret = tret;
diff --git a/hal/audio_extn/maxxaudio.c b/hal/audio_extn/maxxaudio.c
index d6329fa..31feb02 100644
--- a/hal/audio_extn/maxxaudio.c
+++ b/hal/audio_extn/maxxaudio.c
@@ -284,7 +284,7 @@
 
     list_for_each(node, &adev->usecase_list) {
         usecase = node_to_item(node, struct audio_usecase, list);
-        if (valid_usecase(usecase)) {
+        if (usecase->stream.out && valid_usecase(usecase)) {
             ma_cal.common.app_type = usecase->stream.out->app_type_cfg.app_type;
             ma_cal.common.device = usecase->stream.out->devices;
             ALOGV("%s: send usecase(%d) app_type(%d) device(%d)",
diff --git a/hal/audio_extn/passthru.c b/hal/audio_extn/passthru.c
index a59717c..e900932 100644
--- a/hal/audio_extn/passthru.c
+++ b/hal/audio_extn/passthru.c
@@ -284,7 +284,7 @@
         /* find max period time among active playback use cases */
         list_for_each(node, &adev->usecase_list) {
             usecase = node_to_item(node, struct audio_usecase, list);
-            if (usecase->type == PCM_PLAYBACK &&
+            if (usecase->stream.out && usecase->type == PCM_PLAYBACK &&
                 usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
                 o = usecase->stream.out;
                 temp = o->config.period_size * 1000000LL / o->sample_rate;
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 41a3d5d..edc4382 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -1616,7 +1616,7 @@
                                                                         usecase->out_snd_device,
                                                                         platform_get_input_snd_device(adev->platform, uc_info->devices));
                     enable_audio_route(adev, usecase);
-                    if (usecase->id == USECASE_AUDIO_PLAYBACK_VOIP) {
+                    if (usecase->stream.out && usecase->id == USECASE_AUDIO_PLAYBACK_VOIP) {
                         out_set_voip_volume(&usecase->stream.out->stream,
                                             usecase->stream.out->volume_l,
                                             usecase->stream.out->volume_r);
@@ -4205,7 +4205,8 @@
          */
         if ((out->devices & AUDIO_DEVICE_OUT_ALL_A2DP) &&
                 (val == AUDIO_DEVICE_NONE) &&
-                !audio_extn_a2dp_source_is_ready()) {
+                !audio_extn_a2dp_source_is_ready() &&
+                !adev->bt_sco_on) {
                 val = AUDIO_DEVICE_OUT_SPEAKER;
         }
         /*
@@ -7813,7 +7814,7 @@
         struct listnode *node;
         list_for_each(node, &adev->usecase_list) {
             usecase = node_to_item(node, struct audio_usecase, list);
-            if ((usecase->type == PCM_PLAYBACK) &&
+            if (usecase->stream.out && (usecase->type == PCM_PLAYBACK) &&
                 (usecase->devices & AUDIO_DEVICE_OUT_ALL_A2DP)){
                 ALOGD("reconfigure a2dp... forcing device switch");
 
@@ -8836,6 +8837,8 @@
     pthread_mutex_lock(&adev_init_lock);
 
     if ((--audio_device_ref_count) == 0) {
+         if (audio_extn_spkr_prot_is_enabled())
+             audio_extn_spkr_prot_deinit();
         audio_extn_snd_mon_unregister_listener(adev);
         audio_extn_sound_trigger_deinit(adev);
         audio_extn_listen_deinit(adev);
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index e199616..ace49a0 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -2939,8 +2939,6 @@
     /* deinit usb */
     audio_extn_usb_deinit();
     audio_extn_dap_hal_deinit();
-    if (audio_extn_spkr_prot_is_enabled())
-        audio_extn_spkr_prot_deinit();
 #ifdef DYNAMIC_LOG_ENABLED
     log_utils_deinit();
 #endif
@@ -3508,7 +3506,7 @@
             list_for_each(node, &(platform->adev)->usecase_list) {
                  usecase = node_to_item(node, struct audio_usecase, list);
 
-                 if (is_offload_usecase(usecase->id) &&
+                 if (usecase->stream.out && is_offload_usecase(usecase->id) &&
                     (usecase->stream.out->devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
                     usecase->stream.out->devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) &&
                     OUTPUT_SAMPLING_RATE_44100 == usecase->stream.out->sample_rate) {
@@ -7812,7 +7810,8 @@
         list_for_each(node, &adev->usecase_list) {
             usecase = node_to_item(node, struct audio_usecase, list);
 
-            if (usecase != NULL && usecase->type == PCM_PLAYBACK) {
+            if (usecase != NULL && usecase->stream.out &&
+                                   usecase->type == PCM_PLAYBACK) {
                 int new_snd_device[2] = {0};
                 int i, num_devices = 1;
 
@@ -8311,7 +8310,7 @@
 
     list_for_each(node, &adev->usecase_list) {
         usecase = node_to_item(node, struct audio_usecase, list);
-        if (usecase->type == PCM_PLAYBACK &&
+        if (usecase->stream.out && usecase->type == PCM_PLAYBACK &&
                 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
             /*
              * If acdb tuning is different for SPEAKER_REVERSE, it is must
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index f5aa3c4..e02b9f0 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -1684,7 +1684,8 @@
         list_for_each(node, &adev->usecase_list) {
             usecase = node_to_item(node, struct audio_usecase, list);
 
-            if (usecase != NULL && usecase->type == PCM_PLAYBACK) {
+            if (usecase != NULL && usecase->stream.out &&
+                                   usecase->type == PCM_PLAYBACK) {
                 int new_snd_device[2] = {0};
                 int i, num_devices = 1;
 
@@ -3832,8 +3833,6 @@
     /* deinit usb */
     audio_extn_usb_deinit();
     audio_extn_dap_hal_deinit();
-    if (audio_extn_spkr_prot_is_enabled())
-        audio_extn_spkr_prot_deinit();
 #ifdef DYNAMIC_LOG_ENABLED
     log_utils_deinit();
 #endif
@@ -4123,7 +4122,7 @@
         goto done;
     }
 
-    if(effect_config == NULL) {
+    if (effect_config == NULL) {
         ALOGE("%s: Invalid effect_config", __func__);
         ret = -EINVAL;
         goto done;
@@ -4151,6 +4150,10 @@
     }
 
     device = (struct external_specific_device *)calloc(1, sizeof(struct external_specific_device));
+    if (device == NULL) {
+        ALOGE("%s: memory allocation failed", __func__);
+        return;
+    }
 
     device->usbid = strdup(usbid);
     device->acdb_id = acdb_id;
@@ -4426,7 +4429,7 @@
             list_for_each(node, &(platform->adev)->usecase_list) {
                  usecase = node_to_item(node, struct audio_usecase, list);
 
-                 if (is_offload_usecase(usecase->id) &&
+                 if (usecase->stream.out && is_offload_usecase(usecase->id) &&
                     (usecase->stream.out->devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
                     usecase->stream.out->devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) &&
                     OUTPUT_SAMPLING_RATE_44100 == usecase->stream.out->sample_rate) {
@@ -10046,7 +10049,7 @@
 
     list_for_each(node, &adev->usecase_list) {
         usecase = node_to_item(node, struct audio_usecase, list);
-        if (usecase->type == PCM_PLAYBACK &&
+        if (usecase->stream.out && usecase->type == PCM_PLAYBACK &&
                 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
             /*
              * If acdb tuning is different for SPEAKER_REVERSE, it is must
diff --git a/visualizer/offload_visualizer.c b/visualizer/offload_visualizer.c
index ccbd8bc..442ef3e 100644
--- a/visualizer/offload_visualizer.c
+++ b/visualizer/offload_visualizer.c
@@ -364,11 +364,11 @@
 // Get sound card number from pcm device
 int get_snd_card_num(char *device_info)
 {
-    char *token = NULL;
+    char *token = NULL, *saveptr = NULL;;
     int num = -1;
 
-    token = strtok(device_info, ": ");
-    token = strtok(token, "-");
+    token = strtok_r(device_info, ": ", &saveptr);
+    token = strtok_r(token, "-", &saveptr);
     if (token)
         num = atoi(token);
 
@@ -381,7 +381,7 @@
     char *token = NULL, *saveptr = NULL;
     int id = -1;
 
-    token = strtok(device_info, ": ");
+    token = strtok_r(device_info, ": ", &saveptr);
     token = strtok_r(token, "-", &saveptr);
     while (token != NULL) {
         token = strtok_r(NULL, "-", &saveptr);
@@ -505,6 +505,7 @@
                         pcm_close(pcm);
                         pcm = NULL;
                         configure_proxy_capture(mixer, 0);
+                        pthread_cond_wait(&cond, &lock);
                     } else {
                         capture_enabled = true;
                         ALOGD("%s: capture ENABLED", __func__);