From 6a99e776867fa567a67416950fcd0b99e255e13f Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Wed, 3 Nov 2021 20:27:50 -0600 Subject: [PATCH] Set pending top and update process state for top resumed change When switching focus between resumed activities, there is no activity state change to trigger update process state. So if it is the case that misses to update, add as pending top to ensure the current top have higher oom-adj, and trigger a full oom-adj update to refresh process states because layer rank of tasks are also changed. Fixes: 204980211 Test: ActivityTaskSupervisorTests#testUpdatePendingTopForTopResumed Test: Enter split with 2 apps, use command adb shell dumpsys activity oom | grep -A2 A/TOP to observe the value of oom-adj after switching focus. Change-Id: I411a3980ea23d875dd8d9ce7af80de74957f1caa --- .../server/wm/ActivityTaskSupervisor.java | 10 +++++++ .../server/wm/WindowProcessController.java | 7 ++++- .../wm/ActivityTaskSupervisorTests.java | 26 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java b/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java index 7c5f059fb89a4..c8b7d982fa0ee 100644 --- a/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java +++ b/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java @@ -2049,6 +2049,16 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks { // Update the current top activity. mTopResumedActivity = topRootTask.getTopResumedActivity(); + // Update process state if there is no activity state change (e.g. focus change between + // multi-window mode activities) to make sure that the current top has top oom-adj. + // If the previous top is null, there should be activity state change from it, Then the + // process state should also have been updated so no need to update again. + if (mTopResumedActivity != null && prevTopActivity != null) { + if (mTopResumedActivity.app != null) { + mTopResumedActivity.app.addToPendingTop(); + } + mService.updateOomAdj(); + } scheduleTopResumedActivityStateIfNeeded(); mService.updateTopApp(mTopResumedActivity); diff --git a/services/core/java/com/android/server/wm/WindowProcessController.java b/services/core/java/com/android/server/wm/WindowProcessController.java index 81878e3ef229c..1cfbe07d3f168 100644 --- a/services/core/java/com/android/server/wm/WindowProcessController.java +++ b/services/core/java/com/android/server/wm/WindowProcessController.java @@ -1110,7 +1110,7 @@ public class WindowProcessController extends ConfigurationContainer