diff --git a/app/src/main/java/com/stevesoltys/seedvault/metadata/MetadataManager.kt b/app/src/main/java/com/stevesoltys/seedvault/metadata/MetadataManager.kt index a1a53065..8964faeb 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/metadata/MetadataManager.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/metadata/MetadataManager.kt @@ -222,8 +222,8 @@ internal class MetadataManager( internal val salt: String @Synchronized get() = metadata.salt - internal val isLegacyFormat: Boolean - @Synchronized get() = metadata.version < VERSION + internal val requiresInit: Boolean + @Synchronized get() = metadata == uninitializedMetadata || metadata.version < VERSION @Synchronized fun getPackageMetadata(packageName: String): PackageMetadata? { diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt index 70f283a4..a7253f2c 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt @@ -136,8 +136,8 @@ internal class BackupCoordinator( TRANSPORT_OK } catch (e: IOException) { Log.e(TAG, "Error initializing device", e) - // Show error notification if we were ready for backups - if (settingsManager.canDoBackupNow()) nm.onBackupError() + // Show error notification if we needed init or were ready for backups + if (metadataManager.requiresInit || settingsManager.canDoBackupNow()) nm.onBackupError() TRANSPORT_ERROR } @@ -243,17 +243,7 @@ internal class BackupCoordinator( // What else we tried can be found in: https://github.com/seedvault-app/seedvault/issues/102 if (packageName == MAGIC_PACKAGE_MANAGER) { val isIncremental = flags and FLAG_INCREMENTAL != 0 - if (!settingsManager.canDoBackupNow()) { - // Returning anything else here (except non-incremental-required which re-tries) - // will make the system consider the backup state compromised - // and force re-initialization on next run. - // Errors for other packages are OK, but this one is not allowed to fail. - Log.w(TAG, "Skipping @pm@ backup as we can't do backup right now.") - state.skippedPmBackup = true - settingsManager.pmBackupNextTimeNonIncremental = true - data.close() - return TRANSPORT_OK - } else if (metadataManager.isLegacyFormat) { + if (metadataManager.requiresInit) { // start a new restore set to upgrade from legacy format // by starting a clean backup with all files using the new version try { @@ -263,6 +253,16 @@ internal class BackupCoordinator( } // this causes a backup error, but things should go back to normal afterwards return TRANSPORT_NOT_INITIALIZED + } else if (!settingsManager.canDoBackupNow()) { + // Returning anything else here (except non-incremental-required which re-tries) + // will make the system consider the backup state compromised + // and force re-initialization on next run. + // Errors for other packages are OK, but this one is not allowed to fail. + Log.w(TAG, "Skipping @pm@ backup as we can't do backup right now.") + state.skippedPmBackup = true + settingsManager.pmBackupNextTimeNonIncremental = true + data.close() + return TRANSPORT_OK } else if (isIncremental && settingsManager.pmBackupNextTimeNonIncremental) { settingsManager.pmBackupNextTimeNonIncremental = false data.close() diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinatorTest.kt b/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinatorTest.kt index 15a5ee0c..6d4aa383 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinatorTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinatorTest.kt @@ -156,7 +156,7 @@ internal class BackupCoordinatorTest : BackupTest() { assertEquals(TRANSPORT_OK, backup.performIncrementalBackup(packageInfo, data, 0)) every { settingsManager.canDoBackupNow() } returns true - every { metadataManager.isLegacyFormat } returns false + every { metadataManager.requiresInit } returns false every { settingsManager.pmBackupNextTimeNonIncremental } returns true every { settingsManager.pmBackupNextTimeNonIncremental = false } just Runs @@ -172,7 +172,7 @@ internal class BackupCoordinatorTest : BackupTest() { val packageInfo = PackageInfo().apply { packageName = MAGIC_PACKAGE_MANAGER } every { settingsManager.canDoBackupNow() } returns true - every { metadataManager.isLegacyFormat } returns true + every { metadataManager.requiresInit } returns true // start new restore set every { clock.time() } returns token + 1 @@ -416,7 +416,7 @@ internal class BackupCoordinatorTest : BackupTest() { val packageMetadata: PackageMetadata = mockk() every { settingsManager.canDoBackupNow() } returns true - every { metadataManager.isLegacyFormat } returns false + every { metadataManager.requiresInit } returns false every { settingsManager.getToken() } returns token every { metadataManager.salt } returns salt // do actual @pm@ backup