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

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

Merge "Commit to the AnrTimerService" into main

parents f0408e28 c6f3f72c
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -106,14 +106,6 @@ class BroadcastProcessQueue {
     */
    private boolean mTimeoutScheduled;

    /**
     * Snapshotted value of {@link ProcessRecord#getCpuDelayTime()}, typically
     * used when deciding if we should extend the soft ANR timeout.
     *
     * Required when Flags.anrTimerServiceEnabled is false.
     */
    long lastCpuDelayTime;

     /**
     * Snapshotted value of {@link ProcessStateRecord#getCurProcState()} before
     * dispatching the current broadcast to the receiver in this process.
+1 −39
Original line number Diff line number Diff line
@@ -282,10 +282,6 @@ class BroadcastQueueImpl extends BroadcastQueue {
    private static final int MSG_PROCESS_FREEZABLE_CHANGED = 6;
    private static final int MSG_UID_STATE_CHANGED = 7;

    // Required when Flags.anrTimerServiceEnabled is false.  This constant should be deleted if and
    // when the flag is fused on.
    private static final int MSG_DELIVERY_TIMEOUT_SOFT = 8;

    private void enqueueUpdateRunningList() {
        mLocalHandler.removeMessages(MSG_UPDATE_RUNNING_LIST);
        mLocalHandler.sendEmptyMessage(MSG_UPDATE_RUNNING_LIST);
@@ -299,14 +295,6 @@ class BroadcastQueueImpl extends BroadcastQueue {
                updateRunningList();
                return true;
            }
            // Required when Flags.anrTimerServiceEnabled is false.  This case should be deleted if
            // and when the flag is fused on.
            case MSG_DELIVERY_TIMEOUT_SOFT: {
                synchronized (mService) {
                    deliveryTimeoutSoftLocked((BroadcastProcessQueue) msg.obj, msg.arg1);
                    return true;
                }
            }
            case MSG_DELIVERY_TIMEOUT: {
                deliveryTimeout((BroadcastProcessQueue) msg.obj);
                return true;
@@ -1296,13 +1284,7 @@ class BroadcastQueueImpl extends BroadcastQueue {
    @GuardedBy("mService")
    private void startDeliveryTimeoutLocked(@NonNull BroadcastProcessQueue queue,
            int softTimeoutMillis) {
        if (mAnrTimer.serviceEnabled()) {
        mAnrTimer.start(queue, softTimeoutMillis);
        } else {
            queue.lastCpuDelayTime = queue.app.getCpuDelayTime();
            mLocalHandler.sendMessageDelayed(Message.obtain(mLocalHandler,
                    MSG_DELIVERY_TIMEOUT_SOFT, softTimeoutMillis, 0, queue), softTimeoutMillis);
        }
    }

    // Required when Flags.anrTimerServiceEnabled is false. This function can be replaced with a
@@ -1310,26 +1292,6 @@ class BroadcastQueueImpl extends BroadcastQueue {
    @GuardedBy("mService")
    private void cancelDeliveryTimeoutLocked(@NonNull BroadcastProcessQueue queue) {
        mAnrTimer.cancel(queue);
        if (!mAnrTimer.serviceEnabled()) {
            mLocalHandler.removeMessages(MSG_DELIVERY_TIMEOUT_SOFT, queue);
        }
    }

    // Required when Flags.anrTimerServiceEnabled is false.  This function can be deleted entirely
    // if and when the flag is fused on.
    @GuardedBy("mService")
    private void deliveryTimeoutSoftLocked(@NonNull BroadcastProcessQueue queue,
            int softTimeoutMillis) {
        if (queue.app != null) {
            // Instead of immediately triggering an ANR, extend the timeout by
            // the amount of time the process was runnable-but-waiting; we're
            // only willing to do this once before triggering an hard ANR
            final long cpuDelayTime = queue.app.getCpuDelayTime() - queue.lastCpuDelayTime;
            final long hardTimeoutMillis = MathUtils.constrain(cpuDelayTime, 0, softTimeoutMillis);
            mAnrTimer.start(queue, hardTimeoutMillis);
        } else {
            deliveryTimeoutLocked(queue);
        }
    }

    private void deliveryTimeout(@NonNull BroadcastProcessQueue queue) {
+2 −10
Original line number Diff line number Diff line
@@ -121,20 +121,12 @@ public abstract class AnrTimer<V> implements AutoCloseable {
     */
    public abstract int getUid(V obj);

    /**
     * Return true if the feature is enabled.  By default, the value is take from the Flags class
     * but it can be changed for local testing.
     */
    private static boolean anrTimerServiceEnabled() {
        return Flags.anrTimerService();
    }

    /**
     * Return true if tracing is feature-enabled.  This has no effect unless tracing is configured.
     * Note that this does not represent any per-process overrides via an Injector.
     */
    public static boolean traceFeatureEnabled() {
        return anrTimerServiceEnabled() && Flags.anrTimerTrace();
        return Flags.anrTimerTrace();
    }

    /**
@@ -142,7 +134,7 @@ public abstract class AnrTimer<V> implements AutoCloseable {
     */
    static class Injector {
        boolean serviceEnabled() {
            return AnrTimer.anrTimerServiceEnabled();
            return true;
        }

        boolean traceEnabled() {
+0 −8
Original line number Diff line number Diff line
package: "com.android.server.utils"
container: "system"

flag {
     name: "anr_timer_service"
     namespace: "system_performance"
     is_fixed_read_only: true
     description: "Feature flag for the ANR timer service"
     bug: "282428924"
}

flag {
     name: "anr_timer_trace"
     namespace: "system_performance"