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

Commit 9098b14c authored by Beverly's avatar Beverly Committed by Beverly Tai
Browse files

Don't check Doze state if device is in the middle of a transition

Checking the doze state in the middle of a transition
will throw an IllegalStateException.

DozeSuppresor doesn't need to update the doze state
if the doze machine is already in the middle of
executing transitions. Whenever the next doze
state is executed, DozeMachine#transitionPolicy
will make sure the device properly exits the
powerSaver AOD state (that keeps AOD off).

If a UDFPS long press is triggered while DozeMachine
is executing a transition, the pulse will be dropped,
so we don't need to set the aodInterrupt.

Fixes: 380642226
Test: atest DozeSuppressorTest
Test: atest DozeTriggersTest
Flag: EXEMPT bugfix
Change-Id: I399240329da6907cac83af64d21fede5e8239da5
parent 28eff15e
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -276,6 +276,23 @@ public class DozeSuppressorTest extends SysuiTestCase {
        verify(mDozeMachine).requestState(DOZE_AOD);
    }


    @Test
    public void testPowerSaveChanged_notActive_dozeMachineStateNull() {
        // GIVEN DOZE (not showing aod content)
        when(mConfig.alwaysOnEnabled(anyInt())).thenReturn(true);
        mDozeSuppressor.transitionTo(UNINITIALIZED, INITIALIZED);
        when(mDozeMachine.getState()).thenReturn(null);
        captureDozeHostCallback();

        // WHEN power save mode is no longer active
        when(mDozeHost.isPowerSaveActive()).thenReturn(false);
        mDozeHostCallback.onPowerSaveChanged(false);

        // THEN the state doesn't change
        verify(mDozeMachine, never()).requestState(DOZE_AOD);
    }

    @Test
    public void testAlwaysOnSuppressedChanged_nowSuppressed() {
        // GIVEN DOZE_AOD
+7 −6
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_AWA
import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_WAKING;

import android.annotation.MainThread;
import android.annotation.Nullable;
import android.content.res.Configuration;
import android.hardware.display.AmbientDisplayConfiguration;
import android.util.Log;
@@ -259,16 +260,16 @@ public class DozeMachine {
    }

    /**
     * @return the current state.
     *
     * This must not be called during a transition.
     * @return the current state. Returns null if the DozeMachine is currently executing a
     * transition.
     */
    @MainThread
    public State getState() {
    public @Nullable State getState() {
        Assert.isMainThread();
        if (isExecutingTransition()) {
            throw new IllegalStateException("Cannot get state because there were pending "
            Log.w(TAG, "Returning null for DozeMachine.getState because there were pending"
                    + " transitions: " + mQueuedRequests);
            return null;
        }
        return mState;
    }
+6 −5
Original line number Diff line number Diff line
@@ -319,7 +319,7 @@ public class DozeTriggers implements DozeMachine.Part {

        if (isWakeOnPresence) {
            onWakeScreen(isWakeDisplayEvent,
                    mMachine.isExecutingTransition() ? null : mMachine.getState(),
                    mMachine.getState(),
                    pulseReason);
        } else if (isLongPress) {
            requestPulse(pulseReason, true /* alreadyPerformedProxCheck */,
@@ -572,9 +572,7 @@ public class DozeTriggers implements DozeMachine.Part {
        Assert.isMainThread();
        mDozeHost.extendPulse(reason);

        // we can't determine the dozing state if we're currently transitioning
        final DozeMachine.State dozeState =
                mMachine.isExecutingTransition() ? null : mMachine.getState();
        final DozeMachine.State dozeState = mMachine.getState();

        // When already pulsing we're allowed to show the wallpaper directly without
        // requesting a new pulse.
@@ -638,7 +636,10 @@ public class DozeTriggers implements DozeMachine.Part {
                .ifPresent(uiEventEnum -> mUiEventLogger.log(uiEventEnum, getKeyguardSessionId()));
    }

    private boolean canPulse(DozeMachine.State dozeState, boolean pulsePerformedProximityCheck) {
    private boolean canPulse(
            @Nullable DozeMachine.State dozeState,
            boolean pulsePerformedProximityCheck
    ) {
        final boolean dozePausedOrPausing = dozeState == State.DOZE_AOD_PAUSED
                || dozeState == State.DOZE_AOD_PAUSING;
        return dozeState == DozeMachine.State.DOZE
+16 −9
Original line number Diff line number Diff line
@@ -438,15 +438,29 @@ public class DozeTriggersTest extends SysuiTestCase {
    }

    @Test
    public void testIsExecutingTransition_dropPulse() {
    public void nullState_dropUdfpsLongPressPulse() {
        when(mHost.isPulsePending()).thenReturn(false);
        when(mMachine.isExecutingTransition()).thenReturn(true);
        when(mMachine.getState()).thenReturn(null);

        mTriggers.onSensor(DozeLog.PULSE_REASON_SENSOR_LONG_PRESS, 100, 100, null);

        verify(mDozeLog).tracePulseDropped(anyString(), eq(null));
    }

    @Test
    public void testIsExecutingTransition_dropPulseForUdfpsLongPress() {
        when(mHost.isPulsePending()).thenReturn(false);
        when(mMachine.isExecutingTransition()).thenReturn(true);

        mTriggers.onSensor(DozeLog.REASON_SENSOR_UDFPS_LONG_PRESS, 100, 100, null);

        // THEN pulse is dropped
        verify(mDozeLog).tracePulseDropped(anyString(), eq(null));

        // THEN aod interrupt is not sent
        verify(mAuthController, never()).onAodInterrupt(anyInt(), anyInt(), anyFloat(), anyFloat());
    }

    @Test
    public void udfpsLongPress_triggeredWhenAodPaused() {
        // GIVEN device is DOZE_AOD_PAUSED
@@ -505,13 +519,6 @@ public class DozeTriggersTest extends SysuiTestCase {
        verify(mAuthController, never()).onAodInterrupt(anyInt(), anyInt(), anyFloat(), anyFloat());
    }

    @Test
    public void udfpsLongPress_dozeState_notRegistered() {
        // GIVEN device is DOZE_AOD_PAUSED
        when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE);
        // beverlyt
    }

    @Test
    @EnableFlags({
            android.hardware.biometrics.Flags.FLAG_SCREEN_OFF_UNLOCK_UDFPS,