Merge remote-tracking branch 'goog/stage-aosp-master' into HEAD
am: a350867cd5

Change-Id: I7c9e7311269cd9acff74475e1140b6583c266660
diff --git a/Android.mk b/Android.mk
index 65bf578..d6f03fb 100644
--- a/Android.mk
+++ b/Android.mk
@@ -1,6 +1,6 @@
 # TODO:  Find a better way to separate build configs for ADP vs non-ADP devices
 ifneq ($(TARGET_BOARD_AUTO),true)
-  ifneq ($(filter msm8960 msm8226 msm8x26 msm8x84 msm8084 msm8992 msm8994 msm8996 msm8909 msm8952 msm8998,$(TARGET_BOARD_PLATFORM)),)
+  ifneq ($(filter msm8960 msm8226 msm8x26 msm8x84 msm8084 msm8992 msm8994 msm8996 msm8909 msm8952 msm8998 sdm845,$(TARGET_BOARD_PLATFORM)),)
 
     MY_LOCAL_PATH := $(call my-dir)
 
diff --git a/hal/Android.mk b/hal/Android.mk
index 923879c..58a79fb 100644
--- a/hal/Android.mk
+++ b/hal/Android.mk
@@ -10,7 +10,7 @@
 ifneq ($(filter msm8960,$(TARGET_BOARD_PLATFORM)),)
   LOCAL_CFLAGS += -DMAX_TARGET_SPECIFIC_CHANNEL_CNT="2"
 endif
-ifneq ($(filter msm8974 msm8226 msm8084 msm8992 msm8994 msm8996 msm8998,$(TARGET_BOARD_PLATFORM)),)
+ifneq ($(filter msm8974 msm8226 msm8084 msm8992 msm8994 msm8996 msm8998 sdm845,$(TARGET_BOARD_PLATFORM)),)
   # B-family platform uses msm8974 code base
   AUDIO_PLATFORM = msm8974
 ifneq ($(filter msm8974,$(TARGET_BOARD_PLATFORM)),)
@@ -47,6 +47,12 @@
   LOCAL_CFLAGS += -DKPI_OPTIMIZE_ENABLED
   MULTIPLE_HW_VARIANTS_ENABLED := true
 endif
+ifneq ($(filter sdm845,$(TARGET_BOARD_PLATFORM)),)
+  LOCAL_CFLAGS := -DPLATFORM_SDM845
+  LOCAL_CFLAGS += -DMAX_TARGET_SPECIFIC_CHANNEL_CNT="4"
+  LOCAL_CFLAGS += -DKPI_OPTIMIZE_ENABLED
+  MULTIPLE_HW_VARIANTS_ENABLED := true
+endif
 endif
 
 ifneq ($(filter msm8916 msm8909 msm8952,$(TARGET_BOARD_PLATFORM)),)
@@ -149,7 +155,7 @@
     LOCAL_SRC_FILES += audio_extn/dsm_feedback.c
 endif
 
-ifneq ($(filter msm8992 msm8994 msm8996 msm8998,$(TARGET_BOARD_PLATFORM)),)
+ifneq ($(filter msm8992 msm8994 msm8996 msm8998 sdm845,$(TARGET_BOARD_PLATFORM)),)
   # push codec/mad calibration to HW dep node
   # applicable to msm8992/8994 or newer platforms
   LOCAL_CFLAGS += -DHWDEP_CAL_ENABLED
diff --git a/hal/audio_extn/audio_extn.h b/hal/audio_extn/audio_extn.h
index c7d6768..2ca76fa 100644
--- a/hal/audio_extn/audio_extn.h
+++ b/hal/audio_extn/audio_extn.h
@@ -81,7 +81,7 @@
 #define audio_extn_usb_is_capture_supported()                          (false)
 #define audio_extn_usb_get_max_channels(dir)                           (0)
 #define audio_extn_usb_get_max_bit_width(dir)                          (0)
-#define audio_extn_usb_sup_sample_rates(t, s, l)                       (0)
+#define audio_extn_usb_sup_sample_rates(t, s, l)        ((t), (s), (l), 0) /* fix unused warn */
 #define audio_extn_usb_alive(adev)                                     (false)
 #else
 void audio_extn_usb_init(void *adev);
diff --git a/hal/audio_extn/hfp.c b/hal/audio_extn/hfp.c
index 07a9711..ad1530a 100644
--- a/hal/audio_extn/hfp.c
+++ b/hal/audio_extn/hfp.c
@@ -438,10 +438,17 @@
     ret = str_parms_get_str(parms, AUDIO_PARAMETER_HFP_ENABLE, value,
                             sizeof(value));
     if (ret >= 0) {
-           if (!strncmp(value,"true",sizeof(value)))
-               ret = start_hfp(adev,parms);
-           else
-               stop_hfp(adev);
+           if (!strncmp(value,"true",sizeof(value))) {
+               if (!hfpmod.is_hfp_running)
+                   start_hfp(adev,parms);
+               else
+                   ALOGW("%s: HFP is already active.", __func__);
+           } else {
+               if (hfpmod.is_hfp_running)
+                   stop_hfp(adev);
+               else
+                   ALOGW("%s: ignore STOP, HFC not active", __func__);
+           }
     }
     memset(value, 0, sizeof(value));
     ret = str_parms_get_str(parms,AUDIO_PARAMETER_HFP_SET_SAMPLING_RATE, value,
diff --git a/hal/audio_extn/spkr_protection.c b/hal/audio_extn/spkr_protection.c
index 8afb0dc..22920b7 100644
--- a/hal/audio_extn/spkr_protection.c
+++ b/hal/audio_extn/spkr_protection.c
@@ -51,7 +51,7 @@
 #define MAX_RESISTANCE_SPKR_Q24 (40 * (1 << 24))
 
 /*Path where the calibration file will be stored*/
-#define CALIB_FILE "/data/misc/audio/audio.cal"
+#define CALIB_FILE "/data/vendor/audio/audio.cal"
 
 /*Time between retries for calibartion or intial wait time
   after boot up*/
@@ -304,6 +304,7 @@
     int32_t pcm_dev_rx_id = -1, pcm_dev_tx_id = -1;
     struct timespec ts;
     int retry_duration;
+    int app_type = 0;
 
     if (!adev) {
         ALOGE("%s: Invalid params", __func__);
@@ -472,7 +473,20 @@
     handle.pcm_tx = NULL;
 
     /* Clear TX calibration to handset mic */
-    platform_send_audio_calibration(adev->platform, SND_DEVICE_IN_HANDSET_MIC);
+    if (platform_supports_app_type_cfg()) {
+        ALOGD("%s: Platform supports APP type configuration, using V2\n", __func__);
+        if (uc_info_tx != NULL) {
+            ALOGD("%s: UC Info TX is not NULL, updating and sending calibration\n", __func__);
+            uc_info_tx->in_snd_device = SND_DEVICE_IN_HANDSET_MIC;
+            uc_info_tx->out_snd_device = SND_DEVICE_NONE;
+            platform_get_default_app_type_v2(adev->platform, PCM_CAPTURE, &app_type);
+            platform_send_audio_calibration_v2(adev->platform, uc_info_tx,
+                                               app_type, 8000);
+        }
+    } else {
+        ALOGW("%s: Platform does NOT support APP type configuration, using V1\n", __func__);
+        platform_send_audio_calibration(adev->platform, SND_DEVICE_IN_HANDSET_MIC);
+    }
     if (!status.status) {
         protCfg.mode = MSM_SPKR_PROT_CALIBRATED;
         protCfg.r0[SP_V2_SPKR_1] = status.r0[SP_V2_SPKR_1];
@@ -804,6 +818,7 @@
     struct audio_usecase *uc_info_tx;
     struct audio_device *adev = handle.adev_handle;
     int32_t pcm_dev_tx_id = -1, ret = 0;
+    int app_type = 0;
 
     ALOGV("%s: Entry", __func__);
     if (!adev) {
@@ -855,7 +870,20 @@
 
 exit:
     /* Clear VI feedback cal and replace with handset MIC  */
-    platform_send_audio_calibration(adev->platform, SND_DEVICE_IN_HANDSET_MIC);
+    if (platform_supports_app_type_cfg()) {
+        ALOGD("%s: Platform supports APP type configuration, using V2\n", __func__);
+        if (uc_info_tx != NULL) {
+            ALOGD("%s: UC Info TX is not NULL, updating and sending calibration\n", __func__);
+            uc_info_tx->in_snd_device = SND_DEVICE_IN_HANDSET_MIC;
+            uc_info_tx->out_snd_device = SND_DEVICE_NONE;
+            platform_get_default_app_type_v2(adev->platform, PCM_CAPTURE, &app_type);
+            platform_send_audio_calibration_v2(adev->platform, uc_info_tx,
+                                               app_type, 8000);
+        }
+    } else {
+        ALOGW("%s: Platform does not support APP type configuration, using V1\n", __func__);
+        platform_send_audio_calibration(adev->platform, SND_DEVICE_IN_HANDSET_MIC);
+    }
     if (ret) {
         if (handle.pcm_tx)
             pcm_close(handle.pcm_tx);
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 7267931..f8c17d0 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -999,9 +999,9 @@
     return ret;
 }
 
-static ssize_t read_usb_sup_sample_rates(bool is_playback __unused,
-                                         uint32_t *supported_sample_rates __unused,
-                                         uint32_t max_rates __unused)
+static ssize_t read_usb_sup_sample_rates(bool is_playback,
+                                         uint32_t *supported_sample_rates,
+                                         uint32_t max_rates)
 {
     ssize_t count = audio_extn_usb_sup_sample_rates(is_playback,
                                                     supported_sample_rates,
@@ -3680,18 +3680,17 @@
 {
     struct audio_device *adev = (struct audio_device *)dev;
     struct stream_out *out;
-    int i, ret;
+    int i, ret = 0;
     bool is_hdmi = devices & AUDIO_DEVICE_OUT_AUX_DIGITAL;
     bool is_usb_dev = audio_is_usb_out_device(devices) &&
                       (devices != AUDIO_DEVICE_OUT_USB_ACCESSORY);
-    bool direct_dev = is_hdmi || is_usb_dev;
 
     if (is_usb_dev && !is_usb_ready(adev, true /* is_playback */)) {
         return -ENOSYS;
     }
 
-    ALOGV("%s: enter: sample_rate(%d) channel_mask(%#x) devices(%#x) flags(%#x)",
-          __func__, config->sample_rate, config->channel_mask, devices, flags);
+    ALOGV("%s: enter: format(%#x) sample_rate(%d) channel_mask(%#x) devices(%#x) flags(%#x)",
+          __func__, config->format, config->sample_rate, config->channel_mask, devices, flags);
     *stream_out = NULL;
     out = (struct stream_out *)calloc(1, sizeof(struct stream_out));
 
@@ -3701,16 +3700,14 @@
     out->flags = flags;
     out->devices = devices;
     out->dev = adev;
-    out->format = config->format;
-    out->sample_rate = config->sample_rate;
-    out->channel_mask = AUDIO_CHANNEL_OUT_STEREO;
     out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_STEREO;
     out->handle = handle;
 
     /* Init use case and pcm_config */
-    if (audio_is_linear_pcm(out->format) &&
-        (out->flags == AUDIO_OUTPUT_FLAG_NONE ||
-         out->flags == AUDIO_OUTPUT_FLAG_DIRECT) && direct_dev) {
+    if ((is_hdmi || is_usb_dev) &&
+        (audio_is_linear_pcm(config->format) || config->format == AUDIO_FORMAT_DEFAULT) &&
+        (flags == AUDIO_OUTPUT_FLAG_NONE ||
+        (flags & AUDIO_OUTPUT_FLAG_DIRECT) != 0)) {
         pthread_mutex_lock(&adev->lock);
         if (is_hdmi) {
             ret = read_hdmi_channel_masks(out);
@@ -3732,25 +3729,38 @@
                                                   &out->supported_sample_rates[0],
                                                   MAX_SUPPORTED_SAMPLE_RATES);
             ALOGV("plugged dev USB ret %d", ret);
-        } else {
-            ret = -1;
         }
         pthread_mutex_unlock(&adev->lock);
         if (ret != 0)
             goto error_open;
 
-        out->channel_mask = config->channel_mask;
+
         out->sample_rate = config->sample_rate;
+        out->channel_mask = config->channel_mask;
         out->format = config->format;
-        out->usecase = USECASE_AUDIO_PLAYBACK_HIFI;
-        // does this change?
-        out->config = is_hdmi ? pcm_config_hdmi_multi : pcm_config_hifi;
-        out->config.rate = config->sample_rate;
+        if (is_hdmi) {
+            out->usecase = USECASE_AUDIO_PLAYBACK_HIFI;
+            out->config = pcm_config_hdmi_multi;
+        } else if (flags & AUDIO_OUTPUT_FLAG_MMAP_NOIRQ) {
+            out->usecase = USECASE_AUDIO_PLAYBACK_MMAP;
+            out->config = pcm_config_mmap_playback;
+            out->stream.start = out_start;
+            out->stream.stop = out_stop;
+            out->stream.create_mmap_buffer = out_create_mmap_buffer;
+            out->stream.get_mmap_position = out_get_mmap_position;
+        } else {
+            out->usecase = USECASE_AUDIO_PLAYBACK_HIFI;
+            out->config = pcm_config_hifi;
+        }
+
+        out->config.rate = out->sample_rate;
         out->config.channels = audio_channel_count_from_out_mask(out->channel_mask);
-        out->config.period_size = HDMI_MULTI_PERIOD_BYTES / (out->config.channels *
-                                                         audio_bytes_per_sample(config->format));
+        if (is_hdmi) {
+            out->config.period_size = HDMI_MULTI_PERIOD_BYTES / (out->config.channels *
+                                                         audio_bytes_per_sample(out->format));
+        }
         out->config.format = pcm_format_from_audio_format(out->format);
-    } else if (out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
+    } else if (flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
         pthread_mutex_lock(&adev->lock);
         bool offline = (adev->card_status == CARD_STATUS_OFFLINE);
         pthread_mutex_unlock(&adev->lock);
@@ -3773,17 +3783,20 @@
             ret = -EINVAL;
             goto error_open;
         }
+        out->sample_rate = config->offload_info.sample_rate;
+        if (config->offload_info.channel_mask != AUDIO_CHANNEL_NONE)
+            out->channel_mask = config->offload_info.channel_mask;
+        else if (config->channel_mask != AUDIO_CHANNEL_NONE)
+            out->channel_mask = config->channel_mask;
+        else
+            out->channel_mask = AUDIO_CHANNEL_OUT_STEREO;
+
+        out->format = config->offload_info.format;
 
         out->compr_config.codec = (struct snd_codec *)
                                     calloc(1, sizeof(struct snd_codec));
 
         out->usecase = USECASE_AUDIO_PLAYBACK_OFFLOAD;
-        if (config->offload_info.channel_mask)
-            out->channel_mask = config->offload_info.channel_mask;
-        else if (config->channel_mask)
-            out->channel_mask = config->channel_mask;
-        out->format = config->offload_info.format;
-        out->sample_rate = config->offload_info.sample_rate;
 
         out->stream.set_callback = out_set_callback;
         out->stream.pause = out_pause;
@@ -3795,11 +3808,11 @@
                 get_snd_codec_id(config->offload_info.format);
         out->compr_config.fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
         out->compr_config.fragments = COMPRESS_OFFLOAD_NUM_FRAGMENTS;
-        out->compr_config.codec->sample_rate = config->offload_info.sample_rate;
+        out->compr_config.codec->sample_rate = out->sample_rate;
         out->compr_config.codec->bit_rate =
                     config->offload_info.bit_rate;
         out->compr_config.codec->ch_in =
-                audio_channel_count_from_out_mask(config->channel_mask);
+                audio_channel_count_from_out_mask(out->channel_mask);
         out->compr_config.codec->ch_out = out->compr_config.codec->ch_in;
 
         if (flags & AUDIO_OUTPUT_FLAG_NON_BLOCKING)
@@ -3812,46 +3825,136 @@
                 config->offload_info.bit_rate);
     } else  if (out->devices == AUDIO_DEVICE_OUT_TELEPHONY_TX) {
         switch (config->sample_rate) {
+            case 0:
+                out->sample_rate = AFE_PROXY_SAMPLING_RATE;
+                break;
             case 8000:
             case 16000:
             case 48000:
                 out->sample_rate = config->sample_rate;
                 break;
             default:
-                out->sample_rate = AFE_PROXY_SAMPLING_RATE;
+                ALOGE("%s: Unsupported sampling rate %d for Telephony TX", __func__,
+                      config->sample_rate);
+                config->sample_rate = AFE_PROXY_SAMPLING_RATE;
+                ret = -EINVAL;
+                break;
         }
-        out->format = AUDIO_FORMAT_PCM_16_BIT;
+        //FIXME: add support for MONO stream configuration when audioflinger mixer supports it
+        switch (config->channel_mask) {
+            case AUDIO_CHANNEL_NONE:
+                out->channel_mask = AUDIO_CHANNEL_OUT_STEREO;
+                break;
+            case AUDIO_CHANNEL_OUT_STEREO:
+                out->channel_mask = config->channel_mask;
+                break;
+            default:
+                ALOGE("%s: Unsupported channel mask %#x for Telephony TX", __func__,
+                      config->channel_mask);
+                config->channel_mask = AUDIO_CHANNEL_OUT_STEREO;
+                ret = -EINVAL;
+                break;
+        }
+        switch (config->format) {
+            case AUDIO_FORMAT_DEFAULT:
+                out->format = AUDIO_FORMAT_PCM_16_BIT;
+                break;
+            case AUDIO_FORMAT_PCM_16_BIT:
+                out->format = config->format;
+                break;
+            default:
+                ALOGE("%s: Unsupported format %#x for Telephony TX", __func__,
+                      config->format);
+                config->format = AUDIO_FORMAT_PCM_16_BIT;
+                ret = -EINVAL;
+                break;
+        }
+        if (ret != 0)
+            goto error_open;
+
         out->usecase = USECASE_AUDIO_PLAYBACK_AFE_PROXY;
         out->config = pcm_config_afe_proxy_playback;
+        out->config.rate = out->sample_rate;
+        out->config.channels =
+                audio_channel_count_from_out_mask(out->channel_mask);
+        out->config.format = pcm_format_from_audio_format(out->format);
         adev->voice_tx_output = out;
-    } else if (out->flags == AUDIO_OUTPUT_FLAG_VOIP_RX) {
+    } else if (flags == AUDIO_OUTPUT_FLAG_VOIP_RX) {
+        switch (config->sample_rate) {
+            case 0:
+                out->sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
+                break;
+            case 8000:
+            case 16000:
+            case 32000:
+            case 48000:
+                out->sample_rate = config->sample_rate;
+                break;
+            default:
+                ALOGE("%s: Unsupported sampling rate %d for Voip RX", __func__,
+                      config->sample_rate);
+                config->sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
+                ret = -EINVAL;
+                break;
+        }
         //FIXME: add support for MONO stream configuration when audioflinger mixer supports it
+        switch (config->channel_mask) {
+            case AUDIO_CHANNEL_NONE:
+                out->channel_mask = AUDIO_CHANNEL_OUT_STEREO;
+                break;
+            case AUDIO_CHANNEL_OUT_STEREO:
+                out->channel_mask = config->channel_mask;
+                break;
+            default:
+                ALOGE("%s: Unsupported channel mask %#x for Voip RX", __func__,
+                      config->channel_mask);
+                config->channel_mask = AUDIO_CHANNEL_OUT_STEREO;
+                ret = -EINVAL;
+                break;
+        }
+        switch (config->format) {
+            case AUDIO_FORMAT_DEFAULT:
+                out->format = AUDIO_FORMAT_PCM_16_BIT;
+                break;
+            case AUDIO_FORMAT_PCM_16_BIT:
+                out->format = config->format;
+                break;
+            default:
+                ALOGE("%s: Unsupported format %#x for Voip RX", __func__,
+                      config->format);
+                config->format = AUDIO_FORMAT_PCM_16_BIT;
+                ret = -EINVAL;
+                break;
+        }
+        if (ret != 0)
+            goto error_open;
+
         uint32_t buffer_size, frame_size;
         out->usecase = USECASE_AUDIO_PLAYBACK_VOIP;
         out->config = pcm_config_voip;
-        out->config.format = pcm_format_from_audio_format(config->format);
-        out->config.rate = config->sample_rate;
+        out->config.rate = out->sample_rate;
+        out->config.format = pcm_format_from_audio_format(out->format);
         buffer_size = get_stream_buffer_size(VOIP_PLAYBACK_PERIOD_DURATION_MSEC,
-                                             config->sample_rate,
-                                             config->format,
+                                             out->sample_rate,
+                                             out->format,
                                              out->config.channels,
                                              false /*is_low_latency*/);
-        frame_size = audio_bytes_per_sample(config->format) * out->config.channels;
+        frame_size = audio_bytes_per_sample(out->format) * out->config.channels;
         out->config.period_size = buffer_size / frame_size;
         out->config.period_count = VOIP_PLAYBACK_PERIOD_COUNT;
         out->af_period_multiplier = 1;
     } else {
-        if (out->flags & AUDIO_OUTPUT_FLAG_DEEP_BUFFER) {
+        if (flags & AUDIO_OUTPUT_FLAG_DEEP_BUFFER) {
             out->usecase = USECASE_AUDIO_PLAYBACK_DEEP_BUFFER;
             out->config = pcm_config_deep_buffer;
-        } else if (out->flags & AUDIO_OUTPUT_FLAG_TTS) {
+        } else if (flags & AUDIO_OUTPUT_FLAG_TTS) {
             out->usecase = USECASE_AUDIO_PLAYBACK_TTS;
             out->config = pcm_config_deep_buffer;
-        } else if (out->flags & AUDIO_OUTPUT_FLAG_RAW) {
+        } else if (flags & AUDIO_OUTPUT_FLAG_RAW) {
             out->usecase = USECASE_AUDIO_PLAYBACK_ULL;
             out->realtime = may_use_noirq_mode(adev, USECASE_AUDIO_PLAYBACK_ULL, out->flags);
             out->config = out->realtime ? pcm_config_rt : pcm_config_low_latency;
-        } else if (out->flags & AUDIO_OUTPUT_FLAG_MMAP_NOIRQ) {
+        } else if (flags & AUDIO_OUTPUT_FLAG_MMAP_NOIRQ) {
             out->usecase = USECASE_AUDIO_PLAYBACK_MMAP;
             out->config = pcm_config_mmap_playback;
             out->stream.start = out_start;
@@ -3862,15 +3965,38 @@
             out->usecase = USECASE_AUDIO_PLAYBACK_LOW_LATENCY;
             out->config = pcm_config_low_latency;
         }
-        if (config->format != audio_format_from_pcm_format(out->config.format)) {
-            out->config.format = pcm_format_from_audio_format(config->format);
+
+        if (config->sample_rate == 0) {
+            out->sample_rate = out->config.rate;
+        } else {
+            out->sample_rate = config->sample_rate;
         }
-        out->sample_rate = out->config.rate;
+        if (config->channel_mask == AUDIO_CHANNEL_NONE) {
+            out->channel_mask = audio_channel_out_mask_from_count(out->config.channels);
+        } else {
+            out->channel_mask = config->channel_mask;
+        }
+        if (config->format == AUDIO_FORMAT_DEFAULT)
+            out->format = audio_format_from_pcm_format(out->config.format);
+        else if (!audio_is_linear_pcm(config->format)) {
+            config->format = AUDIO_FORMAT_PCM_16_BIT;
+            ret = -EINVAL;
+            goto error_open;
+        } else {
+            out->format = config->format;
+        }
+
+        out->config.rate = out->sample_rate;
+        out->config.channels =
+                audio_channel_count_from_out_mask(out->channel_mask);
+        if (out->format != audio_format_from_pcm_format(out->config.format)) {
+            out->config.format = pcm_format_from_audio_format(out->format);
+        }
     }
 
     if ((config->sample_rate != 0 && config->sample_rate != out->sample_rate) ||
         (config->format != AUDIO_FORMAT_DEFAULT && config->format != out->format) ||
-        (config->channel_mask != 0 && config->channel_mask != out->channel_mask)) {
+        (config->channel_mask != AUDIO_CHANNEL_NONE && config->channel_mask != out->channel_mask)) {
         ALOGI("%s: Unsupported output config. sample_rate:%u format:%#x channel_mask:%#x",
               __func__, config->sample_rate, config->format, config->channel_mask);
         config->sample_rate = out->sample_rate;
@@ -3999,6 +4125,7 @@
     out->error_log = NULL;
 
     pthread_cond_destroy(&out->cond);
+    pthread_mutex_destroy(&out->pre_lock);
     pthread_mutex_destroy(&out->lock);
     free(stream);
     ALOGV("%s: exit", __func__);
@@ -4544,6 +4671,9 @@
     error_log_destroy(in->error_log);
     in->error_log = NULL;
 
+    pthread_mutex_destroy(&in->pre_lock);
+    pthread_mutex_destroy(&in->lock);
+
     free(stream);
 
     return;
@@ -4711,6 +4841,7 @@
         }
         if (adev->adm_deinit)
             adev->adm_deinit(adev->adm_data);
+        pthread_mutex_destroy(&adev->lock);
         free(device);
     }
 
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index c113eca..5f056a8 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -34,10 +34,10 @@
 #include "audio_extn/tfa_98xx.h"
 #include <dirent.h>
 #define MAX_MIXER_XML_PATH  100
-#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
-#define MIXER_XML_PATH_MTP "/system/etc/mixer_paths_mtp.xml"
-#define MIXER_XML_PATH_MSM8909_PM8916 "/system/etc/mixer_paths_msm8909_pm8916.xml"
-#define MIXER_XML_PATH_L9300 "/system/etc/mixer_paths_l9300.xml"
+#define MIXER_XML_PATH "mixer_paths.xml"
+#define MIXER_XML_PATH_MTP "mixer_paths_mtp.xml"
+#define MIXER_XML_PATH_MSM8909_PM8916 "mixer_paths_msm8909_pm8916.xml"
+#define MIXER_XML_PATH_L9300 "mixer_paths_l9300.xml"
 
 #define LIB_ACDB_LOADER "libacdbloader.so"
 #define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
@@ -485,6 +485,7 @@
     {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
     {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
     {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
+    {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO_WB)},
     {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
 };
 
@@ -836,6 +837,28 @@
     return result;
 }
 
+// Treblized config files will be located in /odm/etc or /vendor/etc.
+static const char *kConfigLocationList[] =
+        {"/odm/etc", "/vendor/etc", "/system/etc"};
+static const int kConfigLocationListSize =
+        (sizeof(kConfigLocationList) / sizeof(kConfigLocationList[0]));
+
+bool resolve_config_file(char file_name[MIXER_PATH_MAX_LENGTH]) {
+    char full_config_path[MIXER_PATH_MAX_LENGTH];
+    for (int i = 0; i < kConfigLocationListSize; i++) {
+        snprintf(full_config_path,
+                 MIXER_PATH_MAX_LENGTH,
+                 "%s/%s",
+                 kConfigLocationList[i],
+                 file_name);
+        if (F_OK == access(full_config_path, 0)) {
+            strcpy(file_name, full_config_path);
+            return true;
+        }
+    }
+    return false;
+}
+
 void *platform_init(struct audio_device *adev)
 {
     char platform[PROPERTY_VALUE_MAX] = {0};
@@ -845,6 +868,7 @@
     int retry_num = 0, snd_card_num = 0, key = 0;
     const char *snd_card_name;
     char mixer_xml_path[MAX_MIXER_XML_PATH] = {0};
+    char platform_info_path[MAX_MIXER_XML_PATH] = {0};
     char ffspEnable[PROPERTY_VALUE_MAX] = {0};
     char *cvd_version = NULL;
     int idx;
@@ -897,6 +921,11 @@
             ALOGE("%s: Failed to init hardware info", __func__);
         } else {
             query_platform(snd_card_name, mixer_xml_path);
+            if (!resolve_config_file(mixer_xml_path)) {
+                memset(mixer_xml_path, 0, sizeof(mixer_xml_path));
+                strlcpy(mixer_xml_path, MIXER_XML_PATH, MAX_MIXER_XML_PATH);
+                resolve_config_file(mixer_xml_path);
+            }
             ALOGD("%s: mixer path file is %s", __func__,
                                     mixer_xml_path);
             adev->audio_route = audio_route_init(snd_card_num,
@@ -1020,7 +1049,9 @@
     set_platform_defaults();
 
     /* Initialize ACDB and PCM ID's */
-    platform_info_init(PLATFORM_INFO_XML_PATH, my_data);
+    strlcpy(platform_info_path, PLATFORM_INFO_XML_PATH, MAX_MIXER_XML_PATH);
+    resolve_config_file(platform_info_path);
+    platform_info_init(platform_info_path, my_data);
 
 
     /* Read one time ssr property */
diff --git a/hal/msm8916/platform.h b/hal/msm8916/platform.h
index c61331a..de81a71 100644
--- a/hal/msm8916/platform.h
+++ b/hal/msm8916/platform.h
@@ -277,7 +277,7 @@
     stop_record_t stop_record;
 };
 
-#define PLATFORM_INFO_XML_PATH          "/system/etc/audio_platform_info.xml"
-#define PLATFORM_INFO_XML_BASE_STRING   "/system/etc/audio_platform_info"
+#define PLATFORM_INFO_XML_PATH          "audio_platform_info.xml"
+#define PLATFORM_INFO_XML_BASE_STRING   "audio_platform_info"
 
 #endif // QCOM_AUDIO_PLATFORM_H
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 6560d14..4addc80 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -30,7 +30,7 @@
 #include "platform.h"
 #include "audio_extn.h"
 #include <linux/msm_audio.h>
-#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
+#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
 #include <sound/devdep_params.h>
 #endif
 
@@ -120,7 +120,7 @@
     bool speaker_lr_swap;
 
     void *acdb_handle;
-#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
+#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
     acdb_init_v2_cvd_t acdb_init;
 #elif defined (PLATFORM_MSM8084)
     acdb_init_v2_t acdb_init;
@@ -720,7 +720,7 @@
 
 inline bool platform_supports_app_type_cfg()
 {
-#ifdef PLATFORM_MSM8998
+#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845)
     return true;
 #else
     return false;
@@ -1146,7 +1146,7 @@
         return 0;
     }
 
-#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
+#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
     char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
     if (!cvd_version)
         ALOGE("failed to allocate cvd_version");
@@ -1472,7 +1472,7 @@
             ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
                   __func__, LIB_ACDB_LOADER);
 
-#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
+#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
         acdb_init_v2_cvd_t acdb_init_local;
         acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
                                               "acdb_loader_init_v2");
@@ -4112,7 +4112,7 @@
 int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
                               int *fd __unused, uint32_t *size __unused)
 {
-#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
+#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
     struct platform_data *my_data = (struct platform_data *)platform;
     struct audio_device *adev = my_data->adev;
     int hw_fd = -1;
diff --git a/hal/voice_extn/voice_extn.c b/hal/voice_extn/voice_extn.c
index edf5523..01a1c3f 100644
--- a/hal/voice_extn/voice_extn.c
+++ b/hal/voice_extn/voice_extn.c
@@ -162,6 +162,7 @@
     struct voice_session *session = NULL;
     int fd = 0;
     int ret = 0;
+    bool is_voice_sess_active = false;
 
     ALOGD("%s: enter:", __func__);
 
@@ -222,6 +223,12 @@
                           __func__, usecase_id);
                 } else {
                     session->state.current = session->state.new;
+
+                    // The flag is not reset if another voice session is active as routing/mode is
+                    // set globally instead of per session.
+                    voice_extn_is_call_state_active(adev, &is_voice_sess_active);
+                    if (!is_voice_sess_active)
+                        adev->voice.in_call = false;
                 }
                 break;
 
diff --git a/post_proc/Android.mk b/post_proc/Android.mk
index 1a2f2e8..c31b769 100644
--- a/post_proc/Android.mk
+++ b/post_proc/Android.mk
@@ -1,4 +1,4 @@
-ifneq ($(filter msm8974 msm8226 msm8084 msm8992 msm8994 msm8996 msm8909 msm8998,$(TARGET_BOARD_PLATFORM)),)
+ifneq ($(filter msm8974 msm8226 msm8084 msm8992 msm8994 msm8996 msm8909 msm8998 sdm845,$(TARGET_BOARD_PLATFORM)),)
 
 LOCAL_PATH:= $(call my-dir)
 
@@ -43,7 +43,7 @@
 
 ################################################################################
 
-ifneq ($(filter msm8992 msm8994 msm8996 msm8909 msm8998,$(TARGET_BOARD_PLATFORM)),)
+ifneq ($(filter msm8992 msm8994 msm8996 msm8909 msm8998 sdm845,$(TARGET_BOARD_PLATFORM)),)
 
 include $(CLEAR_VARS)