Merge "Revert "Revert "installd: Fix set dex2oat to background after boot_complete""" am: 3031a838c2 am: 25cd8c1f2a am: cbd7c0aad3

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1526379

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: If1779213eb1894dee28bf590cb6695e8e37cae86
diff --git a/cmds/installd/dexopt.cpp b/cmds/installd/dexopt.cpp
index 594880a..65fc46e 100644
--- a/cmds/installd/dexopt.cpp
+++ b/cmds/installd/dexopt.cpp
@@ -1818,10 +1818,13 @@
 
     pid_t pid = fork();
     if (pid == 0) {
+        // Need to set schedpolicy before dropping privileges
+        // for cgroup migration. See details at b/175178520.
+        SetDex2OatScheduling(boot_complete);
+
         /* child -- drop privileges before continuing */
         drop_capabilities(uid);
 
-        SetDex2OatScheduling(boot_complete);
         if (flock(out_oat.fd(), LOCK_EX | LOCK_NB) != 0) {
             PLOG(ERROR) << "flock(" << out_oat.path() << ") failed";
             _exit(DexoptReturnCodes::kFlock);