Adjust Java Language thread priority in new processes.

Previously init started the Zygote with -20 nice value and then
immediately switched it to 0 in ZygoteInit.main so that new applications
forked from the Zygote have the correct Java Language thread priority.
This patch delays this priority change so that it only affects the new
processes and not the priority of the Zygote.

Test: m & flash & check ps
Change-Id: Id00d0cfd642f02640c40b6e7b2aa8933a320b60c
diff --git a/core/java/com/android/internal/os/Zygote.java b/core/java/com/android/internal/os/Zygote.java
index da99edf..95564ae 100644
--- a/core/java/com/android/internal/os/Zygote.java
+++ b/core/java/com/android/internal/os/Zygote.java
@@ -643,6 +643,9 @@
             // End of the postFork event.
             Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
 
+            // Set the Java Language thread priority to the default value for new apps.
+            Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
+
             return ZygoteInit.zygoteInit(args.mTargetSdkVersion,
                                          args.mRemainingArgs,
                                          null /* classLoader */);
diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java
index 8b0899d..e81ab4f 100644
--- a/core/java/com/android/internal/os/ZygoteConnection.java
+++ b/core/java/com/android/internal/os/ZygoteConnection.java
@@ -472,6 +472,9 @@
 
         Zygote.setAppProcessName(parsedArgs, TAG);
 
+        // Set the Java Language thread priority to the default value for new apps.
+        Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
+
         // End of the postFork event.
         Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
         if (parsedArgs.mInvokeWith != null) {
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 6c358db..861b105 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -507,6 +507,9 @@
             }
         }
 
+        // Set the Java Language thread priority to the default value for the system server.
+        Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
+
         if (parsedArgs.mInvokeWith != null) {
             String[] args = parsedArgs.mRemainingArgs;
             // If we have a non-null system server class path, we'll have to duplicate the
@@ -815,13 +818,22 @@
         return result;
     }
 
+    /**
+     * This is the entry point for a Zygote process.  It creates the Zygote server, loads resources,
+     * and handles other tasks related to preparing the process for forking into applications.
+     *
+     * This process is started with a nice value of -20 (highest priority).  All paths that flow
+     * into new processes are required to either set the priority to the default value or terminate
+     * before executing any non-system code.  The native side of this occurs in SpecializeCommon,
+     * while the Java Language priority is changed in ZygoteInit.handleSystemServerProcess,
+     * ZygoteConnection.handleChildProc, and Zygote.usapMain.
+     *
+     * @param argv  Command line arguments used to specify the Zygote's configuration.
+     */
     @UnsupportedAppUsage
     public static void main(String argv[]) {
         ZygoteServer zygoteServer = null;
 
-        // Set the initial thread priority to the "normal" value.
-        Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
-
         // Mark zygote start. This ensures that thread creation will throw
         // an error.
         ZygoteHooks.startZygoteNoThreadCreation();