Remove background app update check

We already check in the foreground. If the app isn't being foregrounded at all, then there isn't much
point in checking for an update.
This commit is contained in:
arkon 2023-02-12 22:44:39 -05:00
parent 6348cbaeb7
commit 42954609b9
4 changed files with 8 additions and 86 deletions

View File

@ -22,7 +22,7 @@ android {
defaultConfig { defaultConfig {
applicationId = "eu.kanade.tachiyomi" applicationId = "eu.kanade.tachiyomi"
versionCode = 96 versionCode = 97
versionName = "0.14.4" versionName = "0.14.4"
buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"") buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"")

View File

@ -1,9 +1,9 @@
package eu.kanade.tachiyomi package eu.kanade.tachiyomi
import android.content.Context import android.content.Context
import android.os.Build
import androidx.core.content.edit import androidx.core.content.edit
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import androidx.work.WorkManager
import eu.kanade.domain.backup.service.BackupPreferences import eu.kanade.domain.backup.service.BackupPreferences
import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.base.BasePreferences
import eu.kanade.domain.library.service.LibraryPreferences import eu.kanade.domain.library.service.LibraryPreferences
@ -15,7 +15,6 @@ import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
import eu.kanade.tachiyomi.data.preference.MANGA_NON_COMPLETED import eu.kanade.tachiyomi.data.preference.MANGA_NON_COMPLETED
import eu.kanade.tachiyomi.data.preference.PreferenceValues import eu.kanade.tachiyomi.data.preference.PreferenceValues
import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.data.updater.AppUpdateJob
import eu.kanade.tachiyomi.extension.ExtensionUpdateJob import eu.kanade.tachiyomi.extension.ExtensionUpdateJob
import eu.kanade.tachiyomi.network.NetworkPreferences import eu.kanade.tachiyomi.network.NetworkPreferences
import eu.kanade.tachiyomi.network.PREF_DOH_CLOUDFLARE import eu.kanade.tachiyomi.network.PREF_DOH_CLOUDFLARE
@ -56,9 +55,6 @@ object Migrations {
lastVersionCode.set(BuildConfig.VERSION_CODE) lastVersionCode.set(BuildConfig.VERSION_CODE)
// Always set up background tasks to ensure they're running // Always set up background tasks to ensure they're running
if (BuildConfig.INCLUDE_UPDATER) {
AppUpdateJob.setupTask(context)
}
ExtensionUpdateJob.setupTask(context) ExtensionUpdateJob.setupTask(context)
LibraryUpdateJob.setupTask(context) LibraryUpdateJob.setupTask(context)
BackupCreatorJob.setupTask(context) BackupCreatorJob.setupTask(context)
@ -72,9 +68,6 @@ object Migrations {
if (oldVersion < 14) { if (oldVersion < 14) {
// Restore jobs after upgrading to Evernote's job scheduler. // Restore jobs after upgrading to Evernote's job scheduler.
if (BuildConfig.INCLUDE_UPDATER) {
AppUpdateJob.setupTask(context)
}
LibraryUpdateJob.setupTask(context) LibraryUpdateJob.setupTask(context)
} }
if (oldVersion < 15) { if (oldVersion < 15) {
@ -105,9 +98,6 @@ object Migrations {
} }
if (oldVersion < 43) { if (oldVersion < 43) {
// Restore jobs after migrating from Evernote's job scheduler to WorkManager. // Restore jobs after migrating from Evernote's job scheduler to WorkManager.
if (BuildConfig.INCLUDE_UPDATER) {
AppUpdateJob.setupTask(context)
}
LibraryUpdateJob.setupTask(context) LibraryUpdateJob.setupTask(context)
BackupCreatorJob.setupTask(context) BackupCreatorJob.setupTask(context)
@ -172,18 +162,8 @@ object Migrations {
putInt("pref_rotation_type_key", 1) putInt("pref_rotation_type_key", 1)
} }
} }
// Disable update check for Android 5.x users
if (BuildConfig.INCLUDE_UPDATER && Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
AppUpdateJob.cancelTask(context)
}
} }
if (oldVersion < 60) { if (oldVersion < 60) {
// Re-enable update check that was previously accidentally disabled for M
if (BuildConfig.INCLUDE_UPDATER && Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
AppUpdateJob.setupTask(context)
}
// Migrate Rotation and Viewer values to default values for viewer_flags // Migrate Rotation and Viewer values to default values for viewer_flags
val newOrientation = when (prefs.getInt("pref_rotation_type_key", 1)) { val newOrientation = when (prefs.getInt("pref_rotation_type_key", 1)) {
1 -> OrientationType.FREE.flagValue 1 -> OrientationType.FREE.flagValue
@ -352,6 +332,9 @@ object Migrations {
LibraryUpdateJob.cancelAllWorks(context) LibraryUpdateJob.cancelAllWorks(context)
LibraryUpdateJob.setupTask(context) LibraryUpdateJob.setupTask(context)
} }
if (oldVersion < 97) {
WorkManager.getInstance(context).cancelAllWorkByTag("UpdateChecker")
}
return true return true
} }

View File

@ -12,7 +12,7 @@ import tachiyomi.core.preference.PreferenceStore
import tachiyomi.core.util.lang.withIOContext import tachiyomi.core.util.lang.withIOContext
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import java.util.Date import java.util.Date
import java.util.concurrent.TimeUnit import kotlin.time.Duration.Companion.days
class AppUpdateChecker { class AppUpdateChecker {
@ -23,8 +23,8 @@ class AppUpdateChecker {
} }
suspend fun checkForUpdate(context: Context, isUserPrompt: Boolean = false): AppUpdateResult { suspend fun checkForUpdate(context: Context, isUserPrompt: Boolean = false): AppUpdateResult {
// Limit checks to once a day at most // Limit checks to once every 3 days at most
if (isUserPrompt.not() && Date().time < lastAppCheck.get() + TimeUnit.DAYS.toMillis(1)) { if (isUserPrompt.not() && Date().time < lastAppCheck.get() + 3.days.inWholeMilliseconds) {
return AppUpdateResult.NoNewUpdate return AppUpdateResult.NoNewUpdate
} }

View File

@ -1,61 +0,0 @@
package eu.kanade.tachiyomi.data.updater
import android.content.Context
import androidx.work.Constraints
import androidx.work.CoroutineWorker
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.NetworkType
import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager
import androidx.work.WorkerParameters
import eu.kanade.tachiyomi.BuildConfig
import kotlinx.coroutines.coroutineScope
import logcat.LogPriority
import tachiyomi.core.util.system.logcat
import java.util.concurrent.TimeUnit
class AppUpdateJob(private val context: Context, workerParams: WorkerParameters) :
CoroutineWorker(context, workerParams) {
override suspend fun doWork() = coroutineScope {
try {
AppUpdateChecker().checkForUpdate(context)
Result.success()
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
Result.failure()
}
}
companion object {
private const val TAG = "UpdateChecker"
fun setupTask(context: Context) {
// Never check for updates in builds that don't include the updater
if (!BuildConfig.INCLUDE_UPDATER) {
cancelTask(context)
return
}
val constraints = Constraints(
requiredNetworkType = NetworkType.CONNECTED,
)
val request = PeriodicWorkRequestBuilder<AppUpdateJob>(
7,
TimeUnit.DAYS,
3,
TimeUnit.HOURS,
)
.addTag(TAG)
.setConstraints(constraints)
.build()
WorkManager.getInstance(context).enqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.UPDATE, request)
}
fun cancelTask(context: Context) {
WorkManager.getInstance(context).cancelAllWorkByTag(TAG)
}
}
}