OSDN Git Service

Fix issue #17829949: Don't kill Bluetooth service...
authorDianne Hackborn <hackbod@google.com>
Fri, 10 Oct 2014 22:03:13 +0000 (15:03 -0700)
committerDianne Hackborn <hackbod@google.com>
Fri, 10 Oct 2014 22:05:33 +0000 (15:05 -0700)
...even in extreme low memory condition

Bind to Bluetooth with BIND_IMPORTANT, so that it is allowed to
go to a higher oom adj level.

Fix some problems when this is done from a system or persistent
process, where this would go to a level that is *too* high.  Instead,
introduce a new oom adj level for it that is right below persistent.

Change-Id: I002bcc4accc36c8579c4cda161be7d2fba21ba17

services/core/java/com/android/server/BluetoothManagerService.java
services/core/java/com/android/server/am/ActivityManagerService.java
services/core/java/com/android/server/am/ProcessList.java

index 7b64139..636228b 100644 (file)
@@ -663,7 +663,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                             mHandler.sendMessageDelayed(timeoutMsg,TIMEOUT_BIND_MS);
                             Intent i = new Intent(IBluetooth.class.getName());
                             if (!doBind(i, mConnection,
-                                    Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
+                                    Context.BIND_AUTO_CREATE | Context.BIND_IMPORTANT,
+                                    UserHandle.CURRENT)) {
                                 mHandler.removeMessages(MESSAGE_TIMEOUT_BIND);
                             } else {
                                 mBinding = true;
@@ -1050,7 +1051,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                 mHandler.sendMessageDelayed(timeoutMsg,TIMEOUT_BIND_MS);
                 mConnection.setGetNameAddressOnly(false);
                 Intent i = new Intent(IBluetooth.class.getName());
-                if (!doBind(i, mConnection,Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
+                if (!doBind(i, mConnection,Context.BIND_AUTO_CREATE | Context.BIND_IMPORTANT,
+                        UserHandle.CURRENT)) {
                     mHandler.removeMessages(MESSAGE_TIMEOUT_BIND);
                 } else {
                     mBinding = true;
@@ -1153,7 +1155,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                     if (mContext.getPackageManager().hasSystemFeature(
                                                      PackageManager.FEATURE_BLUETOOTH_LE)) {
                         Intent i = new Intent(IBluetoothGatt.class.getName());
-                        doBind(i, mConnection, Context.BIND_AUTO_CREATE, UserHandle.CURRENT);
+                        doBind(i, mConnection, Context.BIND_AUTO_CREATE | Context.BIND_IMPORTANT,
+                                UserHandle.CURRENT);
                     }
                 } else {
                     //If Bluetooth is off, send service down event to proxy objects, and unbind
index 0c8e26e..8357366 100755 (executable)
@@ -13083,6 +13083,7 @@ public final class ActivityManagerService extends ActivityManagerNative
             pw.println("  OOM levels:");
             printOomLevel(pw, "SYSTEM_ADJ", ProcessList.SYSTEM_ADJ);
             printOomLevel(pw, "PERSISTENT_PROC_ADJ", ProcessList.PERSISTENT_PROC_ADJ);
+            printOomLevel(pw, "PERSISTENT_SERVICE_ADJ", ProcessList.PERSISTENT_SERVICE_ADJ);
             printOomLevel(pw, "FOREGROUND_APP_ADJ", ProcessList.FOREGROUND_APP_ADJ);
             printOomLevel(pw, "VISIBLE_APP_ADJ", ProcessList.VISIBLE_APP_ADJ);
             printOomLevel(pw, "PERCEPTIBLE_APP_ADJ", ProcessList.PERCEPTIBLE_APP_ADJ);
@@ -13883,7 +13884,8 @@ public final class ActivityManagerService extends ActivityManagerNative
 
     static final int[] DUMP_MEM_OOM_ADJ = new int[] {
             ProcessList.NATIVE_ADJ,
-            ProcessList.SYSTEM_ADJ, ProcessList.PERSISTENT_PROC_ADJ, ProcessList.FOREGROUND_APP_ADJ,
+            ProcessList.SYSTEM_ADJ, ProcessList.PERSISTENT_PROC_ADJ,
+            ProcessList.PERSISTENT_SERVICE_ADJ, ProcessList.FOREGROUND_APP_ADJ,
             ProcessList.VISIBLE_APP_ADJ, ProcessList.PERCEPTIBLE_APP_ADJ,
             ProcessList.BACKUP_APP_ADJ, ProcessList.HEAVY_WEIGHT_APP_ADJ,
             ProcessList.SERVICE_ADJ, ProcessList.HOME_APP_ADJ,
@@ -13891,7 +13893,7 @@ public final class ActivityManagerService extends ActivityManagerNative
     };
     static final String[] DUMP_MEM_OOM_LABEL = new String[] {
             "Native",
-            "System", "Persistent", "Foreground",
+            "System", "Persistent", "Persistent Service", "Foreground",
             "Visible", "Perceptible",
             "Heavy Weight", "Backup",
             "A Services", "Home",
@@ -13899,7 +13901,7 @@ public final class ActivityManagerService extends ActivityManagerNative
     };
     static final String[] DUMP_MEM_OOM_COMPACT_LABEL = new String[] {
             "native",
-            "sys", "pers", "fore",
+            "sys", "pers", "persvc", "fore",
             "vis", "percept",
             "heavy", "backup",
             "servicea", "home",
@@ -16811,7 +16813,8 @@ public final class ActivityManagerService extends ActivityManagerNative
                             } else {
                                 if ((cr.flags&(Context.BIND_ABOVE_CLIENT
                                         |Context.BIND_IMPORTANT)) != 0) {
-                                    adj = clientAdj;
+                                    adj = clientAdj >= ProcessList.PERSISTENT_SERVICE_ADJ
+                                            ? clientAdj : ProcessList.PERSISTENT_SERVICE_ADJ;
                                 } else if ((cr.flags&Context.BIND_NOT_VISIBLE) != 0
                                         && clientAdj < ProcessList.PERCEPTIBLE_APP_ADJ
                                         && adj > ProcessList.PERCEPTIBLE_APP_ADJ) {
index 0ea66b9..5b22255 100644 (file)
@@ -97,6 +97,10 @@ final class ProcessList {
     // rather not kill it!
     static final int FOREGROUND_APP_ADJ = 0;
 
+    // This is a process that the system or a persistent process has bound to,
+    // and indicated it is important.
+    static final int PERSISTENT_SERVICE_ADJ = -11;
+
     // This is a system persistent process, such as telephony.  Definitely
     // don't want to kill it, but doing so is not completely fatal.
     static final int PERSISTENT_PROC_ADJ = -12;
@@ -336,6 +340,8 @@ final class ProcessList {
             return buildOomTag("vis  ", null, setAdj, ProcessList.VISIBLE_APP_ADJ);
         } else if (setAdj >= ProcessList.FOREGROUND_APP_ADJ) {
             return buildOomTag("fore ", null, setAdj, ProcessList.FOREGROUND_APP_ADJ);
+        } else if (setAdj >= ProcessList.PERSISTENT_SERVICE_ADJ) {
+            return buildOomTag("psvc ", null, setAdj, ProcessList.PERSISTENT_SERVICE_ADJ);
         } else if (setAdj >= ProcessList.PERSISTENT_PROC_ADJ) {
             return buildOomTag("pers ", null, setAdj, ProcessList.PERSISTENT_PROC_ADJ);
         } else if (setAdj >= ProcessList.SYSTEM_ADJ) {