Add migration to cap minimum sync frequency to 15m

This change ensures that upgrading from older version of K-9 would not
set the frequency to unsupported value (below 15 minutes).
This commit is contained in:
Wiktor Kwapisiewicz 2018-12-18 15:23:24 +01:00
parent 8468ea5f77
commit 7d3ba67380
No known key found for this signature in database
GPG key ID: B97A1EE09DB417EC
3 changed files with 39 additions and 1 deletions

View file

@ -21,7 +21,7 @@ import timber.log.Timber;
public class K9StoragePersister implements StoragePersister {
private static final int DB_VERSION = 4;
private static final int DB_VERSION = 5;
private static final String DB_NAME = "preferences_storage";
private final Context context;

View file

@ -0,0 +1,37 @@
package com.fsck.k9.preferences.migrations
import android.database.sqlite.SQLiteDatabase
/**
* Rewrite frequencies lower than LOWEST_FREQUENCY_SUPPORTED
*/
class StorageMigrationTo5(
private val db: SQLiteDatabase,
private val migrationsHelper: StorageMigrationsHelper
) {
fun fixMailCheckFrequencies() {
val accountUuidsListValue = migrationsHelper.readValue(db, "accountUuids")
if (accountUuidsListValue == null || accountUuidsListValue.isEmpty()) {
return
}
val accountUuids = accountUuidsListValue.split(",")
for (accountUuid in accountUuids) {
fixFrequencyForAccount(accountUuid)
}
}
private fun fixFrequencyForAccount(accountUuid: String) {
val key = "$accountUuid.automaticCheckIntervalMinutes"
val frequencyValue = migrationsHelper.readValue(db, key)?.toIntOrNull()
if (frequencyValue != null && frequencyValue > -1 && frequencyValue < LOWEST_FREQUENCY_SUPPORTED) {
migrationsHelper.writeValue(db, key, LOWEST_FREQUENCY_SUPPORTED.toString())
}
}
companion object {
// see: https://github.com/evernote/android-job/wiki/FAQ#why-cant-an-interval-be-smaller-than-15-minutes-for-periodic-jobs
private const val LOWEST_FREQUENCY_SUPPORTED = 15
}
}

View file

@ -10,5 +10,6 @@ internal object StorageMigrations {
if (oldVersion <= 1) StorageMigrationTo2.urlEncodeUserNameAndPassword(db, migrationsHelper)
if (oldVersion <= 2) StorageMigrationTo3(db, migrationsHelper).rewriteFolderNone()
if (oldVersion <= 3) StorageMigrationTo4(db, migrationsHelper).insertSpecialFolderSelectionValues()
if (oldVersion <= 4) StorageMigrationTo5(db, migrationsHelper).fixMailCheckFrequencies()
}
}