diff options
2 files changed, 26 insertions, 6 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/shade/GlanceableHubContainerController.kt b/packages/SystemUI/src/com/android/systemui/shade/GlanceableHubContainerController.kt index 2e67277d8327..52cb8d6df7e1 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/GlanceableHubContainerController.kt +++ b/packages/SystemUI/src/com/android/systemui/shade/GlanceableHubContainerController.kt @@ -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) { - touchMonitor = - ambientTouchComponentFactory.create(this, HashSet(), TAG).getTouchMonitor().apply { - init() - } - } + 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") } diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/GlanceableHubContainerControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/shade/GlanceableHubContainerControllerTest.kt index b4a0f23be9b1..859f84edda39 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/GlanceableHubContainerControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/GlanceableHubContainerControllerTest.kt @@ -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> { |