summaryrefslogtreecommitdiffstats
path: root/libnativebridge
diff options
context:
space:
mode:
authordimitry <dimitry@google.com>2019-02-04 15:06:43 +0100
committerdimitry <dimitry@google.com>2019-02-04 15:06:43 +0100
commitd2ace387f58baa34061f1deea1f1a03f5b392e1a (patch)
tree5e2be0e14b2bd3d3b08e3a95d6f44df8abb2b032 /libnativebridge
parentfaa6c4894d76a4b173f2161bcd22603489331545 (diff)
downloadsystem_core-d2ace387f58baa34061f1deea1f1a03f5b392e1a.tar.gz
system_core-d2ace387f58baa34061f1deea1f1a03f5b392e1a.tar.bz2
system_core-d2ace387f58baa34061f1deea1f1a03f5b392e1a.zip
Add getExportedNamespace NB callback
This callback replaces getVendorNamespace(). Fix nativeloader to use NativeBridgeGetExportedNamespace instead of NativeBridgeGetVendorNamespace. Bug: http://b/121248172 Bug: http://b/121372395 Test: make Change-Id: I8fa2081e37815f6f65490c9536bed0687b7f1e77
Diffstat (limited to 'libnativebridge')
-rw-r--r--libnativebridge/include/nativebridge/native_bridge.h15
-rw-r--r--libnativebridge/libnativebridge.map.txt2
-rw-r--r--libnativebridge/native_bridge.cc18
3 files changed, 29 insertions, 6 deletions
diff --git a/libnativebridge/include/nativebridge/native_bridge.h b/libnativebridge/include/nativebridge/native_bridge.h
index 5aea9670b..e9c950025 100644
--- a/libnativebridge/include/nativebridge/native_bridge.h
+++ b/libnativebridge/include/nativebridge/native_bridge.h
@@ -164,8 +164,9 @@ bool NativeBridgeLinkNamespaces(struct native_bridge_namespace_t* from,
void* NativeBridgeLoadLibraryExt(const char* libpath, int flag,
struct native_bridge_namespace_t* ns);
-// Returns vendor namespace if it is enabled for the device and null otherwise
-struct native_bridge_namespace_t* NativeBridgeGetVendorNamespace();
+// Returns exported namespace by the name. This is a reflection of
+// android_get_exported_namespace function. Introduced in v5.
+struct native_bridge_namespace_t* NativeBridgeGetExportedNamespace(const char* name);
// Native bridge interfaces to runtime.
struct NativeBridgeCallbacks {
@@ -362,7 +363,17 @@ struct NativeBridgeCallbacks {
//
// Returns:
// vendor namespace or null if it was not set up for the device
+ //
+ // Starting with v5 (Android Q) this function is no longer used.
+ // Use getExportedNamespace() below.
struct native_bridge_namespace_t* (*getVendorNamespace)();
+
+ // Get native bridge version of exported namespace. Peer of
+ // android_get_exported_namespace(const char*) function.
+ //
+ // Returns:
+ // exported namespace or null if it was not set up for the device
+ struct native_bridge_namespace_t* (*getExportedNamespace)(const char* name);
};
// Runtime interfaces to native bridge.
diff --git a/libnativebridge/libnativebridge.map.txt b/libnativebridge/libnativebridge.map.txt
index a616b8526..a6841a3a8 100644
--- a/libnativebridge/libnativebridge.map.txt
+++ b/libnativebridge/libnativebridge.map.txt
@@ -24,7 +24,7 @@ LIBNATIVEBRIDGE_1 {
NativeBridgeGetError;
NativeBridgeIsPathSupported;
NativeBridgeCreateNamespace;
- NativeBridgeGetVendorNamespace;
+ NativeBridgeGetExportedNamespace;
NativeBridgeLinkNamespaces;
NativeBridgeLoadLibraryExt;
NativeBridgeInitAnonymousNamespace;
diff --git a/libnativebridge/native_bridge.cc b/libnativebridge/native_bridge.cc
index a2d8d81ef..9adba9a50 100644
--- a/libnativebridge/native_bridge.cc
+++ b/libnativebridge/native_bridge.cc
@@ -101,6 +101,8 @@ enum NativeBridgeImplementationVersion {
NAMESPACE_VERSION = 3,
// The version with vendor namespaces
VENDOR_NAMESPACE_VERSION = 4,
+ // The version with runtime namespaces
+ RUNTIME_NAMESPACE_VERSION = 5,
};
// Whether we had an error at some point.
@@ -610,12 +612,22 @@ bool NativeBridgeLinkNamespaces(native_bridge_namespace_t* from, native_bridge_n
return false;
}
-native_bridge_namespace_t* NativeBridgeGetVendorNamespace() {
- if (!NativeBridgeInitialized() || !isCompatibleWith(VENDOR_NAMESPACE_VERSION)) {
+native_bridge_namespace_t* NativeBridgeGetExportedNamespace(const char* name) {
+ if (!NativeBridgeInitialized()) {
return nullptr;
}
- return callbacks->getVendorNamespace();
+ if (isCompatibleWith(RUNTIME_NAMESPACE_VERSION)) {
+ return callbacks->getExportedNamespace(name);
+ }
+
+ // sphal is vendor namespace name -> use v4 callback in the case NB callbacks
+ // are not compatible with v5
+ if (isCompatibleWith(VENDOR_NAMESPACE_VERSION) && name != nullptr && strcmp("sphal", name) == 0) {
+ return callbacks->getVendorNamespace();
+ }
+
+ return nullptr;
}
void* NativeBridgeLoadLibraryExt(const char* libpath, int flag, native_bridge_namespace_t* ns) {