Snap for 6877830 from 58a4d1f46b7273b5c9e20eeb0dbba4ae2a47c40d to sdk-release

Change-Id: I047aa7dacaf7affaed0bda0135248fa4322ee0c7
diff --git a/drm/drmdevice.cpp b/drm/drmdevice.cpp
index bef41d8..d7fd2f2 100644
--- a/drm/drmdevice.cpp
+++ b/drm/drmdevice.cpp
@@ -59,7 +59,7 @@
 
 static std::vector<std::string> read_primary_display_order_prop() {
   std::array<char, PROPERTY_VALUE_MAX> display_order_buf;
-  property_get("hwc.drm.primary_display_order", display_order_buf.data(),
+  property_get("vendor.hwc.drm.primary_display_order", display_order_buf.data(),
                "...");
 
   std::vector<std::string> display_order;
@@ -254,7 +254,7 @@
   }
 
   // Primary display priority:
-  // 1) hwc.drm.primary_display_order property
+  // 1) vendor.hwc.drm.primary_display_order property
   // 2) internal connectors
   // 3) anything else
   std::vector<DrmConnector *>
@@ -267,8 +267,8 @@
     found_primary = true;
   } else {
     ALOGE(
-        "Failed to find primary display from \"hwc.drm.primary_display_order\" "
-        "property");
+        "Failed to find primary display from "
+        "\"vendor.hwc.drm.primary_display_order\" property");
   }
 
   // If no priority display were found then pick first available as primary and
diff --git a/drm/resourcemanager.cpp b/drm/resourcemanager.cpp
index da1a2db..986d4ab 100644
--- a/drm/resourcemanager.cpp
+++ b/drm/resourcemanager.cpp
@@ -20,6 +20,7 @@
 
 #include <cutils/properties.h>
 #include <log/log.h>
+#include <sys/stat.h>
 #include <sstream>
 #include <string>
 
@@ -32,7 +33,8 @@
   char path_pattern[PROPERTY_VALUE_MAX];
   // Could be a valid path or it can have at the end of it the wildcard %
   // which means that it will try open all devices until an error is met.
-  int path_len = property_get("hwc.drm.device", path_pattern, "/dev/dri/card0");
+  int path_len = property_get("vendor.hwc.drm.device", path_pattern,
+                              "/dev/dri/card%");
   int ret = 0;
   if (path_pattern[path_len - 1] != '%') {
     ret = AddDrmDevice(std::string(path_pattern));
@@ -41,7 +43,13 @@
     for (int idx = 0; !ret; ++idx) {
       std::ostringstream path;
       path << path_pattern << idx;
-      ret = AddDrmDevice(path.str());
+
+      struct stat buf;
+      if (stat(path.str().c_str(), &buf)) {
+        break;
+      } else if (IsKMSDev(path.str().c_str())) {
+        ret = AddDrmDevice(path.str());
+      }
     }
   }
 
@@ -51,7 +59,7 @@
   }
 
   char scale_with_gpu[PROPERTY_VALUE_MAX];
-  property_get("hwc.drm.scale_with_gpu", scale_with_gpu, "0");
+  property_get("vendor.hwc.drm.scale_with_gpu", scale_with_gpu, "0");
   scale_with_gpu_ = bool(strncmp(scale_with_gpu, "0", 1));
 
   return hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
@@ -94,6 +102,26 @@
   return writeback_conn;
 }
 
+bool ResourceManager::IsKMSDev(const char *path) {
+  int fd = open(path, O_RDWR | O_CLOEXEC);
+  if (fd < 0)
+    return false;
+
+  auto res = drmModeGetResources(fd);
+  if (!res) {
+    close(fd);
+    return false;
+  }
+
+  bool is_kms = res->count_crtcs > 0 && res->count_connectors > 0 &&
+                res->count_encoders > 0;
+
+  drmModeFreeResources(res);
+  close(fd);
+
+  return is_kms;
+}
+
 DrmDevice *ResourceManager::GetDrmDevice(int display) {
   for (auto &drm : drms_) {
     if (drm->HandlesDisplay(display))
diff --git a/drmhwctwo.cpp b/drmhwctwo.cpp
index 5afc96d..a847c35 100644
--- a/drmhwctwo.cpp
+++ b/drmhwctwo.cpp
@@ -271,7 +271,8 @@
   // Split up the given display planes into primary and overlay to properly
   // interface with the composition
   char use_overlay_planes_prop[PROPERTY_VALUE_MAX];
-  property_get("hwc.drm.use_overlay_planes", use_overlay_planes_prop, "1");
+  property_get("vendor.hwc.drm.use_overlay_planes", use_overlay_planes_prop,
+               "1");
   bool use_overlay_planes = atoi(use_overlay_planes_prop);
   for (auto &plane : *planes) {
     if (plane->type() == DRM_PLANE_TYPE_PRIMARY)
diff --git a/include/resourcemanager.h b/include/resourcemanager.h
index 7a86828..9fefb46 100644
--- a/include/resourcemanager.h
+++ b/include/resourcemanager.h
@@ -46,6 +46,7 @@
 
  private:
   int AddDrmDevice(std::string path);
+  static bool IsKMSDev(const char *path);
 
   int num_displays_;
   std::vector<std::unique_ptr<DrmDevice>> drms_;
diff --git a/platform/platformdrmgeneric.cpp b/platform/platformdrmgeneric.cpp
index 1aa8160..bc28dd5 100644
--- a/platform/platformdrmgeneric.cpp
+++ b/platform/platformdrmgeneric.cpp
@@ -66,7 +66,8 @@
         gralloc_->common.author);
 
   char exclude_non_hwfb_prop[PROPERTY_VALUE_MAX];
-  property_get("hwc.drm.exclude_non_hwfb_imports", exclude_non_hwfb_prop, "0");
+  property_get("vendor.hwc.drm.exclude_non_hwfb_imports", exclude_non_hwfb_prop,
+               "0");
   exclude_non_hwfb_ = static_cast<bool>(strncmp(exclude_non_hwfb_prop, "0", 1));
 
   return 0;