From 82048f27541186c034aaf5f5bea7f203258be26a Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Wed, 21 Oct 2020 10:44:05 -0300 Subject: [PATCH] Don't mess with backup system settings as they can't be used to reliably prevent automatic updates anyway --- .../settings/BackupManagerSettings.kt | 34 +++++++------------ .../seedvault/ui/storage/StorageViewModel.kt | 3 +- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/stevesoltys/seedvault/settings/BackupManagerSettings.kt b/app/src/main/java/com/stevesoltys/seedvault/settings/BackupManagerSettings.kt index af95d992..622693c1 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/settings/BackupManagerSettings.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/settings/BackupManagerSettings.kt @@ -2,36 +2,26 @@ package com.stevesoltys.seedvault.settings import android.content.ContentResolver import android.provider.Settings -import java.util.concurrent.TimeUnit.DAYS private val SETTING = Settings.Secure.BACKUP_MANAGER_CONSTANTS -private const val DELIMITER = ',' - -private const val KEY_VALUE_BACKUP_INTERVAL_MILLISECONDS = "key_value_backup_interval_milliseconds" -private const val FULL_BACKUP_INTERVAL_MILLISECONDS = "full_backup_interval_milliseconds" object BackupManagerSettings { /** * This clears the backup settings, so that default values will be used. + * + * Before end of 2020 (Android 11) we changed the settings in an attempt + * to prevent automatic backups when flash drives are not plugged in. + * This turned out to not work reliably, so reset to defaults again here. + * + * We can remove this code after the last users can be expected + * to have changed storage at least once with this code deployed. */ - fun enableAutomaticBackups(resolver: ContentResolver) { - // setting this to null will cause the BackupManagerConstants to use default values - setSettingValue(resolver, null) - } - - /** - * This sets the backup intervals to a longer than default value. Currently 30 days - */ - fun disableAutomaticBackups(resolver: ContentResolver) { - val value = DAYS.toMillis(30) - val kv = "$KEY_VALUE_BACKUP_INTERVAL_MILLISECONDS=$value" - val full = "$FULL_BACKUP_INTERVAL_MILLISECONDS=$value" - setSettingValue(resolver, "$kv$DELIMITER$full") - } - - private fun setSettingValue(resolver: ContentResolver, value: String?) { - Settings.Secure.putString(resolver, SETTING, value) + fun resetDefaults(resolver: ContentResolver) { + if (Settings.Secure.getString(resolver, SETTING) != null) { + // setting this to null will cause the BackupManagerConstants to use default values + Settings.Secure.putString(resolver, SETTING, null) + } } } diff --git a/app/src/main/java/com/stevesoltys/seedvault/ui/storage/StorageViewModel.kt b/app/src/main/java/com/stevesoltys/seedvault/ui/storage/StorageViewModel.kt index e5e48b01..0f12b0f5 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/ui/storage/StorageViewModel.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/ui/storage/StorageViewModel.kt @@ -109,11 +109,10 @@ internal abstract class StorageViewModel( val wasSaved = saveUsbDevice() // reset stored flash drive, if we did not update it if (!wasSaved) settingsManager.setFlashDrive(null) - BackupManagerSettings.disableAutomaticBackups(app.contentResolver) } else { settingsManager.setFlashDrive(null) - BackupManagerSettings.enableAutomaticBackups(app.contentResolver) } + BackupManagerSettings.resetDefaults(app.contentResolver) Log.d(TAG, "New storage location saved: $uri")