Don't do backup, if space is already low, warn instead
This commit is contained in:
parent
36910fc777
commit
49262682d1
2 changed files with 22 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
||||||
package com.stevesoltys.seedvault.plugins
|
package com.stevesoltys.seedvault.plugins
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.util.Log
|
||||||
import androidx.annotation.WorkerThread
|
import androidx.annotation.WorkerThread
|
||||||
import com.stevesoltys.seedvault.getStorageContext
|
import com.stevesoltys.seedvault.getStorageContext
|
||||||
import com.stevesoltys.seedvault.permitDiskReads
|
import com.stevesoltys.seedvault.permitDiskReads
|
||||||
|
@ -131,4 +132,17 @@ class StoragePluginManager(
|
||||||
return storage.isUnavailableUsb(systemContext)
|
return storage.isUnavailableUsb(systemContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the amount of free space in bytes, or null if unknown.
|
||||||
|
*/
|
||||||
|
@WorkerThread
|
||||||
|
suspend fun getFreeSpace(): Long? {
|
||||||
|
return try {
|
||||||
|
appPlugin.getFreeSpace()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("StoragePluginManager", "Error getting free space: ", e)
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import androidx.work.OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST
|
||||||
import androidx.work.PeriodicWorkRequestBuilder
|
import androidx.work.PeriodicWorkRequestBuilder
|
||||||
import androidx.work.WorkManager
|
import androidx.work.WorkManager
|
||||||
import androidx.work.WorkerParameters
|
import androidx.work.WorkerParameters
|
||||||
|
import com.stevesoltys.seedvault.plugins.StoragePluginManager
|
||||||
import com.stevesoltys.seedvault.settings.SettingsManager
|
import com.stevesoltys.seedvault.settings.SettingsManager
|
||||||
import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager
|
import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager
|
||||||
import com.stevesoltys.seedvault.ui.notification.NOTIFICATION_ID_OBSERVER
|
import com.stevesoltys.seedvault.ui.notification.NOTIFICATION_ID_OBSERVER
|
||||||
|
@ -38,6 +39,7 @@ class AppBackupWorker(
|
||||||
private val TAG = AppBackupWorker::class.simpleName
|
private val TAG = AppBackupWorker::class.simpleName
|
||||||
internal const val UNIQUE_WORK_NAME = "com.stevesoltys.seedvault.APP_BACKUP"
|
internal const val UNIQUE_WORK_NAME = "com.stevesoltys.seedvault.APP_BACKUP"
|
||||||
private const val TAG_RESCHEDULE = "com.stevesoltys.seedvault.TAG_RESCHEDULE"
|
private const val TAG_RESCHEDULE = "com.stevesoltys.seedvault.TAG_RESCHEDULE"
|
||||||
|
private const val MIN_FREE_SPACE = 1024 * 1024 * 500 // 500 MB
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (Re-)schedules the [AppBackupWorker].
|
* (Re-)schedules the [AppBackupWorker].
|
||||||
|
@ -99,6 +101,7 @@ class AppBackupWorker(
|
||||||
private val backupRequester: BackupRequester by inject()
|
private val backupRequester: BackupRequester by inject()
|
||||||
private val settingsManager: SettingsManager by inject()
|
private val settingsManager: SettingsManager by inject()
|
||||||
private val apkBackupManager: ApkBackupManager by inject()
|
private val apkBackupManager: ApkBackupManager by inject()
|
||||||
|
private val storagePluginManager: StoragePluginManager by inject()
|
||||||
private val nm: BackupNotificationManager by inject()
|
private val nm: BackupNotificationManager by inject()
|
||||||
|
|
||||||
override suspend fun doWork(): Result {
|
override suspend fun doWork(): Result {
|
||||||
|
@ -108,6 +111,11 @@ class AppBackupWorker(
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Error while running setForeground: ", e)
|
Log.e(TAG, "Error while running setForeground: ", e)
|
||||||
}
|
}
|
||||||
|
val freeSpace = storagePluginManager.getFreeSpace()
|
||||||
|
if (freeSpace != null && freeSpace < MIN_FREE_SPACE) {
|
||||||
|
nm.onInsufficientSpaceError()
|
||||||
|
return Result.failure()
|
||||||
|
}
|
||||||
return try {
|
return try {
|
||||||
if (isStopped) {
|
if (isStopped) {
|
||||||
Result.retry()
|
Result.retry()
|
||||||
|
|
Loading…
Reference in a new issue