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

Commit f9419f0f authored by Narayan Kamath's avatar Narayan Kamath
Browse files

Allow splits to declare a classloader type.

Add an attribute android:classLoader which can be set to the name
of the classloader the base or split wishes to use. For now, this can
only be set to "dalvik.system.PathClassLoader" or
"dalvik.system.DelegateLastClassLoader". The current implementation
only allows the classloader to exist in the boot classpath but that
restriction can be loosened in a future change if necessary.

Test: cts-tradefed run cts-dev -m CtsAppSecurityHostTestCases
Bug: 36044779

Change-Id: I5a51f7aa0c8c4c398d2f46129eb06785cc8e3c3f
parent c276c79e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -388,6 +388,7 @@ package android {
    field public static final int childIndicatorRight = 16843024; // 0x1010110
    field public static final int childIndicatorStart = 16843731; // 0x10103d3
    field public static final int choiceMode = 16843051; // 0x101012b
    field public static final int classLoader = 16844139; // 0x101056b
    field public static final int clearTaskOnLaunch = 16842773; // 0x1010015
    field public static final int clickable = 16842981; // 0x10100e5
    field public static final int clipChildren = 16842986; // 0x10100ea
+1 −0
Original line number Diff line number Diff line
@@ -511,6 +511,7 @@ package android {
    field public static final int childIndicatorRight = 16843024; // 0x1010110
    field public static final int childIndicatorStart = 16843731; // 0x10103d3
    field public static final int choiceMode = 16843051; // 0x101012b
    field public static final int classLoader = 16844139; // 0x101056b
    field public static final int clearTaskOnLaunch = 16842773; // 0x1010015
    field public static final int clickable = 16842981; // 0x10100e5
    field public static final int clipChildren = 16842986; // 0x10100ea
+1 −0
Original line number Diff line number Diff line
@@ -388,6 +388,7 @@ package android {
    field public static final int childIndicatorRight = 16843024; // 0x1010110
    field public static final int childIndicatorStart = 16843731; // 0x10103d3
    field public static final int choiceMode = 16843051; // 0x101012b
    field public static final int classLoader = 16844139; // 0x101056b
    field public static final int clearTaskOnLaunch = 16842773; // 0x1010015
    field public static final int clickable = 16842981; // 0x10100e5
    field public static final int clipChildren = 16842986; // 0x10100ea
+1 −1
Original line number Diff line number Diff line
@@ -414,7 +414,7 @@ public final class Pm {
                try {
                    ApkLite baseApk = PackageParser.parseApkLite(file, 0);
                    PackageLite pkgLite = new PackageLite(null, baseApk, null, null, null, null,
                            null, null);
                            null, null, null);
                    params.sessionParams.setSize(
                            PackageHelper.calculateInstalledSize(pkgLite, false,
                            params.sessionParams.abiOverride));
+16 −19
Original line number Diff line number Diff line
@@ -18,9 +18,8 @@ package android.app;

import android.os.Build;
import android.os.Trace;
import android.text.TextUtils;
import android.util.ArrayMap;
import com.android.internal.os.PathClassLoaderFactory;
import com.android.internal.os.ClassLoaderFactory;
import dalvik.system.PathClassLoader;

/** @hide */
@@ -31,15 +30,16 @@ public class ApplicationLoaders {

    ClassLoader getClassLoader(String zip, int targetSdkVersion, boolean isBundled,
                               String librarySearchPath, String libraryPermittedPath,
                               ClassLoader parent) {
                               ClassLoader parent, String classLoaderName) {
        // For normal usage the cache key used is the same as the zip path.
        return getClassLoader(zip, targetSdkVersion, isBundled, librarySearchPath,
                              libraryPermittedPath, parent, zip);
                              libraryPermittedPath, parent, zip, classLoaderName);
    }

    private ClassLoader getClassLoader(String zip, int targetSdkVersion, boolean isBundled,
                                       String librarySearchPath, String libraryPermittedPath,
                                       ClassLoader parent, String cacheKey) {
                                       ClassLoader parent, String cacheKey,
                                       String classLoaderName) {
        /*
         * This is the parent we use if they pass "null" in.  In theory
         * this should be the "system" class loader; in practice we
@@ -66,28 +66,25 @@ public class ApplicationLoaders {

                Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, zip);

                PathClassLoader pathClassloader = PathClassLoaderFactory.createClassLoader(
                                                      zip,
                                                      librarySearchPath,
                                                      libraryPermittedPath,
                                                      parent,
                                                      targetSdkVersion,
                                                      isBundled);
                ClassLoader classloader = ClassLoaderFactory.createClassLoader(
                        zip,  librarySearchPath, libraryPermittedPath, parent,
                        targetSdkVersion, isBundled, classLoaderName);

                Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);

                Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setupVulkanLayerPath");
                setupVulkanLayerPath(pathClassloader, librarySearchPath);
                setupVulkanLayerPath(classloader, librarySearchPath);
                Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);

                mLoaders.put(cacheKey, pathClassloader);
                return pathClassloader;
                mLoaders.put(cacheKey, classloader);
                return classloader;
            }

            Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, zip);
            PathClassLoader pathClassloader = new PathClassLoader(zip, parent);
            ClassLoader loader = ClassLoaderFactory.createClassLoader(
                    zip, null, parent, classLoaderName);
            Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
            return pathClassloader;
            return loader;
        }
    }

@@ -105,7 +102,7 @@ public class ApplicationLoaders {
        // The cache key is passed separately to enable the stub WebView to be cached under the
        // stub's APK path, when the actual package path is the donor APK.
        return getClassLoader(packagePath, Build.VERSION.SDK_INT, false, libsPath, null, null,
                              cacheKey);
                              cacheKey, null /* classLoaderName */);
    }

    private static native void setupVulkanLayerPath(ClassLoader classLoader, String librarySearchPath);
@@ -122,7 +119,7 @@ public class ApplicationLoaders {
        baseDexClassLoader.addDexPath(dexPath);
    }

    private final ArrayMap<String, ClassLoader> mLoaders = new ArrayMap<String, ClassLoader>();
    private final ArrayMap<String, ClassLoader> mLoaders = new ArrayMap<>();

    private static final ApplicationLoaders gApplicationLoaders = new ApplicationLoaders();
}
Loading