Don't mess with backup system settings as they can't be used to reliably prevent automatic updates anyway
This commit is contained in:
parent
e2f0d19f77
commit
82048f2754
2 changed files with 13 additions and 24 deletions
|
@ -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) {
|
||||
fun resetDefaults(resolver: ContentResolver) {
|
||||
if (Settings.Secure.getString(resolver, SETTING) != null) {
|
||||
// setting this to null will cause the BackupManagerConstants to use default values
|
||||
setSettingValue(resolver, null)
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
Loading…
Reference in a new issue