From 42954609b94e13d8fadbf1f3769e9f32fa9e8447 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 12 Feb 2023 22:44:39 -0500 Subject: [PATCH] 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. --- app/build.gradle.kts | 2 +- .../java/eu/kanade/tachiyomi/Migrations.kt | 25 ++------ .../data/updater/AppUpdateChecker.kt | 6 +- .../tachiyomi/data/updater/AppUpdateJob.kt | 61 ------------------- 4 files changed, 8 insertions(+), 86 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateJob.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 562ee34cc5..4b5e2c2636 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -22,7 +22,7 @@ android { defaultConfig { applicationId = "eu.kanade.tachiyomi" - versionCode = 96 + versionCode = 97 versionName = "0.14.4" buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"") diff --git a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt index df35b51e53..21d5c5b73f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt @@ -1,9 +1,9 @@ package eu.kanade.tachiyomi import android.content.Context -import android.os.Build import androidx.core.content.edit import androidx.preference.PreferenceManager +import androidx.work.WorkManager import eu.kanade.domain.backup.service.BackupPreferences import eu.kanade.domain.base.BasePreferences 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.PreferenceValues import eu.kanade.tachiyomi.data.track.TrackManager -import eu.kanade.tachiyomi.data.updater.AppUpdateJob import eu.kanade.tachiyomi.extension.ExtensionUpdateJob import eu.kanade.tachiyomi.network.NetworkPreferences import eu.kanade.tachiyomi.network.PREF_DOH_CLOUDFLARE @@ -56,9 +55,6 @@ object Migrations { lastVersionCode.set(BuildConfig.VERSION_CODE) // Always set up background tasks to ensure they're running - if (BuildConfig.INCLUDE_UPDATER) { - AppUpdateJob.setupTask(context) - } ExtensionUpdateJob.setupTask(context) LibraryUpdateJob.setupTask(context) BackupCreatorJob.setupTask(context) @@ -72,9 +68,6 @@ object Migrations { if (oldVersion < 14) { // Restore jobs after upgrading to Evernote's job scheduler. - if (BuildConfig.INCLUDE_UPDATER) { - AppUpdateJob.setupTask(context) - } LibraryUpdateJob.setupTask(context) } if (oldVersion < 15) { @@ -105,9 +98,6 @@ object Migrations { } if (oldVersion < 43) { // Restore jobs after migrating from Evernote's job scheduler to WorkManager. - if (BuildConfig.INCLUDE_UPDATER) { - AppUpdateJob.setupTask(context) - } LibraryUpdateJob.setupTask(context) BackupCreatorJob.setupTask(context) @@ -172,18 +162,8 @@ object Migrations { 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) { - // 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 val newOrientation = when (prefs.getInt("pref_rotation_type_key", 1)) { 1 -> OrientationType.FREE.flagValue @@ -352,6 +332,9 @@ object Migrations { LibraryUpdateJob.cancelAllWorks(context) LibraryUpdateJob.setupTask(context) } + if (oldVersion < 97) { + WorkManager.getInstance(context).cancelAllWorkByTag("UpdateChecker") + } return true } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt index 0cd1576214..c853490a0d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt @@ -12,7 +12,7 @@ import tachiyomi.core.preference.PreferenceStore import tachiyomi.core.util.lang.withIOContext import uy.kohesive.injekt.injectLazy import java.util.Date -import java.util.concurrent.TimeUnit +import kotlin.time.Duration.Companion.days class AppUpdateChecker { @@ -23,8 +23,8 @@ class AppUpdateChecker { } suspend fun checkForUpdate(context: Context, isUserPrompt: Boolean = false): AppUpdateResult { - // Limit checks to once a day at most - if (isUserPrompt.not() && Date().time < lastAppCheck.get() + TimeUnit.DAYS.toMillis(1)) { + // Limit checks to once every 3 days at most + if (isUserPrompt.not() && Date().time < lastAppCheck.get() + 3.days.inWholeMilliseconds) { return AppUpdateResult.NoNewUpdate } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateJob.kt deleted file mode 100644 index 8145acf3c8..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateJob.kt +++ /dev/null @@ -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( - 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) - } - } -}