Merge "Use shared namespace for bundled app classloader"

This commit is contained in:
Dimitry Ivanov
2015-12-21 23:10:49 +00:00
committed by Gerrit Code Review
3 changed files with 15 additions and 7 deletions

View File

@@ -27,7 +27,7 @@ class ApplicationLoaders
return gApplicationLoaders; return gApplicationLoaders;
} }
public ClassLoader getClassLoader(String zip, String librarySearchPath, public ClassLoader getClassLoader(String zip, boolean isBundled, String librarySearchPath,
String libraryPermittedPath, ClassLoader parent) String libraryPermittedPath, ClassLoader parent)
{ {
/* /*
@@ -56,7 +56,8 @@ class ApplicationLoaders
Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, zip); Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, zip);
PathClassLoader pathClassloader = PathClassLoader pathClassloader =
new PathClassLoader(zip, librarySearchPath, libraryPermittedPath, parent); new PathClassLoader(zip, isBundled, librarySearchPath,
libraryPermittedPath, parent);
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
mLoaders.put(zip, pathClassloader); mLoaders.put(zip, pathClassloader);

View File

@@ -359,12 +359,21 @@ public final class LoadedApk {
} }
} }
String libraryPermittedPath = mAppDir + File.pathSeparator + mDataDir;
boolean isBundledApp = false;
if (mApplicationInfo.isSystemApp()) { if (mApplicationInfo.isSystemApp()) {
isBundledApp = true;
// Add path to system libraries to libPaths; // Add path to system libraries to libPaths;
// Access to system libs should be limited // Access to system libs should be limited
// to bundled applications; this is why updated // to bundled applications; this is why updated
// system apps are not included. // system apps are not included.
libPaths.add(System.getProperty("java.library.path")); 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); final String librarySearchPath = TextUtils.join(File.pathSeparator, libPaths);
@@ -382,10 +391,8 @@ public final class LoadedApk {
// as this is early and necessary. // as this is early and necessary.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
String libraryPermittedPath = mAppDir + File.pathSeparator + mDataDir; mClassLoader = ApplicationLoaders.getDefault().getClassLoader(zip, isBundledApp,
librarySearchPath, libraryPermittedPath, mBaseClassLoader);
mClassLoader = ApplicationLoaders.getDefault().getClassLoader(zip, librarySearchPath,
libraryPermittedPath, mBaseClassLoader);
StrictMode.setThreadPolicy(oldPolicy); StrictMode.setThreadPolicy(oldPolicy);
} else { } else {

View File

@@ -270,7 +270,7 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName
bool needNativeBridge = false; bool needNativeBridge = false;
void* handle = OpenNativeLibrary(env, sdkVersion, pathStr, classLoader, void* handle = OpenNativeLibrary(env, sdkVersion, pathStr, classLoader,
libraryPath, isolationPath); false, libraryPath, isolationPath);
if (handle == NULL) { if (handle == NULL) {
if (NativeBridgeIsSupported(pathStr)) { if (NativeBridgeIsSupported(pathStr)) {
handle = NativeBridgeLoadLibrary(pathStr, RTLD_LAZY); handle = NativeBridgeLoadLibrary(pathStr, RTLD_LAZY);