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
1 changed files with 8 additions and 1 deletions

View File

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