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

Commit 7e77854b authored by Robin Lee's avatar Robin Lee
Browse files

All keyguard occludes go in-band with transitions

Previously the logic was as follows:

 - If keyguard is locked, send occlude in a transition
   - And send a direct update after all transitions finish
 - If keyguard is not locked, send occlude directly

This had a race if some activity decided to occlude the keyguard and
request its dismissal at the same time, since an occlude transition
could be generated followed by a direct update. The direct update is
applied instantly but the occlude transition is not so it could run
later and since there is no sequencing between the two the keyguard
service could still end up confused.

Now although we still send the direct updates, they wait to go out until
SystemUI has reported to us that it finished handling all the active
transitions. This prevents racing ahead of enqueued transitions. To
prevent racing behind future transitions we rely on the guarantees
about ordering of oneway RPCs on the same IBinder.

Test: atest CtsWindowManagerDeviceTestCases:KeyguardTests
Fix: 284811687
Change-Id: I6c369c922170a5c9aab96a5060089c1b6fb8fd85
parent f42fbb92
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -3570,19 +3570,17 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    }

    @Override
    public void onKeyguardOccludedChangedLw(boolean occluded, boolean waitAppTransition) {
        if (mKeyguardDelegate != null && waitAppTransition) {
    public void onKeyguardOccludedChangedLw(boolean occluded) {
        if (mKeyguardDelegate != null) {
            mPendingKeyguardOccluded = occluded;
            mKeyguardOccludedChanged = true;
        } else {
            setKeyguardOccludedLw(occluded);
        }
    }

    @Override
    public int applyKeyguardOcclusionChange() {
        if (DEBUG_KEYGUARD) Slog.d(TAG, "transition/occluded commit occluded="
                + mPendingKeyguardOccluded);
                + mPendingKeyguardOccluded + " changed=" + mKeyguardOccludedChanged);

        // TODO(b/276433230): Explicitly save before/after for occlude state in each
        // Transition so we don't need to update SysUI every time.
+1 −1
Original line number Diff line number Diff line
@@ -169,7 +169,7 @@ public interface WindowManagerPolicy extends WindowManagerPolicyConstants {
     *
     * @param occluded Whether Keyguard is currently occluded or not.
     */
    void onKeyguardOccludedChangedLw(boolean occluded, boolean waitAppTransition);
    void onKeyguardOccludedChangedLw(boolean occluded);

    /**
     * Commit any queued changes to keyguard occlude status that had been deferred during the
+25 −10
Original line number Diff line number Diff line
@@ -418,13 +418,17 @@ class KeyguardController {
            return;
        }

        final boolean waitAppTransition = isKeyguardLocked(displayId);
        mWindowManager.mPolicy.onKeyguardOccludedChangedLw(isDisplayOccluded(DEFAULT_DISPLAY),
                waitAppTransition);
        if (waitAppTransition) {
        final TransitionController tc = mRootWindowContainer.mTransitionController;

        final boolean occluded = isDisplayOccluded(displayId);
        final boolean performTransition = isKeyguardLocked(displayId);
        final boolean executeTransition = performTransition && !tc.isCollecting();

        mWindowManager.mPolicy.onKeyguardOccludedChangedLw(occluded);
        mService.deferWindowLayout();
        try {
                if (isDisplayOccluded(DEFAULT_DISPLAY)) {
            if (isKeyguardLocked(displayId)) {
                if (occluded) {
                    mRootWindowContainer.getDefaultDisplay().requestTransitionAndLegacyPrepare(
                            TRANSIT_KEYGUARD_OCCLUDE,
                            TRANSIT_FLAG_KEYGUARD_OCCLUDING,
@@ -434,13 +438,21 @@ class KeyguardController {
                            TRANSIT_KEYGUARD_UNOCCLUDE,
                            TRANSIT_FLAG_KEYGUARD_UNOCCLUDING);
                }
                updateKeyguardSleepToken(DEFAULT_DISPLAY);
            } else {
                if (tc.inTransition()) {
                    tc.mStateValidators.add(mWindowManager.mPolicy::applyKeyguardOcclusionChange);
                } else {
                    mWindowManager.mPolicy.applyKeyguardOcclusionChange();
                }
            }
            updateKeyguardSleepToken(displayId);
            if (performTransition && executeTransition) {
                mWindowManager.executeAppTransition();
            }
        } finally {
            mService.continueWindowLayout();
        }
    }
    }

    /**
     * Called when keyguard going away state changed.
@@ -485,6 +497,9 @@ class KeyguardController {
        }
    }

    /**
     * @return true if Keyguard is occluded or the device is dreaming.
     */
    boolean isDisplayOccluded(int displayId) {
        return getDisplayState(displayId).mOccluded;
    }
+2 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.INVALID_DISPLAY;
import static android.view.WindowManager.INPUT_CONSUMER_RECENTS_ANIMATION;
import static android.view.WindowManager.KEYGUARD_VISIBILITY_TRANSIT_FLAGS;
import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_SEAMLESS;
import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_UNSPECIFIED;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
@@ -2649,7 +2650,7 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener {
    }

    private void validateKeyguardOcclusion() {
        if ((mFlags & TRANSIT_FLAG_KEYGUARD_LOCKED) != 0) {
        if ((mFlags & KEYGUARD_VISIBILITY_TRANSIT_FLAGS) != 0) {
            mController.mStateValidators.add(
                mController.mAtm.mWindowManager.mPolicy::applyKeyguardOcclusionChange);
        }
+1 −1
Original line number Diff line number Diff line
@@ -233,7 +233,7 @@ class TestWindowManagerPolicy implements WindowManagerPolicy {
    }

    @Override
    public void onKeyguardOccludedChangedLw(boolean occluded, boolean waitAppTransition) {
    public void onKeyguardOccludedChangedLw(boolean occluded) {
    }

    public void setSafeMode(boolean safeMode) {