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

Commit 7e50738d authored by Lee Shombert's avatar Lee Shombert Committed by Android (Google) Code Review
Browse files

Merge "Make native ANR timers opt-out" into main

parents 7d2777eb 45413c8c
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -134,10 +134,6 @@ public abstract class AnrTimer<V> implements AutoCloseable {
     * This class allows test code to provide instance-specific overrides.
     */
    static class Injector {
        boolean serviceEnabled() {
            return true;
        }

        boolean traceEnabled() {
            return AnrTimer.traceFeatureEnabled();
        }
@@ -154,6 +150,9 @@ public abstract class AnrTimer<V> implements AutoCloseable {
        /** The Injector (used only for testing). */
        private Injector mInjector = AnrTimer.sDefaultInjector;

        /** Enable native timers (if they are available). */
        private boolean mEnable = true;

        /** Grant timer extensions when the system is heavily loaded. */
        private boolean mExtend = false;

@@ -163,6 +162,11 @@ public abstract class AnrTimer<V> implements AutoCloseable {
            return this;
        }

        public Args enable(boolean flag) {
            mEnable = flag;
            return this;
        }

        public Args extend(boolean flag) {
            mExtend = flag;
            return this;
@@ -330,7 +334,7 @@ public abstract class AnrTimer<V> implements AutoCloseable {
        mWhat = what;
        mLabel = label;
        mArgs = args;
        boolean enabled = args.mInjector.serviceEnabled() && nativeTimersSupported();
        boolean enabled = args.mEnable && nativeTimersSupported();
        mFeature = createFeatureSwitch(enabled);
    }

@@ -842,8 +846,6 @@ public abstract class AnrTimer<V> implements AutoCloseable {
    /** Dumpsys output, allowing for overrides. */
    @VisibleForTesting
    static void dump(@NonNull PrintWriter pw, boolean verbose, @NonNull Injector injector) {
        if (!injector.serviceEnabled()) return;

        final IndentingPrintWriter ipw = new IndentingPrintWriter(pw);
        ipw.println("AnrTimer statistics");
        ipw.increaseIndent();
+2 −12
Original line number Diff line number Diff line
@@ -114,22 +114,12 @@ public class AnrTimerTest {
        }
    }

    /**
     * Force AnrTimer to use the test parameter for the feature flag.
     */
    private class TestInjector extends AnrTimer.Injector {
        @Override
        boolean serviceEnabled() {
            return mEnabled;
        }
    }

    /**
     * An instrumented AnrTimer.
     */
    private class TestAnrTimer extends AnrTimer<TestArg> {
        private TestAnrTimer(Handler h, int key, String tag) {
            super(h, key, tag, new AnrTimer.Args().injector(new TestInjector()));
          super(h, key, tag, new AnrTimer.Args().enable(mEnabled));
        }

        TestAnrTimer(Helper helper) {
@@ -312,7 +302,7 @@ public class AnrTimerTest {
    private String getDumpOutput() {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        AnrTimer.dump(pw, true, new TestInjector());
        AnrTimer.dump(pw, true);
        pw.close();
        return sw.getBuffer().toString();
    }