audio: Reconfigure backend based on stream's capability

If a stream configuration (bit width, rate, channel count)
is a better match for the sink (e.g. USB) than the existing
configuration, do a force routing to match the better
configuration.

Test: test music/video/ringtone playback, camcorder, OK google capture,
voice call

Change-Id: I5a7c4c4350518e53829c01757f4dc7fed54f3eca
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 9fad3fd..3318cc1 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -801,7 +801,9 @@
     bool switch_device[AUDIO_USECASE_MAX];
     int i, num_uc_to_switch = 0;
 
-    platform_check_and_set_playback_backend_cfg(adev, uc_info, snd_device);
+    bool force_routing =  platform_check_and_set_playback_backend_cfg(adev,
+                                                                      uc_info,
+                                                                      snd_device);
 
     /*
      * This function is to make sure that all the usecases that are active on
@@ -820,11 +822,13 @@
 
     list_for_each(node, &adev->usecase_list) {
         usecase = node_to_item(node, struct audio_usecase, list);
-        if (usecase->type != PCM_CAPTURE &&
-                usecase != uc_info &&
-                usecase->out_snd_device != snd_device &&
-                usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND &&
-                platform_check_backends_match(snd_device, usecase->out_snd_device)) {
+        if (usecase->type == PCM_CAPTURE || usecase == uc_info)
+            continue;
+
+        if (force_routing ||
+            (usecase->out_snd_device != snd_device &&
+             usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND &&
+             platform_check_backends_match(snd_device, usecase->out_snd_device))) {
             ALOGV("%s: Usecase (%s) is active on (%s) - disabling ..",
                   __func__, use_case_table[usecase->id],
                   platform_get_snd_device_name(usecase->out_snd_device));