diff options
author | Devin Moore <devinmoore@google.com> | 2023-11-27 17:33:30 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-11-27 17:33:30 +0000 |
commit | a6bad01fd77bdbaaec59a04391af8cea408db862 (patch) | |
tree | eff39c6dd18cc34f67c1152588cbe5e16b9079e0 | |
parent | 84e59531c03c16e9327895b03aedcffed07a09c7 (diff) | |
parent | 304e1719d4d2511ed3df91feb277fa9a1d69a151 (diff) | |
download | libhidl-a6bad01fd77bdbaaec59a04391af8cea408db862.tar.gz |
Add isHidlSupported API and use it am: 22e6f1e1c5 am: 20ed057929 am: 304e1719d4
Original change: https://android-review.googlesource.com/c/platform/system/libhidl/+/2844966
Change-Id: Ia18a5db961084fbcdf4b5402827fd85a81348fd0
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | transport/ServiceManagement.cpp | 30 | ||||
-rw-r--r-- | transport/include/hidl/ServiceManagement.h | 3 |
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(); |