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

Commit 99dc8109 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Do not blur when changing brightness

Test: manual
Test: atest NotificationShadeDepthControllerTest
Fixes: 191850924
Change-Id: I32636783cccbae15c5ca4d139e34b2d38ba563ad
parent 43038ca7
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -96,6 +96,15 @@ class NotificationShadeDepthController @Inject constructor(
    var globalActionsSpring = DepthAnimation()
    var showingHomeControls: Boolean = false

    @VisibleForTesting
    var brightnessMirrorSpring = DepthAnimation()
    var brightnessMirrorVisible: Boolean = false
        set(value) {
            field = value
            brightnessMirrorSpring.animateTo(if (value) blurUtils.blurRadiusOfRatio(1f)
                else 0)
        }

    var qsPanelExpansion = 0f
        set(value) {
            if (field == value) return
@@ -189,10 +198,13 @@ class NotificationShadeDepthController @Inject constructor(
        if (scrimsVisible || !blurUtils.supportsBlursOnWindows()) {
            blur = 0
        }
        val zoomOut = blurUtils.ratioOfBlurRadius(blur)

        // Brightness slider removes blur, but doesn't affect zooms
        blur = (blur * (1f - brightnessMirrorSpring.ratio)).toInt()

        val opaque = scrimsVisible && !ignoreShadeBlurUntilHidden
        blurUtils.applyBlur(blurRoot?.viewRootImpl ?: root.viewRootImpl, blur, opaque)
        val zoomOut = blurUtils.ratioOfBlurRadius(blur)
        try {
            if (root.isAttachedToWindow && root.windowToken != null) {
                wallpaperManager.setWallpaperZoomOut(root.windowToken, zoomOut)
@@ -260,6 +272,7 @@ class NotificationShadeDepthController @Inject constructor(
                shadeSpring.finishIfRunning()
                shadeAnimation.finishIfRunning()
                globalActionsSpring.finishIfRunning()
                brightnessMirrorSpring.finishIfRunning()
            }
        }

@@ -425,6 +438,7 @@ class NotificationShadeDepthController @Inject constructor(
            it.println("shadeRadius: ${shadeSpring.radius}")
            it.println("shadeAnimation: ${shadeAnimation.radius}")
            it.println("globalActionsRadius: ${globalActionsSpring.radius}")
            it.println("brightnessMirrorRadius: ${brightnessMirrorSpring.radius}")
            it.println("wakeAndUnlockBlur: $wakeAndUnlockBlurRadius")
            it.println("ignoreShadeBlurUntilHidden: $ignoreShadeBlurUntilHidden")
        }
+2 −0
Original line number Diff line number Diff line
@@ -74,11 +74,13 @@ public class BrightnessMirrorController
        mBrightnessMirror.setVisibility(View.VISIBLE);
        mVisibilityCallback.accept(true);
        mNotificationPanel.setPanelAlpha(0, true /* animate */);
        mDepthController.setBrightnessMirrorVisible(true);
    }

    public void hideMirror() {
        mVisibilityCallback.accept(false);
        mNotificationPanel.setPanelAlpha(255, true /* animate */);
        mDepthController.setBrightnessMirrorVisible(false);
    }

    /**
+31 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() {
    @Mock private lateinit var shadeSpring: NotificationShadeDepthController.DepthAnimation
    @Mock private lateinit var shadeAnimation: NotificationShadeDepthController.DepthAnimation
    @Mock private lateinit var globalActionsSpring: NotificationShadeDepthController.DepthAnimation
    @Mock private lateinit var brightnessSpring: NotificationShadeDepthController.DepthAnimation
    @Mock private lateinit var listener: NotificationShadeDepthController.DepthListener
    @Mock private lateinit var dozeParameters: DozeParameters
    @Captor private lateinit var scrimVisibilityCaptor: ArgumentCaptor<Consumer<Int>>
@@ -91,6 +92,9 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() {
        `when`(blurUtils.blurRadiusOfRatio(anyFloat())).then { answer ->
            (answer.arguments[0] as Float * maxBlur).toInt()
        }
        `when`(blurUtils.ratioOfBlurRadius(anyInt())).then { answer ->
            answer.arguments[0] as Int / maxBlur.toFloat()
        }
        `when`(blurUtils.supportsBlursOnWindows()).thenReturn(true)
        `when`(blurUtils.maxBlurRadius).thenReturn(maxBlur)
        `when`(blurUtils.maxBlurRadius).thenReturn(maxBlur)
@@ -101,6 +105,7 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() {
                notificationShadeWindowController, dozeParameters, dumpManager)
        notificationShadeDepthController.shadeSpring = shadeSpring
        notificationShadeDepthController.shadeAnimation = shadeAnimation
        notificationShadeDepthController.brightnessMirrorSpring = brightnessSpring
        notificationShadeDepthController.globalActionsSpring = globalActionsSpring
        notificationShadeDepthController.root = root

@@ -276,6 +281,32 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() {
                eq(notificationShadeDepthController.updateBlurCallback))
    }

    @Test
    fun brightnessMirrorVisible_whenVisible() {
        notificationShadeDepthController.brightnessMirrorVisible = true
        verify(brightnessSpring).animateTo(eq(maxBlur), any())
    }

    @Test
    fun brightnessMirrorVisible_whenHidden() {
        notificationShadeDepthController.brightnessMirrorVisible = false
        verify(brightnessSpring).animateTo(eq(0), any())
    }

    @Test
    fun brightnessMirror_hidesShadeBlur() {
        // Brightness mirror is fully visible
        `when`(brightnessSpring.ratio).thenReturn(1f)
        // And shade is blurred
        `when`(shadeSpring.radius).thenReturn(maxBlur)
        `when`(shadeAnimation.radius).thenReturn(maxBlur)

        notificationShadeDepthController.updateBlurCallback.doFrame(0)
        verify(notificationShadeWindowController).setBackgroundBlurRadius(eq(0))
        verify(wallpaperManager).setWallpaperZoomOut(any(), eq(1f))
        verify(blurUtils).applyBlur(eq(viewRootImpl), eq(0), eq(false))
    }

    @Test
    fun ignoreShadeBlurUntilHidden_whennNull_ignoresIfShadeHasNoBlur() {
        `when`(shadeSpring.radius).thenReturn(0)