Set background job expedited policies

This commit is contained in:
arkon 2021-06-02 22:58:03 -04:00
parent 2b8347f899
commit c69420373a
4 changed files with 16 additions and 0 deletions

View File

@ -3,6 +3,8 @@ package eu.kanade.tachiyomi.data.backup
import android.content.Context import android.content.Context
import androidx.core.net.toUri import androidx.core.net.toUri
import androidx.work.ExistingPeriodicWorkPolicy import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.ExperimentalExpeditedWork
import androidx.work.OutOfQuotaPolicy
import androidx.work.PeriodicWorkRequestBuilder import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager import androidx.work.WorkManager
import androidx.work.Worker import androidx.work.Worker
@ -31,6 +33,7 @@ class BackupCreatorJob(private val context: Context, workerParams: WorkerParamet
companion object { companion object {
private const val TAG = "BackupCreator" private const val TAG = "BackupCreator"
@ExperimentalExpeditedWork
fun setupTask(context: Context, prefInterval: Int? = null) { fun setupTask(context: Context, prefInterval: Int? = null) {
val preferences = Injekt.get<PreferencesHelper>() val preferences = Injekt.get<PreferencesHelper>()
val interval = prefInterval ?: preferences.backupInterval().get() val interval = prefInterval ?: preferences.backupInterval().get()
@ -41,6 +44,7 @@ class BackupCreatorJob(private val context: Context, workerParams: WorkerParamet
10, 10,
TimeUnit.MINUTES TimeUnit.MINUTES
) )
.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST)
.addTag(TAG) .addTag(TAG)
.build() .build()

View File

@ -3,7 +3,9 @@ package eu.kanade.tachiyomi.data.library
import android.content.Context import android.content.Context
import androidx.work.Constraints import androidx.work.Constraints
import androidx.work.ExistingPeriodicWorkPolicy import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.ExperimentalExpeditedWork
import androidx.work.NetworkType import androidx.work.NetworkType
import androidx.work.OutOfQuotaPolicy
import androidx.work.PeriodicWorkRequestBuilder import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager import androidx.work.WorkManager
import androidx.work.Worker import androidx.work.Worker
@ -29,6 +31,7 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
companion object { companion object {
private const val TAG = "LibraryUpdate" private const val TAG = "LibraryUpdate"
@ExperimentalExpeditedWork
fun setupTask(context: Context, prefInterval: Int? = null) { fun setupTask(context: Context, prefInterval: Int? = null) {
val preferences = Injekt.get<PreferencesHelper>() val preferences = Injekt.get<PreferencesHelper>()
val interval = prefInterval ?: preferences.libraryUpdateInterval().get() val interval = prefInterval ?: preferences.libraryUpdateInterval().get()
@ -52,6 +55,7 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
10, 10,
TimeUnit.MINUTES TimeUnit.MINUTES
) )
.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST)
.addTag(TAG) .addTag(TAG)
.setConstraints(constraints) .setConstraints(constraints)
.build() .build()

View File

@ -3,7 +3,9 @@ package eu.kanade.tachiyomi.data.updater
import android.content.Context import android.content.Context
import androidx.work.Constraints import androidx.work.Constraints
import androidx.work.ExistingPeriodicWorkPolicy import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.ExperimentalExpeditedWork
import androidx.work.NetworkType import androidx.work.NetworkType
import androidx.work.OutOfQuotaPolicy
import androidx.work.PeriodicWorkRequestBuilder import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager import androidx.work.WorkManager
import androidx.work.Worker import androidx.work.Worker
@ -30,6 +32,7 @@ class UpdaterJob(private val context: Context, workerParams: WorkerParameters) :
companion object { companion object {
private const val TAG = "UpdateChecker" private const val TAG = "UpdateChecker"
@ExperimentalExpeditedWork
fun setupTask(context: Context) { fun setupTask(context: Context) {
val constraints = Constraints.Builder() val constraints = Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED) .setRequiredNetworkType(NetworkType.CONNECTED)
@ -41,6 +44,7 @@ class UpdaterJob(private val context: Context, workerParams: WorkerParameters) :
3, 3,
TimeUnit.HOURS TimeUnit.HOURS
) )
.setExpedited(OutOfQuotaPolicy.DROP_WORK_REQUEST)
.addTag(TAG) .addTag(TAG)
.setConstraints(constraints) .setConstraints(constraints)
.build() .build()

View File

@ -6,7 +6,9 @@ import androidx.core.app.NotificationManagerCompat
import androidx.work.Constraints import androidx.work.Constraints
import androidx.work.CoroutineWorker import androidx.work.CoroutineWorker
import androidx.work.ExistingPeriodicWorkPolicy import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.ExperimentalExpeditedWork
import androidx.work.NetworkType import androidx.work.NetworkType
import androidx.work.OutOfQuotaPolicy
import androidx.work.PeriodicWorkRequestBuilder import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager import androidx.work.WorkManager
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
@ -64,6 +66,7 @@ class ExtensionUpdateJob(private val context: Context, workerParams: WorkerParam
companion object { companion object {
private const val TAG = "ExtensionUpdate" private const val TAG = "ExtensionUpdate"
@ExperimentalExpeditedWork
fun setupTask(context: Context, forceAutoUpdateJob: Boolean? = null) { fun setupTask(context: Context, forceAutoUpdateJob: Boolean? = null) {
val preferences = Injekt.get<PreferencesHelper>() val preferences = Injekt.get<PreferencesHelper>()
val autoUpdateJob = forceAutoUpdateJob ?: preferences.automaticExtUpdates().get() val autoUpdateJob = forceAutoUpdateJob ?: preferences.automaticExtUpdates().get()
@ -78,6 +81,7 @@ class ExtensionUpdateJob(private val context: Context, workerParams: WorkerParam
1, 1,
TimeUnit.HOURS TimeUnit.HOURS
) )
.setExpedited(OutOfQuotaPolicy.DROP_WORK_REQUEST)
.addTag(TAG) .addTag(TAG)
.setConstraints(constraints) .setConstraints(constraints)
.build() .build()