Search in sources :

Example 51 with PathClassLoader

use of dalvik.system.PathClassLoader in project android_frameworks_base by crdroidandroid.

the class ApplicationLoaders method getClassLoader.

public ClassLoader getClassLoader(String zip, int targetSdkVersion, boolean isBundled, String librarySearchPath, String libraryPermittedPath, ClassLoader parent) {
    /*
         * This is the parent we use if they pass "null" in.  In theory
         * this should be the "system" class loader; in practice we
         * don't use that and can happily (and more efficiently) use the
         * bootstrap class loader.
         */
    ClassLoader baseParent = ClassLoader.getSystemClassLoader().getParent();
    synchronized (mLoaders) {
        if (parent == null) {
            parent = baseParent;
        }
        /*
             * If we're one step up from the base class loader, find
             * something in our cache.  Otherwise, we create a whole
             * new ClassLoader for the zip archive.
             */
        if (parent == baseParent) {
            ClassLoader loader = mLoaders.get(zip);
            if (loader != null) {
                return loader;
            }
            Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, zip);
            PathClassLoader pathClassloader = PathClassLoaderFactory.createClassLoader(zip, librarySearchPath, libraryPermittedPath, parent, targetSdkVersion, isBundled);
            Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
            Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setupVulkanLayerPath");
            setupVulkanLayerPath(pathClassloader, librarySearchPath);
            Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
            mLoaders.put(zip, pathClassloader);
            return pathClassloader;
        }
        Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, zip);
        PathClassLoader pathClassloader = new PathClassLoader(zip, parent);
        Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
        return pathClassloader;
    }
}
Also used : PathClassLoader(dalvik.system.PathClassLoader) PathClassLoader(dalvik.system.PathClassLoader)

Example 52 with PathClassLoader

use of dalvik.system.PathClassLoader in project android_frameworks_base by crdroidandroid.

the class PathClassLoaderFactory method createClassLoader.

/**
     * Create a PathClassLoader and initialize a linker-namespace for it.
     *
     * @hide
     */
public static PathClassLoader createClassLoader(String dexPath, String librarySearchPath, String libraryPermittedPath, ClassLoader parent, int targetSdkVersion, boolean isNamespaceShared) {
    PathClassLoader pathClassloader = new PathClassLoader(dexPath, librarySearchPath, parent);
    Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "createClassloaderNamespace");
    String errorMessage = createClassloaderNamespace(pathClassloader, targetSdkVersion, librarySearchPath, libraryPermittedPath, isNamespaceShared);
    Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
    if (errorMessage != null) {
        throw new UnsatisfiedLinkError("Unable to create namespace for the classloader " + pathClassloader + ": " + errorMessage);
    }
    return pathClassloader;
}
Also used : PathClassLoader(dalvik.system.PathClassLoader)

Example 53 with PathClassLoader

use of dalvik.system.PathClassLoader in project My-MVP by REBOOTERS.

the class FixDexUtils method doDexInject.

private static void doDexInject(Context appContext, HashSet<File> loadedDex) {
    // data/data/包名/files/optimize_dex(这个必须是自己程序下的目录)
    String optimizeDir = appContext.getFilesDir().getAbsolutePath() + File.separator + OPTIMIZE_DEX_DIR;
    File fopt = new File(optimizeDir);
    if (!fopt.exists()) {
        fopt.mkdirs();
    }
    try {
        // 1.加载应用程序的dex
        PathClassLoader pathLoader = (PathClassLoader) appContext.getClassLoader();
        for (File dex : loadedDex) {
            // 2.加载指定的修复的dex文件
            DexClassLoader dexLoader = new DexClassLoader(// 修复好的dex(补丁)所在目录
            dex.getAbsolutePath(), // 存放dex的解压目录(用于jar、zip、apk格式的补丁)
            fopt.getAbsolutePath(), // 加载dex时需要的库
            null, // 父类加载器
            pathLoader);
            // 3.合并
            Object dexPathList = getPathList(dexLoader);
            Object pathPathList = getPathList(pathLoader);
            Object leftDexElements = getDexElements(dexPathList);
            Object rightDexElements = getDexElements(pathPathList);
            // 合并完成
            Object dexElements = combineArray(leftDexElements, rightDexElements);
            // 重写给PathList里面的Element[] dexElements;赋值
            Object pathList = getPathList(pathLoader);
            setField(pathList, pathList.getClass(), "dexElements", dexElements);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : PathClassLoader(dalvik.system.PathClassLoader) DexClassLoader(dalvik.system.DexClassLoader) File(java.io.File)

Example 54 with PathClassLoader

use of dalvik.system.PathClassLoader in project AndroidLife by CaMnter.

the class HotFix method injectAboveEqualApiLevel14.

/**
 * 大于 API 14 的插桩策略
 *
 * @param context context
 * @param str dex 的路径
 * @param str2 插件 dex 中要修复的类 name
 * @throws ClassNotFoundException
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 */
private static void injectAboveEqualApiLevel14(Context context, String str, String str2) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
    PathClassLoader pathClassLoader = (PathClassLoader) context.getClassLoader();
    Object a = combineArray(getDexElements(getPathList(pathClassLoader)), getDexElements(getPathList(new DexClassLoader(str, context.getDir("dex", 0).getAbsolutePath(), str, context.getClassLoader()))));
    Object a2 = getPathList(pathClassLoader);
    setField(a2, a2.getClass(), "dexElements", a);
    pathClassLoader.loadClass(str2);
}
Also used : PathClassLoader(dalvik.system.PathClassLoader) DexClassLoader(dalvik.system.DexClassLoader)

Example 55 with PathClassLoader

use of dalvik.system.PathClassLoader in project AndroidLife by CaMnter.

the class HotFix method injectBelowApiLevel14.

/**
 * 小于 API 14 的插桩策略
 *
 * @param context context
 * @param str 插件 dex 的路径
 * @param str2 插件 dex 中要修复的类 name
 * @throws ClassNotFoundException
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 */
@TargetApi(14)
private static void injectBelowApiLevel14(Context context, String str, String str2) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
    PathClassLoader obj = (PathClassLoader) context.getClassLoader();
    DexClassLoader dexClassLoader = new DexClassLoader(str, context.getDir("dex", 0).getAbsolutePath(), str, context.getClassLoader());
    dexClassLoader.loadClass(str2);
    setField(obj, PathClassLoader.class, "mPaths", appendArray(getField(obj, PathClassLoader.class, "mPaths"), getField(dexClassLoader, DexClassLoader.class, "mRawDexPath")));
    setField(obj, PathClassLoader.class, "mFiles", combineArray(getField(obj, PathClassLoader.class, "mFiles"), getField(dexClassLoader, DexClassLoader.class, "mFiles")));
    setField(obj, PathClassLoader.class, "mZips", combineArray(getField(obj, PathClassLoader.class, "mZips"), getField(dexClassLoader, DexClassLoader.class, "mZips")));
    setField(obj, PathClassLoader.class, "mDexs", combineArray(getField(obj, PathClassLoader.class, "mDexs"), getField(dexClassLoader, DexClassLoader.class, "mDexs")));
    obj.loadClass(str2);
}
Also used : PathClassLoader(dalvik.system.PathClassLoader) DexClassLoader(dalvik.system.DexClassLoader) TargetApi(android.annotation.TargetApi)

Aggregations

PathClassLoader (dalvik.system.PathClassLoader)57 File (java.io.File)14 DexClassLoader (dalvik.system.DexClassLoader)8 IOException (java.io.IOException)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 TargetApi (android.annotation.TargetApi)4 Context (android.content.Context)4 RemoteException (android.os.RemoteException)4 Method (java.lang.reflect.Method)3 ZipFile (java.util.zip.ZipFile)3 ActivityManagerInternal (android.app.ActivityManagerInternal)2 INotificationManager (android.app.INotificationManager)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2 Intent (android.content.Intent)2 IntentFilter (android.content.IntentFilter)2 Configuration (android.content.res.Configuration)2 Resources (android.content.res.Resources)2 Theme (android.content.res.Resources.Theme)2 CameraAccessException (android.hardware.camera2.CameraAccessException)2 InputManagerInternal (android.hardware.input.InputManagerInternal)2