binder: add openDeclaredPassthroughHal()
It handles dlopen()ing a declared native hal. This can replace
android_load_sphal_library to load declared native instance. The new API
also supports when instances are from APEX.
Bug: 316051788
Test: atest servicemanager_test
Test: atest vts_treble_vintf_vendor_test
Change-Id: I95b752253e0b550d38f0543ff56134d38d838855
diff --git a/libs/ui/Gralloc5.cpp b/libs/ui/Gralloc5.cpp
index c3b2d3d..123bef4 100644
--- a/libs/ui/Gralloc5.cpp
+++ b/libs/ui/Gralloc5.cpp
@@ -83,10 +83,18 @@
return nullptr;
}
- std::string lib_name = "mapper." + mapperSuffix + ".so";
- void *so = android_load_sphal_library(lib_name.c_str(), RTLD_LOCAL | RTLD_NOW);
+ void* so = nullptr;
+ // TODO(b/322384429) switch this to __ANDROID_API_V__ when V is finalized
+ // TODO(b/302113279) use __ANDROID_VENDOR_API__ for vendor variant
+ if (__builtin_available(android __ANDROID_API_FUTURE__, *)) {
+ so = AServiceManager_openDeclaredPassthroughHal("mapper", mapperSuffix.c_str(),
+ RTLD_LOCAL | RTLD_NOW);
+ } else {
+ std::string lib_name = "mapper." + mapperSuffix + ".so";
+ so = android_load_sphal_library(lib_name.c_str(), RTLD_LOCAL | RTLD_NOW);
+ }
if (!so) {
- ALOGE("Failed to load %s", lib_name.c_str());
+ ALOGE("Failed to load mapper.%s.so", mapperSuffix.c_str());
}
return so;
}();