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

Commit cae88753 authored by Michael Wright's avatar Michael Wright Committed by Lucas Dupin
Browse files

Have doze update the scrim controller rather than the scrim state.

Right now, when Doze wants to update the front alpha in AOD, it updates
the scrim state's front alpha value. Unfortunately, this is only looked
at when transitioning into the state, but entirely ignored once we're in
it. With this, we instead tell the scrim controller which tells the
scrim state but also updates the current front scrim alpha if we're
currently in the AOD state.

Bug: 78124574
Bug: 70939994
Test: atest ScrimControllerTest\#transitionToAod_withFrontAlphaUpdates
Change-Id: I09b33208bd3e3fd6d3829b33776364aa7b61a4f6
parent 2e79c79e
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -449,6 +449,18 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, OnCo
        mScrimBehind.setDrawable(drawable);
    }

    /**
     * Sets the front alpha while in AOD.
     */
    public void setAodFrontScrimAlpha(float alpha) {
        if (mState == ScrimState.AOD && mCurrentInFrontAlpha != alpha) {
            mCurrentInFrontAlpha = alpha;
            scheduleUpdate();
        }

        mState.AOD.setAodFrontScrimAlpha(alpha);
    }

    protected void scheduleUpdate() {
        if (mUpdatePending) return;

+1 −1
Original line number Diff line number Diff line
@@ -4884,7 +4884,7 @@ public class StatusBar extends SystemUI implements DemoMode,

        @Override
        public void setAodDimmingScrim(float scrimOpacity) {
            ScrimState.AOD.setAodFrontScrimAlpha(scrimOpacity);
            mScrimController.setAodFrontScrimAlpha(scrimOpacity);
        }

        public void dispatchDoubleTap(float viewX, float viewY) {
+32 −0
Original line number Diff line number Diff line
@@ -155,6 +155,38 @@ public class ScrimControllerTest extends SysuiTestCase {
        assertScrimTint(mScrimInFront, true /* tinted */);
    }

    @Test
    public void transitionToAod_withFrontAlphaUpdates() {
        // Assert that setting the AOD front scrim alpha doesn't take effect in a non-AOD state.
        mScrimController.transitionTo(ScrimState.KEYGUARD);
        mScrimController.setAodFrontScrimAlpha(0.5f);
        mScrimController.finishAnimationsImmediately();
        // Front scrim should be transparent
        // Back scrim should be visible without tint
        assertScrimVisibility(VISIBILITY_FULLY_TRANSPARENT, VISIBILITY_SEMI_TRANSPARENT);

        // ... but that it does take effect once we enter the AOD state.
        mScrimController.transitionTo(ScrimState.AOD);
        mScrimController.finishAnimationsImmediately();
        // Front scrim should be semi-transparent
        // Back scrim should be visible
        assertScrimVisibility(VISIBILITY_SEMI_TRANSPARENT, VISIBILITY_FULLY_OPAQUE);

        // ... and that if we set it while we're in AOD, it does take immediate effect.
        mScrimController.setAodFrontScrimAlpha(1f);
        assertScrimVisibility(VISIBILITY_FULLY_OPAQUE, VISIBILITY_FULLY_OPAQUE);

        // ... and make sure we recall the previous front scrim alpha even if we transition away
        // for a bit.
        mScrimController.transitionTo(ScrimState.UNLOCKED);
        mScrimController.transitionTo(ScrimState.AOD);
        mScrimController.finishAnimationsImmediately();
        assertScrimVisibility(VISIBILITY_FULLY_OPAQUE, VISIBILITY_FULLY_OPAQUE);

        // Reset value since enums are static.
        mScrimController.setAodFrontScrimAlpha(0f);
    }

    @Test
    public void transitionToPulsing() {
        // Pre-condition