Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 44fadb21 authored by Dimitry Ivanov's avatar Dimitry Ivanov
Browse files

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
(cherry picked from commit 75b10ecc)

Change-Id: I836e5fed4713f2a605a5de673c40970ef6d988dd
parent 78d5f90d
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ class ApplicationLoaders
        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 @@ class ApplicationLoaders
    
                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);
+11 −4
Original line number Diff line number Diff line
@@ -359,12 +359,21 @@ public final class LoadedApk {
                    }
                }

                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);
@@ -382,10 +391,8 @@ public final class LoadedApk {
                // 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 {
+1 −1
Original line number Diff line number Diff line
@@ -270,7 +270,7 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName
    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);