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

Commit 977f867e authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Add a small delay for scheduling idle while sleeping

This is a follow up of [1]. Though that already covers most launch
duration, the twice switches of power mode may be unnecessary.
So add a small delay to check idle while device is sleeping and
there is a launching app, then if the device is unlocked before
the delay idle message reaches, the launch power mode can cover
entire launch operation.

[1]: I2383eaacdef9830a9b6fe638b2953f6a069f8d32

Bug: 332221147
Flag: EXEMPT bugfix
Test: Hot launch app from notification on lockscreen.
      Check trace StartModeLaunch ~ EndModeLaunch.
      The duration can cover most of "launching: $pkgName".
Change-Id: I723ce0da1434c6f69a77c10f19f7826b4f68dbde
parent 4cc6b39f
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -4755,6 +4755,10 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        }
    }

    boolean mayBeLaunchingApp() {
        return (mPowerModeReasons & POWER_MODE_REASON_START_ACTIVITY) != 0;
    }

    void startPowerMode(@PowerModeReason int reason) {
        final int prevReasons = mPowerModeReasons;
        mPowerModeReasons |= reason;
+9 −1
Original line number Diff line number Diff line
@@ -202,6 +202,12 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
     */
    private static final int KILL_TASK_PROCESSES_TIMEOUT_MS = 1000;

    /**
     * The delay to run idle check. It may give a chance to keep launch power mode if an activity
     * is starting while the device is sleeping and then the device is unlocked in a short time.
     */
    private static final int IDLE_NOW_DELAY_WHILE_SLEEPING_MS = 100;

    private static final int IDLE_TIMEOUT_MSG = FIRST_SUPERVISOR_TASK_MSG;
    private static final int IDLE_NOW_MSG = FIRST_SUPERVISOR_TASK_MSG + 1;
    private static final int RESUME_TOP_ACTIVITY_MSG = FIRST_SUPERVISOR_TASK_MSG + 2;
@@ -2252,7 +2258,9 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
    final void scheduleIdle() {
        if (!mHandler.hasMessages(IDLE_NOW_MSG)) {
            if (DEBUG_IDLE) Slog.d(TAG_IDLE, "scheduleIdle: Callers=" + Debug.getCallers(4));
            mHandler.sendEmptyMessage(IDLE_NOW_MSG);
            final long delayMs = mService.isSleepingLocked() && mService.mayBeLaunchingApp()
                    ? IDLE_NOW_DELAY_WHILE_SLEEPING_MS : 0;
            mHandler.sendEmptyMessageDelayed(IDLE_NOW_MSG, delayMs);
        }
    }