HIDL stuff on host.
am: 2056cf3eee
Change-Id: I9a3f61a91f2d2c8f259045dc33c7155bf8ad5e8b
diff --git a/Android.bp b/Android.bp
index 29f9b56..7476db5 100644
--- a/Android.bp
+++ b/Android.bp
@@ -36,6 +36,7 @@
cc_test {
name: "libhidl_test",
+ host_supported: true,
defaults: ["libhidl-defaults"],
gtest: false,
srcs: ["test_main.cpp"],
@@ -75,6 +76,7 @@
cc_library {
name: "libhidlbase",
defaults: ["libhidlbase-combined-impl"],
+ host_supported: true,
recovery_available: true,
vendor_available: true,
vndk: {
diff --git a/base/Android.bp b/base/Android.bp
index 0bc3af0..ca4e259 100644
--- a/base/Android.bp
+++ b/base/Android.bp
@@ -28,8 +28,9 @@
cc_library {
name: "libhidlbase-impl-internal",
- vendor_available: true,
+ host_supported: true,
recovery_available: true,
+ vendor_available: true,
defaults: [
"libhidlbase-impl-shared-libs",
"libhidl-defaults"
diff --git a/base/HidlInternal.cpp b/base/HidlInternal.cpp
index 440b30f..956effd 100644
--- a/base/HidlInternal.cpp
+++ b/base/HidlInternal.cpp
@@ -21,7 +21,6 @@
#include <android-base/logging.h>
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
-#include <cutils/properties.h>
#ifdef LIBHIDL_TARGET_DEBUGGABLE
#include <dirent.h>
@@ -56,7 +55,7 @@
// "0" means the vndkVersion must be initialized with the property value.
// Otherwise, return the value.
if (vndkVersion == "0") {
- vndkVersion = android::base::GetProperty("ro.vndk.version", "");
+ vndkVersion = base::GetProperty("ro.vndk.version", "");
if (vndkVersion != "" && vndkVersion != "current") {
vndkVersion = "-" + vndkVersion;
} else {
@@ -76,44 +75,44 @@
configureInstrumentation(false);
if (__sanitizer_cov_dump != nullptr) {
::android::add_sysprop_change_callback(
- []() {
- bool enableCoverage = property_get_bool(kSysPropHalCoverage, false);
- if (enableCoverage) {
- __sanitizer_cov_dump();
- }
- },
- 0);
+ []() {
+ bool enableCoverage = base::GetBoolProperty(kSysPropHalCoverage, false);
+ if (enableCoverage) {
+ __sanitizer_cov_dump();
+ }
+ },
+ 0);
}
- if (property_get_bool("ro.vts.coverage", false)) {
+ if (base::GetBoolProperty("ro.vts.coverage", false)) {
const char* prefixOverride = getenv(kGcovPrefixOverrideEnvVar);
if (prefixOverride == nullptr || strcmp(prefixOverride, "true") != 0) {
const std::string gcovPath = kGcovPrefixPath + std::to_string(getpid());
setenv(kGcovPrefixEnvVar, gcovPath.c_str(), true /* overwrite */);
}
::android::add_sysprop_change_callback(
- []() {
- const bool enableCoverage = property_get_bool(kSysPropHalCoverage, false);
- if (enableCoverage) {
- dl_iterate_phdr(
- [](struct dl_phdr_info* info, size_t /* size */, void* /* data */) {
- if (strlen(info->dlpi_name) == 0) return 0;
+ []() {
+ const bool enableCoverage = base::GetBoolProperty(kSysPropHalCoverage, false);
+ if (enableCoverage) {
+ dl_iterate_phdr(
+ [](struct dl_phdr_info* info, size_t /* size */, void* /* data */) {
+ if (strlen(info->dlpi_name) == 0) return 0;
- void* handle = dlopen(info->dlpi_name, RTLD_LAZY);
- if (handle == nullptr) {
- LOG(INFO) << "coverage dlopen failed: " << dlerror();
- return 0;
- }
- void (*flush)() = (void (*)())dlsym(handle, "__gcov_flush");
- if (flush == nullptr) {
- return 0;
- }
- flush();
- return 0;
- },
- nullptr /* data */);
- }
- },
- 0 /* priority */);
+ void* handle = dlopen(info->dlpi_name, RTLD_LAZY);
+ if (handle == nullptr) {
+ LOG(INFO) << "coverage dlopen failed: " << dlerror();
+ return 0;
+ }
+ void (*flush)() = (void (*)())dlsym(handle, "__gcov_flush");
+ if (flush == nullptr) {
+ return 0;
+ }
+ flush();
+ return 0;
+ },
+ nullptr /* data */);
+ }
+ },
+ 0 /* priority */);
}
#endif
}
@@ -121,7 +120,7 @@
HidlInstrumentor::~HidlInstrumentor() {}
void HidlInstrumentor::configureInstrumentation(bool log) {
- mEnableInstrumentation = property_get_bool("hal.instrumentation.enable", false);
+ mEnableInstrumentation = base::GetBoolProperty("hal.instrumentation.enable", false);
if (mEnableInstrumentation) {
if (log) {
LOG(INFO) << "Enable instrumentation.";
@@ -140,8 +139,8 @@
std::vector<InstrumentationCallback> *instrumentationCallbacks) {
#ifdef LIBHIDL_TARGET_DEBUGGABLE
std::vector<std::string> instrumentationLibPaths;
- char instrumentationLibPath[PROPERTY_VALUE_MAX];
- if (property_get(kSysPropInstrumentationPath, instrumentationLibPath, "") > 0) {
+ const std::string instrumentationLibPath = base::GetProperty(kSysPropInstrumentationPath, "");
+ if (instrumentationLibPath.size() > 0) {
instrumentationLibPaths.push_back(instrumentationLibPath);
} else {
static std::string halLibPathVndkSp = android::base::StringPrintf(
diff --git a/test_main.cpp b/test_main.cpp
index 083cee4..fc71231 100644
--- a/test_main.cpp
+++ b/test_main.cpp
@@ -33,6 +33,12 @@
#include <fstream>
#include <vector>
+#ifdef __ANDROID__
+static bool kAndroid = true;
+#else
+static bool kAndroid = false;
+#endif
+
#define EXPECT_ARRAYEQ(__a1__, __a2__, __size__) EXPECT_TRUE(isArrayEqual(__a1__, __a2__, __size__))
#define EXPECT_2DARRAYEQ(__a1__, __a2__, __size1__, __size2__) \
EXPECT_TRUE(is2dArrayEqual(__a1__, __a2__, __size1__, __size2__))
@@ -563,6 +569,10 @@
}
TEST_F(LibHidlTest, PreloadTest) {
+ // HIDL doesn't have support to load passthrough implementations on host, but we
+ // could do this by loading implementations from the output directory
+ if (!kAndroid) GTEST_SKIP();
+
using ::android::hardware::preloadPassthroughService;
using ::android::hidl::memory::V1_0::IMemory;
diff --git a/transport/Android.bp b/transport/Android.bp
index 29c820a..f1b086e 100644
--- a/transport/Android.bp
+++ b/transport/Android.bp
@@ -24,21 +24,28 @@
"libutils",
"libhwbinder",
"libcutils",
- "libvndksupport"
],
export_shared_lib_headers: [
"libutils",
],
target: {
+ android: {
+ shared_libs: [
+ "libvndksupport",
+ ],
+ },
recovery: {
- exclude_shared_libs: ["libvndksupport"],
+ exclude_shared_libs: [
+ "libvndksupport",
+ ],
},
},
}
cc_library_static {
name: "libhidltransport-impl-internal",
+ host_supported: true,
vendor_available: true,
recovery_available: true,
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
}