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

Commit e62999e3 authored by Michal Brzezinski's avatar Michal Brzezinski
Browse files

Fix ConcurrentModificationException in FoldableDisplaySwitchTrackingInteractorTest

We're modifying callback list in UnfoldTransitionRepository while FakeUnfoldTransitionProvider is still iterating over them.
This exception is only thrown when running Robolectric tests as Robolectric's ArrayList implementation differs from Android's one.
While Android implementation will just stop iterating, Robolectric will continue and throw exception when trying to get `next()` element.

Solution is to either not modify the list from within callback method or modify it safely and I went for the later with CopyOnWriteArrayList.

Fixes: 412727194
Test: FoldableDisplaySwitchTrackingInteractorTest -  on device and deviceless
Flag: NONE just fixing test
Change-Id: I59558cd6a74a3afbdfaa7b8549bbc7083ae9c87d
parent 64824e20
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
package com.android.systemui.unfold

import com.android.systemui.unfold.UnfoldTransitionProgressProvider.TransitionProgressListener
import java.util.concurrent.CopyOnWriteArrayList

class FakeUnfoldTransitionProvider : UnfoldTransitionProgressProvider, TransitionProgressListener {

    private val listeners = mutableListOf<TransitionProgressListener>()
    // CopyOnWriteArrayList to safely iterate while callbacks are added/removed, see b/412727194
    private val listeners = CopyOnWriteArrayList<TransitionProgressListener>()

    override fun destroy() {
        listeners.clear()