OSDN Git Service

Only show dialog if top app is killed
authorNg Zhi An <zhin@google.com>
Sat, 7 Oct 2017 00:17:11 +0000 (17:17 -0700)
committerNg Zhi An <zhin@google.com>
Thu, 12 Oct 2017 23:03:04 +0000 (16:03 -0700)
This changes the check from only looking at the
app's curSchedGroup to checking if the app that is
killed matches the current top app (retrieved
using resumedAppLocked)

Bug: 67513077
Bug: 67416130
Test: manual
Change-Id: Idda4c4b21081737ee3ab2101a8cf2a94f0d8df23

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

index b4741d1..a95b7f3 100644 (file)
@@ -5459,7 +5459,7 @@ public class ActivityManagerService extends IActivityManager.Stub
             boolean doLowMem = app.instr == null;
             boolean doOomAdj = doLowMem;
             if (!app.killedByAm) {
-                maybeNotifyTopAppKilled(app);
+                maybeNotifyTopAppKilledLocked(app);
                 Slog.i(TAG, "Process " + app.processName + " (pid " + pid + ") has died: "
                         + ProcessList.makeOomAdjString(app.setAdj)
                         + ProcessList.makeProcStateString(app.setProcState));
@@ -5494,8 +5494,8 @@ public class ActivityManagerService extends IActivityManager.Stub
     }
 
     /** Show system error dialog when a top app is killed by LMK */
-    void maybeNotifyTopAppKilled(ProcessRecord app) {
-        if (!shouldNotifyTopAppKilled(app)) {
+    void maybeNotifyTopAppKilledLocked(ProcessRecord app) {
+        if (!shouldNotifyTopAppKilledLocked(app)) {
             return;
         }
 
@@ -5505,8 +5505,10 @@ public class ActivityManagerService extends IActivityManager.Stub
     }
 
     /** Only show notification when the top app is killed on low ram devices */
-    private boolean shouldNotifyTopAppKilled(ProcessRecord app) {
-        return app.curSchedGroup == ProcessList.SCHED_GROUP_TOP_APP &&
+    private boolean shouldNotifyTopAppKilledLocked(ProcessRecord app) {
+        final ActivityRecord TOP_ACT = resumedAppLocked();
+        final ProcessRecord TOP_APP = TOP_ACT != null ? TOP_ACT.app : null;
+        return app == TOP_APP &&
             ActivityManager.isLowRamDeviceStatic();
     }