SelfUpdateWorker: Make update check interval configurable
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import androidx.work.Constraints
|
||||
import androidx.work.CoroutineWorker
|
||||
import androidx.work.ExistingPeriodicWorkPolicy.KEEP
|
||||
import androidx.work.NetworkType
|
||||
import androidx.work.PeriodicWorkRequest
|
||||
import androidx.work.PeriodicWorkRequestBuilder
|
||||
import androidx.work.WorkManager
|
||||
import androidx.work.WorkerParameters
|
||||
@@ -19,6 +20,7 @@ import com.aurora.store.util.CertUtil
|
||||
import com.aurora.store.util.DownloadWorkerUtil
|
||||
import com.aurora.store.util.Preferences
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_SELF_UPDATE
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_UPDATES_CHECK_INTERVAL
|
||||
import com.google.gson.Gson
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedInject
|
||||
@@ -43,7 +45,22 @@ class SelfUpdateWorker @AssistedInject constructor(
|
||||
}
|
||||
|
||||
fun scheduleAutomatedCheck(context: Context) {
|
||||
Log.i(TAG, "Scheduling periodic self-updates!")
|
||||
Log.i(TAG,"Scheduling periodic self-updates!")
|
||||
WorkManager.getInstance(context)
|
||||
.enqueueUniquePeriodicWork(SELF_UPDATE_WORKER, KEEP, buildUpdateWork(context))
|
||||
}
|
||||
|
||||
fun updateAutomatedCheck(context: Context) {
|
||||
Log.i(TAG,"Updating periodic self-updates!")
|
||||
WorkManager.getInstance(context).updateWork(buildUpdateWork(context))
|
||||
}
|
||||
|
||||
private fun buildUpdateWork(context: Context): PeriodicWorkRequest {
|
||||
val updateCheckInterval = Preferences.getInteger(
|
||||
context,
|
||||
PREFERENCE_UPDATES_CHECK_INTERVAL,
|
||||
3
|
||||
).toLong()
|
||||
|
||||
val constraints = Constraints.Builder()
|
||||
.setRequiredNetworkType(NetworkType.UNMETERED)
|
||||
@@ -51,15 +68,12 @@ class SelfUpdateWorker @AssistedInject constructor(
|
||||
|
||||
if (isMAndAbove()) constraints.setRequiresDeviceIdle(true)
|
||||
|
||||
val workRequest = PeriodicWorkRequestBuilder<UpdateWorker>(
|
||||
repeatInterval = 24,
|
||||
return PeriodicWorkRequestBuilder<UpdateWorker>(
|
||||
repeatInterval = updateCheckInterval,
|
||||
repeatIntervalTimeUnit = HOURS,
|
||||
flexTimeInterval = 30,
|
||||
flexTimeIntervalUnit = MINUTES
|
||||
).setConstraints(constraints.build()).build()
|
||||
|
||||
val workManager = WorkManager.getInstance(context)
|
||||
workManager.enqueueUniquePeriodicWork(SELF_UPDATE_WORKER, KEEP, workRequest)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +74,7 @@ class UpdatesPreference : PreferenceFragmentCompat() {
|
||||
findPreference<SeekBarPreference>(PREFERENCE_UPDATES_CHECK_INTERVAL)
|
||||
?.setOnPreferenceChangeListener { _, _ ->
|
||||
UpdateWorker.updateAutomatedCheck(requireContext())
|
||||
SelfUpdateWorker.updateAutomatedCheck(requireContext())
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,7 +376,7 @@
|
||||
<string name="pref_updates_auto_notify">Check & notify for available updates</string>
|
||||
<string name="pref_updates_auto_install">Check & install available updates automatically</string>
|
||||
<string name="pref_updates_check_frequency">Automatic updates frequency</string>
|
||||
<string name="pref_updates_check_frequency_desc">Configure intervals for auto updates, in hour.</string>
|
||||
<string name="pref_updates_check_frequency_desc">Configure intervals for auto and self updates, in hour.</string>
|
||||
<string name="failed_to_fetch_report">Failed to fetch privacy report</string>
|
||||
<string name="access_denied_using_vpn">Access denied! Are you using VPN or Tor?</string>
|
||||
<string name="bad_request">Internal error! Please retry after sometime</string>
|
||||
@@ -405,6 +405,6 @@
|
||||
<string name="device_doze_description">Please, disable battery optimizations to allow background operations.</string>
|
||||
<string name="device_doze_extra">Optionally you can choose to keep the optimizations enabled, but then you won\'t be able to take benefit of background downloads and automated updates, so choice is yours.</string>
|
||||
<string name="pref_self_update_title">Self-updates</string>
|
||||
<string name="pref_self_update_summary">Check and notify if a new stable version of Aurora Store is available</string>
|
||||
<string name="pref_self_update_summary">Check and install if a new stable version of Aurora Store is available</string>
|
||||
<string name="failed_apk_export">Failed to export APKs</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user