Search in sources :

Example 6 with DexFile

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

the class ClassPathPackageInfoSource method findClassesInApk.

/**
     * Finds all classes and sub packages that are below the packageName and
     * add them to the respective sets. Searches the package in a single apk file.
     */
private void findClassesInApk(String apkPath, String packageName, Set<String> classNames, Set<String> subpackageNames) throws IOException {
    DexFile dexFile = null;
    try {
        dexFile = new DexFile(apkPath);
        Enumeration<String> apkClassNames = dexFile.entries();
        while (apkClassNames.hasMoreElements()) {
            String className = apkClassNames.nextElement();
            if (className.startsWith(packageName)) {
                String subPackageName = packageName;
                int lastPackageSeparator = className.lastIndexOf('.');
                if (lastPackageSeparator > 0) {
                    subPackageName = className.substring(0, lastPackageSeparator);
                }
                if (subPackageName.length() > packageName.length()) {
                    subpackageNames.add(subPackageName);
                } else if (isToplevelClass(className)) {
                    classNames.add(className);
                }
            }
        }
    } catch (IOException e) {
        if (false) {
            Log.w("ClassPathPackageInfoSource", "Error finding classes at apk path: " + apkPath, e);
        }
    } finally {
        if (dexFile != null) {
        // Todo: figure out why closing causes a dalvik error resulting in vm shutdown.
        //                dexFile.close();
        }
    }
}
Also used : IOException(java.io.IOException) DexFile(dalvik.system.DexFile)

Example 7 with DexFile

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

the class RunTestCommand method addTestClassesFromJars.

/**
     * Add test classes from jars passed on the command line. Use this if nothing was explicitly
     * specified on the command line.
     */
private void addTestClassesFromJars() {
    String jars = mParams.getString(JARS_PARAM);
    if (jars == null)
        return;
    String[] jarFileNames = jars.split(JARS_SEPARATOR);
    for (String fileName : jarFileNames) {
        fileName = fileName.trim();
        if (fileName.isEmpty())
            continue;
        try {
            DexFile dexFile = new DexFile(fileName);
            for (Enumeration<String> e = dexFile.entries(); e.hasMoreElements(); ) {
                String className = e.nextElement();
                if (isTestClass(className)) {
                    mTestClasses.add(className);
                }
            }
            dexFile.close();
        } catch (IOException e) {
            Log.w(LOGTAG, String.format("Could not read %s: %s", fileName, e.getMessage()));
        }
    }
}
Also used : IOException(java.io.IOException) DexFile(dalvik.system.DexFile)

Example 8 with DexFile

use of dalvik.system.DexFile in project android_frameworks_base by AOSPA.

the class RunTestCommand method addTestClassesFromJars.

/**
     * Add test classes from jars passed on the command line. Use this if nothing was explicitly
     * specified on the command line.
     */
private void addTestClassesFromJars() {
    String jars = mParams.getString(JARS_PARAM);
    if (jars == null)
        return;
    String[] jarFileNames = jars.split(JARS_SEPARATOR);
    for (String fileName : jarFileNames) {
        fileName = fileName.trim();
        if (fileName.isEmpty())
            continue;
        try {
            DexFile dexFile = new DexFile(fileName);
            for (Enumeration<String> e = dexFile.entries(); e.hasMoreElements(); ) {
                String className = e.nextElement();
                if (isTestClass(className)) {
                    mTestClasses.add(className);
                }
            }
            dexFile.close();
        } catch (IOException e) {
            Log.w(LOGTAG, String.format("Could not read %s: %s", fileName, e.getMessage()));
        }
    }
}
Also used : IOException(java.io.IOException) DexFile(dalvik.system.DexFile)

Example 9 with DexFile

use of dalvik.system.DexFile in project platform_frameworks_base by android.

the class RunTestCommand method addTestClassesFromJars.

/**
     * Add test classes from jars passed on the command line. Use this if nothing was explicitly
     * specified on the command line.
     */
private void addTestClassesFromJars() {
    String jars = mParams.getString(JARS_PARAM);
    if (jars == null)
        return;
    String[] jarFileNames = jars.split(JARS_SEPARATOR);
    for (String fileName : jarFileNames) {
        fileName = fileName.trim();
        if (fileName.isEmpty())
            continue;
        try {
            DexFile dexFile = new DexFile(fileName);
            for (Enumeration<String> e = dexFile.entries(); e.hasMoreElements(); ) {
                String className = e.nextElement();
                if (isTestClass(className)) {
                    mTestClasses.add(className);
                }
            }
            dexFile.close();
        } catch (IOException e) {
            Log.w(LOGTAG, String.format("Could not read %s: %s", fileName, e.getMessage()));
        }
    }
}
Also used : IOException(java.io.IOException) DexFile(dalvik.system.DexFile)

Example 10 with DexFile

use of dalvik.system.DexFile in project platform_frameworks_base by android.

the class ClassPathPackageInfoSource method findClassesInApk.

/**
     * Finds all classes and sub packages that are below the packageName and
     * add them to the respective sets. Searches the package in a single apk file.
     */
private void findClassesInApk(String apkPath, String packageName, Set<String> classNames, Set<String> subpackageNames) throws IOException {
    DexFile dexFile = null;
    try {
        dexFile = new DexFile(apkPath);
        Enumeration<String> apkClassNames = dexFile.entries();
        while (apkClassNames.hasMoreElements()) {
            String className = apkClassNames.nextElement();
            if (className.startsWith(packageName)) {
                String subPackageName = packageName;
                int lastPackageSeparator = className.lastIndexOf('.');
                if (lastPackageSeparator > 0) {
                    subPackageName = className.substring(0, lastPackageSeparator);
                }
                if (subPackageName.length() > packageName.length()) {
                    subpackageNames.add(subPackageName);
                } else if (isToplevelClass(className)) {
                    classNames.add(className);
                }
            }
        }
    } catch (IOException e) {
        if (false) {
            Log.w("ClassPathPackageInfoSource", "Error finding classes at apk path: " + apkPath, e);
        }
    } finally {
        if (dexFile != null) {
        // Todo: figure out why closing causes a dalvik error resulting in vm shutdown.
        //                dexFile.close();
        }
    }
}
Also used : IOException(java.io.IOException) DexFile(dalvik.system.DexFile)

Aggregations

DexFile (dalvik.system.DexFile)59 File (java.io.File)32 IOException (java.io.IOException)28 ArrayList (java.util.ArrayList)17 Field (java.lang.reflect.Field)13 ZipFile (java.util.zip.ZipFile)13 Method (java.lang.reflect.Method)11 DexClassLoader (dalvik.system.DexClassLoader)9 Enumeration (java.util.Enumeration)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 ApplicationInfo (android.content.pm.ApplicationInfo)3 NClassLoader (android.taobao.atlas.startup.NClassLoader)2 URL (java.net.URL)2 HashSet (java.util.HashSet)2 Application (android.app.Application)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Context (android.content.Context)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 Main (com.android.dx.command.dexer.Main)1 Action (com.jia.base.annotation.Action)1