From af654b8c40ec96c8d6f415a407ca47e0a884e235 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Mon, 14 Aug 2023 09:44:56 +0300 Subject: [PATCH] Remove WorkManager bug workaround --- .../kotlin/org/koitharu/kotatsu/KotatsuApp.kt | 2 - .../core/util/WorkServiceStopHelper.kt | 48 ------------------- 2 files changed, 50 deletions(-) delete mode 100644 app/src/main/kotlin/org/koitharu/kotatsu/core/util/WorkServiceStopHelper.kt diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/KotatsuApp.kt b/app/src/main/kotlin/org/koitharu/kotatsu/KotatsuApp.kt index f636b4417..ea5f3f253 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/KotatsuApp.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/KotatsuApp.kt @@ -23,7 +23,6 @@ import org.acra.sender.HttpSender import org.koitharu.kotatsu.core.db.MangaDatabase import org.koitharu.kotatsu.core.os.AppValidator import org.koitharu.kotatsu.core.prefs.AppSettings -import org.koitharu.kotatsu.core.util.WorkServiceStopHelper import org.koitharu.kotatsu.core.util.ext.processLifecycleScope import org.koitharu.kotatsu.local.data.LocalMangaRepository import org.koitharu.kotatsu.local.data.PagesCache @@ -73,7 +72,6 @@ class KotatsuApp : Application(), Configuration.Provider { setupDatabaseObservers() } workScheduleManager.init() - WorkServiceStopHelper(workManagerProvider).setup() } override fun attachBaseContext(base: Context?) { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/WorkServiceStopHelper.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/WorkServiceStopHelper.kt deleted file mode 100644 index 6d5b5344c..000000000 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/WorkServiceStopHelper.kt +++ /dev/null @@ -1,48 +0,0 @@ -package org.koitharu.kotatsu.core.util - -import android.annotation.SuppressLint -import androidx.lifecycle.asFlow -import androidx.work.WorkInfo -import androidx.work.WorkManager -import androidx.work.WorkQuery -import androidx.work.impl.foreground.SystemForegroundService -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.delay -import kotlinx.coroutines.flow.collectLatest -import kotlinx.coroutines.flow.distinctUntilChanged -import kotlinx.coroutines.flow.map -import kotlinx.coroutines.launch -import org.koitharu.kotatsu.core.util.ext.processLifecycleScope -import javax.inject.Provider - -/** - * Workaround for issue - * https://issuetracker.google.com/issues/270245927 - * https://issuetracker.google.com/issues/280504155 - */ -class WorkServiceStopHelper( - private val workManagerProvider: Provider, -) { - - fun setup() { - processLifecycleScope.launch(Dispatchers.Default) { - workManagerProvider.get() - .getWorkInfosLiveData(WorkQuery.fromStates(WorkInfo.State.RUNNING)) - .asFlow() - .map { it.isEmpty() } - .distinctUntilChanged() - .collectLatest { - if (it) { - delay(1_000) - stopWorkerService() - } - } - } - } - - @SuppressLint("RestrictedApi") - private fun stopWorkerService() { - SystemForegroundService.getInstance()?.stop() - } -} -