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

Commit 2ce0d86a authored by Martijn Coenen's avatar Martijn Coenen
Browse files

Call into application to do AppZygote preloading.

For now, assume a class named <package_name>.ZygotePreload
exists, with a method named doPreload() to do the preload.

This should probably be replaced by having an entry in
the manifest.

Bug: 111434506
Test: preload called
Change-Id: Id632e46087eb5c719e6b310ffe007f76d3cbaf7d
parent 01e719be
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.util.Log;

import java.io.DataOutputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Startup class for an Application zygote process.
@@ -70,9 +72,21 @@ class AppZygoteInit {
        protected void handlePreloadApp(ApplicationInfo appInfo) {
            Log.i(TAG, "Beginning application preload for " + appInfo.packageName);
            LoadedApk loadedApk = new LoadedApk(null, appInfo, null, null, false, true, false);
            // Initialize the classLoader
            ClassLoader loader = loadedApk.getClassLoader();

            Class<?> cl;
            Method m;
            try {
                cl = Class.forName(appInfo.packageName + ".ZygotePreload", true, loader);
                m = cl.getMethod("doPreload");
                m.setAccessible(true);
                m.invoke(null);
            } catch (ClassNotFoundException e) {
                // Don't treat this as an error since an app may not want to do any preloads
                Log.w(TAG, "No ZygotePreload class found for " + appInfo.packageName);
            } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
                Log.e(TAG, "AppZygote application preload failed for "
                        + appInfo.packageName, e);
            }
            try {
                DataOutputStream socketOut = getSocketOutputStream();
                socketOut.writeInt(loader != null ? 1 : 0);