hal: Fix device disable/enable sequence

  In Skype call, observed no rx data when headset is inserted
  during call.

  During device switch from handset to headset, audio HAL is
  enabling the headset mixer controls first then disabling
  handset mixer controls leading to no audio during downlink
  as codec clock in 8916 is disabled due to the followed
  sequence.

  The current device switch logic doesn't make sure that all
  previous devices are disabled before enabling the selected
  devices. Fix this by changing the logic to disable all the
  previous devices first and enable the selected devices.

  CRs-Fixed: 648710

Change-Id: I0adfb62ea0ad8e2a2fe1a5473732e8bef61c492a
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 9f76d31..c41759c 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -437,23 +437,22 @@
         /* Make sure all the streams are de-routed before disabling the device */
         audio_route_update_mixer(adev->audio_route);
 
+        /* Make sure the previous devices to be disabled first and then enable the
+           selected devices */
         list_for_each(node, &adev->usecase_list) {
             usecase = node_to_item(node, struct audio_usecase, list);
             if (switch_device[usecase->id]) {
-                disable_snd_device(adev, usecase->out_snd_device, false);
+                disable_snd_device(adev, usecase->out_snd_device, true);
             }
         }
 
         list_for_each(node, &adev->usecase_list) {
             usecase = node_to_item(node, struct audio_usecase, list);
             if (switch_device[usecase->id]) {
-                enable_snd_device(adev, snd_device, false);
+                enable_snd_device(adev, snd_device, true);
             }
         }
 
-        /* Make sure new snd device is enabled before re-routing the streams */
-        audio_route_update_mixer(adev->audio_route);
-
         /* Re-route all the usecases on the shared backend other than the
            specified usecase to new snd devices */
         list_for_each(node, &adev->usecase_list) {
@@ -507,23 +506,22 @@
         /* Make sure all the streams are de-routed before disabling the device */
         audio_route_update_mixer(adev->audio_route);
 
+        /* Make sure the previous devices to be disabled first and then enable the
+           selected devices */
         list_for_each(node, &adev->usecase_list) {
             usecase = node_to_item(node, struct audio_usecase, list);
             if (switch_device[usecase->id]) {
-                disable_snd_device(adev, usecase->in_snd_device, false);
+                disable_snd_device(adev, usecase->in_snd_device, true);
             }
         }
 
         list_for_each(node, &adev->usecase_list) {
             usecase = node_to_item(node, struct audio_usecase, list);
             if (switch_device[usecase->id]) {
-                enable_snd_device(adev, snd_device, false);
+                enable_snd_device(adev, snd_device, true);
             }
         }
 
-        /* Make sure new snd device is enabled before re-routing the streams */
-        audio_route_update_mixer(adev->audio_route);
-
         /* Re-route all the usecases on the shared backend other than the
            specified usecase to new snd devices */
         list_for_each(node, &adev->usecase_list) {
@@ -698,12 +696,12 @@
     /* Disable current sound devices */
     if (usecase->out_snd_device != SND_DEVICE_NONE) {
         disable_audio_route(adev, usecase, true);
-        disable_snd_device(adev, usecase->out_snd_device, false);
+        disable_snd_device(adev, usecase->out_snd_device, true);
     }
 
     if (usecase->in_snd_device != SND_DEVICE_NONE) {
         disable_audio_route(adev, usecase, true);
-        disable_snd_device(adev, usecase->in_snd_device, false);
+        disable_snd_device(adev, usecase->in_snd_device, true);
     }
 
     /* Applicable only on the targets that has external modem.