Stop backing up excluded app APKs

This commit is contained in:
Steve Soltys 2024-01-19 03:34:30 +00:00
parent 0319d733c1
commit d1e577aec9
3 changed files with 20 additions and 2 deletions

View file

@ -55,6 +55,12 @@ internal class ApkBackup(
// do not back up when setting is not enabled // do not back up when setting is not enabled
if (!settingsManager.backupApks()) return null 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 // 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 // see: https://commonsware.com/blog/2017/10/31/android-studio-3p0-flag-test-only.html
if (packageInfo.isTestOnly()) { if (packageInfo.isTestOnly()) {

View file

@ -107,6 +107,7 @@ internal class ApkBackupRestoreTest : TransportTest() {
writeBytes(splitBytes) writeBytes(splitBytes)
}.absolutePath) }.absolutePath)
every { settingsManager.isBackupEnabled(any()) } returns true
every { settingsManager.backupApks() } returns true every { settingsManager.backupApks() } returns true
every { sigInfo.hasMultipleSigners() } returns false every { sigInfo.hasMultipleSigners() } returns false
every { sigInfo.signingCertificateHistory } returns sigs every { sigInfo.signingCertificateHistory } returns sigs

View file

@ -62,6 +62,15 @@ internal class ApkBackupTest : BackupTest() {
@Test @Test
fun `does not back up when setting disabled`() = runBlocking { fun `does not back up when setting disabled`() = runBlocking {
every { settingsManager.backupApks() } returns false 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)) assertNull(apkBackup.backupApkIfNecessary(packageInfo, UNKNOWN_ERROR, streamGetter))
} }
@ -70,8 +79,8 @@ internal class ApkBackupTest : BackupTest() {
fun `does not back up test-only apps`() = runBlocking { fun `does not back up test-only apps`() = runBlocking {
packageInfo.applicationInfo.flags = FLAG_TEST_ONLY packageInfo.applicationInfo.flags = FLAG_TEST_ONLY
every { settingsManager.isBackupEnabled(any()) } returns true
every { settingsManager.backupApks() } returns true every { settingsManager.backupApks() } returns true
assertNull(apkBackup.backupApkIfNecessary(packageInfo, UNKNOWN_ERROR, streamGetter)) assertNull(apkBackup.backupApkIfNecessary(packageInfo, UNKNOWN_ERROR, streamGetter))
} }
@ -79,8 +88,8 @@ internal class ApkBackupTest : BackupTest() {
fun `does not back up system apps`() = runBlocking { fun `does not back up system apps`() = runBlocking {
packageInfo.applicationInfo.flags = FLAG_SYSTEM packageInfo.applicationInfo.flags = FLAG_SYSTEM
every { settingsManager.isBackupEnabled(any()) } returns true
every { settingsManager.backupApks() } returns true every { settingsManager.backupApks() } returns true
assertNull(apkBackup.backupApkIfNecessary(packageInfo, UNKNOWN_ERROR, streamGetter)) assertNull(apkBackup.backupApkIfNecessary(packageInfo, UNKNOWN_ERROR, streamGetter))
} }
@ -112,6 +121,7 @@ internal class ApkBackupTest : BackupTest() {
@Test @Test
fun `do not accept empty signature`() = runBlocking { fun `do not accept empty signature`() = runBlocking {
every { settingsManager.backupApks() } returns true every { settingsManager.backupApks() } returns true
every { settingsManager.isBackupEnabled(any()) } returns true
every { every {
metadataManager.getPackageMetadata(packageInfo.packageName) metadataManager.getPackageMetadata(packageInfo.packageName)
} returns packageMetadata } returns packageMetadata
@ -229,6 +239,7 @@ internal class ApkBackupTest : BackupTest() {
} }
private fun expectChecks(packageMetadata: PackageMetadata = this.packageMetadata) { private fun expectChecks(packageMetadata: PackageMetadata = this.packageMetadata) {
every { settingsManager.isBackupEnabled(any()) } returns true
every { settingsManager.backupApks() } returns true every { settingsManager.backupApks() } returns true
every { every {
metadataManager.getPackageMetadata(packageInfo.packageName) metadataManager.getPackageMetadata(packageInfo.packageName)