Add GraphicBufferMapper::preloadHal
Plumbing to allow Zygote to explicitly preload the a.h.graphics.mapper
HAL. An earlier attempt did this implicitly with a static initializer in
libui.so, but the library is also used by non-Zygote processes that
don't have access to HALs. This way, the HIDL libraries and HAL are only
loaded in Zygote and its children, not random other processes.
Bug: 62353585
Test: check that a.h.graphics.mapper is in /proc/`pid zygote64`/maps
Change-Id: I4989c8089e3a4cfd627f8940f5552950c1c617fc
diff --git a/libs/ui/Gralloc2.cpp b/libs/ui/Gralloc2.cpp
index 87dbaf4..0eb08e5 100644
--- a/libs/ui/Gralloc2.cpp
+++ b/libs/ui/Gralloc2.cpp
@@ -16,6 +16,7 @@
#define LOG_TAG "Gralloc2"
+#include <hidl/ServiceManagement.h>
#include <hwbinder/IPCThreadState.h>
#include <ui/Gralloc2.h>
@@ -31,6 +32,10 @@
static constexpr Error kTransactionError = Error::NO_RESOURCES;
+void Mapper::preload() {
+ android::hardware::preloadPassthroughService<hardware::graphics::mapper::V2_0::IMapper>();
+}
+
Mapper::Mapper()
{
mMapper = IMapper::getService();