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

Commit de3e8d9a authored by Robin Lee's avatar Robin Lee
Browse files

Add test for KeyguardController removing AOD during unlock

There is a heavily-exercised special case for KeyguardController:
if the keyguard is going away but AOD is still showing, calling
setKeyguardShown(true, false) will be treated as a request to
remove the AOD bit without interfering with the keyguardGoingAway
state.

This is a surprising special case that was not caught by unit tests
when a change to the surrounding code was submitted. Adding a test
codifies that this is a deliberate "feature" and shouldn't be
changed without a plan for alternative ways of clearing the AOD
status during keyguardGoingAway

Change-Id: Ide11cc6cfd33e826c54da704fd66997938735cc3
Flag: EXEMPT test only
Test: atest 'DisplayContentTests#testKeyguardGoingAwayWhileAodShown'
Bug: 396134691
parent c13717cd
Loading
Loading
Loading
Loading
+60 −8
Original line number Diff line number Diff line
@@ -164,6 +164,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.BooleanSupplier;

/**
 * Tests for the {@link DisplayContent} class.
@@ -2674,16 +2675,67 @@ public class DisplayContentTests extends WindowTestsBase {
    public void testKeyguardGoingAwayWhileAodShown() {
        mDisplayContent.getDisplayPolicy().setAwake(true);

        final WindowState appWin = newWindowBuilder("appWin", TYPE_APPLICATION).setDisplay(
                mDisplayContent).build();
        final ActivityRecord activity = appWin.mActivityRecord;
        final KeyguardController keyguard = mAtm.mKeyguardController;
        final ActivityRecord activity = new ActivityBuilder(mAtm).setCreateTask(true).build();
        final int displayId = mDisplayContent.getDisplayId();

        final BooleanSupplier keyguardShowing = () -> keyguard.isKeyguardShowing(displayId);
        final BooleanSupplier keyguardGoingAway = () -> keyguard.isKeyguardGoingAway(displayId);
        final BooleanSupplier appVisible = activity::isVisibleRequested;

        // Begin locked and in AOD
        keyguard.setKeyguardShown(displayId, true /* keyguard */, true /* aod */);
        assertFalse(keyguardGoingAway.getAsBoolean());
        assertFalse(appVisible.getAsBoolean());

        // Start unlocking from AOD.
        keyguard.keyguardGoingAway(displayId, 0x0 /* flags */);
        assertTrue(keyguardGoingAway.getAsBoolean());
        assertTrue(appVisible.getAsBoolean());

        mAtm.mKeyguardController.setKeyguardShown(appWin.getDisplayId(), true /* keyguardShowing */,
                true /* aodShowing */);
        assertFalse(activity.isVisibleRequested());
        // Clear AOD. This does *not* clear the going-away status.
        keyguard.setKeyguardShown(displayId, true /* keyguard */, false /* aod */);
        assertTrue(keyguardGoingAway.getAsBoolean());
        assertTrue(appVisible.getAsBoolean());

        // Finish unlock
        keyguard.setKeyguardShown(displayId, false /* keyguard */, false /* aod */);
        assertFalse(keyguardGoingAway.getAsBoolean());
        assertTrue(appVisible.getAsBoolean());
    }

    @Test
    public void testKeyguardGoingAwayCanceledWhileAodShown() {
        mDisplayContent.getDisplayPolicy().setAwake(true);

        mAtm.mKeyguardController.keyguardGoingAway(appWin.getDisplayId(), 0 /* flags */);
        assertTrue(activity.isVisibleRequested());
        final KeyguardController keyguard = mAtm.mKeyguardController;
        final ActivityRecord activity = new ActivityBuilder(mAtm).setCreateTask(true).build();
        final int displayId = mDisplayContent.getDisplayId();

        final BooleanSupplier keyguardShowing = () -> keyguard.isKeyguardShowing(displayId);
        final BooleanSupplier keyguardGoingAway = () -> keyguard.isKeyguardGoingAway(displayId);
        final BooleanSupplier appVisible = activity::isVisibleRequested;

        // Begin locked and in AOD
        keyguard.setKeyguardShown(displayId, true /* keyguard */, true /* aod */);
        assertFalse(keyguardGoingAway.getAsBoolean());
        assertFalse(appVisible.getAsBoolean());

        // Start unlocking from AOD.
        keyguard.keyguardGoingAway(displayId, 0x0 /* flags */);
        assertTrue(keyguardGoingAway.getAsBoolean());
        assertTrue(appVisible.getAsBoolean());

        // Clear AOD. This does *not* clear the going-away status.
        keyguard.setKeyguardShown(displayId, true /* keyguard */, false /* aod */);
        assertTrue(keyguardGoingAway.getAsBoolean());
        assertTrue(appVisible.getAsBoolean());

        // Same API call a second time cancels the unlock, because AOD isn't changing.
        keyguard.setKeyguardShown(displayId, true /* keyguard */, false /* aod */);
        assertTrue(keyguardShowing.getAsBoolean());
        assertFalse(keyguardGoingAway.getAsBoolean());
        assertFalse(appVisible.getAsBoolean());
    }

    @Test