summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevin Moore <devinmoore@google.com>2024-03-26 22:00:23 +0000
committerDevin Moore <devinmoore@google.com>2024-04-05 21:55:21 +0000
commit50ced9f4397e21c69156e42cdebd4dd9113ff66d (patch)
tree416bb920d9a77e1613f7751991adcf1eed32a43b
parent4e0961bf2e8c305f5a966e60effffbfdd14b7ab3 (diff)
downloadlibhidl-50ced9f4397e21c69156e42cdebd4dd9113ff66d.tar.gz
Check hwservicemanager.disabled for isHidlSupported
Check for this when checking for "hwservicemanager.ready". If it's disabled, it's not going to be ready. This also makes the isHidlSupported call waitForHwservicemanager so isHidlSupported doesn't hit any races. Test: launch_cvd Test: atest vts_treble_vintf_framework_test vts_treble_no_hidl Test: atest vts_treble_vintf_vendor_test Bug: 218588089 Merged-In: Iff99e91e2d555d9868bc04ef58acfdcf3d81955c Change-Id: If32e7c2f30b260703c793699693d4b198d580cb2
-rw-r--r--transport/ServiceManagement.cpp63
1 files changed, 28 insertions, 35 deletions
diff --git a/transport/ServiceManagement.cpp b/transport/ServiceManagement.cpp
index 8807898..54bb8dc 100644
--- a/transport/ServiceManagement.cpp
+++ b/transport/ServiceManagement.cpp
@@ -71,7 +71,16 @@ static constexpr bool kIsRecovery = true;
static constexpr bool kIsRecovery = false;
#endif
-static void waitForHwServiceManager() {
+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;
+ }
// TODO(b/31559095): need bionic host so that we can use 'prop_info' returned
// from WaitForProperty
#ifdef __ANDROID__
@@ -80,10 +89,21 @@ static void waitForHwServiceManager() {
using std::literals::chrono_literals::operator""s;
using android::base::WaitForProperty;
- while (!WaitForProperty(kHwServicemanagerReadyProperty, "true", 1s)) {
+ while (true) {
+ if (base::GetBoolProperty("hwservicemanager.disabled", false)) {
+ return false;
+ }
+ if (WaitForProperty(kHwServicemanagerReadyProperty, "true", 1s)) {
+ return true;
+ }
LOG(WARNING) << "Waited for hwservicemanager.ready for a second, waiting another...";
}
#endif // __ANDROID__
+ return true;
+}
+
+bool isHidlSupported() {
+ return waitForHwServiceManager();
}
static std::string binaryName() {
@@ -211,31 +231,6 @@ static bool isServiceManager(const hidl_string& fqName) {
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.
*
@@ -397,20 +392,18 @@ sp<IServiceManager1_2> defaultServiceManager1_2() {
return gDefaultServiceManager;
}
- if (!isHidlSupported()) {
- // hwservicemanager is not available on this device.
- LOG(WARNING) << "hwservicemanager is not supported on the device.";
- gDefaultServiceManager = sp<NoHwServiceManager>::make();
- 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();
+ if (!isHidlSupported()) {
+ // hwservicemanager is not available on this device.
+ LOG(WARNING) << "hwservicemanager is not supported on the device.";
+ gDefaultServiceManager = sp<NoHwServiceManager>::make();
+ return gDefaultServiceManager;
+ }
while (gDefaultServiceManager == nullptr) {
gDefaultServiceManager =