Search in sources :

Example 1 with ZygoteProcess

use of android.os.ZygoteProcess in project platform_frameworks_base by android.

the class WebViewZygote method connectToZygoteIfNeededLocked.

@GuardedBy("sLock")
private static void connectToZygoteIfNeededLocked() {
    if (sZygote != null)
        return;
    if (sPackage == null) {
        Log.e(LOGTAG, "Cannot connect to zygote, no package specified");
        return;
    }
    final String serviceName = getServiceNameLocked();
    if (!SystemService.isRunning(serviceName)) {
        Log.e(LOGTAG, serviceName + " is not running");
        return;
    }
    try {
        sZygote = new ZygoteProcess("webview_zygote", null);
        // All the work below is usually done by LoadedApk, but the zygote can't talk to
        // PackageManager or construct a LoadedApk since it's single-threaded pre-fork, so
        // doesn't have an ActivityThread and can't use Binder.
        // Instead, figure out the paths here, in the system server where we have access to
        // the package manager. Reuse the logic from LoadedApk to determine the correct
        // paths and pass them to the zygote as strings.
        final List<String> zipPaths = new ArrayList<>(10);
        final List<String> libPaths = new ArrayList<>(10);
        LoadedApk.makePaths(null, false, sPackage.applicationInfo, zipPaths, libPaths);
        final String librarySearchPath = TextUtils.join(File.pathSeparator, libPaths);
        final String zip = (zipPaths.size() == 1) ? zipPaths.get(0) : TextUtils.join(File.pathSeparator, zipPaths);
        Log.d(LOGTAG, "Preloading package " + zip + " " + librarySearchPath);
        sZygote.preloadPackageForAbi(zip, librarySearchPath, Build.SUPPORTED_ABIS[0]);
    } catch (Exception e) {
        Log.e(LOGTAG, "Error connecting to " + serviceName, e);
        sZygote = null;
    }
}
Also used : ZygoteProcess(android.os.ZygoteProcess) ArrayList(java.util.ArrayList) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) GuardedBy(com.android.internal.annotations.GuardedBy)

Aggregations

ZygoteProcess (android.os.ZygoteProcess)1 GuardedBy (com.android.internal.annotations.GuardedBy)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 TimeoutException (java.util.concurrent.TimeoutException)1