Make TOP_SLEEPING procstate more like a cached process.

When an app is on the top of the activity stack but the screen
is not on, this doesn't really count as a top app in the normal
sense.  In particular, we'd really like to apply the normal
restrictions we have on background and cached apps: no network
access, no ability to use wake locks, etc.  (In other words, in
this state the app's activity is stopped, so from its perspective
it is no different than the user leaving it to go to another app.)

To do this, we change the order of the TOP_SLEEPING proc state
out from the range of foreground states down to between the
cached and background states.

Test: ActivityManagerProcessStateTest
Bug: 70808931
Change-Id: I994caba8c27553a452de75efa358be0e683d046f
diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java
index 2e9eeb1..9513b9b 100644
--- a/core/java/android/os/BatteryStats.java
+++ b/core/java/android/os/BatteryStats.java
@@ -658,32 +658,40 @@
          */
         public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1;
         /**
-         * Time this uid has any process that is top while the device is sleeping, but none
-         * in the "foreground service" or better state.
-         */
-        public static final int PROCESS_STATE_TOP_SLEEPING = 2;
-        /**
          * Time this uid has any process in an active foreground state, but none in the
          * "top sleeping" or better state.
          */
-        public static final int PROCESS_STATE_FOREGROUND = 3;
+        public static final int PROCESS_STATE_FOREGROUND = 2;
         /**
          * Time this uid has any process in an active background state, but none in the
          * "foreground" or better state.
          */
-        public static final int PROCESS_STATE_BACKGROUND = 4;
+        public static final int PROCESS_STATE_BACKGROUND = 3;
+        /**
+         * Time this uid has any process that is top while the device is sleeping, but not
+         * active for any other reason.  We kind-of consider it a kind of cached process
+         * for execution restrictions.
+         */
+        public static final int PROCESS_STATE_TOP_SLEEPING = 4;
+        /**
+         * Time this uid has any process that is in the background but it has an activity
+         * marked as "can't save state".  This is essentially a cached process, though the
+         * system will try much harder than normal to avoid killing it.
+         */
+        public static final int PROCESS_STATE_HEAVY_WEIGHT = 5;
         /**
          * Time this uid has any processes that are sitting around cached, not in one of the
          * other active states.
          */
-        public static final int PROCESS_STATE_CACHED = 5;
+        public static final int PROCESS_STATE_CACHED = 6;
         /**
          * Total number of process states we track.
          */
-        public static final int NUM_PROCESS_STATE = 6;
+        public static final int NUM_PROCESS_STATE = 7;
 
         static final String[] PROCESS_STATE_NAMES = {
-            "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached"
+                "Top", "Fg Service", "Foreground", "Background", "Top Sleeping", "Heavy Weight",
+                "Cached"
         };
 
         public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);