don't record excluded apps in backup

This commit is contained in:
Torsten Grote 2024-05-28 17:54:34 -03:00
parent e54d96d548
commit 4b1c76d585
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF
2 changed files with 26 additions and 0 deletions

View file

@ -80,6 +80,7 @@ internal class ApkBackupManager(
nm.onAppsNotBackedUp() nm.onAppsNotBackedUp()
packageService.notBackedUpPackages.forEach { packageInfo -> packageService.notBackedUpPackages.forEach { packageInfo ->
val packageName = packageInfo.packageName val packageName = packageInfo.packageName
if (!settingsManager.isBackupEnabled(packageName)) return@forEach
try { try {
val packageState = if (packageInfo.isStopped()) WAS_STOPPED else NOT_ALLOWED val packageState = if (packageInfo.isStopped()) WAS_STOPPED else NOT_ALLOWED
val packageMetadata = metadataManager.getPackageMetadata(packageName) val packageMetadata = metadataManager.getPackageMetadata(packageName)

View file

@ -66,6 +66,7 @@ internal class ApkBackupManagerTest : TransportTest() {
fun `Package state of app that is not stopped gets recorded as not-allowed`() = runBlocking { fun `Package state of app that is not stopped gets recorded as not-allowed`() = runBlocking {
every { nm.onAppsNotBackedUp() } just Runs every { nm.onAppsNotBackedUp() } just Runs
every { packageService.notBackedUpPackages } returns listOf(packageInfo) every { packageService.notBackedUpPackages } returns listOf(packageInfo)
every { settingsManager.isBackupEnabled(packageInfo.packageName) } returns true
expectUploadIcons() expectUploadIcons()
@ -91,6 +92,7 @@ internal class ApkBackupManagerTest : TransportTest() {
fun `Package state of app gets recorded even if no previous state`() = runBlocking { fun `Package state of app gets recorded even if no previous state`() = runBlocking {
every { nm.onAppsNotBackedUp() } just Runs every { nm.onAppsNotBackedUp() } just Runs
every { packageService.notBackedUpPackages } returns listOf(packageInfo) every { packageService.notBackedUpPackages } returns listOf(packageInfo)
every { settingsManager.isBackupEnabled(packageInfo.packageName) } returns true
expectUploadIcons() expectUploadIcons()
@ -122,6 +124,7 @@ internal class ApkBackupManagerTest : TransportTest() {
every { nm.onAppsNotBackedUp() } just Runs every { nm.onAppsNotBackedUp() } just Runs
every { packageService.notBackedUpPackages } returns listOf(packageInfo) every { packageService.notBackedUpPackages } returns listOf(packageInfo)
every { settingsManager.isBackupEnabled(packageInfo.packageName) } returns true
expectUploadIcons() expectUploadIcons()
@ -147,6 +150,7 @@ internal class ApkBackupManagerTest : TransportTest() {
fun `Package state only updated when changed`() = runBlocking { fun `Package state only updated when changed`() = runBlocking {
every { nm.onAppsNotBackedUp() } just Runs every { nm.onAppsNotBackedUp() } just Runs
every { packageService.notBackedUpPackages } returns listOf(packageInfo) every { packageService.notBackedUpPackages } returns listOf(packageInfo)
every { settingsManager.isBackupEnabled(packageInfo.packageName) } returns true
expectUploadIcons() expectUploadIcons()
@ -166,6 +170,25 @@ internal class ApkBackupManagerTest : TransportTest() {
} }
} }
@Test
fun `Package state only updated if not excluded`() = runBlocking {
every { nm.onAppsNotBackedUp() } just Runs
every { packageService.notBackedUpPackages } returns listOf(packageInfo)
every { settingsManager.isBackupEnabled(packageInfo.packageName) } returns false
expectUploadIcons()
every { settingsManager.backupApks() } returns false
expectFinalUpload()
every { nm.onApkBackupDone() } just Runs
apkBackupManager.backup()
verifyAll(inverse = true) {
metadataManager.onPackageDoesNotGetBackedUp(packageInfo, NOT_ALLOWED)
}
}
@Test @Test
fun `two packages get backed up, one their APK uploaded`() = runBlocking { fun `two packages get backed up, one their APK uploaded`() = runBlocking {
val notAllowedPackages = listOf( val notAllowedPackages = listOf(
@ -217,6 +240,7 @@ internal class ApkBackupManagerTest : TransportTest() {
fun `we keep trying to upload metadata at the end`() = runBlocking { fun `we keep trying to upload metadata at the end`() = runBlocking {
every { nm.onAppsNotBackedUp() } just Runs every { nm.onAppsNotBackedUp() } just Runs
every { packageService.notBackedUpPackages } returns listOf(packageInfo) every { packageService.notBackedUpPackages } returns listOf(packageInfo)
every { settingsManager.isBackupEnabled(packageInfo.packageName) } returns true
expectUploadIcons() expectUploadIcons()
@ -247,6 +271,7 @@ internal class ApkBackupManagerTest : TransportTest() {
} }
private suspend fun expectUploadIcons() { private suspend fun expectUploadIcons() {
every { settingsManager.getToken() } returns token
val stream = ByteArrayOutputStream() val stream = ByteArrayOutputStream()
coEvery { plugin.getOutputStream(token, FILE_BACKUP_ICONS) } returns stream coEvery { plugin.getOutputStream(token, FILE_BACKUP_ICONS) } returns stream
every { iconManager.uploadIcons(token, stream) } just Runs every { iconManager.uploadIcons(token, stream) } just Runs