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

Commit 728b5280 authored by Santiago Etchebehere's avatar Santiago Etchebehere
Browse files

Do not set wallpaper zoom on non-attached window

Make sure the window is attached before updating wallpaper zoom.
When the device boots, the first call to updateBlurCallback
happens before NotificationShadeWindowView is attached so it
doesn't have a proper windowToken.

Fixes: 165816006
Test: updated updateBlurCallback_invalidWindow
Change-Id: I99af7f5c27c637cf3365b7a622f73ffad91c1f70
parent 5574089d
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -189,7 +189,11 @@ class NotificationShadeDepthController @Inject constructor(
        blurUtils.applyBlur(blurRoot?.viewRootImpl ?: root.viewRootImpl, blur)
        val zoomOut = blurUtils.ratioOfBlurRadius(blur)
        try {
            if (root.isAttachedToWindow) {
                wallpaperManager.setWallpaperZoomOut(root.windowToken, zoomOut)
            } else {
                Log.i(TAG, "Won't set zoom. Window not attached $root")
            }
        } catch (e: IllegalArgumentException) {
            Log.w(TAG, "Can't set zoom. Window is gone: ${root.windowToken}", e)
        }
+9 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import org.mockito.Mockito.anyString
import org.mockito.Mockito.clearInvocations
import org.mockito.Mockito.doThrow
import org.mockito.Mockito.never
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
import org.mockito.junit.MockitoJUnit

@@ -79,6 +80,7 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() {
    @Before
    fun setup() {
        `when`(root.viewRootImpl).thenReturn(viewRootImpl)
        `when`(root.isAttachedToWindow).thenReturn(true)
        `when`(statusBarStateController.state).then { statusBarState }
        `when`(blurUtils.blurRadiusOfRatio(anyFloat())).then { answer ->
            (answer.arguments[0] as Float * maxBlur).toInt()
@@ -219,6 +221,13 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() {

    @Test
    fun updateBlurCallback_invalidWindow() {
        `when`(root.isAttachedToWindow).thenReturn(false)
        notificationShadeDepthController.updateBlurCallback.doFrame(0)
        verify(wallpaperManager, times(0)).setWallpaperZoomOut(any(), anyFloat())
    }

    @Test
    fun updateBlurCallback_exception() {
        doThrow(IllegalArgumentException("test exception")).`when`(wallpaperManager)
                .setWallpaperZoomOut(any(), anyFloat())
        notificationShadeDepthController.updateBlurCallback.doFrame(0)