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

Commit 79bfab3f authored by Nicolo' Mazzucato's avatar Nicolo' Mazzucato
Browse files

Fix ConcurrentModificationException in RotationChangeProvider

When bgHandler and CallbackHandler were different, ConcurrentModificationException could have happened.

Using a lock here is not ideal, as we would block {un}registration of listeners in the main thread.

Using a CopyOnWriteArrayList will fix the problem with a negligible memory overhead.

Fix: 344626706
Test: RotationChangeProviderTest
Flag: NONE bugfix
Change-Id: Ia2bf884e4f889b19ab85f0b7734509bbcd1f3b96
parent 584f2b26
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import com.android.systemui.unfold.util.CallbackController
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import java.util.concurrent.CopyOnWriteArrayList

/**
 * Allows to subscribe to rotation changes. Updates are provided for the display associated to
@@ -41,7 +42,7 @@ constructor(
    @Assisted private val callbackHandler: Handler,
) : CallbackController<RotationChangeProvider.RotationListener> {

    private val listeners = mutableListOf<RotationListener>()
    private val listeners = CopyOnWriteArrayList<RotationListener>()

    private val displayListener = RotationDisplayListener()
    private var lastRotation: Int? = null