Merge "hal: don't mute stream with combo device during a2dpsuspended"
diff --git a/configs/lahaina/lahaina.mk b/configs/lahaina/lahaina.mk
index d8b3ea1..b6f2bca 100644
--- a/configs/lahaina/lahaina.mk
+++ b/configs/lahaina/lahaina.mk
@@ -120,6 +120,7 @@
 PRODUCT_PACKAGES += $(AUDIO_HAL_TEST_APPS)
 PRODUCT_PACKAGES += ftm_test_config_lahaina-qrd-snd-card
 PRODUCT_PACKAGES += ftm_test_config_lahaina-hdk-snd-card
+PRODUCT_PACKAGES += ftm_test_config_lahaina-hhg-snd-card
 PRODUCT_PACKAGES += ftm_test_config_lahaina-shimaidp-snd-card
 PRODUCT_PACKAGES += ftm_test_config_lahaina-shimaidps-snd-card
 PRODUCT_PACKAGES += ftm_test_config_lahaina-shimaqrd-snd-card
diff --git a/hal/audio_extn/spkr_protection.c b/hal/audio_extn/spkr_protection.c
index f35198f..1badc1b 100644
--- a/hal/audio_extn/spkr_protection.c
+++ b/hal/audio_extn/spkr_protection.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 - 2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013 - 2021, 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
@@ -2491,6 +2491,8 @@
         list_remove(&uc_info_tx->list);
         uc_info_tx->in_snd_device = in_snd_device;
         uc_info_tx->out_snd_device = SND_DEVICE_NONE;
+        audio_route_reset_and_update_path(adev->audio_route,
+           device_name);
         fp_disable_snd_device(adev, in_snd_device);
         fp_disable_audio_route(adev, uc_info_tx);
         free(uc_info_tx);
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index c285139..7886355 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -948,7 +948,8 @@
 
     new_backend_idx = platform_get_backend_index(snd_device);
     spkr_hph_single_be_native_concurrency = platform_get_spkr_hph_single_be_native_concurrency_flag();
-    if ( spkr_hph_single_be_native_concurrency && (new_backend_idx == DEFAULT_CODEC_BACKEND)) {
+    if ((spkr_hph_single_be_native_concurrency && (new_backend_idx == DEFAULT_CODEC_BACKEND)) ||
+            uc_info->id == USECASE_AUDIO_PLAYBACK_WITH_HAPTICS) {
         list_for_each(node, &adev->usecase_list) {
             usecase = node_to_item(node, struct audio_usecase, list);
             if ((usecase->type != PCM_CAPTURE) && (usecase != uc_info)) {
@@ -961,8 +962,8 @@
                     usecase->stream.out->sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
                     platform_check_and_set_codec_backend_cfg(adev, usecase,
                                                             usecase->out_snd_device);
-                    enable_audio_route(adev, usecase);
                     enable_snd_device(adev, usecase->out_snd_device);
+                    enable_audio_route(adev, usecase);
                 }
             }
         }
@@ -4070,7 +4071,7 @@
 
         if (out->realtime)
             platform_set_stream_channel_map(adev->platform, out->channel_mask,
-                   out->pcm_device_id, &out->channel_map_param.channel_map[0]);
+                   out->pcm_device_id, -1, &out->channel_map_param.channel_map[0]);
 
         out->pcm = pcm_open_prepare_helper(adev->snd_card, out->pcm_device_id,
                                        flags, pcm_open_retry_count,
@@ -4096,7 +4097,7 @@
 
         if (!out->realtime)
             platform_set_stream_channel_map(adev->platform, out->channel_mask,
-                   out->pcm_device_id, &out->channel_map_param.channel_map[0]);
+                   out->pcm_device_id, -1, &out->channel_map_param.channel_map[0]);
 
         // apply volume for voip playback after path is set up
         if (out->usecase == USECASE_AUDIO_PLAYBACK_VOIP)
@@ -4117,7 +4118,7 @@
          */
         if (popcount(out->channel_mask) > 2 || out->channel_map_param.channel_map[0])
             platform_set_stream_channel_map(adev->platform, out->channel_mask,
-                       out->pcm_device_id, &out->channel_map_param.channel_map[0]);
+                       out->pcm_device_id, -1, &out->channel_map_param.channel_map[0]);
         audio_enable_asm_bit_width_enforce_mode(adev->mixer,
                                                 adev->dsp_bit_width_enforce_mode,
                                                 true);
@@ -9506,6 +9507,12 @@
             goto err_open;
         }
         ALOGV("%s: car_audio_stream 0x%x", __func__, in->car_audio_stream);
+        ret = audio_extn_auto_hal_open_input_stream(in);
+        if (ret) {
+            ALOGE("%s: Failed to open input stream for bus device", __func__);
+            ret = -EINVAL;
+            goto err_open;
+        }
     }
 
     if (in->source == AUDIO_SOURCE_FM_TUNER) {
@@ -9607,10 +9614,6 @@
         in->config = pcm_config_afe_proxy_record;
         in->config.rate = config->sample_rate;
         in->af_period_multiplier = 1;
-    } else if (in->realtime) {
-        in->config = pcm_config_audio_capture_rt;
-        in->config.format = pcm_format_from_audio_format(config->format);
-        in->af_period_multiplier = af_period_multiplier;
     } else if (in->source == AUDIO_SOURCE_VOICE_COMMUNICATION &&
                (!voice_extn_is_compress_voip_supported()) &&
                in->flags & AUDIO_INPUT_FLAG_VOIP_TX &&
@@ -9630,6 +9633,10 @@
         in->config.period_count = VOIP_CAPTURE_PERIOD_COUNT;
         in->config.rate = config->sample_rate;
         in->af_period_multiplier = 1;
+    } else if (in->realtime) {
+        in->config = pcm_config_audio_capture_rt;
+        in->config.format = pcm_format_from_audio_format(config->format);
+        in->af_period_multiplier = af_period_multiplier;
     } else {
         int ret_val;
         pthread_mutex_lock(&adev->lock);
@@ -9712,14 +9719,6 @@
                 }
             }
         }
-        if (compare_device_type(&in->device_list, AUDIO_DEVICE_IN_BUS)) {
-           ret = audio_extn_auto_hal_open_input_stream(in);
-           if (ret) {
-               ALOGE("%s: Failed to open input stream for bus device", __func__);
-               ret = -EINVAL;
-               goto err_open;
-           }
-        }
     }
     if (audio_extn_ssr_get_stream() != in)
         in->config.channels = channel_count;
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index d9957ef..2f8a6f2 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2021, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -7263,14 +7263,14 @@
 }
 
 int platform_set_stream_channel_map(void *platform, audio_channel_mask_t channel_mask,
-                                               int snd_id, uint8_t *input_channel_map)
+                                    int snd_id, int be_idx, uint8_t *input_channel_map)
 {
     int ret = 0, i = 0;
     int channels = audio_channel_count_from_out_mask(channel_mask);
 
     char channel_map[AUDIO_CHANNEL_COUNT_MAX];
     memset(channel_map, 0, sizeof(channel_map));
-    if (*input_channel_map) {
+    if ((input_channel_map != NULL) && *input_channel_map) {
         for (i = 0; i < channels; i++) {
              ALOGV("%s:: Channel Map channel_map[%d] - %d", __func__, i, *input_channel_map);
              channel_map[i] = *input_channel_map;
@@ -7357,7 +7357,7 @@
                 return -1;
         }
     }
-    ret = platform_set_channel_map(platform, channels, channel_map, snd_id, -1);
+    ret = platform_set_channel_map(platform, channels, channel_map, snd_id, be_idx);
     return ret;
 }
 
@@ -7704,7 +7704,9 @@
                 platform_set_channel_map(platform, adev_device_cfg_ptr->dev_cfg_params.channels,
                                    (char *)adev_device_cfg_ptr->dev_cfg_params.channel_map, -1, -1);
             } else {
-                platform_set_channel_map(platform, channels, info->channel_map, -1, -1);
+                platform_set_stream_channel_map(platform,
+                        audio_channel_out_mask_from_count(channels),
+                        -1, -1, NULL);
             }
 
             if (adev_device_cfg_ptr->use_client_dev_cfg) {
diff --git a/hal/msm8960/platform.c b/hal/msm8960/platform.c
index 90105cd..94c0a62 100644
--- a/hal/msm8960/platform.c
+++ b/hal/msm8960/platform.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2019, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2019, 2021 The Linux Foundation. All rights reserved.
  * Not a contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -1202,14 +1202,16 @@
 }
 
 int platform_set_channel_map(void *platform __unused, int ch_count __unused,
-                             char *ch_map __unused, int snd_id __unused)
+                             char *ch_map __unused, int snd_id __unused,
+                             int be_idx __unused)
 {
     return -ENOSYS;
 }
 
 int platform_set_stream_channel_map(void *platform __unused,
                                     audio_channel_mask_t channel_mask __unused,
-                                    int snd_id __unused
+                                    int snd_id __unused,
+                                    int be_idx __unused,
                                     uint8_t *input_channel_map __unused)
 {
     return -ENOSYS;
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 572ae99..4ebe8cd 100755
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -10802,14 +10802,14 @@
 }
 
 int platform_set_stream_channel_map(void *platform, audio_channel_mask_t channel_mask,
-                                               int snd_id, uint8_t *input_channel_map)
+                                    int snd_id, int be_idx, uint8_t *input_channel_map)
 {
     int ret = 0, i = 0;
     int channels = audio_channel_count_from_out_mask(channel_mask);
 
     char channel_map[AUDIO_CHANNEL_COUNT_MAX];
     memset(channel_map, 0, sizeof(channel_map));
-    if (*input_channel_map) {
+    if ((input_channel_map != NULL) && *input_channel_map) {
         for (i = 0; i < channels; i++) {
              ALOGV("%s:: Channel Map channel_map[%d] - %d", __func__, i, *input_channel_map);
              channel_map[i] = *input_channel_map;
@@ -10935,7 +10935,7 @@
                 return -1;
         }
     }
-    ret = platform_set_channel_map(platform, channels, channel_map, snd_id, -1);
+    ret = platform_set_channel_map(platform, channels, channel_map, snd_id, be_idx);
     return ret;
 }
 
@@ -11486,7 +11486,9 @@
                 platform_set_channel_map(platform, adev_device_cfg_ptr->dev_cfg_params.channels,
                                      (char *)adev_device_cfg_ptr->dev_cfg_params.channel_map, -1, be_idx);
             } else {
-                platform_set_channel_map(platform, channels, info->channel_map, -1, be_idx);
+                platform_set_stream_channel_map(platform,
+                        audio_channel_out_mask_from_count(channels),
+                        -1, be_idx, NULL);
             }
 
             if (adev_device_cfg_ptr->use_client_dev_cfg) {
diff --git a/hal/platform_api.h b/hal/platform_api.h
index d4eb4f5..ca72708 100644
--- a/hal/platform_api.h
+++ b/hal/platform_api.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2021, The Linux Foundation. All rights reserved.
  * Not a contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -283,7 +283,7 @@
 int platform_set_channel_map(void *platform, int ch_count, char *ch_map,
                              int snd_id, int be_idx);
 int platform_set_stream_channel_map(void *platform, audio_channel_mask_t channel_mask,
-                                   int snd_id, uint8_t *input_channel_map);
+                                   int snd_id, int be_idx, uint8_t *input_channel_map);
 int platform_set_stream_pan_scale_params(void *platform,
                                          int snd_id,
                                          struct mix_matrix_params mm_params);