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

Commit 42ac180b authored by Beverly's avatar Beverly Committed by Beverly Tai
Browse files

Add the ability to end pulsing immediately

If a HUN is immediately cancelled after posting,
make sure the Doze pulsing state can correctly exit
so that the device isn't stuck pulsing in screen on.

Test: manually (hardcode) a notification to immediately stop
pulsing after its been requested to pulse. observe that AoD
eventually exits the pulsing state.
Test: atest DozeTriggersTest DozeServiceHostTest
Fixes: 221601821

Change-Id: Ibf349f97edbb54a9eb36eb4d33175867d7cf7b13
parent fa561d39
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -32,6 +32,18 @@ public interface DozeHost {
    boolean isPulsingBlocked();
    boolean isProvisioned();

    /**
     * Whether there's a pulse that's been requested but hasn't started transitioning to pulsing
     * states yet.
     */
    boolean isPulsePending();

    /**
     * @param isPulsePending whether a pulse has been requested but hasn't started transitioning
     *                       to the pulse state yet
     */
    void setPulsePending(boolean isPulsePending);

    /**
     * Makes a current pulse last for twice as long.
     * @param reason why we're extending it.
+9 −2
Original line number Diff line number Diff line
@@ -280,8 +280,8 @@ public class DozeLog implements Dumpable {
    /**
     * Appends pulse dropped event to logs
     */
    public void tracePulseDropped(boolean pulsePending, DozeMachine.State state, boolean blocked) {
        mLogger.logPulseDropped(pulsePending, state, blocked);
    public void tracePulseDropped(String from, DozeMachine.State state) {
        mLogger.logPulseDropped(from, state);
    }

    /**
@@ -291,6 +291,13 @@ public class DozeLog implements Dumpable {
        mLogger.logSensorEventDropped(sensorEvent, reason);
    }

    /**
     * Appends pulsing event to logs.
     */
    public void tracePulseEvent(String pulseEvent, boolean dozing, int pulseReason) {
        mLogger.logPulseEvent(pulseEvent, dozing, DozeLog.reasonToString(pulseReason));
    }

    /**
     * Appends pulse dropped event to logs
     * @param reason why the pulse was dropped
+14 −5
Original line number Diff line number Diff line
@@ -224,13 +224,12 @@ class DozeLogger @Inject constructor(
        })
    }

    fun logPulseDropped(pulsePending: Boolean, state: DozeMachine.State, blocked: Boolean) {
    fun logPulseDropped(from: String, state: DozeMachine.State) {
        buffer.log(TAG, INFO, {
            bool1 = pulsePending
            str1 = state.name
            bool2 = blocked
            str1 = from
            str2 = state.name
        }, {
            "Pulse dropped, pulsePending=$bool1 state=$str1 blocked=$bool2"
            "Pulse dropped, cannot pulse from=$str1 state=$str2"
        })
    }

@@ -243,6 +242,16 @@ class DozeLogger @Inject constructor(
        })
    }

    fun logPulseEvent(pulseEvent: String, dozing: Boolean, pulseReason: String) {
        buffer.log(TAG, DEBUG, {
            str1 = pulseEvent
            bool1 = dozing
            str2 = pulseReason
        }, {
            "Pulse-$str1 dozing=$bool1 pulseReason=$str2"
        })
    }

    fun logPulseDropped(reason: String) {
        buffer.log(TAG, INFO, {
            str1 = reason
+34 −25
Original line number Diff line number Diff line
@@ -102,7 +102,6 @@ public class DozeTriggers implements DozeMachine.Part {
    private final UiEventLogger mUiEventLogger;

    private long mNotificationPulseTime;
    private boolean mPulsePending;
    private Runnable mAodInterruptRunnable;

    /** see {@link #onProximityFar} prox for callback */
@@ -303,8 +302,8 @@ public class DozeTriggers implements DozeMachine.Part {
                        null /* onPulseSuppressedListener */);
            }
        } else {
            proximityCheckThenCall((result) -> {
                if (result != null && result) {
            proximityCheckThenCall((isNear) -> {
                if (isNear != null && isNear) {
                    // In pocket, drop event.
                    mDozeLog.traceSensorEventDropped(pulseReason, "prox reporting near");
                    return;
@@ -410,8 +409,8 @@ public class DozeTriggers implements DozeMachine.Part {
        sWakeDisplaySensorState = wake;

        if (wake) {
            proximityCheckThenCall((result) -> {
                if (result != null && result) {
            proximityCheckThenCall((isNear) -> {
                if (isNear != null && isNear) {
                    // In pocket, drop event.
                    return;
                }
@@ -537,24 +536,44 @@ public class DozeTriggers implements DozeMachine.Part {
            return;
        }

        if (mPulsePending || !mAllowPulseTriggers || !canPulse()) {
            if (mAllowPulseTriggers) {
                mDozeLog.tracePulseDropped(mPulsePending, dozeState, mDozeHost.isPulsingBlocked());
        if (!mAllowPulseTriggers || mDozeHost.isPulsePending() || !canPulse()) {
            if (!mAllowPulseTriggers) {
                mDozeLog.tracePulseDropped("requestPulse - !mAllowPulseTriggers");
            } else if (mDozeHost.isPulsePending()) {
                mDozeLog.tracePulseDropped("requestPulse - pulsePending");
            } else if (!canPulse()) {
                mDozeLog.tracePulseDropped("requestPulse", dozeState);
            }
            runIfNotNull(onPulseSuppressedListener);
            return;
        }

        mPulsePending = true;
        proximityCheckThenCall((result) -> {
            if (result != null && result) {
        mDozeHost.setPulsePending(true);
        proximityCheckThenCall((isNear) -> {
            if (isNear != null && isNear) {
                // in pocket, abort pulse
                mDozeLog.tracePulseDropped("inPocket");
                mPulsePending = false;
                mDozeLog.tracePulseDropped("requestPulse - inPocket");
                mDozeHost.setPulsePending(false);
                runIfNotNull(onPulseSuppressedListener);
            } else {
                // not in pocket, continue pulsing
                continuePulseRequest(reason);
                final boolean isPulsePending = mDozeHost.isPulsePending();
                mDozeHost.setPulsePending(false);
                if (!isPulsePending || mDozeHost.isPulsingBlocked() || !canPulse()) {
                    if (!isPulsePending) {
                        mDozeLog.tracePulseDropped("continuePulseRequest - pulse no longer"
                                + " pending, pulse was cancelled before it could start"
                                + " transitioning to pulsing state.");
                    } else if (mDozeHost.isPulsingBlocked()) {
                        mDozeLog.tracePulseDropped("continuePulseRequest - pulsingBlocked");
                    } else if (!canPulse()) {
                        mDozeLog.tracePulseDropped("continuePulseRequest", mMachine.getState());
                    }
                    runIfNotNull(onPulseSuppressedListener);
                    return;
                }

                mMachine.requestPulse(reason);
            }
        }, !mDozeParameters.getProxCheckBeforePulse() || performedProxCheck, reason);

@@ -569,16 +588,6 @@ public class DozeTriggers implements DozeMachine.Part {
                || mMachine.getState() == DozeMachine.State.DOZE_AOD_DOCKED;
    }

    private void continuePulseRequest(int reason) {
        mPulsePending = false;
        if (mDozeHost.isPulsingBlocked() || !canPulse()) {
            mDozeLog.tracePulseDropped(mPulsePending, mMachine.getState(),
                    mDozeHost.isPulsingBlocked());
            return;
        }
        mMachine.requestPulse(reason);
    }

    @Nullable
    private InstanceId getKeyguardSessionId() {
        return mSessionTracker.getSessionId(SESSION_KEYGUARD);
@@ -591,7 +600,7 @@ public class DozeTriggers implements DozeMachine.Part {
        pw.print(" notificationPulseTime=");
        pw.println(Formatter.formatShortElapsedTime(mContext, mNotificationPulseTime));

        pw.println(" pulsePending=" + mPulsePending);
        pw.println(" DozeHost#isPulsePending=" + mDozeHost.isPulsePending());
        pw.println("DozeSensors:");
        IndentingPrintWriter idpw = new IndentingPrintWriter(pw);
        idpw.increaseIndent();
+1 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ public class LogModule {
    @SysUISingleton
    @DozeLog
    public static LogBuffer provideDozeLogBuffer(LogBufferFactory factory) {
        return factory.create("DozeLog", 100);
        return factory.create("DozeLog", 120);
    }

    /** Provides a logging buffer for all logs related to the data layer of notifications. */
Loading