Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 32917d88 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

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
parent 6f383b1b
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -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 {
+37 −1
Original line number Diff line number Diff line
@@ -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;
            }
        }
    }
+6 −2
Original line number Diff line number Diff line
@@ -1594,14 +1594,18 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
        updateRunningRemoteOrRecentsAnimation();
    }

    private void updateRunningRemoteOrRecentsAnimation() {

    void updateRunningRemoteOrRecentsAnimation() {
        // Posting on handler so WM lock isn't held when we call into AM.
        mAtm.mH.sendMessage(PooledLambda.obtainMessage(
                WindowProcessListener::setRunningRemoteAnimation, mListener,
                mRunningRecentsAnimation || mRunningRemoteAnimation));
    }

    /** Adjusts scheduling group for animation. This method MUST NOT be called inside WM lock. */
    void setRunningAnimationUnsafe() {
        mListener.setRunningRemoteAnimation(true);
    }

    @Override
    public String toString() {
        return mOwner != null ? mOwner.toString() : null;