Implement #10744011: Serialize running of background services

Added some code to the activity manager to keep track of
services that are launching and limit the number that can
be launched concurrently.  This only comes into play under
specific circumstances: when the service launch is a background
request (so timing is not important) and its process is not
already running at a high priority.

In this case, we have a list of services that are currently
launching and when that gets too big we start delaying the
launch of future services until currently launching ones are
finished.

There are some important tuning parameters for this: how many
background services we allow to launch concurrently (currently
1 on low-ram devices, 3 on other devices), and how long we
wait for a background service to run before consider it to be
a more long-running service and go on to the next pending
launch (currently set to 15 seconds).

Also while in here, did some cleanup of the service code:

- A little refactoring to make per-user data cleaner.
- Switch to ArrayMap.

Change-Id: I09f372eb5e0f81a8de7c64f8320af41e84b90aa3
diff --git a/services/java/com/android/server/am/ProcessRecord.java b/services/java/com/android/server/am/ProcessRecord.java
index 283d122..892271f 100644
--- a/services/java/com/android/server/am/ProcessRecord.java
+++ b/services/java/com/android/server/am/ProcessRecord.java
@@ -527,7 +527,33 @@
         sb.append('}');
         return stringName = sb.toString();
     }
-    
+
+    public String makeAdjReason() {
+        StringBuilder sb = new StringBuilder(128);
+        sb.append('(').append(adjType).append(')');
+        if (adjSource != null || adjTarget != null) {
+            sb.append(' ');
+            if (adjTarget instanceof ComponentName) {
+                sb.append(((ComponentName)adjTarget).flattenToShortString());
+            } else if (adjTarget != null) {
+                sb.append(adjTarget.toString());
+            } else {
+                sb.append("{null}");
+            }
+            sb.append("<=");
+            if (adjSource instanceof ProcessRecord) {
+                sb.append("Proc{");
+                sb.append(((ProcessRecord)adjSource).toShortString());
+                sb.append("}");
+            } else if (adjSource != null) {
+                sb.append(adjSource.toString());
+            } else {
+                sb.append("{null}");
+            }
+        }
+        return sb.toString();
+    }
+
     /*
      *  Return true if package has been added false if not
      */