Don't mess with backup system settings as they can't be used to reliably prevent automatic updates anyway

This commit is contained in:
Torsten Grote 2020-10-21 10:44:05 -03:00
parent e2f0d19f77
commit 82048f2754
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF
2 changed files with 13 additions and 24 deletions

View file

@ -2,36 +2,26 @@ package com.stevesoltys.seedvault.settings
import android.content.ContentResolver import android.content.ContentResolver
import android.provider.Settings import android.provider.Settings
import java.util.concurrent.TimeUnit.DAYS
private val SETTING = Settings.Secure.BACKUP_MANAGER_CONSTANTS 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 { object BackupManagerSettings {
/** /**
* This clears the backup settings, so that default values will be used. * 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) { fun resetDefaults(resolver: ContentResolver) {
// setting this to null will cause the BackupManagerConstants to use default values if (Settings.Secure.getString(resolver, SETTING) != null) {
setSettingValue(resolver, null) // setting this to null will cause the BackupManagerConstants to use default values
} Settings.Secure.putString(resolver, SETTING, 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)
} }
} }

View file

@ -109,11 +109,10 @@ internal abstract class StorageViewModel(
val wasSaved = saveUsbDevice() val wasSaved = saveUsbDevice()
// reset stored flash drive, if we did not update it // reset stored flash drive, if we did not update it
if (!wasSaved) settingsManager.setFlashDrive(null) if (!wasSaved) settingsManager.setFlashDrive(null)
BackupManagerSettings.disableAutomaticBackups(app.contentResolver)
} else { } else {
settingsManager.setFlashDrive(null) settingsManager.setFlashDrive(null)
BackupManagerSettings.enableAutomaticBackups(app.contentResolver)
} }
BackupManagerSettings.resetDefaults(app.contentResolver)
Log.d(TAG, "New storage location saved: $uri") Log.d(TAG, "New storage location saved: $uri")