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

Commit 47dbfaeb authored by Lee Shombert's avatar Lee Shombert
Browse files

Correct AnrTimer use in ActiveServices

This fixes three places where the AnrTimer was being used incorrectly
in ActiveServices.  In both cases, the error is in the location of
discard() and accept(), and these two functions are no-ops unless the
AnrTimer feature is flag-enabled (which it is not, at the moment).

The SERVICE_SHORT_FGS_ANR_TIMEOUT_MSG was being handled in the wrong
completion routine.  The correct completion routine is
onShortFgsAnrTimeout().

The SERVICE_TIMEOUT_MSG was accept()ing the ANR too early.  The call
to accept() is moved into the conditional that creates the
TimeoutRecord; the other branch of the conditional discards the timer.

The SERVICE_FOREGROUND_TIMEOUT_MSG call to accept() was too early.
The correct location is after the last possible call to discard().

Test: atest
 * FrameworksServicesTests:com.android.server.am
 * FrameworksMockingServicesTests:com.android.server.am

Flag: com.android.server.utils.anr_timer_service
Bug: 325594551
Change-Id: I75b16bd5339c755774da6a232f3513e3ca119293
parent e6e2ada8
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -3583,11 +3583,9 @@ public final class ActiveServices {
                    Slog.d(TAG_SERVICE, "[STALE] Short FGS timed out: " + sr
                            + " " + sr.getShortFgsTimedEventDescription(nowUptime));
                }
                mShortFGSAnrTimer.discard(sr);
                return;
            }
            Slog.e(TAG_SERVICE, "Short FGS timed out: " + sr);
            mShortFGSAnrTimer.accept(sr);
            traceInstant("short FGS timeout: ", sr);

            logFGSStateChangeLocked(sr,
@@ -3667,8 +3665,10 @@ public final class ActiveServices {
                    Slog.d(TAG_SERVICE, "[STALE] Short FGS ANR'ed: " + sr
                            + " " + sr.getShortFgsTimedEventDescription(nowUptime));
                }
                mShortFGSAnrTimer.discard(sr);
                return;
            }
            mShortFGSAnrTimer.accept(sr);

            final String message = "Short FGS ANR'ed: " + sr;
            if (DEBUG_SHORT_SERVICE) {
@@ -7328,7 +7328,6 @@ public final class ActiveServices {
                    mActiveServiceAnrTimer.discard(proc);
                    return;
                }
                mActiveServiceAnrTimer.accept(proc);
                final long now = SystemClock.uptimeMillis();
                final long maxTime =  now
                        - (psr.shouldExecServicesFg()
@@ -7347,6 +7346,7 @@ public final class ActiveServices {
                    }
                }
                if (timeout != null && mAm.mProcessList.isInLruListLOSP(proc)) {
                    mActiveServiceAnrTimer.accept(proc);
                    Slog.w(TAG, "Timeout executing service: " + timeout);
                    StringWriter sw = new StringWriter();
                    PrintWriter pw = new FastPrintWriter(sw, false, 1024);
@@ -7361,6 +7361,7 @@ public final class ActiveServices {
                    timeoutRecord = TimeoutRecord.forServiceExec(timeout.shortInstanceName,
                            waitedMillis);
                } else {
                    mActiveServiceAnrTimer.discard(proc);
                    final long delay = psr.shouldExecServicesFg()
                                       ? (nextTime + mAm.mConstants.SERVICE_TIMEOUT) :
                                       (nextTime + mAm.mConstants.SERVICE_BACKGROUND_TIMEOUT)
@@ -7395,7 +7396,6 @@ public final class ActiveServices {
                    return;
                }

                mServiceFGAnrTimer.accept(r);
                app = r.app;
                if (app != null && app.isDebugging()) {
                    // The app's being debugged; let it ride
@@ -7403,6 +7403,8 @@ public final class ActiveServices {
                    return;
                }

                mServiceFGAnrTimer.accept(r);

                if (DEBUG_BACKGROUND_CHECK) {
                    Slog.i(TAG, "Service foreground-required timeout for " + r);
                }