summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Lucas Dupin <dupin@google.com> 2020-04-01 01:28:19 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2020-04-01 01:28:19 +0000
commit12a796779141dcad81999a4e2eb65ad8e502f3bd (patch)
treee29a35b1867e3a8e3dc37559af366376d1879612
parent5add803be8958db2593ba2488c28e823503d5f86 (diff)
parent7ee64cc4363f87b5ca8906001bc201599ec9114e (diff)
Merge "Do not crash if window is invalid" into rvc-dev
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt13
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationShadeDepthControllerTest.kt18
2 files changed, 29 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt
index a3faa80485d0..7f5134117c70 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt
@@ -20,6 +20,7 @@ import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.ValueAnimator
import android.app.WallpaperManager
+import android.util.Log
import android.view.Choreographer
import android.view.View
import androidx.annotation.VisibleForTesting
@@ -38,6 +39,7 @@ import com.android.systemui.statusbar.phone.PanelExpansionListener
import com.android.systemui.statusbar.policy.KeyguardStateController
import java.io.FileDescriptor
import java.io.PrintWriter
+import java.lang.IllegalArgumentException
import javax.inject.Inject
import javax.inject.Singleton
import kotlin.math.max
@@ -58,6 +60,7 @@ class NotificationShadeDepthController @Inject constructor(
) : PanelExpansionListener, Dumpable {
companion object {
private const val WAKE_UP_ANIMATION_ENABLED = true
+ private const val TAG = "DepthController"
}
lateinit var root: View
@@ -84,12 +87,18 @@ class NotificationShadeDepthController @Inject constructor(
/**
* Callback that updates the window blur value and is called only once per frame.
*/
- private val updateBlurCallback = Choreographer.FrameCallback {
+ @VisibleForTesting
+ val updateBlurCallback = Choreographer.FrameCallback {
updateScheduled = false
val blur = max(max(shadeSpring.radius, wakeAndUnlockBlurRadius), globalActionsSpring.radius)
blurUtils.applyBlur(blurRoot?.viewRootImpl ?: root.viewRootImpl, blur)
- wallpaperManager.setWallpaperZoomOut(root.windowToken, blurUtils.ratioOfBlurRadius(blur))
+ try {
+ wallpaperManager.setWallpaperZoomOut(root.windowToken,
+ blurUtils.ratioOfBlurRadius(blur))
+ } catch (e: IllegalArgumentException) {
+ Log.w(TAG, "Can't set zoom. Window is gone: ${root.windowToken}", e)
+ }
notificationShadeWindowController.setBackgroundBlurRadius(blur)
}
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 f4583f99f2d6..956bfd0337de 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationShadeDepthControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationShadeDepthControllerTest.kt
@@ -34,6 +34,7 @@ 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.eq
import org.mockito.Mock
import org.mockito.Mockito.`when`
@@ -41,8 +42,10 @@ import org.mockito.Mockito.any
import org.mockito.Mockito.anyFloat
import org.mockito.Mockito.anyString
import org.mockito.Mockito.clearInvocations
+import org.mockito.Mockito.doThrow
import org.mockito.Mockito.verify
import org.mockito.junit.MockitoJUnit
+import java.lang.IllegalArgumentException
@RunWith(AndroidTestingRunner::class)
@RunWithLooper
@@ -116,6 +119,21 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() {
verify(globalActionsSpring).animateTo(eq(maxBlur / 2), safeEq(root))
}
+ @Test
+ fun updateBlurCallback_setsBlurAndZoom() {
+ notificationShadeDepthController.updateBlurCallback.doFrame(0)
+ verify(wallpaperManager).setWallpaperZoomOut(any(), anyFloat())
+ verify(blurUtils).applyBlur(any(), anyInt())
+ }
+
+ @Test
+ fun updateBlurCallback_invalidWindow() {
+ doThrow(IllegalArgumentException("test exception")).`when`(wallpaperManager)
+ .setWallpaperZoomOut(any(), anyFloat())
+ notificationShadeDepthController.updateBlurCallback.doFrame(0)
+ verify(wallpaperManager).setWallpaperZoomOut(any(), anyFloat())
+ }
+
private fun <T : Any> safeEq(value: T): T {
return eq(value) ?: value
}