HIDL stuff on host.
The motivation of this is for quickly running unit tests of HAL
implementations on host. Before, you would have to abstract away
HIDL stuff, but now, you can just call a class that inherits from
HIDL stuff directly.
Currently, there is no binder or passthrough support on host though.
This is only for unit tests of C++ classes.
Bug: 124524556
Test: libhidl_test on host
Change-Id: I922060e48406ca196fbf864e549c05f5e1113d62
diff --git a/transport/ServiceManagement.cpp b/transport/ServiceManagement.cpp
index 2187740..bb690f4 100644
--- a/transport/ServiceManagement.cpp
+++ b/transport/ServiceManagement.cpp
@@ -16,7 +16,10 @@
#define LOG_TAG "HidlServiceManagement"
+#ifdef __ANDROID__
#include <android/dlext.h>
+#endif // __ANDROID__
+
#include <condition_variable>
#include <dlfcn.h>
#include <dirent.h>
@@ -43,7 +46,7 @@
#include <android-base/strings.h>
#include <hwbinder/IPCThreadState.h>
#include <hwbinder/Parcel.h>
-#if !defined(__ANDROID_RECOVERY__)
+#if !defined(__ANDROID_RECOVERY__) && defined(__ANDROID__)
#include <vndksupport/linker.h>
#endif
@@ -55,8 +58,6 @@
#define RE_PATH RE_COMPONENT "(?:[.]" RE_COMPONENT ")*"
static const std::regex gLibraryFileNamePattern("(" RE_PATH "@[0-9]+[.][0-9]+)-impl(.*?).so");
-using android::base::WaitForProperty;
-
using ::android::hidl::base::V1_0::IBase;
using IServiceManager1_0 = android::hidl::manager::V1_0::IServiceManager;
using IServiceManager1_1 = android::hidl::manager::V1_1::IServiceManager;
@@ -66,8 +67,6 @@
namespace android {
namespace hardware {
-static const char* kHwServicemanagerReadyProperty = "hwservicemanager.ready";
-
#if defined(__ANDROID_RECOVERY__)
static constexpr bool kIsRecovery = true;
#else
@@ -75,11 +74,18 @@
#endif
static void waitForHwServiceManager() {
+ // TODO(b/31559095): need bionic host so that we can use 'prop_info' returned
+ // from WaitForProperty
+#ifdef __ANDROID__
+ static const char* kHwServicemanagerReadyProperty = "hwservicemanager.ready";
+
using std::literals::chrono_literals::operator""s;
+ using android::base::WaitForProperty;
while (!WaitForProperty(kHwServicemanagerReadyProperty, "true", 1s)) {
LOG(WARNING) << "Waited for hwservicemanager.ready for a second, waiting another...";
}
+#endif // __ANDROID__
}
static std::string binaryName() {
@@ -395,7 +401,7 @@
if (kIsRecovery || path == HAL_LIBRARY_PATH_SYSTEM) {
handle = dlopen(fullPath.c_str(), dlMode);
} else {
-#if !defined(__ANDROID_RECOVERY__)
+#if !defined(__ANDROID_RECOVERY__) && defined(__ANDROID__)
handle = android_load_sphal_library(fullPath.c_str(), dlMode);
#endif
}