Skip to content

Commit

Permalink
Don't mess with backup system settings as they can't be used to relia…
Browse files Browse the repository at this point in the history
…bly prevent automatic updates anyway
  • Loading branch information
grote committed Oct 23, 2020
1 parent e2f0d19 commit 82048f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 82048f2

Please sign in to comment.