From 12c9cc00a1fee5de86ddad31d47f42dd669e1af3 Mon Sep 17 00:00:00 2001 From: rhenwinch Date: Sat, 9 Nov 2024 00:26:13 +0800 Subject: [PATCH] fix(provider): attempt to fix `ConcurrentModificationException` on updater Former-commit-id: ab5187c970b27f35cf8e7fe4fb01824f445032d6 --- .../kotlin/com/flixclusive/data/provider/ProviderManager.kt | 4 ++++ .../com/flixclusive/domain/updater/ProviderUpdaterUseCase.kt | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/data/provider/src/main/kotlin/com/flixclusive/data/provider/ProviderManager.kt b/data/provider/src/main/kotlin/com/flixclusive/data/provider/ProviderManager.kt index 43c73eaa..58b3ce01 100644 --- a/data/provider/src/main/kotlin/com/flixclusive/data/provider/ProviderManager.kt +++ b/data/provider/src/main/kotlin/com/flixclusive/data/provider/ProviderManager.kt @@ -31,6 +31,7 @@ import com.flixclusive.provider.Provider import com.flixclusive.provider.settings.ProviderSettings import dagger.hilt.android.qualifiers.ApplicationContext import dalvik.system.PathClassLoader +import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch import okhttp3.OkHttpClient @@ -58,6 +59,7 @@ class ProviderManager @Inject constructor( private val classLoaders: MutableMap = Collections.synchronizedMap(HashMap()) private var notificationChannelHasBeenInitialized = false + val initialization = CompletableDeferred() /** * An observable map of provider data @@ -117,6 +119,8 @@ class ProviderManager @Inject constructor( notificationChannelHasBeenInitialized = true } + + initialization.complete(Unit) } } diff --git a/domain/updater/src/main/kotlin/com/flixclusive/domain/updater/ProviderUpdaterUseCase.kt b/domain/updater/src/main/kotlin/com/flixclusive/domain/updater/ProviderUpdaterUseCase.kt index 0b43f557..b3de3a2a 100644 --- a/domain/updater/src/main/kotlin/com/flixclusive/domain/updater/ProviderUpdaterUseCase.kt +++ b/domain/updater/src/main/kotlin/com/flixclusive/domain/updater/ProviderUpdaterUseCase.kt @@ -43,6 +43,10 @@ class ProviderUpdaterUseCase @Inject constructor( private var notificationChannelHasBeenInitialized = false suspend fun checkForUpdates(notify: Boolean) { + // Wait for providers to be initialized + // To avoid ConcurrentModificationException + providerManager.initialization.await() + val appSettingsProvider = appSettingsManager.providerSettings.data.first() outdatedProviders.clear()