Use new storage API for full backups
diff --git a/app/src/main/java/com/stevesoltys/seedvault/metadata/MetadataManager.kt b/app/src/main/java/com/stevesoltys/seedvault/metadata/MetadataManager.kt
index 648816b..a1a5306 100644
--- a/app/src/main/java/com/stevesoltys/seedvault/metadata/MetadataManager.kt
+++ b/app/src/main/java/com/stevesoltys/seedvault/metadata/MetadataManager.kt
@@ -219,6 +219,9 @@
     private val mLastBackupTime = MutableLiveData<Long>()
     internal val lastBackupTime: LiveData<Long> = mLastBackupTime.distinctUntilChanged()
 
+    internal val salt: String
+        @Synchronized get() = metadata.salt
+
     internal val isLegacyFormat: Boolean
         @Synchronized get() = metadata.version < VERSION
 
diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt
index e0b0a93..11ded3d 100644
--- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt
+++ b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt
@@ -310,7 +310,9 @@
         flags: Int
     ): Int {
         state.cancelReason = UNKNOWN_ERROR
-        return full.performFullBackup(targetPackage, fileDescriptor, flags)
+        val token = settingsManager.getToken() ?: error("no token in performFullBackup")
+        val salt = metadataManager.salt
+        return full.performFullBackup(targetPackage, fileDescriptor, flags, token, salt)
     }
 
     suspend fun sendBackupData(numBytes: Int) = full.sendBackupData(numBytes)
@@ -336,7 +338,9 @@
                 " because of ${state.cancelReason}"
         )
         onPackageBackupError(packageInfo, BackupType.FULL)
-        full.cancelFullBackup()
+        val token = settingsManager.getToken() ?: error("no token in cancelFullBackup")
+        val salt = metadataManager.salt
+        full.cancelFullBackup(token, salt)
     }
 
     // Clear and Finish
@@ -353,6 +357,8 @@
     suspend fun clearBackupData(packageInfo: PackageInfo): Int {
         val packageName = packageInfo.packageName
         Log.i(TAG, "Clear Backup Data of $packageName.")
+        val token = settingsManager.getToken() ?: error("no token in clearBackupData")
+        val salt = metadataManager.salt
         try {
             kv.clearBackupData(packageInfo)
         } catch (e: IOException) {
@@ -360,7 +366,7 @@
             return TRANSPORT_ERROR
         }
         try {
-            full.clearBackupData(packageInfo)
+            full.clearBackupData(packageInfo, token, salt)
         } catch (e: IOException) {
             Log.w(TAG, "Error clearing full backup data for $packageName", e)
             return TRANSPORT_ERROR
diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupModule.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupModule.kt
index 44836d4..a3fc645 100644
--- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupModule.kt
+++ b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupModule.kt
@@ -29,7 +29,7 @@
     }
     single {
         FullBackup(
-            plugin = get<BackupPlugin>().fullBackupPlugin,
+            plugin = get(),
             settingsManager = get(),
             inputFactory = get(),
             crypto = get()
diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/FullBackup.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/FullBackup.kt
index 4356ae6..e14899b 100644
--- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/FullBackup.kt
+++ b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/FullBackup.kt
@@ -38,7 +38,7 @@
 
 @Suppress("BlockingMethodInNonBlockingContext")
 internal class FullBackup(
-    private val plugin: FullBackupPlugin,
+    private val plugin: BackupPlugin,
     private val settingsManager: SettingsManager,
     private val inputFactory: InputFactory,
     private val crypto: Crypto
@@ -51,7 +51,7 @@
     fun getCurrentPackage() = state?.packageInfo
 
     fun getQuota(): Long {
-        return if (settingsManager.isQuotaUnlimited()) Long.MAX_VALUE else plugin.getQuota()
+        return if (settingsManager.isQuotaUnlimited()) Long.MAX_VALUE else DEFAULT_QUOTA_FULL_BACKUP
     }
 
     fun checkFullBackupSize(size: Long): Int {
@@ -101,20 +101,24 @@
     suspend fun performFullBackup(
         targetPackage: PackageInfo,
         socket: ParcelFileDescriptor,
-        @Suppress("UNUSED_PARAMETER") flags: Int = 0
+        @Suppress("UNUSED_PARAMETER") flags: Int = 0,
+        token: Long,
+        salt: String
     ): Int {
         if (state != null) throw AssertionError()
-        Log.i(TAG, "Perform full backup for ${targetPackage.packageName}.")
+        val packageName = targetPackage.packageName
+        Log.i(TAG, "Perform full backup for $packageName.")
 
         // create new state
         val inputStream = inputFactory.getInputStream(socket)
         state = FullBackupState(targetPackage, socket, inputStream) {
-            Log.d(TAG, "Initializing OutputStream for ${targetPackage.packageName}.")
+            Log.d(TAG, "Initializing OutputStream for $packageName.")
+            val name = crypto.getNameForPackage(salt, packageName)
             // get OutputStream to write backup data into
             val outputStream = try {
-                plugin.getOutputStream(targetPackage)
+                plugin.getOutputStream(token, name)
             } catch (e: IOException) {
-                "Error getting OutputStream for full backup of ${targetPackage.packageName}".let {
+                "Error getting OutputStream for full backup of $packageName".let {
                     Log.e(TAG, it, e)
                 }
                 throw(e)
@@ -167,15 +171,16 @@
     }
 
     @Throws(IOException::class)
-    suspend fun clearBackupData(packageInfo: PackageInfo) {
-        plugin.removeDataOfPackage(packageInfo)
+    suspend fun clearBackupData(packageInfo: PackageInfo, token: Long, salt: String) {
+        val name = crypto.getNameForPackage(salt, packageInfo.packageName)
+        plugin.removeData(token, name)
     }
 
-    suspend fun cancelFullBackup() {
+    suspend fun cancelFullBackup(token: Long, salt: String) {
         Log.i(TAG, "Cancel full backup")
         val state = this.state ?: throw AssertionError("No state when canceling")
         try {
-            plugin.removeDataOfPackage(state.packageInfo)
+            clearBackupData(state.packageInfo, token, salt)
         } catch (e: IOException) {
             Log.w(TAG, "Error cancelling full backup for ${state.packageName}", e)
         }
diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/CoordinatorIntegrationTest.kt b/app/src/test/java/com/stevesoltys/seedvault/transport/CoordinatorIntegrationTest.kt
index f5647c2..5098851 100644
--- a/app/src/test/java/com/stevesoltys/seedvault/transport/CoordinatorIntegrationTest.kt
+++ b/app/src/test/java/com/stevesoltys/seedvault/transport/CoordinatorIntegrationTest.kt
@@ -73,7 +73,7 @@
     )
     private val fullBackupPlugin = mockk<FullBackupPlugin>()
     private val fullBackup = FullBackup(
-        plugin = fullBackupPlugin,
+        plugin = backupPlugin,
         settingsManager = settingsManager,
         inputFactory = inputFactory,
         crypto = cryptoImpl
@@ -295,11 +295,13 @@
         val packageMetadata = metadata.packageMetadataMap[packageInfo.packageName]!!
         metadata.packageMetadataMap[packageInfo.packageName] =
             packageMetadata.copy(backupType = BackupType.FULL)
+        // as we use real crypto, we need a real name for packageInfo
+        val name = cryptoImpl.getNameForPackage(salt, packageInfo.packageName)
 
         // return streams from plugin and app data
         val bOutputStream = ByteArrayOutputStream()
         val bInputStream = ByteArrayInputStream(appData)
-        coEvery { fullBackupPlugin.getOutputStream(packageInfo) } returns bOutputStream
+        coEvery { backupPlugin.getOutputStream(token, name) } returns bOutputStream
         every { inputFactory.getInputStream(fileDescriptor) } returns bInputStream
         every { settingsManager.isQuotaUnlimited() } returns false
         every { fullBackupPlugin.getQuota() } returns DEFAULT_QUOTA_FULL_BACKUP
@@ -311,6 +313,7 @@
             )
         } returns packageMetadata
         every { settingsManager.getToken() } returns token
+        every { metadataManager.salt } returns salt
         coEvery {
             backupPlugin.getOutputStream(token, FILE_BACKUP_METADATA)
         } returns metadataOutputStream
@@ -336,7 +339,7 @@
         assertEquals(TRANSPORT_OK, restore.startRestore(token, arrayOf(packageInfo)))
 
         // finds data for full backup
-        every { crypto.getNameForPackage(metadata.salt, packageInfo.packageName) } returns name
+        every { crypto.getNameForPackage(salt, packageInfo.packageName) } returns name
         coEvery { backupPlugin.hasData(token, name) } returns true
 
         val restoreDescription = restore.nextRestorePackage() ?: fail()
diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/TransportTest.kt b/app/src/test/java/com/stevesoltys/seedvault/transport/TransportTest.kt
index d3060f9..9d44152 100644
--- a/app/src/test/java/com/stevesoltys/seedvault/transport/TransportTest.kt
+++ b/app/src/test/java/com/stevesoltys/seedvault/transport/TransportTest.kt
@@ -58,6 +58,7 @@
             put(packageInfo.packageName, PackageMetadata(backupType = BackupType.KV))
         }
     )
+    protected val salt = metadata.salt
     protected val name = getRandomString(12)
     protected val name2 = getRandomString(23)
 
diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinatorTest.kt b/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinatorTest.kt
index 089c573..6f0ee3d 100644
--- a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinatorTest.kt
+++ b/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinatorTest.kt
@@ -220,6 +220,8 @@
 
     @Test
     fun `clearing KV backup data throws`() = runBlocking {
+        every { settingsManager.getToken() } returns token
+        every { metadataManager.salt } returns salt
         coEvery { kv.clearBackupData(packageInfo) } throws IOException()
 
         assertEquals(TRANSPORT_ERROR, backup.clearBackupData(packageInfo))
@@ -227,16 +229,20 @@
 
     @Test
     fun `clearing full backup data throws`() = runBlocking {
+        every { settingsManager.getToken() } returns token
+        every { metadataManager.salt } returns salt
         coEvery { kv.clearBackupData(packageInfo) } just Runs
-        coEvery { full.clearBackupData(packageInfo) } throws IOException()
+        coEvery { full.clearBackupData(packageInfo, token, salt) } throws IOException()
 
         assertEquals(TRANSPORT_ERROR, backup.clearBackupData(packageInfo))
     }
 
     @Test
     fun `clearing backup data succeeds`() = runBlocking {
+        every { settingsManager.getToken() } returns token
+        every { metadataManager.salt } returns salt
         coEvery { kv.clearBackupData(packageInfo) } just Runs
-        coEvery { full.clearBackupData(packageInfo) } just Runs
+        coEvery { full.clearBackupData(packageInfo, token, salt) } just Runs
 
         assertEquals(TRANSPORT_OK, backup.clearBackupData(packageInfo))
 
@@ -288,7 +294,11 @@
 
     @Test
     fun `metadata does not get updated when no APK was backed up`() = runBlocking {
-        coEvery { full.performFullBackup(packageInfo, fileDescriptor, 0) } returns TRANSPORT_OK
+        every { settingsManager.getToken() } returns token
+        every { metadataManager.salt } returns salt
+        coEvery {
+            full.performFullBackup(packageInfo, fileDescriptor, 0, token, salt)
+        } returns TRANSPORT_OK
         coEvery { apkBackup.backupApkIfNecessary(packageInfo, UNKNOWN_ERROR, any()) } returns null
 
         assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, fileDescriptor, 0))
@@ -296,7 +306,11 @@
 
     @Test
     fun `app exceeding quota gets cancelled and reason written to metadata`() = runBlocking {
-        coEvery { full.performFullBackup(packageInfo, fileDescriptor, 0) } returns TRANSPORT_OK
+        every { settingsManager.getToken() } returns token
+        every { metadataManager.salt } returns salt
+        coEvery {
+            full.performFullBackup(packageInfo, fileDescriptor, 0, token, salt)
+        } returns TRANSPORT_OK
         expectApkBackupAndMetadataWrite()
         every { full.getQuota() } returns DEFAULT_QUOTA_FULL_BACKUP
         every {
@@ -311,7 +325,7 @@
                 BackupType.FULL
             )
         } just Runs
-        coEvery { full.cancelFullBackup() } just Runs
+        coEvery { full.cancelFullBackup(token, metadata.salt) } just Runs
         every { settingsManager.getStorage() } returns storage
         every { metadataOutputStream.close() } just Runs
 
@@ -343,7 +357,11 @@
 
     @Test
     fun `app with no data gets cancelled and reason written to metadata`() = runBlocking {
-        coEvery { full.performFullBackup(packageInfo, fileDescriptor, 0) } returns TRANSPORT_OK
+        every { settingsManager.getToken() } returns token
+        every { metadataManager.salt } returns salt
+        coEvery {
+            full.performFullBackup(packageInfo, fileDescriptor, 0, token, salt)
+        } returns TRANSPORT_OK
         expectApkBackupAndMetadataWrite()
         every { full.getQuota() } returns DEFAULT_QUOTA_FULL_BACKUP
         every { full.checkFullBackupSize(0) } returns TRANSPORT_PACKAGE_REJECTED
@@ -356,7 +374,7 @@
                 BackupType.FULL
             )
         } just Runs
-        coEvery { full.cancelFullBackup() } just Runs
+        coEvery { full.cancelFullBackup(token, metadata.salt) } just Runs
         every { settingsManager.getStorage() } returns storage
         every { metadataOutputStream.close() } just Runs
 
diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupTest.kt b/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupTest.kt
index f6dc5cc..b1f85b7 100644
--- a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupTest.kt
+++ b/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupTest.kt
@@ -12,6 +12,6 @@
     protected val outputStream = mockk<OutputStream>()
     protected val encryptedOutputStream = mockk<OutputStream>()
 
-    protected val quota = 42L
+    protected val quota = DEFAULT_QUOTA_FULL_BACKUP
 
 }
diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/FullBackupTest.kt b/app/src/test/java/com/stevesoltys/seedvault/transport/backup/FullBackupTest.kt
index 4c364fb..4e44c9b 100644
--- a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/FullBackupTest.kt
+++ b/app/src/test/java/com/stevesoltys/seedvault/transport/backup/FullBackupTest.kt
@@ -23,7 +23,7 @@
 @Suppress("BlockingMethodInNonBlockingContext")
 internal class FullBackupTest : BackupTest() {
 
-    private val plugin = mockk<FullBackupPlugin>()
+    private val plugin = mockk<BackupPlugin>()
     private val backup = FullBackup(plugin, settingsManager, inputFactory, crypto)
 
     private val bytes = ByteArray(23).apply { Random.nextBytes(this) }
@@ -38,9 +38,8 @@
     @Test
     fun `checkFullBackupSize exceeds quota`() {
         every { settingsManager.isQuotaUnlimited() } returns false
-        every { plugin.getQuota() } returns quota
 
-        assertEquals(TRANSPORT_QUOTA_EXCEEDED, backup.checkFullBackupSize(quota + 1))
+        assertEquals(TRANSPORT_QUOTA_EXCEEDED, backup.checkFullBackupSize(DEFAULT_QUOTA_FULL_BACKUP + 1))
     }
 
     @Test
@@ -63,7 +62,6 @@
     @Test
     fun `checkFullBackupSize accepts min data`() {
         every { settingsManager.isQuotaUnlimited() } returns false
-        every { plugin.getQuota() } returns quota
 
         assertEquals(TRANSPORT_OK, backup.checkFullBackupSize(1))
     }
@@ -71,7 +69,6 @@
     @Test
     fun `checkFullBackupSize accepts max data`() {
         every { settingsManager.isQuotaUnlimited() } returns false
-        every { plugin.getQuota() } returns quota
 
         assertEquals(TRANSPORT_OK, backup.checkFullBackupSize(quota))
     }
@@ -81,7 +78,7 @@
         every { inputFactory.getInputStream(data) } returns inputStream
         expectClearState()
 
-        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data))
+        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data, 0, token, salt))
         assertTrue(backup.hasState())
         assertEquals(TRANSPORT_OK, backup.finishBackup())
         assertFalse(backup.hasState())
@@ -96,7 +93,7 @@
         expectSendData(numBytes)
         expectClearState()
 
-        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data))
+        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data, 0, token, salt))
         assertTrue(backup.hasState())
         assertEquals(TRANSPORT_QUOTA_EXCEEDED, backup.sendBackupData(numBytes))
         assertTrue(backup.hasState())
@@ -115,7 +112,7 @@
         expectSendData(numBytes2)
         expectClearState()
 
-        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data))
+        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data, 0, token, salt))
         assertTrue(backup.hasState())
         assertEquals(TRANSPORT_OK, backup.sendBackupData(numBytes1))
         assertTrue(backup.hasState())
@@ -130,12 +127,11 @@
         every { inputFactory.getInputStream(data) } returns inputStream
         expectInitializeOutputStream()
         every { settingsManager.isQuotaUnlimited() } returns false
-        every { plugin.getQuota() } returns quota
         every { crypto.newEncryptingStream(outputStream, ad) } returns encryptedOutputStream
         every { inputStream.read(any(), any(), bytes.size) } throws IOException()
         expectClearState()
 
-        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data))
+        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data, 0, token, salt))
         assertTrue(backup.hasState())
         assertEquals(TRANSPORT_ERROR, backup.sendBackupData(bytes.size))
         assertTrue(backup.hasState())
@@ -148,11 +144,11 @@
         every { inputFactory.getInputStream(data) } returns inputStream
 
         every { settingsManager.isQuotaUnlimited() } returns false
-        every { plugin.getQuota() } returns quota
-        coEvery { plugin.getOutputStream(packageInfo) } throws IOException()
+        every { crypto.getNameForPackage(salt, packageInfo.packageName) } returns name
+        coEvery { plugin.getOutputStream(token, name) } throws IOException()
         expectClearState()
 
-        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data))
+        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data, 0, token, salt))
         assertTrue(backup.hasState())
         assertEquals(TRANSPORT_ERROR, backup.sendBackupData(bytes.size))
         assertTrue(backup.hasState())
@@ -165,13 +161,13 @@
         every { inputFactory.getInputStream(data) } returns inputStream
 
         every { settingsManager.isQuotaUnlimited() } returns false
-        every { plugin.getQuota() } returns quota
-        coEvery { plugin.getOutputStream(packageInfo) } returns outputStream
+        every { crypto.getNameForPackage(salt, packageInfo.packageName) } returns name
+        coEvery { plugin.getOutputStream(token, name) } returns outputStream
         every { inputFactory.getInputStream(data) } returns inputStream
         every { outputStream.write(ByteArray(1) { VERSION }) } throws IOException()
         expectClearState()
 
-        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data))
+        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data, 0, token, salt))
         assertTrue(backup.hasState())
         assertEquals(TRANSPORT_ERROR, backup.sendBackupData(bytes.size))
         assertTrue(backup.hasState())
@@ -185,13 +181,12 @@
             every { inputFactory.getInputStream(data) } returns inputStream
             expectInitializeOutputStream()
             every { settingsManager.isQuotaUnlimited() } returns false
-            every { plugin.getQuota() } returns quota
             every { crypto.newEncryptingStream(outputStream, ad) } returns encryptedOutputStream
             every { inputStream.read(any(), any(), bytes.size) } returns bytes.size
             every { encryptedOutputStream.write(any<ByteArray>()) } throws IOException()
             expectClearState()
 
-            assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data))
+            assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data, 0, token, salt))
             assertTrue(backup.hasState())
             assertEquals(TRANSPORT_ERROR, backup.sendBackupData(bytes.size))
             assertTrue(backup.hasState())
@@ -210,7 +205,7 @@
         expectSendData(numBytes2)
         expectClearState()
 
-        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data))
+        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data, 0, token, salt))
         assertTrue(backup.hasState())
         assertEquals(TRANSPORT_OK, backup.sendBackupData(numBytes1))
         assertTrue(backup.hasState())
@@ -222,9 +217,10 @@
 
     @Test
     fun `clearBackupData delegates to plugin`() = runBlocking {
-        coEvery { plugin.removeDataOfPackage(packageInfo) } just Runs
+        every { crypto.getNameForPackage(salt, packageInfo.packageName) } returns name
+        coEvery { plugin.removeData(token, name) } just Runs
 
-        backup.clearBackupData(packageInfo)
+        backup.clearBackupData(packageInfo, token, salt)
     }
 
     @Test
@@ -232,11 +228,12 @@
         every { inputFactory.getInputStream(data) } returns inputStream
         expectInitializeOutputStream()
         expectClearState()
-        coEvery { plugin.removeDataOfPackage(packageInfo) } just Runs
+        every { crypto.getNameForPackage(salt, packageInfo.packageName) } returns name
+        coEvery { plugin.removeData(token, name) } just Runs
 
-        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data))
+        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data, 0, token, salt))
         assertTrue(backup.hasState())
-        backup.cancelFullBackup()
+        backup.cancelFullBackup(token, salt)
         assertFalse(backup.hasState())
     }
 
@@ -245,11 +242,12 @@
         every { inputFactory.getInputStream(data) } returns inputStream
         expectInitializeOutputStream()
         expectClearState()
-        coEvery { plugin.removeDataOfPackage(packageInfo) } throws IOException()
+        every { crypto.getNameForPackage(salt, packageInfo.packageName) } returns name
+        coEvery { plugin.removeData(token, name) } throws IOException()
 
-        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data))
+        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data, 0, token, salt))
         assertTrue(backup.hasState())
-        backup.cancelFullBackup()
+        backup.cancelFullBackup(token, salt)
         assertFalse(backup.hasState())
     }
 
@@ -262,7 +260,7 @@
         expectSendData(numBytes)
         every { encryptedOutputStream.flush() } throws IOException()
 
-        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data))
+        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data, 0, token, salt))
         assertTrue(backup.hasState())
         assertEquals(TRANSPORT_OK, backup.sendBackupData(numBytes))
         assertEquals(TRANSPORT_ERROR, backup.finishBackup())
@@ -278,7 +276,7 @@
         every { inputStream.close() } just Runs
         every { data.close() } just Runs
 
-        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data))
+        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data, 0, token, salt))
         assertTrue(backup.hasState())
         assertEquals(TRANSPORT_OK, backup.finishBackup())
         assertFalse(backup.hasState())
@@ -293,7 +291,7 @@
         every { inputStream.close() } throws IOException()
         every { data.close() } just Runs
 
-        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data))
+        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data, 0, token, salt))
         assertTrue(backup.hasState())
         assertEquals(TRANSPORT_OK, backup.finishBackup())
         assertFalse(backup.hasState())
@@ -308,19 +306,19 @@
         every { inputStream.close() } just Runs
         every { data.close() } throws IOException()
 
-        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data))
+        assertEquals(TRANSPORT_OK, backup.performFullBackup(packageInfo, data, 0, token, salt))
         assertTrue(backup.hasState())
         assertEquals(TRANSPORT_OK, backup.finishBackup())
         assertFalse(backup.hasState())
     }
 
     private fun expectInitializeOutputStream() {
-        coEvery { plugin.getOutputStream(packageInfo) } returns outputStream
+        every { crypto.getNameForPackage(salt, packageInfo.packageName) } returns name
+        coEvery { plugin.getOutputStream(token, name) } returns outputStream
         every { outputStream.write(ByteArray(1) { VERSION }) } just Runs
     }
 
     private fun expectSendData(numBytes: Int, readBytes: Int = numBytes) {
-        every { plugin.getQuota() } returns quota
         every { inputStream.read(any(), any(), numBytes) } returns readBytes
         every { crypto.newEncryptingStream(outputStream, ad) } returns encryptedOutputStream
         every { encryptedOutputStream.write(any<ByteArray>()) } just Runs