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

Commit 1632053e authored by Matt Pietal's avatar Matt Pietal Committed by Android (Google) Code Review
Browse files

Merge "Protect callbacks from concurrent modification" into main

parents 5fbdbc1c a86fe5b7
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -31,15 +31,17 @@ class DozeTransitionListener @Inject constructor() :
    override fun transitionTo(oldState: DozeMachine.State, newState: DozeMachine.State) {
        this.oldState = oldState
        this.newState = newState
        callbacks.forEach { it.onDozeTransition(oldState, newState) }

        val cbs = synchronized(this) { callbacks.toSet() }
        cbs.forEach { it.onDozeTransition(oldState, newState) }
    }

    override fun addCallback(callback: DozeTransitionCallback) {
        callbacks.add(callback)
        synchronized(this) { callbacks.add(callback) }
    }

    override fun removeCallback(callback: DozeTransitionCallback) {
        callbacks.remove(callback)
        synchronized(this) { callbacks.remove(callback) }
    }
}