利用oom_adj提高Application所在进程的优先级

1.增加Application属性android:gnHeavyWeight

2.在Manifest Application中声明使用属性android:gnHeavyWeight="true"

diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java
index 665b606..b81c9d6 100644
--- a/core/java/android/content/pm/ApplicationInfo.java
+++ b/core/java/android/content/pm/ApplicationInfo.java
@@ -301,6 +301,12 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
      */
     public static final int FLAG_CANT_SAVE_STATE = 1<<27;
 
+    // Gionee 2011-12-30 huyuke add for CR00XXXX begin
+    /**
+     * @hide
+     */
+    public static final int FLAG_GN_HEAVY_WEIGHT = 1<<26;
+    // Gionee 2011-12-30 huyuke add for CR00XXXX end
     /**
      * Flags associated with the application.  Any combination of
      * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE},
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index ff3656c..bc97e46 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -1519,8 +1519,17 @@ public class PackageParser {
             if (sa.getBoolean(
                     com.android.internal.R.styleable.AndroidManifestApplication_persistent,
                     false)) {
+                Log.d(TAG, "HHHHHH parseApplication set FLAG_PERSISTENT pkg: " + pkgName);
                 ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
             }
+           // Gionee 2011-12-30 huyuke add for CR00XXXX begin
+            if (sa.getBoolean(
+                    com.android.internal.R.styleable.AndroidManifestApplication_gnHeavyWeight,
+                    false)) {
+                Log.d(TAG, "HHHHHH parseApplication set FLAG_GN_HEAVY_WEIGHT pkg: " + pkgName);
+                ai.flags |= ApplicationInfo.FLAG_GN_HEAVY_WEIGHT;
+            }
+           // Gionee 2011-12-30 huyuke add for CR00XXXX end
         }
 
         if ((flags & PARSE_FORWARD_LOCK) != 0) {
diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml
index f31dfec..6d4d12a 100644
--- a/core/res/res/values/attrs_manifest.xml
+++ b/core/res/res/values/attrs_manifest.xml
@@ -680,6 +680,10 @@
         <enum name="preferExternal" value="2" />
     </attr>
 
+    <!-- Gionee 2011-12-30 huyuke add for CR00XXXX begin -->
+    <attr name="gnHeavyWeight" format="boolean" />
+    <!-- Gionee 2011-12-30 huyuke add for CR00XXXX end -->
+
     <!-- The <code>manifest</code> tag is the root of an
          <code>AndroidManifest.xml</code> file,
          describing the contents of an Android package (.apk) file.  One
@@ -773,6 +777,9 @@
              application is running, the user will be informed of this.
              @hide -->
         <attr name="cantSaveState" format="boolean" />
+        <!-- Gionee 2011-12-30 huyuke add for CR00XXXX begin -->
+        <attr name="gnHeavyWeight" />
+        <!-- Gionee 2011-12-30 huyuke add for CR00XXXX end -->
     </declare-styleable>
     
     <!-- The <code>permission</code> tag declares a security permission that can be
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 4005e96..19c9189 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -572,6 +572,9 @@
   <public type="attr" name="listChoiceIndicatorMultiple" id="0x0101021a" />
   <public type="attr" name="versionCode" id="0x0101021b" />
   <public type="attr" name="versionName" id="0x0101021c" />
+  <!-- Gionee 2011-12-30 huyuke add for CR00XXXX begin -->
+  <public type="attr" name="gnHeavyWeight" id="0x010102dd" />
+  <!-- Gionee 2011-12-30 huyuke add for CR00XXXX end -->
 
   <public type="id" name="background" id="0x01020000" />
   <public type="id" name="checkbox" id="0x01020001" />
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index 6db4559..529defe 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -142,7 +142,7 @@ import java.util.concurrent.atomic.AtomicLong;
 public final class ActivityManagerService extends ActivityManagerNative
         implements Watchdog.Monitor, BatteryStatsImpl.BatteryCallback {
     static final String TAG = "ActivityManager";
-    static final boolean DEBUG = false;
+    static final boolean DEBUG = true;
     static final boolean localLOGV = DEBUG ? Config.LOGD : Config.LOGV;
     static final boolean DEBUG_SWITCH = localLOGV || false;
     static final boolean DEBUG_TASKS = localLOGV || false;
@@ -309,6 +309,9 @@ public final class ActivityManagerService extends ActivityManagerNative
     // don't want to kill it, but doing so is not completely fatal.
     static final int CORE_SERVER_ADJ = -12;
 
+    // Gionee 2011-12-30 huyuke add for CR00XXXX begin
+    static final int GN_CORE_SERVER_ADJ = -1;
+    // Gionee 2011-12-30 huyuke add for CR00XXXX end
     // The system process runs at the default adjustment.
     static final int SYSTEM_ADJ = -16;
 
@@ -3640,6 +3643,14 @@ public final class ActivityManagerService extends ActivityManagerNative
             return false;
         }
 
+        // Gionee 2011-12-30 huyuke add for CR00XXXX begin
+        Log.d(TAG, "HHHHHH attachApplicationLocked: " + app.info.processName);
+        if ((app.info.flags&(ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_GN_HEAVY_WEIGHT))
+                == (ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_GN_HEAVY_WEIGHT)) {
+            Log.d(TAG, "HHHHHH attachApplicationLocked gn heavy app: " + app.info.processName);
+            app.maxAdj = GN_CORE_SERVER_ADJ;
+        }
+        // Gionee 2011-12-30 huyuke add for CR00XXXX end
         if (!didSomething) {
             updateOomAdjLocked();
         }
@@ -5616,6 +5627,7 @@ public final class ActivityManagerService extends ActivityManagerNative
     final ProcessRecord addAppLocked(ApplicationInfo info) {
         ProcessRecord app = getProcessRecordLocked(info.processName, info.uid);
 
+        Log.d(TAG, "HHHHHH addAppLocked: " + info.processName);
         if (app == null) {
             app = newProcessRecordLocked(null, info, null);
             mProcessNames.put(info.processName, info.uid, app);
@@ -5624,6 +5636,7 @@ public final class ActivityManagerService extends ActivityManagerNative
 
         if ((info.flags&(ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PERSISTENT))
                 == (ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PERSISTENT)) {
+            Log.d(TAG, "HHHHHH persistent app: " + info.processName);
             app.persistent = true;
             app.maxAdj = CORE_SERVER_ADJ;
         }


你可能感兴趣的:(android,server,null,application,System,Class)