• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java ProcessCompat类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中com.morgoo.helper.compat.ProcessCompat的典型用法代码示例。如果您正苦于以下问题:Java ProcessCompat类的具体用法?Java ProcessCompat怎么用?Java ProcessCompat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

ProcessCompat类属于com.morgoo.helper.compat包,在下文中一共展示了ProcessCompat类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: preLoadApk

点赞 2

import com.morgoo.helper.compat.ProcessCompat; //导入依赖的package包/类
public static void preLoadApk(Context hostContext, ComponentInfo pluginInfo) throws IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, PackageManager.NameNotFoundException, ClassNotFoundException {
    if (pluginInfo == null && hostContext == null) {
        return;
    }
    if (pluginInfo != null && getPluginContext(pluginInfo.packageName) != null) {
        return;
    }

    /*添加插件的LoadedApk对象到ActivityThread.mPackages*/

    boolean found = false;
    synchronized (sPluginLoadedApkCache) {
        Object object = ActivityThreadCompat.currentActivityThread();
        if (object != null) {
            Object mPackagesObj = FieldUtils.readField(object, "mPackages");
            Object containsKeyObj = MethodUtils.invokeMethod(mPackagesObj, "containsKey", pluginInfo.packageName);
            if (containsKeyObj instanceof Boolean && !(Boolean) containsKeyObj) {
                final Object loadedApk;
                if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
                    loadedApk = MethodUtils.invokeMethod(object, "getPackageInfoNoCheck", pluginInfo.applicationInfo, CompatibilityInfoCompat.DEFAULT_COMPATIBILITY_INFO());
                } else {
                    loadedApk = MethodUtils.invokeMethod(object, "getPackageInfoNoCheck", pluginInfo.applicationInfo);
                }
                sPluginLoadedApkCache.put(pluginInfo.packageName, loadedApk);

            /*添加ClassLoader LoadedApk.mClassLoader*/

                String optimizedDirectory = PluginDirHelper.getPluginDalvikCacheDir(hostContext, pluginInfo.packageName);
                String libraryPath = PluginDirHelper.getPluginNativeLibraryDir(hostContext, pluginInfo.packageName);
                String apk = pluginInfo.applicationInfo.publicSourceDir;
                if (TextUtils.isEmpty(apk)) {
                    pluginInfo.applicationInfo.publicSourceDir = PluginDirHelper.getPluginApkFile(hostContext, pluginInfo.packageName);
                    apk = pluginInfo.applicationInfo.publicSourceDir;
                }
                if (apk != null) {
                    ClassLoader classloader = null;
                    try {
                        classloader = new PluginClassLoader(apk, optimizedDirectory, libraryPath, ClassLoader.getSystemClassLoader());
                    } catch (Exception e) {
                    }
                    if(classloader==null){
                        PluginDirHelper.cleanOptimizedDirectory(optimizedDirectory);
                        classloader = new PluginClassLoader(apk, optimizedDirectory, libraryPath, ClassLoader.getSystemClassLoader());
                    }
                    synchronized (loadedApk) {
                        FieldUtils.writeDeclaredField(loadedApk, "mClassLoader", classloader);
                    }
                    sPluginClassLoaderCache.put(pluginInfo.packageName, classloader);
                    Thread.currentThread().setContextClassLoader(classloader);
                    found = true;
                }
                ProcessCompat.setArgV0(pluginInfo.processName);
            }
        }
    }
    if (found) {
        PluginProcessManager.preMakeApplication(hostContext, pluginInfo);
    }
}
 

开发者ID:amikey,
项目名称:DroidPlugin,
代码行数:60,
代码来源:PluginProcessManager.java

示例2: preLoadApk

点赞 2

import com.morgoo.helper.compat.ProcessCompat; //导入依赖的package包/类
public static void preLoadApk(Context hostContext, ComponentInfo pluginInfo) throws IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, PackageManager.NameNotFoundException, ClassNotFoundException {
    if (pluginInfo == null && hostContext == null) {
        return;
    }
    if (pluginInfo != null && getPluginContext(pluginInfo.packageName) != null) {
        return;
    }

    /*添加插件的LoadedApk对象到ActivityThread.mPackages*/

    boolean found = false;
    synchronized (sPluginLoadedApkCache) {
        Object object = ActivityThreadCompat.currentActivityThread();
        if (object != null) {
            Object mPackagesObj = FieldUtils.readField(object, "mPackages");
            Object containsKeyObj = MethodUtils.invokeMethod(mPackagesObj, "containsKey", pluginInfo.packageName);
            if (containsKeyObj instanceof Boolean && !(Boolean) containsKeyObj) {
                final Object loadedApk;
                if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
                    loadedApk = MethodUtils.invokeMethod(object, "getPackageInfoNoCheck", pluginInfo.applicationInfo, CompatibilityInfoCompat.DEFAULT_COMPATIBILITY_INFO());
                } else {
                    loadedApk = MethodUtils.invokeMethod(object, "getPackageInfoNoCheck", pluginInfo.applicationInfo);
                }
                sPluginLoadedApkCache.put(pluginInfo.packageName, loadedApk);

            /*添加ClassLoader LoadedApk.mClassLoader*/

                String optimizedDirectory = PluginDirHelper.getPluginDalvikCacheDir(hostContext, pluginInfo.packageName);
                String libraryPath = PluginDirHelper.getPluginNativeLibraryDir(hostContext, pluginInfo.packageName);
                String apk = pluginInfo.applicationInfo.publicSourceDir;
                if (TextUtils.isEmpty(apk)) {
                    pluginInfo.applicationInfo.publicSourceDir = PluginDirHelper.getPluginApkFile(hostContext, pluginInfo.packageName);
                    apk = pluginInfo.applicationInfo.publicSourceDir;
                }
                if (apk != null) {
                    ClassLoader classloader = new PluginClassLoader(apk, optimizedDirectory, libraryPath, ClassLoader.getSystemClassLoader());
                    synchronized (loadedApk) {
                        FieldUtils.writeDeclaredField(loadedApk, "mClassLoader", classloader);
                    }
                    sPluginClassLoaderCache.put(pluginInfo.packageName, classloader);
                    Thread.currentThread().setContextClassLoader(classloader);
                    found = true;
                }
                ProcessCompat.setArgV0(pluginInfo.processName);
            }
        }
    }
    if (found) {
        PluginProcessManager.preMakeApplication(hostContext, pluginInfo);
    }
}
 

开发者ID:SteamedBunZL,
项目名称:DroidPluginLibrary,
代码行数:52,
代码来源:PluginProcessManager.java

示例3: preLoadApk

点赞 2

import com.morgoo.helper.compat.ProcessCompat; //导入依赖的package包/类
public static void preLoadApk(Context hostContext, ComponentInfo pluginInfo) throws IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, PackageManager.NameNotFoundException, ClassNotFoundException {
    if (pluginInfo == null && hostContext == null) {
        return;
    }
    if (pluginInfo != null && getPluginContext(pluginInfo.packageName) != null) {
        return;
    }

    /*添加插件的LoadedApk对象到ActivityThread.mPackages*/

    boolean found = false;
    synchronized (sPluginLoadedApkCache) {
        Object object = ActivityThreadCompat.currentActivityThread();
        if (object != null) {
            Object mPackagesObj = FieldUtils.readField(object, "mPackages");
            Object containsKeyObj = MethodUtils.invokeMethod(mPackagesObj, "containsKey", pluginInfo.packageName);
            if (containsKeyObj instanceof Boolean && !(Boolean) containsKeyObj) {
                final Object loadedApk;
                if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
                    loadedApk = MethodUtils.invokeMethod(object, "getPackageInfoNoCheck", pluginInfo.applicationInfo, CompatibilityInfoCompat.DEFAULT_COMPATIBILITY_INFO());
                } else {
                    loadedApk = MethodUtils.invokeMethod(object, "getPackageInfoNoCheck", pluginInfo.applicationInfo);
                }
                sPluginLoadedApkCache.put(pluginInfo.packageName, loadedApk);

            /*添加ClassLoader LoadedApk.mClassLoader*/

                String optimizedDirectory = PluginDirHelper.getPluginDalvikCacheDir(hostContext, pluginInfo.packageName);
                String libraryPath = PluginDirHelper.getPluginNativeLibraryDir(hostContext, pluginInfo.packageName);
                String apk = pluginInfo.applicationInfo.publicSourceDir;
                if (TextUtils.isEmpty(apk)) {
                    pluginInfo.applicationInfo.publicSourceDir = PluginDirHelper.getPluginApkFile(hostContext, pluginInfo.packageName);
                    apk = pluginInfo.applicationInfo.publicSourceDir;
                }
                if (apk != null) {
                    ClassLoader classloader = null;
                    try {
                        classloader = new PluginClassLoader(apk, optimizedDirectory, libraryPath, hostContext.getClassLoader().getParent());
                    } catch (Exception e) {
                    }
                    if(classloader==null){
                        PluginDirHelper.cleanOptimizedDirectory(optimizedDirectory);
                        classloader = new PluginClassLoader(apk, optimizedDirectory, libraryPath, hostContext.getClassLoader().getParent());
                    }
                    synchronized (loadedApk) {
                        FieldUtils.writeDeclaredField(loadedApk, "mClassLoader", classloader);
                    }
                    sPluginClassLoaderCache.put(pluginInfo.packageName, classloader);
                    Thread.currentThread().setContextClassLoader(classloader);
                    found = true;
                }
                ProcessCompat.setArgV0(pluginInfo.processName);
            }
        }
    }
    if (found) {
        PluginProcessManager.preMakeApplication(hostContext, pluginInfo);
    }
}
 

开发者ID:weijianfeng,
项目名称:DynamicAppLoader,
代码行数:60,
代码来源:PluginProcessManager.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)