FileDocCategorySizeDatePackage
TouchDex.javaAPI DocAndroid 1.5 API5132Wed May 06 22:41:02 BST 2009dalvik.system

TouchDex

public class TouchDex extends Object
Induces optimization/verification of a set of DEX files. TODO: This class is public, so SystemServer can access it. This is NOT the correct long-term solution; once we have a real installer and/or dalvik-cache manager, this class should be removed.
cts
See to-do about removing this class...
since
Android 1.0

Fields Summary
Constructors Summary
Methods Summary
private static java.lang.StringexpandDirectories(java.lang.String dexPath)

        String[] parts = dexPath.split(":");
        StringBuilder outPath = new StringBuilder(dexPath.length());

        // A filename filter accepting *.jar and *.apk
        FilenameFilter filter = new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.endsWith(".jar") || name.endsWith(".apk");
            }
        };

        for (String part: parts) {
            File f = new File(part);

            if (f.isFile()) {
                outPath.append(part);
                outPath.append(':");
            } else if (f.isDirectory()) {
                String[] filenames = f.list(filter);

                if (filenames == null) {
                    System.err.println("I/O error with directory: " + part);
                    continue;
                }

                for (String filename: filenames) {
                    outPath.append(part);
                    outPath.append(File.separatorChar);
                    outPath.append(filename);
                    outPath.append(':");
                }
            } else {
                System.err.println("File not found: " + part);
            }
        }


        return outPath.toString();
    
public static voidmain(java.lang.String[] args)
The entry point for the child process. args[0] can be a colon-separated path list, or "-" to read from stdin.

Alternatively, if we're invoked directly from the command line we just start here (skipping the fork/exec stuff).

param
args command line args


        if ("-".equals(args[0])) {
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(System.in), 256);

            String line;
            try {
                while ((line = in.readLine()) != null) {
                    prepFiles(line);
                }
            } catch (IOException ex) {
                throw new RuntimeException ("Error processing stdin");
            }
        } else {
            prepFiles(args[0]);
        }

        System.out.println(" Prep complete");
    
private static voidprepFiles(java.lang.String dexPath)


        System.out.println(" Prepping: " + dexPath);

        TouchDexLoader loader
                = new TouchDexLoader(expandDirectories(dexPath), null);

        try {
            /* By looking for a nonexistent class, we'll trick TouchDexLoader
             * into trying to load something from every file on dexPath,
             * optimizing all of them as a side-effect.
             *
             * The optimization happens implicitly in the VM the first time
             * someone tries to load a class from an unoptimized dex file.
             */
            loader.loadClass("com.google.NonexistentClassNeverFound");
            throw new RuntimeException("nonexistent class loaded?!");
        } catch (ClassNotFoundException cnfe) {
            //System.out.println("got expected dnfe");
        }
    
public static intstart(java.lang.String dexFiles)
Forks a process, makes sure the DEX files are prepared, and returns when everything is finished.

The filenames must be the same as will be used when the files are actually opened, because the dalvik-cache filename is based upon this filename. (The absolute path to the JAR/ZIP/APK should work.)

param
dexFiles a colon-separated list of DEX files.
return
zero on success
cts
What about error cases?

        return trampoline(dexFiles, System.getProperty("java.boot.class.path"));
    
private static native inttrampoline(java.lang.String dexFiles, java.lang.String bcp)
This calls fork() and then, in the child, calls cont(dexFiles).

param
dexFiles Colon-separated list of DEX files.
return
zero on success