mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-20 19:18:37 +00:00
Add error case for when you don't have enough disk space to create a backup.
This commit is contained in:
committed by
Alex Hart
parent
ccdec5113f
commit
dd8104bf61
@@ -88,6 +88,12 @@ fun BackupCreateErrorRow(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BackupValues.BackupCreationError.NOT_ENOUGH_DISK_SPACE -> {
|
||||||
|
BackupAlertText {
|
||||||
|
append(stringResource(R.string.BackupStatusRow__not_enough_disk_space, DateUtils.getDayPrecisionTimeString(context, locale, lastMessageCutoffTime)))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import android.content.pm.PackageManager
|
|||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import androidx.core.app.NotificationManagerCompat
|
import androidx.core.app.NotificationManagerCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import okio.IOException
|
||||||
import org.signal.core.util.PendingIntentFlags
|
import org.signal.core.util.PendingIntentFlags
|
||||||
import org.signal.core.util.Stopwatch
|
import org.signal.core.util.Stopwatch
|
||||||
import org.signal.core.util.isNotNullOrBlank
|
import org.signal.core.util.isNotNullOrBlank
|
||||||
@@ -445,22 +446,32 @@ class BackupMessagesJob private constructor(
|
|||||||
val attachmentInfoBuffer: MutableSet<ArchiveAttachmentInfo> = mutableSetOf()
|
val attachmentInfoBuffer: MutableSet<ArchiveAttachmentInfo> = mutableSetOf()
|
||||||
val messageInclusionCutoffTime = SignalStore.backup.messageCuttoffDuration?.let { currentTime - it.inWholeMilliseconds } ?: 0
|
val messageInclusionCutoffTime = SignalStore.backup.messageCuttoffDuration?.let { currentTime - it.inWholeMilliseconds } ?: 0
|
||||||
|
|
||||||
BackupRepository.exportForSignalBackup(
|
try {
|
||||||
outputStream = outputStream,
|
BackupRepository.exportForSignalBackup(
|
||||||
messageBackupKey = backupKey,
|
outputStream = outputStream,
|
||||||
forwardSecrecyMetadata = forwardSecrecyMetadata,
|
messageBackupKey = backupKey,
|
||||||
forwardSecrecyToken = forwardSecrecyToken,
|
forwardSecrecyMetadata = forwardSecrecyMetadata,
|
||||||
progressEmitter = ArchiveUploadProgress.ArchiveBackupProgressListener,
|
forwardSecrecyToken = forwardSecrecyToken,
|
||||||
append = { tempBackupFile.appendBytes(it) },
|
progressEmitter = ArchiveUploadProgress.ArchiveBackupProgressListener,
|
||||||
cancellationSignal = { this.isCanceled },
|
append = { tempBackupFile.appendBytes(it) },
|
||||||
currentTime = currentTime,
|
cancellationSignal = { this.isCanceled },
|
||||||
messageInclusionCutoffTime = messageInclusionCutoffTime
|
currentTime = currentTime,
|
||||||
) { frame ->
|
messageInclusionCutoffTime = messageInclusionCutoffTime
|
||||||
attachmentInfoBuffer += frame.getAllReferencedArchiveAttachmentInfos()
|
) { frame ->
|
||||||
if (attachmentInfoBuffer.size > ATTACHMENT_SNAPSHOT_BUFFER_SIZE) {
|
attachmentInfoBuffer += frame.getAllReferencedArchiveAttachmentInfos()
|
||||||
SignalDatabase.backupMediaSnapshots.writePendingMediaEntries(attachmentInfoBuffer.toFullSizeMediaEntries(mediaRootBackupKey))
|
if (attachmentInfoBuffer.size > ATTACHMENT_SNAPSHOT_BUFFER_SIZE) {
|
||||||
SignalDatabase.backupMediaSnapshots.writePendingMediaEntries(attachmentInfoBuffer.toThumbnailMediaEntries(mediaRootBackupKey))
|
SignalDatabase.backupMediaSnapshots.writePendingMediaEntries(attachmentInfoBuffer.toFullSizeMediaEntries(mediaRootBackupKey))
|
||||||
attachmentInfoBuffer.clear()
|
SignalDatabase.backupMediaSnapshots.writePendingMediaEntries(attachmentInfoBuffer.toThumbnailMediaEntries(mediaRootBackupKey))
|
||||||
|
attachmentInfoBuffer.clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: IOException) {
|
||||||
|
if (e.message?.contains("ENOSPC") == true) {
|
||||||
|
Log.w(TAG, "Not enough space to make a backup!", e, true)
|
||||||
|
tempBackupFile.delete()
|
||||||
|
this.dataFile = ""
|
||||||
|
BackupRepository.markBackupCreationFailed(BackupValues.BackupCreationError.NOT_ENOUGH_DISK_SPACE)
|
||||||
|
return BackupFileResult.Failure
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -602,11 +602,14 @@ class BackupValues(store: KeyValueStore) : SignalStoreValues(store) {
|
|||||||
/** A temporary failure, usually cause by poor network. */
|
/** A temporary failure, usually cause by poor network. */
|
||||||
TRANSIENT(1),
|
TRANSIENT(1),
|
||||||
|
|
||||||
/** The validation of the backup file failed. This likely cannot be fixed without an app update. */
|
/** The validation of the backup file failed. This likely cannot be fixed without an app update. */
|
||||||
VALIDATION(2),
|
VALIDATION(2),
|
||||||
|
|
||||||
/** The backup file itself is too large. The only resolution would be for the user to delete some number of messages. */
|
/** The backup file itself is too large. The only resolution would be for the user to delete some number of messages. */
|
||||||
BACKUP_FILE_TOO_LARGE(3);
|
BACKUP_FILE_TOO_LARGE(3),
|
||||||
|
|
||||||
|
/** We do not have enough space on the device to create the backup file. */
|
||||||
|
NOT_ENOUGH_DISK_SPACE(4);
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
|||||||
@@ -8058,6 +8058,8 @@
|
|||||||
<string name="BackupStatusRow__backup_file_too_large">The number of messages you have exceeds the storage limit. Delete some messages and try again.</string>
|
<string name="BackupStatusRow__backup_file_too_large">The number of messages you have exceeds the storage limit. Delete some messages and try again.</string>
|
||||||
<!-- Text displayed when we're not backing up all messages. The placeholder represents the cutoff date for the messages we're backing up. -->
|
<!-- Text displayed when we're not backing up all messages. The placeholder represents the cutoff date for the messages we're backing up. -->
|
||||||
<string name="BackupStatusRow__not_backing_up_old_messages">Messages sent or received before %1$s are not being backed up.</string>
|
<string name="BackupStatusRow__not_backing_up_old_messages">Messages sent or received before %1$s are not being backed up.</string>
|
||||||
|
<!-- Text displayed when we failed to create a backup because of low disk space. -->
|
||||||
|
<string name="BackupStatusRow__not_enough_disk_space">Your backup couldn\'t be completed because you are low on disk space. Free up space on your device and try again.</string>
|
||||||
<!-- Text displayed in a row to learn more about why a backup failed -->
|
<!-- Text displayed in a row to learn more about why a backup failed -->
|
||||||
<string name="BackupStatusRow__learn_more">Learn more</string>
|
<string name="BackupStatusRow__learn_more">Learn more</string>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user