Add APIs for finding heavy-weight apps.

Change-Id: I6c865cce404cac1a08eee056f963de5d276d5898
diff --git a/api/current.xml b/api/current.xml
index f8c644e..8cc95ab 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -21750,6 +21750,17 @@
  visibility="public"
 >
 </field>
+<field name="FLAG_HEAVY_WEIGHT"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="1"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="IMPORTANCE_BACKGROUND"
  type="int"
  transient="false"
@@ -21860,6 +21871,16 @@
  visibility="public"
 >
 </field>
+<field name="flags"
+ type="int"
+ transient="false"
+ volatile="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="importance"
  type="int"
  transient="false"
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java
index 7f95bf5..eb7520f 100644
--- a/core/java/android/app/ActivityManager.java
+++ b/core/java/android/app/ActivityManager.java
@@ -717,9 +717,24 @@
          */
         public int uid;
         
+        /**
+         * All packages that have been loaded into the process.
+         */
         public String pkgList[];
         
         /**
+         * Constant for {@link #flags}: this is a heavy-weight process,
+         * meaning it will not be killed while in the background.
+         */
+        public static final int FLAG_HEAVY_WEIGHT = 1<<0;
+        
+        /**
+         * Flags of information.  May be any of
+         * {@link #FLAG_HEAVY_WEIGHT}.
+         */
+        public int flags;
+        
+        /**
          * Constant for {@link #importance}: this process is running the
          * foreground UI.
          */
@@ -846,6 +861,7 @@
             dest.writeInt(pid);
             dest.writeInt(uid);
             dest.writeStringArray(pkgList);
+            dest.writeInt(this.flags);
             dest.writeInt(importance);
             dest.writeInt(lru);
             dest.writeInt(importanceReasonCode);
@@ -858,6 +874,7 @@
             pid = source.readInt();
             uid = source.readInt();
             pkgList = source.readStringArray();
+            flags = source.readInt();
             importance = source.readInt();
             lru = source.readInt();
             importanceReasonCode = source.readInt();
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index d59ecdd..b3f49d9 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -9814,6 +9814,9 @@
                         new ActivityManager.RunningAppProcessInfo(app.processName,
                                 app.pid, app.getPackageList());
                     currApp.uid = app.info.uid;
+                    if (mHeavyWeightProcess == app) {
+                        currApp.flags |= ActivityManager.RunningAppProcessInfo.FLAG_HEAVY_WEIGHT;
+                    }
                     int adj = app.curAdj;
                     if (adj >= EMPTY_APP_ADJ) {
                         currApp.importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_EMPTY;