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

Commit 95b05dcf authored by Hui Yu's avatar Hui Yu
Browse files

Remove SERVICE_FOREGROUND_TIMEOUT_MSG when scheduling service restart.

When scheduling service restart, if the service is waiting to become a foreground service, remove the pending
SERVICE_FOREGROUND_TIMEOUT_MSG msg, and set fgWaiting to false, so next time the service
is brought up, scheduleServiceForegroundTransitionTimeoutLocked() can be called again and
a new SERVICE_FOREGROUND_TIMEOUT_MSG is scheduled in SERVICE_START_FOREGROUND_TIMEOUT
again.

Bug: 218909914
Test: Manual test, crash a service as b/218909914, watch the service is
scheudle to restart and a new SERVICE_FOREGROUND_TIMEOUT_MSG is
scheduled in SERVICE_START_FOREGROUND_TIMEOUT.

Change-Id: I6194c0ff09ad14a5d04e42729207fa5780d06742
parent 40ca086c
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -3801,6 +3801,18 @@ public final class ActiveServices {
    @GuardedBy("mAm")
    void performScheduleRestartLocked(ServiceRecord r, @NonNull String scheduling,
            @NonNull String reason, @UptimeMillisLong long now) {

        // If the service is waiting to become a foreground service, remove the pending
        // SERVICE_FOREGROUND_TIMEOUT_MSG msg, and set fgWaiting to false, so next time the service
        // is brought up, scheduleServiceForegroundTransitionTimeoutLocked() can be called again and
        // a new SERVICE_FOREGROUND_TIMEOUT_MSG is scheduled in SERVICE_START_FOREGROUND_TIMEOUT
        // again.
        if (r.fgRequired && r.fgWaiting) {
            mAm.mHandler.removeMessages(
                    ActivityManagerService.SERVICE_FOREGROUND_TIMEOUT_MSG, r);
            r.fgWaiting = false;
        }

        mAm.mHandler.removeCallbacks(r.restarter);
        mAm.mHandler.postAtTime(r.restarter, r.nextRestartTime);
        r.nextRestartTime = now + r.restartDelay;
@@ -5678,7 +5690,7 @@ public final class ActiveServices {
    void serviceForegroundTimeout(ServiceRecord r) {
        ProcessRecord app;
        synchronized (mAm) {
            if (!r.fgRequired || r.destroying) {
            if (!r.fgRequired || !r.fgWaiting || r.destroying) {
                return;
            }