Work on issue #26390161: Throttle syncs/jobs when system is low on RAM

We now have a fixed array of job service contexts, which doesn't
vary by build configuration.  Instead, we keep track of the maximum
number of concurrent jobs we want to allow to run, and don't
make use of a context if it would put us over that limit.

The available contexts is now 8 (the largest used to be 6), although
the maximum we will normally schedule is still 6.  We have the other
two around only for use by the current foreground app, to allow it
to schedule work while the user is in it, even if we have reached
our normal limit on the number of concurrent jobs.

The maximum number of concurrent jobs varies based on the memory
state of the device, from 6 (if memory is normal) down to 1
(if memory is critical).  We aren't yet trying to stop all jobs
if memory gets lower than critical.

Instead of just keeping track of whether a uid is in the foreground,
we now track whether it is the top as well.  Only the top uid
can schedule additional jobs above the current limit.

Also improved some of the dumpsys output.

Change-Id: Icc95e42231a806f0bfa3e2f99ccc2b85cefac320
diff --git a/core/java/android/app/job/JobInfo.java b/core/java/android/app/job/JobInfo.java
index 4cbaf6c..039c9d7 100644
--- a/core/java/android/app/job/JobInfo.java
+++ b/core/java/android/app/job/JobInfo.java
@@ -102,12 +102,19 @@
     public static final int PRIORITY_SYNC_INITIALIZATION = 20;
 
     /**
-     * Value of {@link #getPriority} for the current foreground app (overrides the supplied
+     * Value of {@link #getPriority} for a foreground app (overrides the supplied
      * JobInfo priority if it is smaller).
      * @hide
      */
     public static final int PRIORITY_FOREGROUND_APP = 30;
 
+    /**
+     * Value of {@link #getPriority} for the current top app (overrides the supplied
+     * JobInfo priority if it is smaller).
+     * @hide
+     */
+    public static final int PRIORITY_TOP_APP = 40;
+
     private final int jobId;
     private final PersistableBundle extras;
     private final ComponentName service;