From 9bfd60ab82c8f9477249b8ea0ecfe4f7a2064c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Go=CC=88llner?= Date: Thu, 14 Apr 2022 11:13:02 +0200 Subject: [PATCH] Disable depth effect during split-shade expansion According to the motion spec for split-shade, there should be no depth effect. Fixes: 228022043 Test: Manually + NotificationShadeDepthControllerTest.kt Change-Id: I1b908e17b3084f94578973d53993b47d9ad22ebb --- .../NotificationShadeDepthController.kt | 23 +++++- .../NotificationShadeDepthControllerTest.kt | 81 +++++++++++++++++-- 2 files changed, 97 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt index 6219164343966..6ef938285263b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt @@ -19,6 +19,8 @@ package com.android.systemui.statusbar import android.animation.Animator import android.animation.AnimatorListenerAdapter import android.animation.ValueAnimator +import android.content.Context +import android.content.res.Configuration import android.os.SystemClock import android.os.Trace import android.util.IndentingPrintWriter @@ -41,7 +43,9 @@ import com.android.systemui.statusbar.phone.BiometricUnlockController.MODE_WAKE_ import com.android.systemui.statusbar.phone.DozeParameters import com.android.systemui.statusbar.phone.ScrimController import com.android.systemui.statusbar.phone.panelstate.PanelExpansionListener +import com.android.systemui.statusbar.policy.ConfigurationController import com.android.systemui.statusbar.policy.KeyguardStateController +import com.android.systemui.util.LargeScreenUtils import com.android.systemui.util.WallpaperController import java.io.PrintWriter import javax.inject.Inject @@ -61,7 +65,9 @@ class NotificationShadeDepthController @Inject constructor( private val wallpaperController: WallpaperController, private val notificationShadeWindowController: NotificationShadeWindowController, private val dozeParameters: DozeParameters, - dumpManager: DumpManager + private val context: Context, + dumpManager: DumpManager, + configurationController: ConfigurationController ) : PanelExpansionListener, Dumpable { companion object { private const val WAKE_UP_ANIMATION_ENABLED = true @@ -84,6 +90,7 @@ class NotificationShadeDepthController @Inject constructor( private var isOpen: Boolean = false private var isBlurred: Boolean = false private var listeners = mutableListOf() + private var inSplitShade: Boolean = false private var prevTracking: Boolean = false private var prevTimestamp: Long = -1 @@ -208,6 +215,10 @@ class NotificationShadeDepthController @Inject constructor( var zoomOut = MathUtils.saturate(blurUtils.ratioOfBlurRadius(shadeRadius)) var blur = shadeRadius.toInt() + if (inSplitShade) { + zoomOut = 0f + } + // Make blur be 0 if it is necessary to stop blur effect. if (scrimsVisible) { blur = 0 @@ -306,6 +317,16 @@ class NotificationShadeDepthController @Inject constructor( } shadeAnimation.setStiffness(SpringForce.STIFFNESS_LOW) shadeAnimation.setDampingRatio(SpringForce.DAMPING_RATIO_NO_BOUNCY) + updateResources() + configurationController.addCallback(object : ConfigurationController.ConfigurationListener { + override fun onConfigChanged(newConfig: Configuration?) { + updateResources() + } + }) + } + + private fun updateResources() { + inSplitShade = LargeScreenUtils.shouldUseSplitNotificationShade(context.resources) } fun addListener(listener: DepthListener) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationShadeDepthControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationShadeDepthControllerTest.kt index 91e5d33d9c9ed..1bcc038e93b60 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationShadeDepthControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationShadeDepthControllerTest.kt @@ -23,6 +23,7 @@ import android.view.Choreographer import android.view.View import android.view.ViewRootImpl import androidx.test.filters.SmallTest +import com.android.systemui.R import com.android.systemui.SysuiTestCase import com.android.systemui.animation.ShadeInterpolation import com.android.systemui.dump.DumpManager @@ -30,18 +31,22 @@ import com.android.systemui.plugins.statusbar.StatusBarStateController import com.android.systemui.statusbar.phone.BiometricUnlockController import com.android.systemui.statusbar.phone.DozeParameters import com.android.systemui.statusbar.phone.ScrimController +import com.android.systemui.statusbar.policy.FakeConfigurationController import com.android.systemui.statusbar.policy.KeyguardStateController import com.android.systemui.util.WallpaperController import com.android.systemui.util.mockito.eq import com.google.common.truth.Truth.assertThat +import java.util.function.Consumer import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.mockito.ArgumentCaptor import org.mockito.ArgumentMatchers.anyInt +import org.mockito.ArgumentMatchers.floatThat import org.mockito.Captor import org.mockito.Mock +import org.mockito.Mockito import org.mockito.Mockito.`when` import org.mockito.Mockito.any import org.mockito.Mockito.anyFloat @@ -51,7 +56,6 @@ import org.mockito.Mockito.never import org.mockito.Mockito.reset import org.mockito.Mockito.verify import org.mockito.junit.MockitoJUnit -import java.util.function.Consumer @RunWith(AndroidTestingRunner::class) @RunWithLooper @@ -80,6 +84,7 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() { private var statusBarState = StatusBarState.SHADE private val maxBlur = 150 private lateinit var notificationShadeDepthController: NotificationShadeDepthController + private val configurationController = FakeConfigurationController() @Before fun setup() { @@ -97,10 +102,19 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() { `when`(blurUtils.maxBlurRadius).thenReturn(maxBlur) `when`(blurUtils.maxBlurRadius).thenReturn(maxBlur) - notificationShadeDepthController = NotificationShadeDepthController( - statusBarStateController, blurUtils, biometricUnlockController, - keyguardStateController, choreographer, wallpaperController, - notificationShadeWindowController, dozeParameters, dumpManager) + notificationShadeDepthController = + NotificationShadeDepthController( + statusBarStateController, + blurUtils, + biometricUnlockController, + keyguardStateController, + choreographer, + wallpaperController, + notificationShadeWindowController, + dozeParameters, + context, + dumpManager, + configurationController) notificationShadeDepthController.shadeAnimation = shadeAnimation notificationShadeDepthController.brightnessMirrorSpring = brightnessSpring notificationShadeDepthController.root = root @@ -110,6 +124,8 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() { statusBarStateListener = captor.value verify(notificationShadeWindowController) .setScrimsVisibilityListener(scrimVisibilityCaptor.capture()) + + disableSplitShade() } @Test @@ -225,6 +241,46 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() { eq(ShadeInterpolation.getNotificationScrimAlpha(0.25f))) } + @Test + fun expandPanel_inSplitShade_setsZoomToZero() { + enableSplitShade() + + notificationShadeDepthController.onPanelExpansionChanged( + rawFraction = 1f, expanded = true, tracking = false) + notificationShadeDepthController.updateBlurCallback.doFrame(0) + + verify(wallpaperController).setNotificationShadeZoom(0f) + } + + @Test + fun expandPanel_notInSplitShade_setsZoomValue() { + disableSplitShade() + + notificationShadeDepthController.onPanelExpansionChanged( + rawFraction = 1f, expanded = true, tracking = false) + notificationShadeDepthController.updateBlurCallback.doFrame(0) + + verify(wallpaperController).setNotificationShadeZoom(floatThat { it > 0 }) + } + + @Test + fun expandPanel_splitShadeEnabledChanged_setsCorrectZoomValueAfterChange() { + disableSplitShade() + val rawFraction = 1f + val expanded = true + val tracking = false + val inOrder = Mockito.inOrder(wallpaperController) + + notificationShadeDepthController.onPanelExpansionChanged(rawFraction, expanded, tracking) + notificationShadeDepthController.updateBlurCallback.doFrame(0) + inOrder.verify(wallpaperController).setNotificationShadeZoom(floatThat { it > 0 }) + + enableSplitShade() + notificationShadeDepthController.onPanelExpansionChanged(rawFraction, expanded, tracking) + notificationShadeDepthController.updateBlurCallback.doFrame(0) + inOrder.verify(wallpaperController).setNotificationShadeZoom(0f) + } + @Test fun setFullShadeTransition_appliesBlur() { notificationShadeDepthController.transitionToFullShadeProgress = 1f @@ -369,4 +425,17 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() { notificationShadeDepthController.blursDisabledForAppLaunch = true verify(shadeAnimation, never()).animateTo(anyInt(), any()) } -} \ No newline at end of file + + private fun enableSplitShade() { + setSplitShadeEnabled(true) + } + + private fun disableSplitShade() { + setSplitShadeEnabled(false) + } + + private fun setSplitShadeEnabled(enabled: Boolean) { + overrideResource(R.bool.config_use_split_notification_shade, enabled) + configurationController.notifyConfigurationChanged() + } +}