Set processes' comm names to their package names.

When debugging audit logs, it is often helpful to
have the package's name. Bear in mind that the
package name is the right most chars up to
TASK_COMM_LEN. Although a possibility of truncation
exists, it can be useful for narrowing down the
possibilities.

(cherry-pick of 5ae4516eb30c7cf674025ab01b097e62c7901b98 from AOSP.)

Change-Id: I27dfd986ebe86af4a5b8c702af955d5065daa12f
diff --git a/runtime/native/dalvik_system_Zygote.cc b/runtime/native/dalvik_system_Zygote.cc
index dac2c89..2e3d6a6 100644
--- a/runtime/native/dalvik_system_Zygote.cc
+++ b/runtime/native/dalvik_system_Zygote.cc
@@ -36,6 +36,7 @@
 #include "ScopedPrimitiveArray.h"
 #include "ScopedUtfChars.h"
 #include "thread-inl.h"
+#include "utils.h"
 
 #if defined(HAVE_PRCTL)
 #include <sys/prctl.h>
@@ -496,6 +497,15 @@
                     << (is_system_server ? "true" : "false") << ", "
                     << "\"" << se_info_c_str << "\", \"" << se_name_c_str << "\") failed";
       }
+
+      // Make it easier to debug audit logs by setting the main thread's name to the
+      // nice name rather than "app_process".
+      if (se_info_c_str == NULL && is_system_server) {
+        se_name_c_str = "system_server";
+      }
+      if (se_info_c_str != NULL) {
+        SetThreadName(se_name_c_str);
+      }
     }
 #else
     UNUSED(is_system_server);