Search in sources :

Example 16 with PathClassLoader

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

the class NetPluginDelegate method loadTetherExtJar.

private static synchronized boolean loadTetherExtJar() {
    final String realProvider = "com.qualcomm.qti.tetherstatsextension.TetherStatsReporting";
    final String realProviderPath = Environment.getRootDirectory().getAbsolutePath() + "/framework/ConnectivityExt.jar";
    if (tetherExtensionClass != null && tetherExtensionObj != null) {
        return true;
    }
    boolean pathExists = new File(realProviderPath).exists();
    if (!pathExists) {
        Log.w(TAG, "ConnectivityExt jar file not present");
        return false;
    }
    if (tetherExtensionClass == null && tetherExtensionObj == null) {
        if (LOGV)
            Slog.v(TAG, "loading ConnectivityExt jar");
        try {
            PathClassLoader classLoader = new PathClassLoader(realProviderPath, ClassLoader.getSystemClassLoader());
            tetherExtensionClass = classLoader.loadClass(realProvider);
            tetherExtensionObj = tetherExtensionClass.newInstance();
            if (LOGV)
                Slog.v(TAG, "ConnectivityExt jar loaded");
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
            Log.w(TAG, "Failed to find, instantiate or access ConnectivityExt jar ");
            return false;
        } catch (Exception e) {
            e.printStackTrace();
            Log.w(TAG, "unable to load ConnectivityExt jar");
            return false;
        }
    }
    return true;
}
Also used : PathClassLoader(dalvik.system.PathClassLoader) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 17 with PathClassLoader

use of dalvik.system.PathClassLoader in project weex-example by KalicyZhou.

the class WXSoInstallMgrSdk method checkSoIsValid.

/**
   *
   * @param libName lib name
   * @param size  the right size of lib
   * @return true for valid  ; false for InValid
   */
static boolean checkSoIsValid(String libName, int size) {
    Context context = mContext;
    if (null == context) {
        return false;
    }
    try {
        long start = System.currentTimeMillis();
        if (WXSoInstallMgrSdk.class.getClassLoader() instanceof PathClassLoader) {
            String path = ((PathClassLoader) (WXSoInstallMgrSdk.class.getClassLoader())).findLibrary(libName);
            File file = new File(path);
            if (!file.exists() || size == file.length()) {
                WXLogUtils.w("weex so size check path :" + path + "   " + (System.currentTimeMillis() - start));
                return true;
            } else {
                return false;
            }
        }
    } catch (Throwable e) {
        WXLogUtils.e("weex so size check fail exception :" + e.getMessage());
    }
    return true;
}
Also used : Context(android.content.Context) PathClassLoader(dalvik.system.PathClassLoader) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 18 with PathClassLoader

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

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 19 with PathClassLoader

use of dalvik.system.PathClassLoader in project incubator-weex by apache.

the class WXSoInstallMgrSdk method checkSoIsValid.

/**
 * @param libName lib name
 * @param size  the right size of lib
 * @return true for valid  ; false for InValid
 */
static boolean checkSoIsValid(String libName, long size) {
    Context context = mContext;
    if (null == context) {
        return false;
    }
    try {
        long start = System.currentTimeMillis();
        if (WXSoInstallMgrSdk.class.getClassLoader() instanceof PathClassLoader) {
            String path = ((PathClassLoader) (WXSoInstallMgrSdk.class.getClassLoader())).findLibrary(libName);
            if (TextUtils.isEmpty(path)) {
                return false;
            }
            File file = new File(path);
            if (!file.exists() || size == file.length()) {
                WXLogUtils.w("weex so size check path :" + path + "   " + (System.currentTimeMillis() - start));
                return true;
            } else {
                return false;
            }
        }
    } catch (Throwable e) {
        WXExceptionUtils.commitCriticalExceptionRT(null, WXErrorCode.WX_KEY_EXCEPTION_SDK_INIT, "checkSoIsValid", "[WX_KEY_EXCEPTION_SDK_INIT_CPU_NOT_SUPPORT] for " + "weex so size check fail exception :" + e.getMessage(), null);
        WXLogUtils.e("weex so size check fail exception :" + e.getMessage());
    }
    return true;
}
Also used : Context(android.content.Context) PathClassLoader(dalvik.system.PathClassLoader) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 20 with PathClassLoader

use of dalvik.system.PathClassLoader in project blog_resource by Guolei1130.

the class MainActivity method loadExtApk.

private void loadExtApk() {
    String apkPath = new File("/sdcard/plugin_1.apk").getPath();
    File dexOptOutDir = new File(getFilesDir(), "dexopt");
    if (!dexOptOutDir.exists()) {
        boolean result = dexOptOutDir.mkdir();
        if (!result) {
            Log.e(TAG, "loadExtJar: create out dir error");
        }
    }
    String dexOptOutDr = dexOptOutDir.getPath();
    ClassLoader classLoader = null;
    if (Constants.isDalvik()) {
        classLoader = new DexClassLoader(apkPath, dexOptOutDr, null, ClassLoader.getSystemClassLoader());
    } else {
        classLoader = new PathClassLoader(apkPath, ClassLoader.getSystemClassLoader());
    }
    try {
        Class userClz = classLoader.loadClass("com.guolei.plugin_1.People");
        Object user = userClz.getConstructor(String.class, int.class).newInstance("guolei", 24);
        Method method = userClz.getDeclaredMethod("toString");
        method.setAccessible(true);
        String msg = (String) method.invoke(user);
        Log.e(TAG, "loadExtApk: " + msg);
        Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : PathClassLoader(dalvik.system.PathClassLoader) DexClassLoader(dalvik.system.DexClassLoader) DexClassLoader(dalvik.system.DexClassLoader) PathClassLoader(dalvik.system.PathClassLoader) Method(java.lang.reflect.Method) ZipFile(java.util.zip.ZipFile) DexFile(dalvik.system.DexFile) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException)

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