Use oom_adj to increase the priority of the process where the application is located

Source: Internet
Author: User

1. added the application property Android: gnheavyweight.

2. Declare the Android: gnheavyweight = "true" attribute in the manifest Application"

diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.javaindex 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.javaindex 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.xmlindex 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 bediff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xmlindex 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.javaindex 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;         }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.