Address repeated initializatin of WorkManagerImpl in #5887

This commit is contained in:
Michael Kaye 2022-05-16 15:54:28 +01:00
parent 4ced6ca179
commit 8950aa38ea

View File

@ -22,6 +22,8 @@ import android.os.Looper
import androidx.lifecycle.ProcessLifecycleOwner
import androidx.work.Configuration
import androidx.work.WorkManager
import androidx.work.impl.WorkManagerImpl
import androidx.work.impl.utils.taskexecutor.WorkManagerTaskExecutor
import com.zhuinden.monarchy.Monarchy
import org.matrix.android.sdk.BuildConfig
import org.matrix.android.sdk.api.MatrixConfiguration
@ -66,7 +68,12 @@ internal class TestMatrix(context: Context, matrixConfiguration: MatrixConfigura
.setExecutor(Executors.newCachedThreadPool())
.setWorkerFactory(matrixWorkerFactory)
.build()
WorkManager.initialize(appContext, configuration)
val delegate = WorkManagerImpl(
context,
configuration,
WorkManagerTaskExecutor(configuration.taskExecutor)
)
WorkManagerImpl.setDelegate(delegate)
uiHandler.post {
ProcessLifecycleOwner.get().lifecycle.addObserver(backgroundDetectionObserver)
}