From 26f23e95feaee86539bceb20622b1b0db05d73fb Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Thu, 19 Sep 2019 16:29:53 -0300 Subject: [PATCH] Disable automatic backups when a removable USB flash drive is used as storage location. The backup backoff time is not reliable for this as the system still attempts to backup the magic @pm@ package without checking for the backoff value. --- app/src/main/AndroidManifest.xml | 5 ++++ .../backup/restore/RestoreProgressFragment.kt | 2 +- .../backup/settings/BackupManagerSettings.kt | 30 +++++++++++++++++++ .../backup/settings/SettingsManager.kt | 14 ++++----- .../transport/backup/BackupCoordinator.kt | 2 +- .../backup/ui/storage/StorageRootFetcher.kt | 11 ++++--- .../backup/ui/storage/StorageViewModel.kt | 13 +++++--- permissions_com.stevesoltys.backup.xml | 1 + 8 files changed, 59 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/com/stevesoltys/backup/settings/BackupManagerSettings.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index fdded5ea..14914e4d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -19,6 +19,11 @@ android:name="android.permission.MANAGE_USB" tools:ignore="ProtectedPermissions" /> + + + ) { for (root in roots) { - if (root.authority == AUTHORITY_STORAGE && root.supportsEject) return + if (root.authority == AUTHORITY_STORAGE && root.isUsb) return } val root = StorageRoot( authority = AUTHORITY_STORAGE, @@ -147,7 +146,7 @@ internal class StorageRootFetcher(private val context: Context) { title = context.getString(R.string.storage_fake_drive_title), summary = context.getString(R.string.storage_fake_drive_summary), availableBytes = null, - supportsEject = true, + isUsb = true, enabled = false ) roots.add(root) diff --git a/app/src/main/java/com/stevesoltys/backup/ui/storage/StorageViewModel.kt b/app/src/main/java/com/stevesoltys/backup/ui/storage/StorageViewModel.kt index 4f76607c..596c6ffa 100644 --- a/app/src/main/java/com/stevesoltys/backup/ui/storage/StorageViewModel.kt +++ b/app/src/main/java/com/stevesoltys/backup/ui/storage/StorageViewModel.kt @@ -15,6 +15,7 @@ import androidx.lifecycle.MutableLiveData import com.stevesoltys.backup.Backup import com.stevesoltys.backup.R import com.stevesoltys.backup.isMassStorage +import com.stevesoltys.backup.settings.BackupManagerSettings import com.stevesoltys.backup.settings.FlashDrive import com.stevesoltys.backup.settings.Storage import com.stevesoltys.backup.transport.ConfigurableBackupTransportService @@ -45,7 +46,7 @@ internal abstract class StorageViewModel(private val app: Application) : Android internal fun validLocationIsSet(context: Context): Boolean { val settingsManager = (context.applicationContext as Backup).settingsManager val storage = settingsManager.getStorage() ?: return false - if (storage.ejectable) return true + if (storage.isUsb) return true return storage.getDocumentFile(context).isDirectory } } @@ -88,16 +89,20 @@ internal abstract class StorageViewModel(private val app: Application) : Android } else { root.title } - val storage = Storage(uri, name, root.supportsEject) + val storage = Storage(uri, name, root.isUsb) settingsManager.setStorage(storage) // reset time of last backup to "Never" settingsManager.resetBackupTime() - if (storage.ejectable) { + if (storage.isUsb) { 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) } // stop backup service to be sure the old location will get updated @@ -114,7 +119,7 @@ internal abstract class StorageViewModel(private val app: Application) : Android return true } } - Log.w(TAG, "No USB device found for ejectable storage.") + Log.e(TAG, "No USB device found even though we were expecting one.") return false } diff --git a/permissions_com.stevesoltys.backup.xml b/permissions_com.stevesoltys.backup.xml index 34ed8dc9..f0195387 100644 --- a/permissions_com.stevesoltys.backup.xml +++ b/permissions_com.stevesoltys.backup.xml @@ -3,5 +3,6 @@ + \ No newline at end of file