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

Commit e4d2cf03 authored by Bryce Lee's avatar Bryce Lee
Browse files

Do not allow GlanceableHub touch monitor to outlive view.

This changelist ensures that the touch monitor associated with the
glanceable hub is torn down whenever the backing view is disposed. This
ensures the backing input session never participates beyond the view
lifespan.

Test: atest GlanceableHubContainerControllerTest#disposeView_destroysTouchMonitor
Flag: EXEMPT bugfix
Fixes: 367549056
Change-Id: Iebb58ac941bee3ee9ed94b55d752f6e9a90780bd
parent 39678faa
Loading
Loading
Loading
Loading
+16 −6
Original line number Diff line number Diff line
@@ -289,6 +289,13 @@ constructor(
        )
    }

    private fun resetTouchMonitor() {
        touchMonitor?.apply {
            destroy()
            touchMonitor = null
        }
    }

    /** Override for testing. */
    @VisibleForTesting
    internal fun initView(containerView: View): View {
@@ -297,12 +304,13 @@ constructor(
            throw RuntimeException("Communal view has already been initialized")
        }

        if (touchMonitor == null) {
        resetTouchMonitor()

        touchMonitor =
            ambientTouchComponentFactory.create(this, HashSet(), TAG).getTouchMonitor().apply {
                init()
            }
        }

        lifecycleRegistry.addObserver(touchLifecycleLogger)
        lifecycleRegistry.currentState = Lifecycle.State.CREATED

@@ -475,6 +483,8 @@ constructor(

        lifecycleRegistry.removeObserver(touchLifecycleLogger)

        resetTouchMonitor()

        logger.d("Hub container disposed")
    }

+10 −0
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.any
import org.mockito.kotlin.clearInvocations
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.never
@@ -717,6 +718,15 @@ class GlanceableHubContainerControllerTest : SysuiTestCase() {
            }
        }

    @Test
    fun disposeView_destroysTouchMonitor() {
        clearInvocations(touchMonitor)

        underTest.disposeView()

        verify(touchMonitor).destroy()
    }

    private fun initAndAttachContainerView() {
        val mockInsets =
            mock<WindowInsets> {