// Enable hidden API checks in case they are disabled by default.
init();
// Put the classes with hiddenapi bits in the boot classpath.
appendToBootClassLoader(DEX_PARENT_BOOT, /* isCorePlatform */ false);
// Create a new class loader so the TestCase class sees the InheritAbstract classes in the boot // classpath.
ClassLoader childLoader = new PathClassLoader(DEX_CHILD, Object.class.getClassLoader()); Class<?> cls = Class.forName("TestCase", true, childLoader);
Method m = cls.getDeclaredMethod("test");
m.invoke(null);
// Create a new native library which 'childLoader' can load.
String absoluteLibraryPath = getNativeLibFileName(args[1]);
// Do the test for JNI code.
m = cls.getDeclaredMethod("testNative", String.class);
m.invoke(null, createNativeLibCopy(absoluteLibraryPath));
}
// Tries to find the absolute path of the native library whose basename is 'arg'. privatestatic String getNativeLibFileName(String arg) throws Exception {
String libName = System.mapLibraryName(arg);
Method libPathsMethod = Runtime.class.getDeclaredMethod("getLibPaths");
libPathsMethod.setAccessible(true);
String[] libPaths = (String[]) libPathsMethod.invoke(Runtime.getRuntime());
String nativeLibFileName = null; for (String p : libPaths) {
String candidate = p + libName; if (new File(candidate).exists()) {
nativeLibFileName = candidate; break;
}
} if (nativeLibFileName == null) { thrownew IllegalStateException("Didn't find " + libName + " in " +
Arrays.toString(libPaths));
} return nativeLibFileName;
}
// Copy native library to a new file with a unique name so it does not // conflict with other loaded instance of the same binary file. privatestatic String createNativeLibCopy(String nativeLibFileName) throws Exception {
String tempFileName = System.mapLibraryName("hiddenapitest");
File tempFile = new File(System.getenv("DEX_LOCATION"), tempFileName);
Files.copy(new File(nativeLibFileName).toPath(), tempFile.toPath());
tempFile.setWritable(false); return tempFile.getAbsolutePath();
}
privatestaticfinal String DEX_PARENT_BOOT = new File(new File(System.getenv("DEX_LOCATION"), "res"), "boot.jar").getAbsolutePath(); privatestaticfinal String DEX_CHILD = new File(System.getenv("DEX_LOCATION"), "817-hiddenapi-ex.jar").getAbsolutePath();
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.