Revert "Check hwservicemanager.disabled for isHidlSupported"

Revert submission 26722372-nomo_hidl

Reason for revert: <Reason for revert: Potential culprit for b/332395670- verifying through ABTD before revert submission. This is part of the standard investigation process, and does not mean your CL will be reverted.>

Reverted changes: /q/submissionid:26722372-nomo_hidl

Change-Id: I64c57cc5c7ad7effd16ef507f629ee8f1e36692e
diff --git a/transport/ServiceManagement.cpp b/transport/ServiceManagement.cpp
index 54bb8dc..8807898 100644
--- a/transport/ServiceManagement.cpp
+++ b/transport/ServiceManagement.cpp
@@ -71,16 +71,7 @@
 static constexpr bool kIsRecovery = false;
 #endif
 
-static bool isHwServiceManagerInstalled() {
-    return access("/system_ext/bin/hwservicemanager", F_OK) == 0 ||
-           access("/system/system_ext/bin/hwservicemanager", F_OK) == 0 ||
-           access("/system/bin/hwservicemanager", F_OK) == 0;
-}
-
-static bool waitForHwServiceManager() {
-    if (!isHwServiceManagerInstalled()) {
-        return false;
-    }
+static void waitForHwServiceManager() {
     // TODO(b/31559095): need bionic host so that we can use 'prop_info' returned
     // from WaitForProperty
 #ifdef __ANDROID__
@@ -89,21 +80,10 @@
     using std::literals::chrono_literals::operator""s;
 
     using android::base::WaitForProperty;
-    while (true) {
-        if (base::GetBoolProperty("hwservicemanager.disabled", false)) {
-            return false;
-        }
-        if (WaitForProperty(kHwServicemanagerReadyProperty, "true", 1s)) {
-            return true;
-        }
+    while (!WaitForProperty(kHwServicemanagerReadyProperty, "true", 1s)) {
         LOG(WARNING) << "Waited for hwservicemanager.ready for a second, waiting another...";
     }
 #endif  // __ANDROID__
-    return true;
-}
-
-bool isHidlSupported() {
-    return waitForHwServiceManager();
 }
 
 static std::string binaryName() {
@@ -231,6 +211,31 @@
            fqName == IServiceManager1_2::descriptor;
 }
 
+static bool isHwServiceManagerInstalled() {
+    return access("/system_ext/bin/hwservicemanager", F_OK) == 0 ||
+           access("/system/system_ext/bin/hwservicemanager", F_OK) == 0 ||
+           access("/system/bin/hwservicemanager", F_OK) == 0;
+}
+
+bool isHidlSupported() {
+    if (!isHwServiceManagerInstalled()) {
+        return false;
+    }
+#ifdef __ANDROID__
+    static const char* kVendorApiProperty = "ro.vendor.api_level";
+    // HIDL and hwservicemanager are not supported in Android V+
+    // This is also set with `max-level="8"` in the framework manifest fragment
+    // for android.hidl.manager. We don't check for android.hidl.manager to be
+    // declared through defaultServiceManager1_2() because the fake
+    // servicemaanger will say it is declared.
+    return android::base::GetIntProperty(kVendorApiProperty, 0) < __ANDROID_API_V__;
+#else
+    // No access to properties and no requirement for dropping HIDL support if
+    // this isn't Android
+    return true;
+#endif  // __ANDROID__
+}
+
 /*
  * A replacement for hwservicemanager when it is not installed on a device.
  *
@@ -392,12 +397,6 @@
             return gDefaultServiceManager;
         }
 
-        if (access("/dev/hwbinder", F_OK|R_OK|W_OK) != 0) {
-            // HwBinder not available on this device or not accessible to
-            // this process.
-            return nullptr;
-        }
-
         if (!isHidlSupported()) {
             // hwservicemanager is not available on this device.
             LOG(WARNING) << "hwservicemanager is not supported on the device.";
@@ -405,6 +404,14 @@
             return gDefaultServiceManager;
         }
 
+        if (access("/dev/hwbinder", F_OK|R_OK|W_OK) != 0) {
+            // HwBinder not available on this device or not accessible to
+            // this process.
+            return nullptr;
+        }
+
+        waitForHwServiceManager();
+
         while (gDefaultServiceManager == nullptr) {
             gDefaultServiceManager =
                 fromBinder<IServiceManager1_2, BpHwServiceManager, BnHwServiceManager>(