Merge pull request #6469 from vector-im/feature/bma/fix_crash_on_DefaultBackgroundDetectionObserver

Fix ConcurrentModificationException on BackgroundDetectionObserver
This commit is contained in:
Adam Brown 2022-07-07 10:58:26 +01:00 committed by GitHub
commit 4126e6418b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

1
changelog.d/6469.bugfix Normal file
View file

@ -0,0 +1 @@
Fix ConcurrentModificationException on BackgroundDetectionObserver

View file

@ -19,6 +19,7 @@ package org.matrix.android.sdk.internal.util
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import timber.log.Timber
import java.util.concurrent.CopyOnWriteArraySet
internal interface BackgroundDetectionObserver : DefaultLifecycleObserver {
val isInBackground: Boolean
@ -37,7 +38,7 @@ internal class DefaultBackgroundDetectionObserver : BackgroundDetectionObserver
override var isInBackground: Boolean = true
private set
private val listeners = LinkedHashSet<BackgroundDetectionObserver.Listener>()
private val listeners = CopyOnWriteArraySet<BackgroundDetectionObserver.Listener>()
override fun register(listener: BackgroundDetectionObserver.Listener) {
listeners.add(listener)