Merge "hal: fix to enable aanc handset dynamically during voice call" into av-userspace.lnx.1.0-dev.1.0
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index f610096..ae7853e 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -959,7 +959,7 @@
          * usecase. This is to avoid switching devices for voice call when
          * check_usecases_codec_backend() is called below.
          */
-        if (voice_is_in_call(adev) && adev->mode == AUDIO_MODE_IN_CALL) {
+        if (voice_is_in_call(adev) && adev->mode != AUDIO_MODE_NORMAL) {
             vc_usecase = get_usecase_from_list(adev,
                                                get_usecase_id_from_usecase_type(adev, VOICE_CALL));
             if ((vc_usecase) && ((vc_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) ||
@@ -3607,8 +3607,7 @@
     if (adev->mode != mode) {
         ALOGD("%s: mode %d\n", __func__, mode);
         adev->mode = mode;
-        if ((mode == AUDIO_MODE_NORMAL || mode == AUDIO_MODE_IN_COMMUNICATION) &&
-                voice_is_in_call(adev)) {
+        if ((mode == AUDIO_MODE_NORMAL) && voice_is_in_call(adev)) {
             voice_stop_call(adev);
             platform_set_gsm_mode(adev->platform, false);
             adev->current_call_output = NULL;
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index 4839451..7cdfc62 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -1677,6 +1677,7 @@
                 ALOGE("%s: Failed to init audio route controls, aborting.",
                        __func__);
                 free(my_data);
+                mixer_close(adev->mixer);
                 return NULL;
             }
             adev->snd_card = snd_card_num;
@@ -1686,6 +1687,7 @@
         }
         retry_num = 0;
         snd_card_num++;
+        mixer_close(adev->mixer);
     }
 
     if (snd_card_num >= MAX_SND_CARD) {
diff --git a/hal/msm8960/platform.c b/hal/msm8960/platform.c
index e7d6920..be50289 100644
--- a/hal/msm8960/platform.c
+++ b/hal/msm8960/platform.c
@@ -243,6 +243,7 @@
     adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
     if (!adev->audio_route) {
         ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
+        mixer_close(adev->mixer);
         return NULL;
     }
 
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index e091547..65ef702 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -1335,6 +1335,7 @@
         if (!snd_card_name) {
             ALOGE("failed to allocate memory for snd_card_name\n");
             free(my_data);
+            mixer_close(adev->mixer);
             return NULL;
         }
         ALOGD("%s: snd_card_name: %s", __func__, snd_card_name);
@@ -1401,6 +1402,7 @@
                 free(my_data);
                 free(snd_card_name);
                 free(snd_card_name_t);
+                mixer_close(adev->mixer);
                 return NULL;
             }
             adev->snd_card = snd_card_num;
@@ -1409,6 +1411,7 @@
         }
         retry_num = 0;
         snd_card_num++;
+        mixer_close(adev->mixer);
     }
 
     if (snd_card_num >= MAX_SND_CARD) {