diff --git a/app/src/androidTest/java/com/stevesoltys/seedvault/KoinInstrumentationTestApp.kt b/app/src/androidTest/java/com/stevesoltys/seedvault/KoinInstrumentationTestApp.kt index d5f98989..d5b78ecc 100644 --- a/app/src/androidTest/java/com/stevesoltys/seedvault/KoinInstrumentationTestApp.kt +++ b/app/src/androidTest/java/com/stevesoltys/seedvault/KoinInstrumentationTestApp.kt @@ -32,7 +32,7 @@ class KoinInstrumentationTestApp : App() { single { spyk(BackupNotificationManager(context)) } single { spyk(FullBackup(get(), get(), get(), get(), get())) } - single { spyk(KVBackup(get(), get(), get(), get(), get())) } + single { spyk(KVBackup(get(), get(), get(), get(), get(), get())) } single { spyk(InputFactory()) } single { spyk(FullRestore(get(), get(), get(), get(), get())) } diff --git a/app/src/main/java/com/stevesoltys/seedvault/plugins/StorageProperties.kt b/app/src/main/java/com/stevesoltys/seedvault/plugins/StorageProperties.kt index 8187d312..5fa3cfd4 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/plugins/StorageProperties.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/plugins/StorageProperties.kt @@ -9,6 +9,7 @@ import android.content.Context import android.net.ConnectivityManager import android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET import androidx.annotation.WorkerThread +import at.bitfire.dav4jvm.exception.HttpException import java.io.IOException abstract class StorageProperties { @@ -37,5 +38,12 @@ abstract class StorageProperties { } fun Exception.isOutOfSpace(): Boolean { - return this is IOException && message?.contains("No space left on device") == true + return when (this) { + is IOException -> message?.contains("No space left on device") == true || + (cause as? HttpException)?.code == 507 + + is HttpException -> code == 507 + + else -> false + } } 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 bacd39a6..82022934 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 @@ -382,6 +382,7 @@ internal class BackupCoordinator( onPackageBackedUp(packageInfo, BackupType.FULL, size) } catch (e: Exception) { Log.e(TAG, "Error calling onPackageBackedUp for $packageName", e) + if (e.isOutOfSpace()) nm.onInsufficientSpaceError() result = TRANSPORT_PACKAGE_REJECTED } result 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 f600c8b0..e120c689 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 @@ -19,6 +19,7 @@ val backupModule = module { KVBackup( pluginManager = get(), settingsManager = get(), + nm = get(), inputFactory = get(), crypto = get(), dbManager = get(), diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/KVBackup.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/KVBackup.kt index c867144f..a4732388 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/KVBackup.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/KVBackup.kt @@ -14,7 +14,9 @@ import com.stevesoltys.seedvault.crypto.Crypto import com.stevesoltys.seedvault.header.VERSION import com.stevesoltys.seedvault.header.getADForKV import com.stevesoltys.seedvault.plugins.StoragePluginManager +import com.stevesoltys.seedvault.plugins.isOutOfSpace import com.stevesoltys.seedvault.settings.SettingsManager +import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager import java.io.IOException import java.util.zip.GZIPOutputStream @@ -34,6 +36,7 @@ private val TAG = KVBackup::class.java.simpleName internal class KVBackup( private val pluginManager: StoragePluginManager, private val settingsManager: SettingsManager, + private val nm: BackupNotificationManager, private val inputFactory: InputFactory, private val crypto: Crypto, private val dbManager: KvDbManager, @@ -214,6 +217,7 @@ internal class KVBackup( TRANSPORT_OK } catch (e: IOException) { Log.e(TAG, "Error uploading DB", e) + if (e.isOutOfSpace()) nm.onInsufficientSpaceError() TRANSPORT_ERROR } finally { this.state = null 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 347641f1..4e0ffd43 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/transport/CoordinatorIntegrationTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/transport/CoordinatorIntegrationTest.kt @@ -63,8 +63,14 @@ internal class CoordinatorIntegrationTest : TransportTest() { @Suppress("Deprecation") private val legacyPlugin = mockk() private val backupPlugin = mockk>() - private val kvBackup = - KVBackup(storagePluginManager, settingsManager, inputFactory, cryptoImpl, dbManager) + private val kvBackup = KVBackup( + pluginManager = storagePluginManager, + settingsManager = settingsManager, + nm = notificationManager, + inputFactory = inputFactory, + crypto = cryptoImpl, + dbManager = dbManager, + ) private val fullBackup = FullBackup( pluginManager = storagePluginManager, settingsManager = settingsManager, diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/KVBackupTest.kt b/app/src/test/java/com/stevesoltys/seedvault/transport/backup/KVBackupTest.kt index f9bbe264..a60c9a11 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/KVBackupTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/transport/backup/KVBackupTest.kt @@ -14,6 +14,7 @@ import com.stevesoltys.seedvault.header.VERSION import com.stevesoltys.seedvault.header.getADForKV import com.stevesoltys.seedvault.plugins.StoragePlugin import com.stevesoltys.seedvault.plugins.StoragePluginManager +import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager import io.mockk.CapturingSlot import io.mockk.Runs import io.mockk.coEvery @@ -34,10 +35,18 @@ import kotlin.random.Random internal class KVBackupTest : BackupTest() { private val pluginManager = mockk() + private val notificationManager = mockk() private val dataInput = mockk() private val dbManager = mockk() - private val backup = KVBackup(pluginManager, settingsManager, inputFactory, crypto, dbManager) + private val backup = KVBackup( + pluginManager = pluginManager, + settingsManager = settingsManager, + nm = notificationManager, + inputFactory = inputFactory, + crypto = crypto, + dbManager = dbManager + ) private val db = mockk() private val plugin = mockk>()