Force backup initialization when we have no cached metadata

as it can happen after clearing app data
This commit is contained in:
Torsten Grote 2021-10-06 20:09:31 +02:00 committed by Chirayu Desai
parent c59a006a00
commit 36c35d6f98
3 changed files with 18 additions and 18 deletions

View file

@ -222,8 +222,8 @@ internal class MetadataManager(
internal val salt: String internal val salt: String
@Synchronized get() = metadata.salt @Synchronized get() = metadata.salt
internal val isLegacyFormat: Boolean internal val requiresInit: Boolean
@Synchronized get() = metadata.version < VERSION @Synchronized get() = metadata == uninitializedMetadata || metadata.version < VERSION
@Synchronized @Synchronized
fun getPackageMetadata(packageName: String): PackageMetadata? { fun getPackageMetadata(packageName: String): PackageMetadata? {

View file

@ -136,8 +136,8 @@ internal class BackupCoordinator(
TRANSPORT_OK TRANSPORT_OK
} catch (e: IOException) { } catch (e: IOException) {
Log.e(TAG, "Error initializing device", e) Log.e(TAG, "Error initializing device", e)
// Show error notification if we were ready for backups // Show error notification if we needed init or were ready for backups
if (settingsManager.canDoBackupNow()) nm.onBackupError() if (metadataManager.requiresInit || settingsManager.canDoBackupNow()) nm.onBackupError()
TRANSPORT_ERROR 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 // What else we tried can be found in: https://github.com/seedvault-app/seedvault/issues/102
if (packageName == MAGIC_PACKAGE_MANAGER) { if (packageName == MAGIC_PACKAGE_MANAGER) {
val isIncremental = flags and FLAG_INCREMENTAL != 0 val isIncremental = flags and FLAG_INCREMENTAL != 0
if (!settingsManager.canDoBackupNow()) { if (metadataManager.requiresInit) {
// 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) {
// start a new restore set to upgrade from legacy format // start a new restore set to upgrade from legacy format
// by starting a clean backup with all files using the new version // by starting a clean backup with all files using the new version
try { try {
@ -263,6 +253,16 @@ internal class BackupCoordinator(
} }
// this causes a backup error, but things should go back to normal afterwards // this causes a backup error, but things should go back to normal afterwards
return TRANSPORT_NOT_INITIALIZED 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) { } else if (isIncremental && settingsManager.pmBackupNextTimeNonIncremental) {
settingsManager.pmBackupNextTimeNonIncremental = false settingsManager.pmBackupNextTimeNonIncremental = false
data.close() data.close()

View file

@ -156,7 +156,7 @@ internal class BackupCoordinatorTest : BackupTest() {
assertEquals(TRANSPORT_OK, backup.performIncrementalBackup(packageInfo, data, 0)) assertEquals(TRANSPORT_OK, backup.performIncrementalBackup(packageInfo, data, 0))
every { settingsManager.canDoBackupNow() } returns true every { settingsManager.canDoBackupNow() } returns true
every { metadataManager.isLegacyFormat } returns false every { metadataManager.requiresInit } returns false
every { settingsManager.pmBackupNextTimeNonIncremental } returns true every { settingsManager.pmBackupNextTimeNonIncremental } returns true
every { settingsManager.pmBackupNextTimeNonIncremental = false } just Runs every { settingsManager.pmBackupNextTimeNonIncremental = false } just Runs
@ -172,7 +172,7 @@ internal class BackupCoordinatorTest : BackupTest() {
val packageInfo = PackageInfo().apply { packageName = MAGIC_PACKAGE_MANAGER } val packageInfo = PackageInfo().apply { packageName = MAGIC_PACKAGE_MANAGER }
every { settingsManager.canDoBackupNow() } returns true every { settingsManager.canDoBackupNow() } returns true
every { metadataManager.isLegacyFormat } returns true every { metadataManager.requiresInit } returns true
// start new restore set // start new restore set
every { clock.time() } returns token + 1 every { clock.time() } returns token + 1
@ -416,7 +416,7 @@ internal class BackupCoordinatorTest : BackupTest() {
val packageMetadata: PackageMetadata = mockk() val packageMetadata: PackageMetadata = mockk()
every { settingsManager.canDoBackupNow() } returns true every { settingsManager.canDoBackupNow() } returns true
every { metadataManager.isLegacyFormat } returns false every { metadataManager.requiresInit } returns false
every { settingsManager.getToken() } returns token every { settingsManager.getToken() } returns token
every { metadataManager.salt } returns salt every { metadataManager.salt } returns salt
// do actual @pm@ backup // do actual @pm@ backup