Increase logging around backup restores.

This commit is contained in:
Nicholas Tinsley 2024-08-27 10:47:49 -04:00
parent ff47f784a3
commit b7af1e09e2
2 changed files with 23 additions and 7 deletions

View file

@ -41,7 +41,7 @@ object RestoreRepository {
suspend fun restoreBackupAsynchronously(context: Context, backupFileUri: Uri, passphrase: String): BackupImportResult = withContext(Dispatchers.IO) {
// TODO [regv2]: migrate this to a service
try {
Log.i(TAG, "Starting backup restore.")
Log.i(TAG, "Initiating backup restore.")
DataRestoreConstraint.isRestoringData = true
val database = SignalDatabase.backupDatabase
@ -49,10 +49,12 @@ object RestoreRepository {
BackupPassphrase.set(context, passphrase)
if (!FullBackupImporter.validatePassphrase(context, backupFileUri, passphrase)) {
// TODO [regv2]: implement a specific, user-visible error for wrong passphrase.
Log.i(TAG, "Restore failed due to invalid passphrase.")
return@withContext BackupImportResult.FAILURE_UNKNOWN
}
Log.i(TAG, "Passphrase validated.")
FullBackupImporter.importFile(
context,
AttachmentSecretProvider.getInstance(context).getOrCreateAttachmentSecret(),
@ -61,6 +63,8 @@ object RestoreRepository {
passphrase
)
Log.i(TAG, "Backup importer complete.")
SignalDatabase.runPostBackupRestoreTasks(database)
NotificationChannels.getInstance().restoreContactNotificationChannels()
@ -81,7 +85,7 @@ object RestoreRepository {
Log.w(TAG, "Failed due to foreign key constraint violations.", e)
return@withContext BackupImportResult.FAILURE_FOREIGN_KEY
} catch (e: IOException) {
Log.w(TAG, e)
Log.w(TAG, "Restore failed due to unknown error!", e)
return@withContext BackupImportResult.FAILURE_UNKNOWN
} finally {
DataRestoreConstraint.isRestoringData = false

View file

@ -64,6 +64,7 @@ class RestoreLocalBackupFragment : LoggingFragment(R.layout.fragment_restore_loc
binding.restoreButton.setOnClickListener { presentBackupPassPhrasePromptDialog() }
binding.cancelLocalRestoreButton.setOnClickListener {
Log.i(TAG, "Cancel clicked.")
findNavController().navigateUp()
}
@ -146,10 +147,21 @@ class RestoreLocalBackupFragment : LoggingFragment(R.layout.fragment_restore_loc
private fun handleBackupImportError(importResult: RestoreRepository.BackupImportResult) {
when (importResult) {
RestoreRepository.BackupImportResult.FAILURE_VERSION_DOWNGRADE -> Toast.makeText(requireContext(), R.string.RegistrationActivity_backup_failure_downgrade, Toast.LENGTH_LONG).show()
RestoreRepository.BackupImportResult.FAILURE_FOREIGN_KEY -> Toast.makeText(requireContext(), R.string.RegistrationActivity_backup_failure_foreign_key, Toast.LENGTH_LONG).show()
RestoreRepository.BackupImportResult.FAILURE_UNKNOWN -> Toast.makeText(requireContext(), R.string.RegistrationActivity_incorrect_backup_passphrase, Toast.LENGTH_LONG).show()
RestoreRepository.BackupImportResult.SUCCESS -> Log.w(TAG, "Successful backup import should not be handled in this function.", IllegalStateException())
RestoreRepository.BackupImportResult.FAILURE_VERSION_DOWNGRADE -> {
Log.i(TAG, "Notifying user of restore failure due to version downgrade.")
Toast.makeText(requireContext(), R.string.RegistrationActivity_backup_failure_downgrade, Toast.LENGTH_LONG).show()
}
RestoreRepository.BackupImportResult.FAILURE_FOREIGN_KEY -> {
Log.i(TAG, "Notifying user of restore failure due to foreign key.")
Toast.makeText(requireContext(), R.string.RegistrationActivity_backup_failure_foreign_key, Toast.LENGTH_LONG).show()
}
RestoreRepository.BackupImportResult.FAILURE_UNKNOWN -> {
Log.i(TAG, "Notifying user of restore failure due to incorrect passphrase.")
Toast.makeText(requireContext(), R.string.RegistrationActivity_incorrect_backup_passphrase, Toast.LENGTH_LONG).show()
}
RestoreRepository.BackupImportResult.SUCCESS -> {
Log.w(TAG, "Successful backup import should not be handled in this function.", IllegalStateException())
}
}
}