drm_hwcomposer: Fix build failure on Linux-native targets

Commit e11f723f ("drm_hwcomposer: Query property when checking virtual
displays availability") introduced a call to
android::base::GetBoolProperty, which is only available in Android.
This caused the test "hwcomposer.filegroups_build_test" to fail because
the code was no longer compiling for Linux-native targets.

Fix that by replacing "android::base::GetBoolProperty" with a new
function "property_get_bool," and define the function for both Android
and non-Android targets:
For Android, utilize the existing function from <cutils/properties.h>
For other targets, a new implementation is provided in
utils/properties.h.

Fixes: e11f723f ("drm_hwcomposer: Query property when checking virtual
displays availability")

Signed-off-by: Paz Zcharya <pazz@google.com>
diff --git a/drm/DrmHwc.cpp b/drm/DrmHwc.cpp
index 6b62457..aaba506 100644
--- a/drm/DrmHwc.cpp
+++ b/drm/DrmHwc.cpp
@@ -19,12 +19,10 @@
 #include "DrmHwc.h"
 
 #include <cinttypes>
-#include <string>
-
-#include <android-base/properties.h>
 
 #include "backend/Backend.h"
 #include "utils/log.h"
+#include "utils/properties.h"
 
 namespace android {
 
@@ -202,9 +200,7 @@
   /* Virtual display is an experimental feature.
    * Unless explicitly set to true, return 0 for no support.
    */
-  if (!base::GetBoolProperty(std::string(
-                                 "vendor.hwc.drm.enable_virtual_display"),
-                             false)) {
+  if (0 == property_get_bool("vendor.hwc.drm.enable_virtual_display", 0)) {
     return 0;
   }
 
diff --git a/utils/properties.h b/utils/properties.h
index e400236..641df91 100644
--- a/utils/properties.h
+++ b/utils/properties.h
@@ -39,4 +39,37 @@
   return static_cast<int>(strlen(value));
 }
 
+/**
+ * Bluntly copied from system/core/libcutils/properties.cpp,
+ * which is part of the Android Project and licensed under Apache 2.
+ * Source:
+ * https://cs.android.com/android/platform/superproject/main/+/main:system/core/libcutils/properties.cpp;l=27
+ */
+auto inline property_get_bool(const char *key, int8_t default_value) -> int8_t {
+  if (!key)
+    return default_value;
+
+  int8_t result = default_value;
+  char buf[PROPERTY_VALUE_MAX] = {};
+
+  int len = property_get(key, buf, "");
+  if (len == 1) {
+    char ch = buf[0];
+    if (ch == '0' || ch == 'n') {
+      result = false;
+    } else if (ch == '1' || ch == 'y') {
+      result = true;
+    }
+  } else if (len > 1) {
+    if (!strcmp(buf, "no") || !strcmp(buf, "false") || !strcmp(buf, "off")) {
+      result = false;
+    } else if (!strcmp(buf, "yes") || !strcmp(buf, "true") ||
+               !strcmp(buf, "on")) {
+      result = true;
+    }
+  }
+
+  return result;
+}
+
 #endif