Loading core/java/android/os/Process.java +11 −7 Original line number Diff line number Diff line Loading @@ -266,7 +266,8 @@ public class Process { * @param uid The user-id under which the process will run. * @param gid The group-id under which the process will run. * @param gids Additional group-ids associated with the process. * @param enableDebugger True if debugging should be enabled for this process. * @param debugFlags Additional flags. * @param targetSdkVersion The target SDK version for the app. * @param zygoteArgs Additional arguments to supply to the zygote process. * * @return int If > 0 the pid of the new process; if 0 the process is Loading @@ -278,13 +279,13 @@ public class Process { public static final int start(final String processClass, final String niceName, int uid, int gid, int[] gids, int debugFlags, int debugFlags, int targetSdkVersion, String[] zygoteArgs) { if (supportsProcesses()) { try { return startViaZygote(processClass, niceName, uid, gid, gids, debugFlags, zygoteArgs); debugFlags, targetSdkVersion, zygoteArgs); } catch (ZygoteStartFailedEx ex) { Log.e(LOG_TAG, "Starting VM process through Zygote failed"); Loading Loading @@ -316,9 +317,10 @@ public class Process { * {@hide} */ public static final int start(String processClass, int uid, int gid, int[] gids, int debugFlags, String[] zygoteArgs) { int[] gids, int debugFlags, int targetSdkVersion, String[] zygoteArgs) { return start(processClass, "", uid, gid, gids, debugFlags, zygoteArgs); debugFlags, targetSdkVersion, zygoteArgs); } private static void invokeStaticMain(String className) { Loading Loading @@ -500,7 +502,8 @@ public class Process { * @param gid a POSIX gid that the new process shuold setgid() to * @param gids null-ok; a list of supplementary group IDs that the * new process should setgroup() to. * @param enableDebugger True if debugging should be enabled for this process. * @param debugFlags Additional flags. * @param targetSdkVersion The target SDK version for the app. * @param extraArgs Additional arguments to supply to the zygote process. * @return PID * @throws ZygoteStartFailedEx if process start failed for any reason Loading @@ -509,7 +512,7 @@ public class Process { final String niceName, final int uid, final int gid, final int[] gids, int debugFlags, int debugFlags, int targetSdkVersion, String[] extraArgs) throws ZygoteStartFailedEx { int pid; Loading Loading @@ -537,6 +540,7 @@ public class Process { if ((debugFlags & Zygote.DEBUG_ENABLE_ASSERT) != 0) { argsForZygote.add("--enable-assert"); } argsForZygote.add("--target-sdk-version=" + targetSdkVersion); //TODO optionally enable debuger //argsForZygote.add("--enable-debugger"); Loading core/java/com/android/internal/os/RuntimeInit.java +8 −5 Original line number Diff line number Diff line Loading @@ -252,9 +252,10 @@ public class RuntimeInit { * <li> <code> [--] <start class name> <args> * </ul> * * @param targetSdkVersion target SDK version * @param argv arg strings */ public static final void zygoteInit(String[] argv) public static final void zygoteInit(int targetSdkVersion, String[] argv) throws ZygoteInit.MethodAndArgsCaller { if (DEBUG) Slog.d(TAG, "RuntimeInit: Starting application from zygote"); Loading @@ -263,7 +264,7 @@ public class RuntimeInit { commonInit(); zygoteInitNative(); applicationInit(argv); applicationInit(targetSdkVersion, argv); } /** Loading @@ -274,20 +275,22 @@ public class RuntimeInit { * which calls {@link WrapperInit#main} which then calls this method. * So we don't need to call commonInit() here. * * @param targetSdkVersion target SDK version * @param argv arg strings */ public static void wrapperInit(String[] argv) public static void wrapperInit(int targetSdkVersion, String[] argv) throws ZygoteInit.MethodAndArgsCaller { if (DEBUG) Slog.d(TAG, "RuntimeInit: Starting application from wrapper"); applicationInit(argv); applicationInit(targetSdkVersion, argv); } private static void applicationInit(String[] argv) private static void applicationInit(int targetSdkVersion, String[] argv) throws ZygoteInit.MethodAndArgsCaller { // We want to be fairly aggressive about heap utilization, to avoid // holding on to a lot of memory that isn't needed. VMRuntime.getRuntime().setTargetHeapUtilization(0.75f); VMRuntime.getRuntime().setTargetSdkVersion(targetSdkVersion); final Arguments args; try { Loading core/java/com/android/internal/os/WrapperInit.java +16 −7 Original line number Diff line number Diff line Loading @@ -47,16 +47,22 @@ public class WrapperInit { * 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 remaining arguments are passed to * the runtime. * 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. */ public static void main(String[] args) { 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). int fdNum = Integer.parseInt(args[0], 10); if (fdNum != 0) { try { FileDescriptor fd = ZygoteInit.createFileDescriptor(fdNum); Loading @@ -73,9 +79,9 @@ public class WrapperInit { ZygoteInit.preload(); // Launch the application. String[] runtimeArgs = new String[args.length - 1]; System.arraycopy(args, 1, runtimeArgs, 0, runtimeArgs.length); RuntimeInit.wrapperInit(runtimeArgs); 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(); } Loading @@ -87,11 +93,12 @@ public class WrapperInit { * * @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}. */ public static void execApplication(String invokeWith, String niceName, FileDescriptor pipeFd, String[] args) { int targetSdkVersion, FileDescriptor pipeFd, String[] args) { StringBuilder command = new StringBuilder(invokeWith); command.append(" /system/bin/app_process /system/bin --application"); if (niceName != null) { Loading @@ -99,6 +106,8 @@ public class WrapperInit { } 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()); } Loading core/java/com/android/internal/os/ZygoteConnection.java +21 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.internal.os; import android.net.Credentials; import android.net.LocalSocket; import android.os.Build; import android.os.Process; import android.os.SystemProperties; import android.util.Log; Loading Loading @@ -333,6 +334,10 @@ class ZygoteConnection { */ int debugFlags; /** from --target-sdk-version. */ int targetSdkVersion; boolean targetSdkVersionSpecified; /** from --classpath */ String classpath; Loading Loading @@ -402,6 +407,14 @@ class ZygoteConnection { gidSpecified = true; gid = Integer.parseInt( arg.substring(arg.indexOf('=') + 1)); } else if (arg.startsWith("--target-sdk-version=")) { if (targetSdkVersionSpecified) { throw new IllegalArgumentException( "Duplicate target-sdk-version specified"); } targetSdkVersionSpecified = true; targetSdkVersion = Integer.parseInt( arg.substring(arg.indexOf('=') + 1)); } else if (arg.equals("--enable-debugger")) { debugFlags |= Zygote.DEBUG_ENABLE_DEBUGGER; } else if (arg.equals("--enable-safemode")) { Loading Loading @@ -505,6 +518,10 @@ class ZygoteConnection { "--runtime-init and -classpath are incompatible"); } if (!targetSdkVersionSpecified) { targetSdkVersion = Build.VERSION.SDK_INT; } remainingArgs = new String[args.length - curArg]; System.arraycopy(args, curArg, remainingArgs, 0, Loading Loading @@ -821,9 +838,11 @@ class ZygoteConnection { if (parsedArgs.runtimeInit) { if (parsedArgs.invokeWith != null) { WrapperInit.execApplication(parsedArgs.invokeWith, parsedArgs.niceName, pipeFd, parsedArgs.remainingArgs); parsedArgs.niceName, parsedArgs.targetSdkVersion, pipeFd, parsedArgs.remainingArgs); } else { RuntimeInit.zygoteInit(parsedArgs.remainingArgs); RuntimeInit.zygoteInit(parsedArgs.targetSdkVersion, parsedArgs.remainingArgs); } } else { String className; Loading core/java/com/android/internal/os/ZygoteInit.java +7 −4 Original line number Diff line number Diff line Loading @@ -48,7 +48,7 @@ import java.util.ArrayList; * Startup class for the zygote process. * * Pre-initializes some classes, and then waits for commands on a UNIX domain * socket. Based on these commands, forks of child processes that inherit * socket. Based on these commands, forks off child processes that inherit * the initial state of the VM. * * Please see {@link ZygoteConnection.Arguments} for documentation on the Loading Loading @@ -453,12 +453,13 @@ public class ZygoteInit { if (parsedArgs.invokeWith != null) { WrapperInit.execApplication(parsedArgs.invokeWith, parsedArgs.niceName, null, parsedArgs.remainingArgs); parsedArgs.niceName, parsedArgs.targetSdkVersion, null, parsedArgs.remainingArgs); } else { /* * Pass the remaining arguments to SystemServer. */ RuntimeInit.zygoteInit(parsedArgs.remainingArgs); RuntimeInit.zygoteInit(parsedArgs.targetSdkVersion, parsedArgs.remainingArgs); } /* should never reach here */ Loading Loading @@ -491,7 +492,9 @@ public class ZygoteInit { /* Request to fork the system server process */ pid = Zygote.forkSystemServer( parsedArgs.uid, parsedArgs.gid, parsedArgs.gids, parsedArgs.debugFlags, null, parsedArgs.gids, parsedArgs.debugFlags, null, parsedArgs.permittedCapabilities, parsedArgs.effectiveCapabilities); } catch (IllegalArgumentException ex) { Loading Loading
core/java/android/os/Process.java +11 −7 Original line number Diff line number Diff line Loading @@ -266,7 +266,8 @@ public class Process { * @param uid The user-id under which the process will run. * @param gid The group-id under which the process will run. * @param gids Additional group-ids associated with the process. * @param enableDebugger True if debugging should be enabled for this process. * @param debugFlags Additional flags. * @param targetSdkVersion The target SDK version for the app. * @param zygoteArgs Additional arguments to supply to the zygote process. * * @return int If > 0 the pid of the new process; if 0 the process is Loading @@ -278,13 +279,13 @@ public class Process { public static final int start(final String processClass, final String niceName, int uid, int gid, int[] gids, int debugFlags, int debugFlags, int targetSdkVersion, String[] zygoteArgs) { if (supportsProcesses()) { try { return startViaZygote(processClass, niceName, uid, gid, gids, debugFlags, zygoteArgs); debugFlags, targetSdkVersion, zygoteArgs); } catch (ZygoteStartFailedEx ex) { Log.e(LOG_TAG, "Starting VM process through Zygote failed"); Loading Loading @@ -316,9 +317,10 @@ public class Process { * {@hide} */ public static final int start(String processClass, int uid, int gid, int[] gids, int debugFlags, String[] zygoteArgs) { int[] gids, int debugFlags, int targetSdkVersion, String[] zygoteArgs) { return start(processClass, "", uid, gid, gids, debugFlags, zygoteArgs); debugFlags, targetSdkVersion, zygoteArgs); } private static void invokeStaticMain(String className) { Loading Loading @@ -500,7 +502,8 @@ public class Process { * @param gid a POSIX gid that the new process shuold setgid() to * @param gids null-ok; a list of supplementary group IDs that the * new process should setgroup() to. * @param enableDebugger True if debugging should be enabled for this process. * @param debugFlags Additional flags. * @param targetSdkVersion The target SDK version for the app. * @param extraArgs Additional arguments to supply to the zygote process. * @return PID * @throws ZygoteStartFailedEx if process start failed for any reason Loading @@ -509,7 +512,7 @@ public class Process { final String niceName, final int uid, final int gid, final int[] gids, int debugFlags, int debugFlags, int targetSdkVersion, String[] extraArgs) throws ZygoteStartFailedEx { int pid; Loading Loading @@ -537,6 +540,7 @@ public class Process { if ((debugFlags & Zygote.DEBUG_ENABLE_ASSERT) != 0) { argsForZygote.add("--enable-assert"); } argsForZygote.add("--target-sdk-version=" + targetSdkVersion); //TODO optionally enable debuger //argsForZygote.add("--enable-debugger"); Loading
core/java/com/android/internal/os/RuntimeInit.java +8 −5 Original line number Diff line number Diff line Loading @@ -252,9 +252,10 @@ public class RuntimeInit { * <li> <code> [--] <start class name> <args> * </ul> * * @param targetSdkVersion target SDK version * @param argv arg strings */ public static final void zygoteInit(String[] argv) public static final void zygoteInit(int targetSdkVersion, String[] argv) throws ZygoteInit.MethodAndArgsCaller { if (DEBUG) Slog.d(TAG, "RuntimeInit: Starting application from zygote"); Loading @@ -263,7 +264,7 @@ public class RuntimeInit { commonInit(); zygoteInitNative(); applicationInit(argv); applicationInit(targetSdkVersion, argv); } /** Loading @@ -274,20 +275,22 @@ public class RuntimeInit { * which calls {@link WrapperInit#main} which then calls this method. * So we don't need to call commonInit() here. * * @param targetSdkVersion target SDK version * @param argv arg strings */ public static void wrapperInit(String[] argv) public static void wrapperInit(int targetSdkVersion, String[] argv) throws ZygoteInit.MethodAndArgsCaller { if (DEBUG) Slog.d(TAG, "RuntimeInit: Starting application from wrapper"); applicationInit(argv); applicationInit(targetSdkVersion, argv); } private static void applicationInit(String[] argv) private static void applicationInit(int targetSdkVersion, String[] argv) throws ZygoteInit.MethodAndArgsCaller { // We want to be fairly aggressive about heap utilization, to avoid // holding on to a lot of memory that isn't needed. VMRuntime.getRuntime().setTargetHeapUtilization(0.75f); VMRuntime.getRuntime().setTargetSdkVersion(targetSdkVersion); final Arguments args; try { Loading
core/java/com/android/internal/os/WrapperInit.java +16 −7 Original line number Diff line number Diff line Loading @@ -47,16 +47,22 @@ public class WrapperInit { * 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 remaining arguments are passed to * the runtime. * 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. */ public static void main(String[] args) { 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). int fdNum = Integer.parseInt(args[0], 10); if (fdNum != 0) { try { FileDescriptor fd = ZygoteInit.createFileDescriptor(fdNum); Loading @@ -73,9 +79,9 @@ public class WrapperInit { ZygoteInit.preload(); // Launch the application. String[] runtimeArgs = new String[args.length - 1]; System.arraycopy(args, 1, runtimeArgs, 0, runtimeArgs.length); RuntimeInit.wrapperInit(runtimeArgs); 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(); } Loading @@ -87,11 +93,12 @@ public class WrapperInit { * * @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}. */ public static void execApplication(String invokeWith, String niceName, FileDescriptor pipeFd, String[] args) { int targetSdkVersion, FileDescriptor pipeFd, String[] args) { StringBuilder command = new StringBuilder(invokeWith); command.append(" /system/bin/app_process /system/bin --application"); if (niceName != null) { Loading @@ -99,6 +106,8 @@ public class WrapperInit { } 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()); } Loading
core/java/com/android/internal/os/ZygoteConnection.java +21 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.internal.os; import android.net.Credentials; import android.net.LocalSocket; import android.os.Build; import android.os.Process; import android.os.SystemProperties; import android.util.Log; Loading Loading @@ -333,6 +334,10 @@ class ZygoteConnection { */ int debugFlags; /** from --target-sdk-version. */ int targetSdkVersion; boolean targetSdkVersionSpecified; /** from --classpath */ String classpath; Loading Loading @@ -402,6 +407,14 @@ class ZygoteConnection { gidSpecified = true; gid = Integer.parseInt( arg.substring(arg.indexOf('=') + 1)); } else if (arg.startsWith("--target-sdk-version=")) { if (targetSdkVersionSpecified) { throw new IllegalArgumentException( "Duplicate target-sdk-version specified"); } targetSdkVersionSpecified = true; targetSdkVersion = Integer.parseInt( arg.substring(arg.indexOf('=') + 1)); } else if (arg.equals("--enable-debugger")) { debugFlags |= Zygote.DEBUG_ENABLE_DEBUGGER; } else if (arg.equals("--enable-safemode")) { Loading Loading @@ -505,6 +518,10 @@ class ZygoteConnection { "--runtime-init and -classpath are incompatible"); } if (!targetSdkVersionSpecified) { targetSdkVersion = Build.VERSION.SDK_INT; } remainingArgs = new String[args.length - curArg]; System.arraycopy(args, curArg, remainingArgs, 0, Loading Loading @@ -821,9 +838,11 @@ class ZygoteConnection { if (parsedArgs.runtimeInit) { if (parsedArgs.invokeWith != null) { WrapperInit.execApplication(parsedArgs.invokeWith, parsedArgs.niceName, pipeFd, parsedArgs.remainingArgs); parsedArgs.niceName, parsedArgs.targetSdkVersion, pipeFd, parsedArgs.remainingArgs); } else { RuntimeInit.zygoteInit(parsedArgs.remainingArgs); RuntimeInit.zygoteInit(parsedArgs.targetSdkVersion, parsedArgs.remainingArgs); } } else { String className; Loading
core/java/com/android/internal/os/ZygoteInit.java +7 −4 Original line number Diff line number Diff line Loading @@ -48,7 +48,7 @@ import java.util.ArrayList; * Startup class for the zygote process. * * Pre-initializes some classes, and then waits for commands on a UNIX domain * socket. Based on these commands, forks of child processes that inherit * socket. Based on these commands, forks off child processes that inherit * the initial state of the VM. * * Please see {@link ZygoteConnection.Arguments} for documentation on the Loading Loading @@ -453,12 +453,13 @@ public class ZygoteInit { if (parsedArgs.invokeWith != null) { WrapperInit.execApplication(parsedArgs.invokeWith, parsedArgs.niceName, null, parsedArgs.remainingArgs); parsedArgs.niceName, parsedArgs.targetSdkVersion, null, parsedArgs.remainingArgs); } else { /* * Pass the remaining arguments to SystemServer. */ RuntimeInit.zygoteInit(parsedArgs.remainingArgs); RuntimeInit.zygoteInit(parsedArgs.targetSdkVersion, parsedArgs.remainingArgs); } /* should never reach here */ Loading Loading @@ -491,7 +492,9 @@ public class ZygoteInit { /* Request to fork the system server process */ pid = Zygote.forkSystemServer( parsedArgs.uid, parsedArgs.gid, parsedArgs.gids, parsedArgs.debugFlags, null, parsedArgs.gids, parsedArgs.debugFlags, null, parsedArgs.permittedCapabilities, parsedArgs.effectiveCapabilities); } catch (IllegalArgumentException ex) { Loading