From 0a8a286826d43a626001eef0b9e8af3b64cffeaf Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Fri, 9 Oct 2020 14:33:23 -0300 Subject: [PATCH] Update state of opt-out apps, even if they never had any state --- .../transport/backup/BackupCoordinator.kt | 2 +- .../transport/backup/BackupCoordinatorTest.kt | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) 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 b4cd67ac..56155918 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 @@ -363,7 +363,7 @@ internal class BackupCoordinator( val packageMetadata = metadataManager.getPackageMetadata(packageName) val oldPackageState = packageMetadata?.state - if (oldPackageState != null && oldPackageState != packageState) { + if (oldPackageState != packageState) { Log.i( TAG, "Package $packageName was in $oldPackageState" + ", update to $packageState" 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 fcf8a4af..03967e66 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 @@ -417,6 +417,34 @@ internal class BackupCoordinatorTest : BackupTest() { } } + @Test + fun `APK backup of not allowed apps updates state even without old state`() = runBlocking { + every { packageService.notAllowedPackages } returns listOf(packageInfo) + every { + notificationManager.onOptOutAppBackup(packageInfo.packageName, 1, 1) + } just Runs + coEvery { apkBackup.backupApkIfNecessary(packageInfo, NOT_ALLOWED, any()) } returns null + every { + metadataManager.getPackageMetadata(packageInfo.packageName) + } returns null + coEvery { plugin.getMetadataOutputStream() } returns metadataOutputStream + every { + metadataManager.onPackageBackupError( + packageInfo, + NOT_ALLOWED, + metadataOutputStream + ) + } just Runs + every { metadataOutputStream.close() } just Runs + + backup.backUpNotAllowedPackages() + + verify { + metadataManager.onPackageBackupError(packageInfo, NOT_ALLOWED, metadataOutputStream) + metadataOutputStream.close() + } + } + private fun expectApkBackupAndMetadataWrite() { coEvery { apkBackup.backupApkIfNecessary(