Stop backing up excluded app APKs
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 02208eb..1942f00 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 @@
         // 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 f8805c7..f712807 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 @@
             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 2137e56..0cbbf9e 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 @@
     @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 @@
     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 @@
     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 @@
     @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 @@
     }
 
     private fun expectChecks(packageMetadata: PackageMetadata = this.packageMetadata) {
+        every { settingsManager.isBackupEnabled(any()) } returns true
         every { settingsManager.backupApks() } returns true
         every {
             metadataManager.getPackageMetadata(packageInfo.packageName)