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

Commit 513e18c3 authored by William Xiao's avatar William Xiao
Browse files

Fix ScrimControllerTest memory leak

Change I577e352eda47af4a03ffdff2aaa788f6f853238c started attaching the
scrim view to collect flows for testing, which didn't happen before.
However the view was never detached so the flows never stopped
collecting and thus each test class instance was never GCed.

This change detaches the view to stop flow collection. See bug for
before and after hprofs. Also fixes the same issue in
GlanceableHubContainerControllerTest.

Bug: 322191262
Fixed: 322191262
Test: atest ScrimControllerTest GlanceableHubContainerControllerTest
Flag: N/A
Change-Id: I155c38f72d33db82bdd185ba366b11711a01236c
parent 5a062374
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import org.junit.After
import org.junit.Assert.assertThrows
import org.junit.Assume.assumeTrue
import org.junit.Before
@@ -118,6 +119,11 @@ class GlanceableHubContainerControllerTest : SysuiTestCase() {
        initAndAttachContainerView()
    }

    @After
    fun tearDown() {
        ViewUtils.detachView(parentView)
    }

    @Test
    fun isEnabled_communalEnabled_returnsTrue() {
        communalRepository.setIsCommunalEnabled(true)
+2 −0
Original line number Diff line number Diff line
@@ -315,6 +315,8 @@ public class ScrimControllerTest extends SysuiTestCase {

    @After
    public void tearDown() {
        // Detaching view stops flow collection and prevents memory leak.
        ViewUtils.detachView(mScrimBehind);
        finishAnimationsImmediately();
        Arrays.stream(ScrimState.values()).forEach((scrim) -> {
            scrim.setAodFrontScrimAlpha(0f);