/** *Preptheenvironmentthenrunthetest.
*/ publicstaticvoid main(String[] args) throws Exception { /* *Createasub-processtoseeiftheProcessManagerwait *interfereswiththedexoptinvocationwait. * */dev/randomneverhitsEOF,sowe'resurethatwe'llstill *bewaitingfortheprocesstocomplete.Onthedeviceit *stopsprettyquickly(whichmeansthechildwon'tbe *spinning).
*/
ProcessBuilder pb = new ProcessBuilder("cat", "/dev/random");
Process p = pb.start();
testDexClassLoader();
testDexFile();
// shouldn't be necessary, but it's good to be tidy
p.destroy(); // let the ProcessManager's daemon thread finish before we shut down // (avoids the occasional segmentation fault) Thread.sleep(500);
System.out.println("done");
}
/** *Createaclassloader,explicitlyspecifyingthesourceDEXand *thelocationfortheoptimizedDEX.
*/ privatestaticvoid testDexClassLoader() throws Exception {
ClassLoader dexClassLoader = getDexClassLoader(); Class<?> Another = dexClassLoader.loadClass("Another");
Object another = Another.newInstance(); // not expected to work; just exercises the call
dexClassLoader.getResource("nonexistent");
}
/* *CreateaninstanceofDexClassLoader.Thetestharnessdoesn't *havevisibilityintodalvik.system.*,sowedothisthrough *reflection.
*/ privatestatic ClassLoader getDexClassLoader() throws Exception {
ClassLoader classLoader = Main.class.getClassLoader(); Class<?> DexClassLoader = classLoader.loadClass("dalvik.system.DexClassLoader");
Constructor<?> DexClassLoader_init = DexClassLoader.getConstructor(String.class,
String.class,
String.class,
ClassLoader.class); // create an instance, using the path we found return (ClassLoader) DexClassLoader_init.newInstance(CLASS_PATH,
getOdexDir(),
LIB_DIR,
classLoader);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.