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

Commit bde4c0cc authored by Jerry Chang's avatar Jerry Chang
Browse files

Fade away wallpapers when long pulse

Add back timeout wallpaper while docking pulses due to docking pulses
may took a long time and should fade away wallpaper to avoid aging.

Reset mWallpaperVisibilityTimedOut flag to reset wallpaper timeout every
time scrim state changed or panel expanded.

Fix: 135134059
Test: atest SystemUITests:ScrimControllerTest
Change-Id: I5ea3e52733734cef6c6850fa4af1d8ad2941f967
parent 2bc56a82
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -84,6 +84,14 @@ public class DozeScrimController implements StateListener {
        public void onCancelled() {
            pulseFinished();
        }

        /**
         * Whether to timeout wallpaper or not.
         */
        @Override
        public boolean shouldTimeoutWallpaper() {
            return mPulseReason == DozeLog.PULSE_REASON_DOCKING;
        }
    };

    public DozeScrimController(DozeParameters dozeParameters) {
+33 −7
Original line number Diff line number Diff line
@@ -284,15 +284,12 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, OnCo

        // AOD wallpapers should fade away after a while.
        // Docking pulses may take a long time, wallpapers should also fade away after a while.
        if (mWallpaperSupportsAmbientMode && mDozeParameters.getAlwaysOn()
                && mState == ScrimState.AOD) {
            if (!mWallpaperVisibilityTimedOut) {
        mWallpaperVisibilityTimedOut = false;
        if (shouldFadeAwayWallpaper()) {
            mTimeTicker.schedule(mDozeParameters.getWallpaperAodDuration(),
                    AlarmTimeout.MODE_IGNORE_IF_SCHEDULED);
            }
        } else {
            mTimeTicker.cancel();
            mWallpaperVisibilityTimedOut = false;
        }

        if (mKeyguardUpdateMonitor.needsSlowUnlockTransition() && mState == ScrimState.UNLOCKED) {
@@ -313,6 +310,23 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, OnCo
        dispatchScrimState(mScrimBehind.getViewAlpha());
    }

    private boolean shouldFadeAwayWallpaper() {
        if (!mWallpaperSupportsAmbientMode) {
            return false;
        }

        if (mState == ScrimState.AOD && mDozeParameters.getAlwaysOn()) {
            return true;
        }

        if (mState == ScrimState.PULSING
                && mCallback != null && mCallback.shouldTimeoutWallpaper()) {
            return true;
        }

        return false;
    }

    public ScrimState getState() {
        return mState;
    }
@@ -387,6 +401,14 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, OnCo
            setOrAdaptCurrentAnimation(mScrimInFront);

            dispatchScrimState(mScrimBehind.getViewAlpha());

            // Reset wallpaper timeout if it's already timeout like expanding panel while PULSING
            // and docking.
            if (mWallpaperVisibilityTimedOut) {
                mWallpaperVisibilityTimedOut = false;
                mTimeTicker.schedule(mDozeParameters.getWallpaperAodDuration(),
                        AlarmTimeout.MODE_IGNORE_IF_SCHEDULED);
            }
        }
    }

@@ -925,6 +947,10 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, OnCo
        }
        default void onCancelled() {
        }
        /** Returns whether to timeout wallpaper or not. */
        default boolean shouldTimeoutWallpaper() {
            return false;
        }
    }

    /**
+32 −0
Original line number Diff line number Diff line
@@ -507,6 +507,38 @@ public class ScrimControllerTest extends SysuiTestCase {
        verify(mAlarmManager).cancel(any(AlarmManager.OnAlarmListener.class));
    }

    @Test
    public void transitionToPulsing_withTimeoutWallpaperCallback_willHideWallpaper() {
        mScrimController.setWallpaperSupportsAmbientMode(true);

        mScrimController.transitionTo(ScrimState.PULSING, new ScrimController.Callback() {
            @Override
            public boolean shouldTimeoutWallpaper() {
                return true;
            }
        });

        verify(mAlarmManager).setExact(anyInt(), anyLong(), any(), any(), any());
    }

    @Test
    public void transitionToPulsing_withDefaultCallback_wontHideWallpaper() {
        mScrimController.setWallpaperSupportsAmbientMode(true);

        mScrimController.transitionTo(ScrimState.PULSING, new ScrimController.Callback() {});

        verify(mAlarmManager, never()).setExact(anyInt(), anyLong(), any(), any(), any());
    }

    @Test
    public void transitionToPulsing_withoutCallback_wontHideWallpaper() {
        mScrimController.setWallpaperSupportsAmbientMode(true);

        mScrimController.transitionTo(ScrimState.PULSING);

        verify(mAlarmManager, never()).setExact(anyInt(), anyLong(), any(), any(), any());
    }

    @Test
    public void testConservesExpansionOpacityAfterTransition() {
        mScrimController.transitionTo(ScrimState.UNLOCKED);