Fix the reset of boosted zygote thread priority.

This fixes the unexpected priority 112 of the daemon threads
(eg. HeapTaskDaemon). The problem was that when the zygote main
thread's priority is reset, it directly calls setpriority() and fails
to update the priority value in java.lang.Thread, which in turn causes
any threads created by the thread to unexpectedly inherit the boosted
priority. Calling java.lang.Thread.setPriority instead fixes.

Bug: 35801778
Bug: 28866384
Test: angler master userdebug boots and thread priorities checked.

Change-Id: I68a6ed7244a9067acc2749feca7f88422bf44b02
diff --git a/core/java/com/android/internal/os/Zygote.java b/core/java/com/android/internal/os/Zygote.java
index fa71a62..e065843 100644
--- a/core/java/com/android/internal/os/Zygote.java
+++ b/core/java/com/android/internal/os/Zygote.java
@@ -100,6 +100,8 @@
           int[][] rlimits, int mountExternal, String seInfo, String niceName, int[] fdsToClose,
           int[] fdsToIgnore, String instructionSet, String appDataDir) {
         VM_HOOKS.preFork();
+        // Resets nice priority for zygote process.
+        resetNicePriority();
         int pid = nativeForkAndSpecialize(
                   uid, gid, gids, debugFlags, rlimits, mountExternal, seInfo, niceName, fdsToClose,
                   fdsToIgnore, instructionSet, appDataDir);
@@ -144,6 +146,8 @@
     public static int forkSystemServer(int uid, int gid, int[] gids, int debugFlags,
             int[][] rlimits, long permittedCapabilities, long effectiveCapabilities) {
         VM_HOOKS.preFork();
+        // Resets nice priority for zygote process.
+        resetNicePriority();
         int pid = nativeForkSystemServer(
                 uid, gid, gids, debugFlags, rlimits, permittedCapabilities, effectiveCapabilities);
         // Enable tracing as soon as we enter the system_server.
@@ -174,9 +178,13 @@
     }
 
     /**
-     * Resets this process' priority to the default value (0).
+     * Resets the calling thread priority to the default value (Thread.NORM_PRIORITY
+     * or nice value 0). This updates both the priority value in java.lang.Thread and
+     * the nice value (setpriority).
      */
-    native static void nativeResetNicePriority();
+    static void resetNicePriority() {
+        Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
+    }
 
     /**
      * Executes "/system/bin/sh -c <command>" using the exec() system call.