From 32917d88cd432cb3f3d3bc27bae892f72dd7f6e2 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Thu, 1 Jul 2021 03:05:41 +0800 Subject: [PATCH] Temporarily increase sched policy for dozing If always-on-display is enabled, there will be an animation for transiting to AOD screen. To prevent the animating process from using lower process scheduling group because of wakefulness, set it as animating to gain top-app group with a short duration. So the animation may be smoother. Though AOD may be disabled or other reasons that there won't be an animation, it should be fine by always setting the state. Because the target process just keeps idle, and the duration is short. Bug: 188253927 Test: Press power key to turn off screen, check: adb shell dumpsys activity o | grep " PERS.*systemui" It will show "T/ /PERU" = SCHED_GROUP_TOP_APP PROCESS_STATE_PERSISTENT_UI After a few seconds it will show "R/ /BFGS" = SCHED_GROUP_RESTRICTED PROCESS_STATE_BOUND_FOREGROUND_SERVICE Change-Id: Ia331a84cf70d28fdbfd4b9b02629c29539197fd5 --- .../com/android/server/am/OomAdjuster.java | 5 ++- .../server/wm/ActivityTaskManagerService.java | 38 ++++++++++++++++++- .../server/wm/WindowProcessController.java | 8 +++- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/am/OomAdjuster.java b/services/core/java/com/android/server/am/OomAdjuster.java index aef402ac32135..e1f862383e87b 100644 --- a/services/core/java/com/android/server/am/OomAdjuster.java +++ b/services/core/java/com/android/server/am/OomAdjuster.java @@ -1572,8 +1572,9 @@ public class OomAdjuster { state.setSystemNoUi(false); } if (!state.isSystemNoUi()) { - if (mService.mWakefulness.get() == PowerManagerInternal.WAKEFULNESS_AWAKE) { - // screen on, promote UI + if (mService.mWakefulness.get() == PowerManagerInternal.WAKEFULNESS_AWAKE + || state.isRunningRemoteAnimation()) { + // screen on or animating, promote UI state.setCurProcState(ActivityManager.PROCESS_STATE_PERSISTENT_UI); state.setCurrentSchedulingGroup(ProcessList.SCHED_GROUP_TOP_APP); } else { diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java index 569c11be01e7c..5c727342c6329 100644 --- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java +++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java @@ -302,6 +302,12 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { // started or finished. static final long ACTIVITY_BG_START_GRACE_PERIOD_MS = 10 * 1000; + /** + * The duration to keep a process in animating state (top scheduling group) when the + * wakefulness is changing from awake to doze or sleep. + */ + private static final long DOZE_ANIMATING_STATE_RETAIN_TIME_MS = 2000; + /** Used to indicate that an app transition should be animated. */ static final boolean ANIMATE = true; @@ -2757,12 +2763,35 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { }); } + // The caller MUST NOT hold the global lock. public void onScreenAwakeChanged(boolean isAwake) { mH.post(() -> { for (int i = mScreenObservers.size() - 1; i >= 0; i--) { mScreenObservers.get(i).onAwakeStateChanged(isAwake); } }); + + if (isAwake) { + return; + } + // If the device is going to sleep, keep a higher priority temporarily for potential + // animation of system UI. Even if AOD is not enabled, it should be no harm. + final WindowProcessController proc; + synchronized (mGlobalLockWithoutBoost) { + final WindowState notificationShade = mRootWindowContainer.getDefaultDisplay() + .getDisplayPolicy().getNotificationShade(); + proc = notificationShade != null + ? mProcessMap.getProcess(notificationShade.mSession.mPid) : null; + } + if (proc == null) { + return; + } + // Set to activity manager directly to make sure the state can be seen by the subsequent + // update of scheduling group. + proc.setRunningAnimationUnsafe(); + mH.removeMessages(H.UPDATE_PROCESS_ANIMATING_STATE, proc); + mH.sendMessageDelayed(mH.obtainMessage(H.UPDATE_PROCESS_ANIMATING_STATE, proc), + DOZE_ANIMATING_STATE_RETAIN_TIME_MS); } @Override @@ -5027,7 +5056,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { final class H extends Handler { static final int REPORT_TIME_TRACKER_MSG = 1; - + static final int UPDATE_PROCESS_ANIMATING_STATE = 2; static final int FIRST_ACTIVITY_TASK_MSG = 100; static final int FIRST_SUPERVISOR_TASK_MSG = 200; @@ -5044,6 +5073,13 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { tracker.deliverResult(mContext); } break; + case UPDATE_PROCESS_ANIMATING_STATE: { + final WindowProcessController proc = (WindowProcessController) msg.obj; + synchronized (mGlobalLock) { + proc.updateRunningRemoteOrRecentsAnimation(); + } + } + break; } } } diff --git a/services/core/java/com/android/server/wm/WindowProcessController.java b/services/core/java/com/android/server/wm/WindowProcessController.java index 26cfbdf806812..1c57aef8a5af5 100644 --- a/services/core/java/com/android/server/wm/WindowProcessController.java +++ b/services/core/java/com/android/server/wm/WindowProcessController.java @@ -1594,14 +1594,18 @@ public class WindowProcessController extends ConfigurationContainer