use of dalvik.system.PathClassLoader in project platform_frameworks_base by android.
the class ApplicationLoaders method addPath.
/**
* Adds a new path the classpath of the given loader.
* @throws IllegalStateException if the provided class loader is not a {@link PathClassLoader}.
*/
void addPath(ClassLoader classLoader, String dexPath) {
if (!(classLoader instanceof PathClassLoader)) {
throw new IllegalStateException("class loader is not a PathClassLoader");
}
final PathClassLoader baseDexClassLoader = (PathClassLoader) classLoader;
baseDexClassLoader.addDexPath(dexPath);
}
use of dalvik.system.PathClassLoader in project android_frameworks_base by ParanoidAndroid.
the class FilterFactory method addFilterLibrary.
/**
* Adds a new Java library to the list to be scanned for filters.
* libraryPath must be an absolute path of the jar file. This needs to be
* static because only one classloader per process can open a shared native
* library, which a filter may well have.
*/
public static void addFilterLibrary(String libraryPath) {
if (mLogVerbose)
Log.v(TAG, "Adding filter library " + libraryPath);
synchronized (mClassLoaderGuard) {
if (mLibraries.contains(libraryPath)) {
if (mLogVerbose)
Log.v(TAG, "Library already added");
return;
}
mLibraries.add(libraryPath);
// Chain another path loader to the current chain
mCurrentClassLoader = new PathClassLoader(libraryPath, mCurrentClassLoader);
}
}
use of dalvik.system.PathClassLoader in project android_frameworks_base by ParanoidAndroid.
the class ZygoteConnection method handleChildProc.
/**
* Handles post-fork setup of child proc, closing sockets as appropriate,
* reopen stdio as appropriate, and ultimately throwing MethodAndArgsCaller
* if successful or returning if failed.
*
* @param parsedArgs non-null; zygote args
* @param descriptors null-ok; new file descriptors for stdio if available.
* @param pipeFd null-ok; pipe for communication back to Zygote.
* @param newStderr null-ok; stream to use for stderr until stdio
* is reopened.
*
* @throws ZygoteInit.MethodAndArgsCaller on success to
* trampoline to code that invokes static main.
*/
private void handleChildProc(Arguments parsedArgs, FileDescriptor[] descriptors, FileDescriptor pipeFd, PrintStream newStderr) throws ZygoteInit.MethodAndArgsCaller {
closeSocket();
ZygoteInit.closeServerSocket();
if (descriptors != null) {
try {
ZygoteInit.reopenStdio(descriptors[0], descriptors[1], descriptors[2]);
for (FileDescriptor fd : descriptors) {
IoUtils.closeQuietly(fd);
}
newStderr = System.err;
} catch (IOException ex) {
Log.e(TAG, "Error reopening stdio", ex);
}
}
if (parsedArgs.niceName != null) {
Process.setArgV0(parsedArgs.niceName);
}
if (parsedArgs.runtimeInit) {
if (parsedArgs.invokeWith != null) {
WrapperInit.execApplication(parsedArgs.invokeWith, parsedArgs.niceName, parsedArgs.targetSdkVersion, pipeFd, parsedArgs.remainingArgs);
} else {
RuntimeInit.zygoteInit(parsedArgs.targetSdkVersion, parsedArgs.remainingArgs);
}
} else {
String className;
try {
className = parsedArgs.remainingArgs[0];
} catch (ArrayIndexOutOfBoundsException ex) {
logAndPrintError(newStderr, "Missing required class name argument", null);
return;
}
String[] mainArgs = new String[parsedArgs.remainingArgs.length - 1];
System.arraycopy(parsedArgs.remainingArgs, 1, mainArgs, 0, mainArgs.length);
if (parsedArgs.invokeWith != null) {
WrapperInit.execStandalone(parsedArgs.invokeWith, parsedArgs.classpath, className, mainArgs);
} else {
ClassLoader cloader;
if (parsedArgs.classpath != null) {
cloader = new PathClassLoader(parsedArgs.classpath, ClassLoader.getSystemClassLoader());
} else {
cloader = ClassLoader.getSystemClassLoader();
}
try {
ZygoteInit.invokeStaticMain(cloader, className, mainArgs);
} catch (RuntimeException ex) {
logAndPrintError(newStderr, "Error starting.", ex);
}
}
}
}
use of dalvik.system.PathClassLoader in project platform_frameworks_base by android.
the class FilterFactory method addFilterLibrary.
/**
* Adds a new Java library to the list to be scanned for filters.
* libraryPath must be an absolute path of the jar file. This needs to be
* static because only one classloader per process can open a shared native
* library, which a filter may well have.
*/
public static void addFilterLibrary(String libraryPath) {
if (mLogVerbose)
Log.v(TAG, "Adding filter library " + libraryPath);
synchronized (mClassLoaderGuard) {
if (mLibraries.contains(libraryPath)) {
if (mLogVerbose)
Log.v(TAG, "Library already added");
return;
}
mLibraries.add(libraryPath);
// Chain another path loader to the current chain
mCurrentClassLoader = new PathClassLoader(libraryPath, mCurrentClassLoader);
}
}
use of dalvik.system.PathClassLoader in project robovm by robovm.
the class PathClassLoaderTest method testLibraryPathSearchOrder.
/**
* Make sure we're searching the application library path first.
* http://b/issue?id=2933456
*/
public void testLibraryPathSearchOrder() throws IOException {
File tmp = new File(System.getProperty("java.io.tmpdir"));
File systemLibPath = new File(tmp, "systemLibPath");
File applicationLibPath = new File(tmp, "applicationLibPath");
makeTempFile(systemLibPath, "libduplicated.so");
File applicationLib = makeTempFile(applicationLibPath, "libduplicated.so");
System.setProperty("java.library.path", systemLibPath.toString());
PathClassLoader pathClassLoader = new PathClassLoader(applicationLibPath.toString(), applicationLibPath.toString(), getClass().getClassLoader());
String path = pathClassLoader.findLibrary("duplicated");
assertEquals(applicationLib.toString(), path);
}
Aggregations