Use a different name for shared classloader namespace, to help debugging.
Test: atest libnativeloader_test
Bug: 130388701
Change-Id: I6dbb53cac7fb7ac8fb5178611a164c83c2ab59ba
diff --git a/libnativeloader/library_namespaces.cpp b/libnativeloader/library_namespaces.cpp
index ef97959..03e0814 100644
--- a/libnativeloader/library_namespaces.cpp
+++ b/libnativeloader/library_namespaces.cpp
@@ -56,6 +56,14 @@
constexpr const char* kClassloaderNamespaceName = "classloader-namespace";
// Same thing for vendor APKs.
constexpr const char* kVendorClassloaderNamespaceName = "vendor-classloader-namespace";
+// If the namespace is shared then add this suffix to form
+// "classloader-namespace-shared" or "vendor-classloader-namespace-shared",
+// respectively. A shared namespace (cf. ANDROID_NAMESPACE_TYPE_SHARED) has
+// inherited all the libraries of the parent classloader namespace, or the
+// platform namespace for the main app classloader. It is used to give full
+// access to the platform libraries for apps bundled in the system image,
+// including their later updates installed in /data.
+constexpr const char* kSharedNamespaceSuffix = "-shared";
// (http://b/27588281) This is a workaround for apps using custom classloaders and calling
// System.load() with an absolute path which is outside of the classloader library search path.
@@ -161,7 +169,7 @@
"There is already a namespace associated with this classloader");
std::string system_exposed_libraries = default_public_libraries();
- const char* namespace_name = kClassloaderNamespaceName;
+ std::string namespace_name = kClassloaderNamespaceName;
bool unbundled_vendor_or_product_app = false;
if ((apk_origin == APK_ORIGIN_VENDOR ||
(apk_origin == APK_ORIGIN_PRODUCT && target_sdk_version > 29)) &&
@@ -204,6 +212,12 @@
}
}
+ if (is_shared) {
+ // Show in the name that the namespace was created as shared, for debugging
+ // purposes.
+ namespace_name = namespace_name + kSharedNamespaceSuffix;
+ }
+
// Create the app namespace
NativeLoaderNamespace* parent_ns = FindParentNamespaceByClassLoader(env, class_loader);
// Heuristic: the first classloader with non-empty library_path is assumed to