Merge "hal: check existence of ext disp device before routing"
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index c829cfb..8f18c8f 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -4725,6 +4725,18 @@
         str_parms_destroy(parms);
     }
 
+    // Workaround: If routing to an non existing hdmi device, fail gracefully
+    if (compare_device_type(&new_devices, AUDIO_DEVICE_OUT_AUX_DIGITAL) &&
+        (platform_get_edid_info_v2(adev->platform,
+                                   out->extconn.cs.controller,
+                                   out->extconn.cs.stream) != 0)) {
+        ALOGW("out_set_parameters() ignoring rerouting to non existing HDMI/DP");
+        pthread_mutex_unlock(&adev->lock);
+        pthread_mutex_unlock(&out->lock);
+        ret = -ENOSYS;
+        goto error;
+    }
+
     /*
      * select_devices() call below switches all the usecases on the same
      * backend to the new device. Refer to check_usecases_codec_backend() in
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index 77606e8..66add14 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -4167,7 +4167,7 @@
     int disp_type;
     struct platform_data *my_data = (struct platform_data *)platform;
 
-    if (my_data->ext_disp_type != EXT_DISPLAY_TYPE_NONE) {
+    if (my_data->ext_disp_type > EXT_DISPLAY_TYPE_NONE) {
          ALOGD("%s: Returning cached ext disp type:%s",
                __func__, (my_data->ext_disp_type == EXT_DISPLAY_TYPE_DP) ? "DisplayPort" : "HDMI");
          return my_data->ext_disp_type;
@@ -4186,12 +4186,12 @@
         }
 
         disp_type = mixer_ctl_get_value(ctl, 0);
-        if (disp_type == EXT_DISPLAY_TYPE_NONE) {
+        if (disp_type <= EXT_DISPLAY_TYPE_NONE) {
              ALOGE("%s: Invalid external display type: %d", __func__, disp_type);
              return -EINVAL;
         }
-    }else {
-            disp_type = EXT_DISPLAY_TYPE_HDMI;
+    } else {
+        disp_type = EXT_DISPLAY_TYPE_HDMI;
     }
 
     my_data->ext_disp_type = disp_type;
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 77ab465..ed23aca 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -5905,7 +5905,7 @@
     }
 
     disp = &my_data->ext_disp[controller][stream];
-    if (disp->type != EXT_DISPLAY_TYPE_NONE) {
+    if (disp->type > EXT_DISPLAY_TYPE_NONE) {
          ALOGD("%s: Returning cached ext disp type:%s",
                __func__, (disp->type == EXT_DISPLAY_TYPE_DP) ? "DisplayPort" : "HDMI");
          return disp->type;