Skip to content

Commit b66de05

Browse files
Jooyung Hanandroid-build-merge-worker-robot
authored andcommitted
Merge "binder: add openDeclaredPassthroughHal()" into main am: a38f2a9
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2952185 Change-Id: I3f85fe1ad55fa4fc4adffaa9c1c74e831106dac7 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2 parents 6be5e45 + a38f2a9 commit b66de05

7 files changed

Lines changed: 77 additions & 3 deletions

File tree

libs/binder/Android.bp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,24 @@ cc_defaults {
320320
"ServiceManagerHost.cpp",
321321
],
322322
},
323+
android: {
324+
shared_libs: [
325+
"libapexsupport",
326+
"libvndksupport",
327+
],
328+
},
329+
recovery: {
330+
exclude_shared_libs: [
331+
"libapexsupport",
332+
"libvndksupport",
333+
],
334+
},
335+
native_bridge: {
336+
exclude_shared_libs: [
337+
"libapexsupport",
338+
"libvndksupport",
339+
],
340+
},
323341
},
324342
cflags: [
325343
"-DBINDER_WITH_KERNEL_IPC",

libs/binder/IServiceManager.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
#include "ServiceManagerHost.h"
4141
#endif
4242

43+
#if defined(__ANDROID__) && !defined(__ANDROID_RECOVERY__) && !defined(__ANDROID_NATIVE_BRIDGE__)
44+
#include <android/apexsupport.h>
45+
#include <vndksupport/linker.h>
46+
#endif
47+
4348
#include "Static.h"
4449

4550
namespace android {
@@ -259,6 +264,27 @@ bool checkPermission(const String16& permission, pid_t pid, uid_t uid, bool logP
259264
}
260265
}
261266

267+
void* openDeclaredPassthroughHal(const String16& interface, const String16& instance, int flag) {
268+
#if defined(__ANDROID__) && !defined(__ANDROID_RECOVERY__) && !defined(__ANDROID_NATIVE_BRIDGE__)
269+
sp<IServiceManager> sm = defaultServiceManager();
270+
String16 name = interface + String16("/") + instance;
271+
if (!sm->isDeclared(name)) {
272+
return nullptr;
273+
}
274+
String16 libraryName = interface + String16(".") + instance + String16(".so");
275+
if (auto updatableViaApex = sm->updatableViaApex(name); updatableViaApex.has_value()) {
276+
return AApexSupport_loadLibrary(String8(libraryName).c_str(),
277+
String8(*updatableViaApex).c_str(), flag);
278+
}
279+
return android_load_sphal_library(String8(libraryName).c_str(), flag);
280+
#else
281+
(void)interface;
282+
(void)instance;
283+
(void)flag;
284+
return nullptr;
285+
#endif
286+
}
287+
262288
#endif //__ANDROID_VNDK__
263289

264290
// ----------------------------------------------------------------------

libs/binder/include/binder/IServiceManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ status_t getService(const String16& name, sp<INTERFACE>* outService)
207207
return NAME_NOT_FOUND;
208208
}
209209

210+
void* openDeclaredPassthroughHal(const String16& interface, const String16& instance, int flag);
211+
210212
bool checkCallingPermission(const String16& permission);
211213
bool checkCallingPermission(const String16& permission,
212214
int32_t* outPid, int32_t* outUid);

libs/binder/ndk/include_platform/android/binder_manager.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,18 @@ void AServiceManager_getUpdatableApexName(const char* instance, void* context,
242242
void (*callback)(const char*, void*))
243243
__INTRODUCED_IN(__ANDROID_API_U__);
244244

245+
/**
246+
* Opens a declared passthrough HAL.
247+
*
248+
* \param instance identifier of the passthrough service (e.g. "mapper")
249+
* \param instance identifier of the implemenatation (e.g. "default")
250+
* \param flag passed to dlopen()
251+
*/
252+
void* AServiceManager_openDeclaredPassthroughHal(const char* interface, const char* instance,
253+
int flag)
254+
// TODO(b/302113279) use __INTRODUCED_LLNDK for vendor variants
255+
__INTRODUCED_IN(__ANDROID_API_V__);
256+
245257
/**
246258
* Prevent lazy services without client from shutting down their process
247259
*

libs/binder/ndk/libbinder_ndk.map.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ LIBBINDER_NDK35 { # introduced=VanillaIceCream
204204
APersistableBundle_getDoubleVectorKeys;
205205
APersistableBundle_getStringVectorKeys;
206206
APersistableBundle_getPersistableBundleKeys;
207+
AServiceManager_openDeclaredPassthroughHal; # systemapi llndk
207208
};
208209

209210
LIBBINDER_NDK_PLATFORM {

libs/binder/ndk/service_manager.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ void AServiceManager_getUpdatableApexName(const char* instance, void* context,
200200
callback(String8(updatableViaApex.value()).c_str(), context);
201201
}
202202
}
203+
void* AServiceManager_openDeclaredPassthroughHal(const char* interface, const char* instance,
204+
int flag) {
205+
LOG_ALWAYS_FATAL_IF(interface == nullptr, "interface == nullptr");
206+
LOG_ALWAYS_FATAL_IF(instance == nullptr, "instance == nullptr");
207+
208+
return openDeclaredPassthroughHal(String16(interface), String16(instance), flag);
209+
}
203210
void AServiceManager_forceLazyServicesPersist(bool persist) {
204211
auto serviceRegistrar = android::binder::LazyServiceRegistrar::getInstance();
205212
serviceRegistrar.forcePersist(persist);

libs/ui/Gralloc5.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,18 @@ static void *loadIMapperLibrary() {
8888
return nullptr;
8989
}
9090

91-
std::string lib_name = "mapper." + mapperSuffix + ".so";
92-
void *so = android_load_sphal_library(lib_name.c_str(), RTLD_LOCAL | RTLD_NOW);
91+
void* so = nullptr;
92+
// TODO(b/322384429) switch this to __ANDROID_API_V__ when V is finalized
93+
// TODO(b/302113279) use __ANDROID_VENDOR_API__ for vendor variant
94+
if (__builtin_available(android __ANDROID_API_FUTURE__, *)) {
95+
so = AServiceManager_openDeclaredPassthroughHal("mapper", mapperSuffix.c_str(),
96+
RTLD_LOCAL | RTLD_NOW);
97+
} else {
98+
std::string lib_name = "mapper." + mapperSuffix + ".so";
99+
so = android_load_sphal_library(lib_name.c_str(), RTLD_LOCAL | RTLD_NOW);
100+
}
93101
if (!so) {
94-
ALOGE("Failed to load %s", lib_name.c_str());
102+
ALOGE("Failed to load mapper.%s.so", mapperSuffix.c_str());
95103
}
96104
return so;
97105
}();

0 commit comments

Comments
 (0)