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

Commit b380c882 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Fix scrim busyness regression

Scrim opacity on the keyguard should vary according to how many
notifications are visible.
A busy lock screen has a more opaque scrim, and an empty lock screen
has a more transparent scrim.

Test: atest packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ScrimControllerTest.java
Test: swipe away or receive notifications on the keyguard
Change-Id: I672b5e1a82d65dd326b40069d61223c3c0161493
parent f3fc8a4d
Loading
Loading
Loading
Loading
+13 −12
Original line number Diff line number Diff line
@@ -167,6 +167,7 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
    private Callback mCallback;
    private boolean mWallpaperSupportsAmbientMode;
    private boolean mScreenOn;
    private float mNotificationDensity;

    // Scrim blanking callbacks
    private Choreographer.FrameCallback mPendingFrameCallback;
@@ -251,7 +252,7 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
        mCurrentInFrontTint = state.getFrontTint();
        mCurrentBehindTint = state.getBehindTint();
        mCurrentInFrontAlpha = state.getFrontAlpha();
        mCurrentBehindAlpha = state.getBehindAlpha();
        mCurrentBehindAlpha = state.getBehindAlpha(mNotificationDensity);
        applyExpansionToAlpha();

        // Cancel blanking transitions that were pending before we requested a new state
@@ -396,12 +397,13 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
            // Either darken of make the scrim transparent when you
            // pull down the shade
            float interpolatedFract = getInterpolatedFraction();
            float alphaBehind = mState.getBehindAlpha(mNotificationDensity);
            if (mDarkenWhileDragging) {
                mCurrentBehindAlpha = MathUtils.lerp(mScrimBehindAlphaUnlocking,
                        mScrimBehindAlphaKeyguard, interpolatedFract);
                mCurrentBehindAlpha = MathUtils.lerp(mScrimBehindAlphaUnlocking, alphaBehind,
                        interpolatedFract);
                mCurrentInFrontAlpha = (1f - interpolatedFract) * SCRIM_IN_FRONT_ALPHA_LOCKED;
            } else {
                mCurrentBehindAlpha = MathUtils.lerp(0 /* start */, mScrimBehindAlphaKeyguard,
                mCurrentBehindAlpha = MathUtils.lerp(0 /* start */, alphaBehind,
                        interpolatedFract);
                mCurrentInFrontAlpha = 0;
            }
@@ -415,17 +417,16 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
    public void setNotificationCount(int notificationCount) {
        final float maxNotificationDensity = 3;
        float notificationDensity = Math.min(notificationCount / maxNotificationDensity, 1f);
        float newAlpha = MathUtils.map(0, 1,
                GRADIENT_SCRIM_ALPHA, GRADIENT_SCRIM_ALPHA_BUSY,
                notificationDensity);
        if (mScrimBehindAlphaKeyguard != newAlpha) {
            mScrimBehindAlphaKeyguard = newAlpha;
        if (mNotificationDensity == notificationDensity) {
            return;
        }
        mNotificationDensity = notificationDensity;

            if (mState == ScrimState.KEYGUARD || mState == ScrimState.BOUNCER) {
        if (mState == ScrimState.KEYGUARD) {
            applyExpansionToAlpha();
            scheduleUpdate();
        }
    }
    }

    /**
     * Sets the given drawable as the background of the scrim that shows up behind the
+9 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.statusbar.phone;

import android.graphics.Color;
import android.os.Trace;
import android.util.MathUtils;

import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.statusbar.ScrimView;
@@ -55,6 +56,13 @@ public enum ScrimState {
            mCurrentBehindAlpha = mScrimBehindAlphaKeyguard;
            mCurrentInFrontAlpha = 0;
        }

        @Override
        public float getBehindAlpha(float busynessFactor) {
            return MathUtils.map(0 /* start */, 1 /* stop */,
                   ScrimController.GRADIENT_SCRIM_ALPHA, ScrimController.GRADIENT_SCRIM_ALPHA_BUSY,
                   busynessFactor);
        }
    },

    /**
@@ -183,7 +191,7 @@ public enum ScrimState {
        return mCurrentInFrontAlpha;
    }

    public float getBehindAlpha() {
    public float getBehindAlpha(float busyness) {
        return mCurrentBehindAlpha;
    }

+46 −0
Original line number Diff line number Diff line
@@ -356,6 +356,52 @@ public class ScrimControllerTest extends SysuiTestCase {
        Assert.assertTrue(mScrimController.wasAnimationJustCancelled());
    }

    /**
     * Number of visible notifications affects scrim opacity.
     */
    @Test
    public void testNotificationDensity() {
        mScrimController.transitionTo(ScrimState.KEYGUARD);
        mScrimController.finishAnimationsImmediately();

        mScrimController.setNotificationCount(0);
        mScrimController.finishAnimationsImmediately();
        Assert.assertEquals("lower density when no notifications",
                ScrimController.GRADIENT_SCRIM_ALPHA,  mScrimBehind.getViewAlpha(), 0.01f);

        mScrimController.setNotificationCount(3);
        mScrimController.finishAnimationsImmediately();
        Assert.assertEquals("stronger density when notifications are visible",
                ScrimController.GRADIENT_SCRIM_ALPHA_BUSY,  mScrimBehind.getViewAlpha(), 0.01f);
    }

    /**
     * Moving from/to states conserves old notification density.
     */
    @Test
    public void testConservesNotificationDensity() {
        testConservesNotificationDensity(0 /* count */, ScrimController.GRADIENT_SCRIM_ALPHA);
        testConservesNotificationDensity(3 /* count */, ScrimController.GRADIENT_SCRIM_ALPHA_BUSY);
    }

    /**
     * Conserves old notification density after leaving state and coming back.
     *
     * @param count How many notification.
     * @param expectedAlpha Expected alpha.
     */
    private void testConservesNotificationDensity(int count, float expectedAlpha) {
        mScrimController.setNotificationCount(count);
        mScrimController.transitionTo(ScrimState.UNLOCKED);
        mScrimController.finishAnimationsImmediately();

        mScrimController.transitionTo(ScrimState.KEYGUARD);
        mScrimController.finishAnimationsImmediately();

        Assert.assertEquals("Doesn't respect notification busyness after transition",
                expectedAlpha,  mScrimBehind.getViewAlpha(), 0.01f);
    }

    private void assertScrimTint(ScrimView scrimView, boolean tinted) {
        final boolean viewIsTinted = scrimView.getTint() != Color.TRANSPARENT;
        final String name = scrimView == mScrimInFront ? "front" : "back";