From d1e577aec90db932d9195a1c7b30066fd868675e Mon Sep 17 00:00:00 2001 From: Steve Soltys Date: Fri, 19 Jan 2024 03:34:30 +0000 Subject: [PATCH 1/2] Stop backing up excluded app APKs --- .../seedvault/transport/backup/ApkBackup.kt | 6 ++++++ .../restore/install/ApkBackupRestoreTest.kt | 1 + .../seedvault/transport/backup/ApkBackupTest.kt | 15 +++++++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/ApkBackup.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/ApkBackup.kt index 02208eb0..1942f006 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/ApkBackup.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/ApkBackup.kt @@ -55,6 +55,12 @@ internal class ApkBackup( // do not back up when setting is not enabled if (!settingsManager.backupApks()) return null + // do not back up if package is blacklisted + if (!settingsManager.isBackupEnabled(packageName)) { + Log.d(TAG, "Package $packageName is blacklisted. Not backing it up.") + return null + } + // do not back up test-only apps as we can't re-install them anyway // see: https://commonsware.com/blog/2017/10/31/android-studio-3p0-flag-test-only.html if (packageInfo.isTestOnly()) { diff --git a/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkBackupRestoreTest.kt b/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkBackupRestoreTest.kt index f8805c78..f712807b 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkBackupRestoreTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkBackupRestoreTest.kt @@ -107,6 +107,7 @@ internal class ApkBackupRestoreTest : TransportTest() { writeBytes(splitBytes) }.absolutePath) + every { settingsManager.isBackupEnabled(any()) } returns true every { settingsManager.backupApks() } returns true every { sigInfo.hasMultipleSigners() } returns false every { sigInfo.signingCertificateHistory } returns sigs diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/ApkBackupTest.kt b/app/src/test/java/com/stevesoltys/seedvault/transport/backup/ApkBackupTest.kt index 2137e565..0cbbf9e0 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/ApkBackupTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/transport/backup/ApkBackupTest.kt @@ -62,6 +62,15 @@ internal class ApkBackupTest : BackupTest() { @Test fun `does not back up when setting disabled`() = runBlocking { every { settingsManager.backupApks() } returns false + every { settingsManager.isBackupEnabled(any()) } returns true + + assertNull(apkBackup.backupApkIfNecessary(packageInfo, UNKNOWN_ERROR, streamGetter)) + } + + @Test + fun `does not back up when app blacklisted`() = runBlocking { + every { settingsManager.backupApks() } returns true + every { settingsManager.isBackupEnabled(any()) } returns false assertNull(apkBackup.backupApkIfNecessary(packageInfo, UNKNOWN_ERROR, streamGetter)) } @@ -70,8 +79,8 @@ internal class ApkBackupTest : BackupTest() { fun `does not back up test-only apps`() = runBlocking { packageInfo.applicationInfo.flags = FLAG_TEST_ONLY + every { settingsManager.isBackupEnabled(any()) } returns true every { settingsManager.backupApks() } returns true - assertNull(apkBackup.backupApkIfNecessary(packageInfo, UNKNOWN_ERROR, streamGetter)) } @@ -79,8 +88,8 @@ internal class ApkBackupTest : BackupTest() { fun `does not back up system apps`() = runBlocking { packageInfo.applicationInfo.flags = FLAG_SYSTEM + every { settingsManager.isBackupEnabled(any()) } returns true every { settingsManager.backupApks() } returns true - assertNull(apkBackup.backupApkIfNecessary(packageInfo, UNKNOWN_ERROR, streamGetter)) } @@ -112,6 +121,7 @@ internal class ApkBackupTest : BackupTest() { @Test fun `do not accept empty signature`() = runBlocking { every { settingsManager.backupApks() } returns true + every { settingsManager.isBackupEnabled(any()) } returns true every { metadataManager.getPackageMetadata(packageInfo.packageName) } returns packageMetadata @@ -229,6 +239,7 @@ internal class ApkBackupTest : BackupTest() { } private fun expectChecks(packageMetadata: PackageMetadata = this.packageMetadata) { + every { settingsManager.isBackupEnabled(any()) } returns true every { settingsManager.backupApks() } returns true every { metadataManager.getPackageMetadata(packageInfo.packageName) From bc189546b3b2069f576535a4d38f0d98d361f00a Mon Sep 17 00:00:00 2001 From: Steve Soltys Date: Fri, 19 Jan 2024 03:34:38 +0000 Subject: [PATCH 2/2] Add '/build' folders to .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 7688171a..4a365e37 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,9 @@ hs_err_pid* ## Intellij out/ +build/ +storage/build/ +contactsbackup/build/ /lib/ .idea/* !.idea/runConfigurations*