Use shared namespace for bundled app classloader
Allow bundled apps to reference platform native libraries
located in subdirectories of the default library path
(/system/lib/hw/* for example).
In addition to this bundled apps need to share native
libraries with default namespace. Added parameter to
ApplicationLoaders.createClassLoader() to do just that.
Bug: 26165097
Bug: 26164393
Change-Id: I833b4f758c4df8f8958d72eafd5d47ef14079ce1
diff --git a/core/java/android/app/ApplicationLoaders.java b/core/java/android/app/ApplicationLoaders.java
index ddb2d46..7d0d1b4 100644
--- a/core/java/android/app/ApplicationLoaders.java
+++ b/core/java/android/app/ApplicationLoaders.java
@@ -27,7 +27,7 @@
return gApplicationLoaders;
}
- public ClassLoader getClassLoader(String zip, String librarySearchPath,
+ public ClassLoader getClassLoader(String zip, boolean isBundled, String librarySearchPath,
String libraryPermittedPath, ClassLoader parent)
{
/*
@@ -56,7 +56,8 @@
Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, zip);
PathClassLoader pathClassloader =
- new PathClassLoader(zip, librarySearchPath, libraryPermittedPath, parent);
+ new PathClassLoader(zip, isBundled, librarySearchPath,
+ libraryPermittedPath, parent);
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
mLoaders.put(zip, pathClassloader);
diff --git a/core/java/android/app/LoadedApk.java b/core/java/android/app/LoadedApk.java
index 7313fd1..855b21e 100644
--- a/core/java/android/app/LoadedApk.java
+++ b/core/java/android/app/LoadedApk.java
@@ -366,12 +366,21 @@
}
}
+ String libraryPermittedPath = mAppDir + File.pathSeparator + mDataDir;
+ boolean isBundledApp = false;
+
if (mApplicationInfo.isSystemApp()) {
+ isBundledApp = true;
// Add path to system libraries to libPaths;
// Access to system libs should be limited
// to bundled applications; this is why updated
// system apps are not included.
libPaths.add(System.getProperty("java.library.path"));
+
+ // This is necessary to grant bundled apps access to
+ // libraries located in subdirectories of /system/lib
+ libraryPermittedPath += File.pathSeparator +
+ System.getProperty("java.library.path");
}
final String librarySearchPath = TextUtils.join(File.pathSeparator, libPaths);
@@ -389,10 +398,8 @@
// as this is early and necessary.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
- String libraryPermittedPath = mAppDir + File.pathSeparator + mDataDir;
-
- mClassLoader = ApplicationLoaders.getDefault().getClassLoader(zip, librarySearchPath,
- libraryPermittedPath, mBaseClassLoader);
+ mClassLoader = ApplicationLoaders.getDefault().getClassLoader(zip, isBundledApp,
+ librarySearchPath, libraryPermittedPath, mBaseClassLoader);
StrictMode.setThreadPolicy(oldPolicy);
} else {
diff --git a/core/jni/android_app_NativeActivity.cpp b/core/jni/android_app_NativeActivity.cpp
index 6ecb3fb..88a56d2 100644
--- a/core/jni/android_app_NativeActivity.cpp
+++ b/core/jni/android_app_NativeActivity.cpp
@@ -270,7 +270,7 @@
bool needNativeBridge = false;
void* handle = OpenNativeLibrary(env, sdkVersion, pathStr, classLoader,
- libraryPath, isolationPath);
+ false, libraryPath, isolationPath);
if (handle == NULL) {
if (NativeBridgeIsSupported(pathStr)) {
handle = NativeBridgeLoadLibrary(pathStr, RTLD_LAZY);