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

Commit 8cc9303a authored by Lucas Dupin's avatar Lucas Dupin Committed by Automerger Merge Worker
Browse files

Merge "Do not crash if window is invalid" into rvc-dev am: 12a79677 am: c4861348

Change-Id: I499362f333f7764d7d3c3f44a4c11c771573baf4
parents 12f778cd c4861348
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -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)
    }

+18 −0
Original line number Diff line number Diff line
@@ -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
    }