Enable strictmode logging in system_server & add a lock.

We weren't logging strictmode violation in the system_server process
in non-user builds (only system apps), even though the rest of the
strictmode logging supports it.

Also add a missing lock in ActivityManagerService.

Change-Id: If2af96a7e4fdde604a647b836097f0029ef1334b
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index 483941d..2cdf31e 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -6535,13 +6535,19 @@
      * Utility function for addErrorToDropBox and handleStrictModeViolation's logging
      * to append various headers to the dropbox log text.
      */
-    private static void appendDropBoxProcessHeaders(ProcessRecord process, StringBuilder sb) {
-        if (process == null || process.pid == MY_PID) {
-            sb.append("Process: system_server\n");
-        } else {
-            sb.append("Process: ").append(process.processName).append("\n");
-        }
-        if (process != null) {
+    private void appendDropBoxProcessHeaders(ProcessRecord process, StringBuilder sb) {
+        // Note: ProcessRecord 'process' is guarded by the service
+        // instance.  (notably process.pkgList, which could otherwise change
+        // concurrently during execution of this method)
+        synchronized (this) {
+            if (process == null || process.pid == MY_PID) {
+                sb.append("Process: system_server\n");
+            } else {
+                sb.append("Process: ").append(process.processName).append("\n");
+            }
+            if (process == null) {
+                return;
+            }
             int flags = process.info.flags;
             IPackageManager pm = AppGlobals.getPackageManager();
             sb.append("Flags: 0x").append(Integer.toString(flags, 16)).append("\n");