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

WrapperInit

public class WrapperInit extends Object
Startup class for the wrapper process.
hide

Fields Summary
private static final String
TAG
Constructors Summary
private WrapperInit()
Class not instantiable.


            
      
    
Methods Summary
public static voidexecApplication(java.lang.String invokeWith, java.lang.String niceName, int targetSdkVersion, java.io.FileDescriptor pipeFd, java.lang.String[] args)
Executes a runtime application with a wrapper command. This method never returns.

param
invokeWith The wrapper command.
param
niceName The nice name for the application, or null if none.
param
targetSdkVersion The target SDK version for the app.
param
pipeFd The pipe to which the application's pid should be written, or null if none.
param
args Arguments for {@link RuntimeInit#main}.

        StringBuilder command = new StringBuilder(invokeWith);
        command.append(" /system/bin/app_process /system/bin --application");
        if (niceName != null) {
            command.append(" '--nice-name=").append(niceName).append("'");
        }
        command.append(" com.android.internal.os.WrapperInit ");
        command.append(pipeFd != null ? pipeFd.getInt$() : 0);
        command.append(' ");
        command.append(targetSdkVersion);
        Zygote.appendQuotedShellArgs(command, args);
        Zygote.execShell(command.toString());
    
public static voidexecStandalone(java.lang.String invokeWith, java.lang.String classPath, java.lang.String className, java.lang.String[] args)
Executes a standalone application with a wrapper command. This method never returns.

param
invokeWith The wrapper command.
param
classPath The class path.
param
className The class name to invoke.
param
args Arguments for the main() method of the specified class.

        StringBuilder command = new StringBuilder(invokeWith);
        command.append(" /system/bin/dalvikvm -classpath '").append(classPath);
        command.append("' ").append(className);
        Zygote.appendQuotedShellArgs(command, args);
        Zygote.execShell(command.toString());
    
public static voidmain(java.lang.String[] args)
The main function called when starting a runtime application through a wrapper process instead of by forking Zygote. The first argument specifies the file descriptor for a pipe that should receive the pid of this process, or 0 if none. The second argument is the target SDK version for the app. The remaining arguments are passed to the runtime.

param
args The command-line arguments.

        try {
            // Parse our mandatory arguments.
            int fdNum = Integer.parseInt(args[0], 10);
            int targetSdkVersion = Integer.parseInt(args[1], 10);

            // Tell the Zygote what our actual PID is (since it only knows about the
            // wrapper that it directly forked).
            if (fdNum != 0) {
                try {
                    FileDescriptor fd = ZygoteInit.createFileDescriptor(fdNum);
                    DataOutputStream os = new DataOutputStream(new FileOutputStream(fd));
                    os.writeInt(Process.myPid());
                    os.close();
                    IoUtils.closeQuietly(fd);
                } catch (IOException ex) {
                    Slog.d(TAG, "Could not write pid of wrapped process to Zygote pipe.", ex);
                }
            }

            // Mimic Zygote preloading.
            ZygoteInit.preload();

            // Launch the application.
            String[] runtimeArgs = new String[args.length - 2];
            System.arraycopy(args, 2, runtimeArgs, 0, runtimeArgs.length);
            RuntimeInit.wrapperInit(targetSdkVersion, runtimeArgs);
        } catch (ZygoteInit.MethodAndArgsCaller caller) {
            caller.run();
        }