Update state of opt-out apps, even if they never had any state

This commit is contained in:
Torsten Grote 2020-10-09 14:33:23 -03:00 committed by Chirayu Desai
parent a9402f4644
commit 0a8a286826
2 changed files with 29 additions and 1 deletions

View file

@ -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"

View file

@ -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(