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

Commit 9f752b49 authored by Lee Shombert's avatar Lee Shombert
Browse files

Initial ANR timer service

Bug: 282428924

Create a service that runs ANR timers in the background.  The service
can collect statistics across different ANRs.  The current commit
provides a legacy service, based on message handlers; this is how
existing ANR timers are handled.  However, the commit lays the
groundwork for a native runtime timer implementation.

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

Change-Id: I33b65d1a6c3348a5704191726e704743c71d5c4c
parent 54c09c36
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -9851,6 +9851,10 @@ public class ActivityManagerService extends IActivityManager.Stub
        PriorityDump.dump(mPriorityDumper, fd, pw, args);
    }
    private static final String TICK =
            "---------------------------------------"
            + "----------------------------------------";
    private void dumpEverything(FileDescriptor fd, PrintWriter pw, String[] args, int opti,
            boolean dumpAll, String dumpPackage, int displayIdFilter, boolean dumpClient,
            boolean dumpNormalPriority, int dumpAppId, boolean dumpProxies) {
@@ -9906,6 +9910,11 @@ public class ActivityManagerService extends IActivityManager.Stub
                sdumper.dumpLocked();
            }
        }
        // No need to hold the lock.
        pw.println(TICK);
        AnrTimer.dump(pw, false);
        // We drop the lock here because we can't call dumpWithClient() with the lock held;
        // if the caller wants a consistent state for the !dumpClient case, it can call this
        // method with the lock held.
@@ -10351,6 +10360,8 @@ public class ActivityManagerService extends IActivityManager.Stub
                    mOomAdjuster.dumpCachedAppOptimizerSettings(pw);
                    mOomAdjuster.dumpCacheOomRankerSettings(pw);
                }
            } else if ("timers".equals(cmd)) {
                AnrTimer.dump(pw, true);
            } else if ("services".equals(cmd) || "s".equals(cmd)) {
                if (dumpClient) {
                    ActiveServices.ServiceDumper dumper;
+1 −0
Original line number Diff line number Diff line
@@ -4095,6 +4095,7 @@ final class ActivityManagerShellCommand extends ShellCommand {
            pw.println("    lru: raw LRU process list");
            pw.println("    binder-proxies: stats on binder objects and IPCs");
            pw.println("    settings: currently applied config settings");
            pw.println("    timers: the current ANR timer state");
            pw.println("    service [COMP_SPEC]: service client-side state");
            pw.println("    package [PACKAGE_NAME]: all state related to given package");
            pw.println("    all: dump all activities");
+3 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;

import android.content.pm.ApplicationInfo;
import android.os.Process;
import android.os.SystemClock;
import android.os.Trace;
import android.util.ArraySet;
@@ -267,6 +268,7 @@ class AnrHelper {
    private class AnrRecord {
        final ProcessRecord mApp;
        final int mPid;
        final int mUid;
        final String mActivityShortComponentName;
        final String mParentShortComponentName;
        final TimeoutRecord mTimeoutRecord;
@@ -283,6 +285,7 @@ class AnrHelper {
                Future<File> firstPidFilePromise) {
            mApp = anrProcess;
            mPid = anrProcess.mPid;
            mUid = anrProcess.uid;
            mActivityShortComponentName = activityShortComponentName;
            mParentShortComponentName = parentShortComponentName;
            mTimeoutRecord = timeoutRecord;
+834 −0

File added.

Preview size limit exceeded, changes collapsed.

+17 −3
Original line number Diff line number Diff line
@@ -101,10 +101,9 @@ class BroadcastProcessQueue {
    boolean runningOomAdjusted;

    /**
     * Snapshotted value of {@link ProcessRecord#getCpuDelayTime()}, typically
     * used when deciding if we should extend the soft ANR timeout.
     * True if a timer has been started against this queue.
     */
    long lastCpuDelayTime;
    private boolean mTimeoutScheduled;

    /**
     * Snapshotted value of {@link ProcessStateRecord#getCurProcState()} before
@@ -1344,6 +1343,21 @@ class BroadcastProcessQueue {
        return head;
    }

    /**
     * Set the timeout flag to indicate that an ANR timer has been started.  A value of true means a
     * timer is running; a value of false means there is no timer running.
     */
    void setTimeoutScheduled(boolean timeoutStarted) {
        mTimeoutScheduled = timeoutStarted;
    }

    /**
     * Get the timeout flag
     */
    boolean timeoutScheduled() {
        return mTimeoutScheduled;
    }

    @Override
    public String toString() {
        if (mCachedToString == null) {
Loading