Merge "Add javadoc for package-name arg passed during the process start."
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java
index 7caf0b1..5cd2ffc 100644
--- a/core/java/android/os/Process.java
+++ b/core/java/android/os/Process.java
@@ -16,6 +16,8 @@
 
 package android.os;
 
+import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.annotation.TestApi;
 import android.system.Os;
 import android.system.OsConstants;
@@ -475,6 +477,7 @@
      * @param instructionSet null-ok the instruction set to use.
      * @param appDataDir null-ok the data directory of the app.
      * @param invokeWith null-ok the command to invoke with.
+     * @param packageName null-ok the name of the package this process belongs to.
      * @param zygoteArgs Additional arguments to supply to the zygote process.
      * 
      * @return An object that describes the result of the attempt to start the process.
@@ -482,36 +485,36 @@
      * 
      * {@hide}
      */
-    public static final ProcessStartResult start(final String processClass,
-                                  final String niceName,
-                                  int uid, int gid, int[] gids,
+    public static final ProcessStartResult start(@NonNull final String processClass,
+                                  @Nullable final String niceName,
+                                  int uid, int gid, @Nullable int[] gids,
                                   int runtimeFlags, int mountExternal,
                                   int targetSdkVersion,
-                                  String seInfo,
-                                  String abi,
-                                  String instructionSet,
-                                  String appDataDir,
-                                  String invokeWith,
-                                  String packageName,
-                                  String[] zygoteArgs) {
+                                  @Nullable String seInfo,
+                                  @NonNull String abi,
+                                  @Nullable String instructionSet,
+                                  @Nullable String appDataDir,
+                                  @Nullable String invokeWith,
+                                  @Nullable String packageName,
+                                  @Nullable String[] zygoteArgs) {
         return zygoteProcess.start(processClass, niceName, uid, gid, gids,
                     runtimeFlags, mountExternal, targetSdkVersion, seInfo,
                     abi, instructionSet, appDataDir, invokeWith, packageName, zygoteArgs);
     }
 
     /** @hide */
-    public static final ProcessStartResult startWebView(final String processClass,
-                                  final String niceName,
-                                  int uid, int gid, int[] gids,
+    public static final ProcessStartResult startWebView(@NonNull final String processClass,
+                                  @Nullable final String niceName,
+                                  int uid, int gid, @Nullable int[] gids,
                                   int runtimeFlags, int mountExternal,
                                   int targetSdkVersion,
-                                  String seInfo,
-                                  String abi,
-                                  String instructionSet,
-                                  String appDataDir,
-                                  String invokeWith,
-                                  String packageName,
-                                  String[] zygoteArgs) {
+                                  @Nullable String seInfo,
+                                  @NonNull String abi,
+                                  @Nullable String instructionSet,
+                                  @Nullable String appDataDir,
+                                  @Nullable String invokeWith,
+                                  @Nullable String packageName,
+                                  @Nullable String[] zygoteArgs) {
         return WebViewZygote.getProcess().start(processClass, niceName, uid, gid, gids,
                     runtimeFlags, mountExternal, targetSdkVersion, seInfo,
                     abi, instructionSet, appDataDir, invokeWith, packageName, zygoteArgs);
diff --git a/core/java/android/os/ZygoteProcess.java b/core/java/android/os/ZygoteProcess.java
index 732d3778..99181ac 100644
--- a/core/java/android/os/ZygoteProcess.java
+++ b/core/java/android/os/ZygoteProcess.java
@@ -16,6 +16,8 @@
 
 package android.os;
 
+import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.net.LocalSocket;
 import android.net.LocalSocketAddress;
 import android.util.Log;
@@ -212,23 +214,24 @@
      * @param instructionSet null-ok the instruction set to use.
      * @param appDataDir null-ok the data directory of the app.
      * @param invokeWith null-ok the command to invoke with.
+     * @param packageName null-ok the name of the package this process belongs to.
      * @param zygoteArgs Additional arguments to supply to the zygote process.
      *
      * @return An object that describes the result of the attempt to start the process.
      * @throws RuntimeException on fatal start failure
      */
-    public final Process.ProcessStartResult start(final String processClass,
+    public final Process.ProcessStartResult start(@NonNull final String processClass,
                                                   final String niceName,
-                                                  int uid, int gid, int[] gids,
+                                                  int uid, int gid, @Nullable int[] gids,
                                                   int runtimeFlags, int mountExternal,
                                                   int targetSdkVersion,
-                                                  String seInfo,
-                                                  String abi,
-                                                  String instructionSet,
-                                                  String appDataDir,
-                                                  String invokeWith,
-                                                  String packageName,
-                                                  String[] zygoteArgs) {
+                                                  @Nullable String seInfo,
+                                                  @NonNull String abi,
+                                                  @Nullable String instructionSet,
+                                                  @Nullable String appDataDir,
+                                                  @Nullable String invokeWith,
+                                                  @Nullable String packageName,
+                                                  @Nullable String[] zygoteArgs) {
         try {
             return startViaZygote(processClass, niceName, uid, gid, gids,
                     runtimeFlags, mountExternal, targetSdkVersion, seInfo,
@@ -351,24 +354,25 @@
      * @param appDataDir null-ok the data directory of the app.
      * @param startChildZygote Start a sub-zygote. This creates a new zygote process
      * that has its state cloned from this zygote process.
+     * @param packageName null-ok the name of the package this process belongs to.
      * @param extraArgs Additional arguments to supply to the zygote process.
      * @return An object that describes the result of the attempt to start the process.
      * @throws ZygoteStartFailedEx if process start failed for any reason
      */
-    private Process.ProcessStartResult startViaZygote(final String processClass,
-                                                      final String niceName,
+    private Process.ProcessStartResult startViaZygote(@NonNull final String processClass,
+                                                      @Nullable final String niceName,
                                                       final int uid, final int gid,
-                                                      final int[] gids,
+                                                      @Nullable final int[] gids,
                                                       int runtimeFlags, int mountExternal,
                                                       int targetSdkVersion,
-                                                      String seInfo,
-                                                      String abi,
-                                                      String instructionSet,
-                                                      String appDataDir,
-                                                      String invokeWith,
+                                                      @Nullable String seInfo,
+                                                      @NonNull String abi,
+                                                      @Nullable String instructionSet,
+                                                      @Nullable String appDataDir,
+                                                      @Nullable String invokeWith,
                                                       boolean startChildZygote,
-                                                      String packageName,
-                                                      String[] extraArgs)
+                                                      @Nullable String packageName,
+                                                      @Nullable String[] extraArgs)
                                                       throws ZygoteStartFailedEx {
         ArrayList<String> argsForZygote = new ArrayList<String>();
 
diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java
index b60b43a..06c41d8 100644
--- a/core/java/com/android/internal/os/ZygoteConnection.java
+++ b/core/java/com/android/internal/os/ZygoteConnection.java
@@ -22,6 +22,7 @@
 import static android.system.OsConstants.STDERR_FILENO;
 import static android.system.OsConstants.STDIN_FILENO;
 import static android.system.OsConstants.STDOUT_FILENO;
+
 import static com.android.internal.os.ZygoteConnectionConstants.CONNECTION_TIMEOUT_MILLIS;
 import static com.android.internal.os.ZygoteConnectionConstants.MAX_ZYGOTE_ARGC;
 import static com.android.internal.os.ZygoteConnectionConstants.WRAPPED_PID_TIMEOUT_MILLIS;
@@ -36,12 +37,15 @@
 import android.system.Os;
 import android.system.StructPollfd;
 import android.util.Log;
+
 import dalvik.system.VMRuntime;
+
+import libcore.io.IoUtils;
+
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
-import java.io.EOFException;
 import java.io.FileDescriptor;
 import java.io.IOException;
 import java.io.InputStreamReader;
@@ -49,8 +53,6 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 
-import libcore.io.IoUtils;
-
 /**
  * A connection that can make spawn requests.
  */
@@ -377,6 +379,7 @@
      *    are the settings for current and max value.</i>
      *   <li> --instruction-set=<i>instruction-set-string</i> which instruction set to use/emulate.
      *   <li> --nice-name=<i>nice name to appear in ps</i>
+     *   <li> --package-name=<i>package name this process belongs to</i>
      *   <li> --runtime-args indicates that the remaining arg list should
      * be handed off to com.android.internal.os.RuntimeInit, rather than
      * processed directly.
@@ -680,6 +683,9 @@
                     }
                     expectRuntimeArgs = false;
                 } else if (arg.startsWith("--package-name=")) {
+                    if (packageName != null) {
+                        throw new IllegalArgumentException("Duplicate arg specified");
+                    }
                     packageName = arg.substring(arg.indexOf('=') + 1);
                 } else {
                     break;