Merge pull request #603 from seedvault-app/bugfix/excluded-apk-backups

Stop backing up excluded app APKs
This commit is contained in:
Steve Soltys 2024-01-19 09:41:51 -05:00 committed by GitHub
commit 695c33e466
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 23 additions and 2 deletions

3
.gitignore vendored
View file

@ -6,6 +6,9 @@ hs_err_pid*
## Intellij
out/
build/
storage/build/
contactsbackup/build/
/lib/
.idea/*
!.idea/runConfigurations*

View file

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

View file

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

View file

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