FileDocCategorySizeDatePackage
Zygote.javaAPI DocAndroid 5.1 API8357Thu Mar 12 22:22:10 GMT 2015com.android.internal.os

Zygote

public final class Zygote extends Object
hide

Fields Summary
private static final String
TAG
public static final int
DEBUG_ENABLE_DEBUGGER
enable debugging over JDWP
public static final int
DEBUG_ENABLE_CHECKJNI
enable JNI checks
public static final int
DEBUG_ENABLE_ASSERT
enable Java programming language "assert" statements
public static final int
DEBUG_ENABLE_SAFEMODE
disable the JIT compiler
public static final int
DEBUG_ENABLE_JNI_LOGGING
Enable logging of third-party JNI activity.
public static final int
MOUNT_EXTERNAL_NONE
No external storage should be mounted.
public static final int
MOUNT_EXTERNAL_SINGLEUSER
Single-user external storage should be mounted.
public static final int
MOUNT_EXTERNAL_MULTIUSER
Multi-user external storage should be mounted.
public static final int
MOUNT_EXTERNAL_MULTIUSER_ALL
All multi-user external storage should be mounted.
private static final dalvik.system.ZygoteHooks
VM_HOOKS
Constructors Summary
private Zygote()


      
Methods Summary
public static voidappendQuotedShellArgs(java.lang.StringBuilder command, java.lang.String[] args)
Appends quotes shell arguments to the specified string builder. The arguments are quoted using single-quotes, escaped if necessary, prefixed with a space, and appended to the command.

param
command A string builder for the shell command being constructed.
param
args An array of argument strings to be quoted and appended to the command.
see
#execShell(String)

        for (String arg : args) {
            command.append(" '").append(arg.replace("'", "'\\''")).append("'");
        }
    
private static voidcallPostForkChildHooks(int debugFlags, java.lang.String instructionSet)

        long startTime = SystemClock.elapsedRealtime();
        VM_HOOKS.postForkChild(debugFlags, instructionSet);
        checkTime(startTime, "Zygote.callPostForkChildHooks");
    
private static voidcheckTime(long startTime, java.lang.String where)
Temporary hack: check time since start time and log if over a fixed threshold.

        long now = SystemClock.elapsedRealtime();
        if ((now-startTime) > 1000) {
            // If we are taking more than a second, log about it.
            Slog.w(TAG, "Slow operation: " + (now-startTime) + "ms so far, now at " + where);
        }
    
public static voidexecShell(java.lang.String command)
Executes "/system/bin/sh -c <command>" using the exec() system call. This method throws a runtime exception if exec() failed, otherwise, this method never returns.

param
command The shell command to execute.

        String[] args = { "/system/bin/sh", "-c", command };
        try {
            Os.execv(args[0], args);
        } catch (ErrnoException e) {
            throw new RuntimeException(e);
        }
    
public static intforkAndSpecialize(int uid, int gid, int[] gids, int debugFlags, int[][] rlimits, int mountExternal, java.lang.String seInfo, java.lang.String niceName, int[] fdsToClose, java.lang.String instructionSet, java.lang.String appDataDir)
Forks a new VM instance. The current VM must have been started with the -Xzygote flag. NOTE: new instance keeps all root capabilities. The new process is expected to call capset().

param
uid the UNIX uid that the new process should setuid() to after fork()ing and and before spawning any threads.
param
gid the UNIX gid that the new process should setgid() to after fork()ing and and before spawning any threads.
param
gids null-ok; a list of UNIX gids that the new process should setgroups() to after fork and before spawning any threads.
param
debugFlags bit flags that enable debugging features.
param
rlimits null-ok an array of rlimit tuples, with the second dimension having a length of 3 and representing (resource, rlim_cur, rlim_max). These are set via the posix setrlimit(2) call.
param
seInfo null-ok a string specifying SELinux information for the new process.
param
niceName null-ok a string specifying the process name.
param
fdsToClose an array of ints, holding one or more POSIX file descriptor numbers that are to be closed by the child (and replaced by /dev/null) after forking. An integer value of -1 in any entry in the array means "ignore this one".
param
instructionSet null-ok the instruction set to use.
param
appDataDir null-ok the data directory of the app.
return
0 if this is the child, pid of the child if this is the parent, or -1 on error.

        long startTime = SystemClock.elapsedRealtime();
        VM_HOOKS.preFork();
        checkTime(startTime, "Zygote.preFork");
        int pid = nativeForkAndSpecialize(
                  uid, gid, gids, debugFlags, rlimits, mountExternal, seInfo, niceName, fdsToClose,
                  instructionSet, appDataDir);
        checkTime(startTime, "Zygote.nativeForkAndSpecialize");
        VM_HOOKS.postForkCommon();
        checkTime(startTime, "Zygote.postForkCommon");
        return pid;
    
public static intforkSystemServer(int uid, int gid, int[] gids, int debugFlags, int[][] rlimits, long permittedCapabilities, long effectiveCapabilities)
Special method to start the system server process. In addition to the common actions performed in forkAndSpecialize, the pid of the child process is recorded such that the death of the child process will cause zygote to exit.

param
uid the UNIX uid that the new process should setuid() to after fork()ing and and before spawning any threads.
param
gid the UNIX gid that the new process should setgid() to after fork()ing and and before spawning any threads.
param
gids null-ok; a list of UNIX gids that the new process should setgroups() to after fork and before spawning any threads.
param
debugFlags bit flags that enable debugging features.
param
rlimits null-ok an array of rlimit tuples, with the second dimension having a length of 3 and representing (resource, rlim_cur, rlim_max). These are set via the posix setrlimit(2) call.
param
permittedCapabilities argument for setcap()
param
effectiveCapabilities argument for setcap()
return
0 if this is the child, pid of the child if this is the parent, or -1 on error.

        VM_HOOKS.preFork();
        int pid = nativeForkSystemServer(
                uid, gid, gids, debugFlags, rlimits, permittedCapabilities, effectiveCapabilities);
        VM_HOOKS.postForkCommon();
        return pid;
    
private static native intnativeForkAndSpecialize(int uid, int gid, int[] gids, int debugFlags, int[][] rlimits, int mountExternal, java.lang.String seInfo, java.lang.String niceName, int[] fdsToClose, java.lang.String instructionSet, java.lang.String appDataDir)

private static native intnativeForkSystemServer(int uid, int gid, int[] gids, int debugFlags, int[][] rlimits, long permittedCapabilities, long effectiveCapabilities)