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

Commit 0ab3fe3f authored by Robin Lee's avatar Robin Lee Committed by Android Build Coastguard Worker
Browse files

Always initialize FLAG_ALWAYS_UNLOCKED DCs unlocked

When adding a new display to a locked device, any keyguard state should
normally be copied. However there is an exception if the new display
does not support locking at all.

Flag: com.android.window.flags.ensure_keyguard_does_transition_starting_bug_fix
Test: atest 'ActivityTaskManagerServiceTests#testSetLockScreenShownWithAlwaysUnlockedVirtualDisplay'
Fix: 446174085
Bug: 436770343
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:4ff0b946ac8c2cb141d5d305d05c4ced5b167387
Merged-In: I8540ffb35fa8cb27fa7159f64f3daf7d7658adbe
Change-Id: I8540ffb35fa8cb27fa7159f64f3daf7d7658adbe
parent 3c2cf351
Loading
Loading
Loading
Loading
+16 −7
Original line number Original line Diff line number Diff line
@@ -612,14 +612,13 @@ class KeyguardController {
    private KeyguardDisplayState getDisplayState(int displayId) {
    private KeyguardDisplayState getDisplayState(int displayId) {
        KeyguardDisplayState state = mDisplayStates.get(displayId);
        KeyguardDisplayState state = mDisplayStates.get(displayId);
        if (state == null) {
        if (state == null) {
            final DisplayContent dc = mRootWindowContainer.getDisplayContent(displayId);

            if (displayId == DEFAULT_DISPLAY || dc == null || dc.isKeyguardAlwaysUnlocked()) {
                state = new KeyguardDisplayState(mService, displayId);
                state = new KeyguardDisplayState(mService, displayId);
            if (displayId != DEFAULT_DISPLAY) {
            } else {
                final KeyguardDisplayState defaultState = mDisplayStates.get(DEFAULT_DISPLAY);
                final KeyguardDisplayState defaultState = mDisplayStates.get(DEFAULT_DISPLAY);
                if (defaultState != null) {
                state = new KeyguardDisplayState(mService, displayId, defaultState);
                    state.mKeyguardShowing = defaultState.mKeyguardShowing;
                    state.mAodShowing = defaultState.mAodShowing;
                    state.mKeyguardGoingAway = defaultState.mKeyguardGoingAway;
                }
            }
            }
            mDisplayStates.append(displayId, state);
            mDisplayStates.append(displayId, state);
        }
        }
@@ -729,6 +728,16 @@ class KeyguardController {
            mDisplayId = displayId;
            mDisplayId = displayId;
        }
        }


        KeyguardDisplayState(ActivityTaskManagerService service, int displayId,
                @Nullable KeyguardDisplayState copyFrom) {
            this(service, displayId);
            if (copyFrom != null) {
                mKeyguardShowing = copyFrom.mKeyguardShowing;
                mAodShowing = copyFrom.mAodShowing;
                mKeyguardGoingAway = copyFrom.mKeyguardGoingAway;
            }
        }

        void onRemoved(@NonNull DisplayContent dc) {
        void onRemoved(@NonNull DisplayContent dc) {
            mTopOccludesActivity = null;
            mTopOccludesActivity = null;
            mDismissingKeyguardActivity = null;
            mDismissingKeyguardActivity = null;
+14 −2
Original line number Original line Diff line number Diff line
@@ -649,19 +649,31 @@ public class ActivityTaskManagerServiceTests extends WindowTestsBase {
    @Test
    @Test
    public void testSetLockScreenShownWithAlwaysUnlockedVirtualDisplay() {
    public void testSetLockScreenShownWithAlwaysUnlockedVirtualDisplay() {
        assertEquals(Display.DEFAULT_DISPLAY, mRootWindowContainer.getChildAt(0).getDisplayId());
        assertEquals(Display.DEFAULT_DISPLAY, mRootWindowContainer.getChildAt(0).getDisplayId());
        final KeyguardController keyguardController = mSupervisor.getKeyguardController();

        // The default display is locked before creating the virtual display
        mAtm.setLockScreenShown(true, true);


        // Create the virtual display
        DisplayInfo displayInfo = new DisplayInfo();
        DisplayInfo displayInfo = new DisplayInfo();
        displayInfo.copyFrom(mDisplayInfo);
        displayInfo.copyFrom(mDisplayInfo);
        displayInfo.type = Display.TYPE_VIRTUAL;
        displayInfo.type = Display.TYPE_VIRTUAL;
        displayInfo.displayGroupId = Display.DEFAULT_DISPLAY_GROUP + 1;
        displayInfo.displayGroupId = Display.DEFAULT_DISPLAY_GROUP + 1;
        displayInfo.flags = Display.FLAG_OWN_DISPLAY_GROUP | Display.FLAG_ALWAYS_UNLOCKED;
        displayInfo.flags = Display.FLAG_OWN_DISPLAY_GROUP | Display.FLAG_ALWAYS_UNLOCKED;
        DisplayContent newDisplay = createNewDisplay(displayInfo);
        DisplayContent newDisplay = createNewDisplay(displayInfo);
        final KeyguardController keyguardController = mSupervisor.getKeyguardController();


        // Make sure we're starting out with 2 unlocked displays
        assertEquals(2, mRootWindowContainer.getChildCount());
        assertEquals(2, mRootWindowContainer.getChildCount());
        assertTrue(mDefaultDisplay.isKeyguardLocked());
        assertFalse(newDisplay.isKeyguardLocked());

        // Unlock the default display (this should have no effect for FLAG_ALWAYS_UNLOCKED)
        mAtm.keyguardGoingAway(0x0);
        mAtm.setLockScreenShown(false, false);

        // Make sure we now have both displays unlocked
        mRootWindowContainer.forAllDisplays(displayContent -> {
        mRootWindowContainer.forAllDisplays(displayContent -> {
            assertFalse(displayContent.isKeyguardLocked());
            assertFalse(displayContent.isKeyguardLocked());
            assertFalse(displayContent.isKeyguardGoingAway());
            assertFalse(keyguardController.isAodShowing(displayContent.mDisplayId));
            assertFalse(keyguardController.isAodShowing(displayContent.mDisplayId));
        });
        });