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

Commit 7615f9b2 authored by Luca Zuccarini's avatar Luca Zuccarini Committed by Android (Google) Code Review
Browse files

Merge "Fix concurrent modification issue with lifecycle listeners." into main

parents 7d5db209 73387d2c
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -232,19 +232,21 @@ constructor(
    private val lifecycleListener =
        object : Listener {
            override fun onTransitionAnimationStart() {
                listeners.forEach { it.onTransitionAnimationStart() }
                LinkedHashSet(listeners).forEach { it.onTransitionAnimationStart() }
            }

            override fun onTransitionAnimationEnd() {
                listeners.forEach { it.onTransitionAnimationEnd() }
                LinkedHashSet(listeners).forEach { it.onTransitionAnimationEnd() }
            }

            override fun onTransitionAnimationProgress(linearProgress: Float) {
                listeners.forEach { it.onTransitionAnimationProgress(linearProgress) }
                LinkedHashSet(listeners).forEach {
                     it.onTransitionAnimationProgress(linearProgress)
                }
            }

            override fun onTransitionAnimationCancelled() {
                listeners.forEach { it.onTransitionAnimationCancelled() }
                LinkedHashSet(listeners).forEach { it.onTransitionAnimationCancelled() }
            }
        }

+22 −0
Original line number Diff line number Diff line
@@ -466,6 +466,28 @@ class ActivityTransitionAnimatorTest : SysuiTestCase() {
        assertNull(runner.delegate)
    }

    @Test
    fun concurrentListenerModification_doesNotThrow() {
        // Need a second listener to trigger the concurrent modification.
        activityTransitionAnimator.addListener(object : ActivityTransitionAnimator.Listener {})
        `when`(listener.onTransitionAnimationStart()).thenAnswer {
            activityTransitionAnimator.removeListener(listener)
            listener
        }

        val runner = activityTransitionAnimator.createEphemeralRunner(controller)
        runner.onAnimationStart(
            TRANSIT_NONE,
            arrayOf(fakeWindow()),
            emptyArray(),
            emptyArray(),
            iCallback,
        )

        waitForIdleSync()
        verify(listener).onTransitionAnimationStart()
    }

    private fun controllerFactory(
        cookie: ActivityTransitionAnimator.TransitionCookie =
            mock(ActivityTransitionAnimator.TransitionCookie::class.java),