| Index: apk/hijack/org/chromium/deconstructed/JavaInstaller.java
|
| diff --git a/apk/hijack/org/chromium/deconstructed/JavaInstaller.java b/apk/hijack/org/chromium/deconstructed/JavaInstaller.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..823abaedba01be4acff24f1beaa14322edcbe4f0
|
| --- /dev/null
|
| +++ b/apk/hijack/org/chromium/deconstructed/JavaInstaller.java
|
| @@ -0,0 +1,55 @@
|
| +package org.chromium.deconstructed;
|
| +
|
| +import android.content.Context;
|
| +import android.content.pm.ApplicationInfo;
|
| +import android.util.Log;
|
| +
|
| +import java.io.File;
|
| +import java.io.IOException;
|
| +import java.lang.reflect.InvocationTargetException;
|
| +import java.util.Arrays;
|
| +import java.util.ArrayList;
|
| +import java.util.List;
|
| +
|
| +public class JavaInstaller {
|
| + private static final String TAG = "org.chromium.deconstructed.JavaInstaller";
|
| + private static final String SECONDARY_FOLDER_NAME =
|
| + "code_cache" + File.separator + "deconstructed-dexes";
|
| +
|
| + public static void install(Context context, File dexDir)
|
| + throws NoSuchFieldException, NoSuchMethodException, InvocationTargetException {
|
| + File[] dexFiles = dexDir.listFiles();
|
| + for (File f : dexFiles) {
|
| + if (!isValidDex(f)) {
|
| + return;
|
| + }
|
| + }
|
| + ApplicationInfo appInfo = context.getApplicationInfo();
|
| + File optimizedDir = new File(appInfo.dataDir, SECONDARY_FOLDER_NAME);
|
| + install(context.getClassLoader(), Arrays.asList(dexFiles), optimizedDir);
|
| + }
|
| +
|
| + private static boolean isValidDex(File f) {
|
| + // TODO
|
| + return true;
|
| + }
|
| +
|
| + private static void install(ClassLoader loader, List<File> additionalClassPathEntries,
|
| + File optimizedDirectory) throws IllegalArgumentException, NoSuchFieldException,
|
| + NoSuchMethodException, InvocationTargetException {
|
| + optimizedDirectory.mkdirs();
|
| + Object dexPathList = Reflect.getField(loader, "pathList");
|
| + ArrayList<IOException> suppressedExceptions = new ArrayList<IOException>();
|
| + Object[] dexElements = (Object[]) Reflect.getField(dexPathList, "dexElements");
|
| + Object[] injectedElements = makeDexElements(dexPathList, new ArrayList<File>(additionalClassPathEntries), optimizedDirectory);
|
| + Reflect.setField(
|
| + dexPathList, "dexElements", Reflect.concatArrays(dexElements, injectedElements));
|
| + }
|
| +
|
| + private static Object[] makeDexElements(Object dexPathList, ArrayList<File> files,
|
| + File optimizedDirectory) throws NoSuchMethodException, InvocationTargetException {
|
| + ArrayList<IOException> suppressedExceptions = new ArrayList<IOException>();
|
| + return (Object[]) Reflect.invokeMethod(dexPathList, "makeDexElements", files, optimizedDirectory, suppressedExceptions);
|
| + }
|
| +
|
| +}
|
|
|