summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevin Moore <devinmoore@google.com>2023-11-22 22:29:54 +0000
committerDevin Moore <devinmoore@google.com>2023-11-22 22:35:54 +0000
commit22e6f1e1c54fbd6d8aa78e1fc87e77e6c271583f (patch)
treeeff39c6dd18cc34f67c1152588cbe5e16b9079e0
parent79dd1fff93f62580f9215fd1a6f13e09ab41836b (diff)
downloadlibhidl-22e6f1e1c54fbd6d8aa78e1fc87e77e6c271583f.tar.gz
Add isHidlSupported API and use it
This is initially always going to return true until we have removed all HIDL from Cuttlefish. Then it will be based on the vendor API level. Test: remove kTempHidlSupport && m && launch_cvd Bug: 218588089 Change-Id: Ic688df8bb0942e1aa8ba9bf5a34514083be1f2b4
-rw-r--r--transport/ServiceManagement.cpp30
-rw-r--r--transport/include/hidl/ServiceManagement.h3
2 files changed, 22 insertions, 11 deletions
diff --git a/transport/ServiceManagement.cpp b/transport/ServiceManagement.cpp
index 6d85b57..8c9bc5b 100644
--- a/transport/ServiceManagement.cpp
+++ b/transport/ServiceManagement.cpp
@@ -17,6 +17,7 @@
#define LOG_TAG "HidlServiceManagement"
#ifdef __ANDROID__
+#include <android/api-level.h>
#include <android/dlext.h>
#endif // __ANDROID__
@@ -209,10 +210,21 @@ static bool isServiceManager(const hidl_string& fqName) {
return fqName == IServiceManager1_0::descriptor || fqName == IServiceManager1_1::descriptor ||
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() {
+#ifdef __ANDROID__
+ // TODO(b/218588089) remove this temporary support variable once Cuttlefish
+ // (the only current Android V launching device) no longer requires HIDL.
+ constexpr bool kTempHidlSupport = true;
+ static const char* kVendorApiProperty = "ro.vendor.api_level";
+ // HIDL and hwservicemanager are not supported in Android V+
+ return android::base::GetIntProperty(kVendorApiProperty, 0) < __ANDROID_API_V__ ||
+ kTempHidlSupport;
+#else
+ // No access to properties and no requirement for dropping HIDL support if
+ // this isn't Android
+ return true;
+#endif // __ANDROID__
}
/*
@@ -323,13 +335,9 @@ sp<IServiceManager1_2> defaultServiceManager1_2() {
return gDefaultServiceManager;
}
- if (!isHwServiceManagerInstalled()) {
+ if (!isHidlSupported()) {
// hwservicemanager is not available on this device.
- LOG(WARNING)
- << "hwservicemanager is not installed on the device. If HIDL support "
- << "is still needed, hwservicemanager and android.hidl.allocator@1.0-service "
- << "need to be added to the device's PRODUCT_PACKAGES and the kernel config "
- << "needs to have 'hwbinder' in CONFIG_ANDROID_BINDER_DEVICES.";
+ LOG(WARNING) << "hwservicemanager is not supported on the device.";
gDefaultServiceManager = sp<NoHwServiceManager>::make();
return gDefaultServiceManager;
}
@@ -533,7 +541,7 @@ struct PassthroughServiceManager : IServiceManager1_1 {
// This is required to run without hwservicemanager while we have
// passthrough HIDL services. Once the passthrough HIDL services have
// been removed, the PassthroughServiceManager will no longer be needed.
- if (!isHwServiceManagerInstalled() && isServiceManager(fqName)) {
+ if (!isHidlSupported() && isServiceManager(fqName)) {
return defaultServiceManager1_2();
}
diff --git a/transport/include/hidl/ServiceManagement.h b/transport/include/hidl/ServiceManagement.h
index 886e816..715f27e 100644
--- a/transport/include/hidl/ServiceManagement.h
+++ b/transport/include/hidl/ServiceManagement.h
@@ -70,6 +70,9 @@ status_t registerAsServiceInternal(const sp<::android::hidl::base::V1_0::IBase>&
const std::string& name);
} // namespace details
+// Returns whether or not HIDL is supported on this device
+bool isHidlSupported();
+
// These functions are for internal use by hidl. If you want to get ahold
// of an interface, the best way to do this is by calling IFoo::getService()
sp<::android::hidl::manager::V1_0::IServiceManager> defaultServiceManager();