mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-22 12:08:34 +00:00
Increase logging around backup restores.
This commit is contained in:
@@ -41,7 +41,7 @@ object RestoreRepository {
|
|||||||
suspend fun restoreBackupAsynchronously(context: Context, backupFileUri: Uri, passphrase: String): BackupImportResult = withContext(Dispatchers.IO) {
|
suspend fun restoreBackupAsynchronously(context: Context, backupFileUri: Uri, passphrase: String): BackupImportResult = withContext(Dispatchers.IO) {
|
||||||
// TODO [regv2]: migrate this to a service
|
// TODO [regv2]: migrate this to a service
|
||||||
try {
|
try {
|
||||||
Log.i(TAG, "Starting backup restore.")
|
Log.i(TAG, "Initiating backup restore.")
|
||||||
DataRestoreConstraint.isRestoringData = true
|
DataRestoreConstraint.isRestoringData = true
|
||||||
|
|
||||||
val database = SignalDatabase.backupDatabase
|
val database = SignalDatabase.backupDatabase
|
||||||
@@ -49,10 +49,12 @@ object RestoreRepository {
|
|||||||
BackupPassphrase.set(context, passphrase)
|
BackupPassphrase.set(context, passphrase)
|
||||||
|
|
||||||
if (!FullBackupImporter.validatePassphrase(context, backupFileUri, 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
|
return@withContext BackupImportResult.FAILURE_UNKNOWN
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.i(TAG, "Passphrase validated.")
|
||||||
|
|
||||||
FullBackupImporter.importFile(
|
FullBackupImporter.importFile(
|
||||||
context,
|
context,
|
||||||
AttachmentSecretProvider.getInstance(context).getOrCreateAttachmentSecret(),
|
AttachmentSecretProvider.getInstance(context).getOrCreateAttachmentSecret(),
|
||||||
@@ -61,6 +63,8 @@ object RestoreRepository {
|
|||||||
passphrase
|
passphrase
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Log.i(TAG, "Backup importer complete.")
|
||||||
|
|
||||||
SignalDatabase.runPostBackupRestoreTasks(database)
|
SignalDatabase.runPostBackupRestoreTasks(database)
|
||||||
NotificationChannels.getInstance().restoreContactNotificationChannels()
|
NotificationChannels.getInstance().restoreContactNotificationChannels()
|
||||||
|
|
||||||
@@ -81,7 +85,7 @@ object RestoreRepository {
|
|||||||
Log.w(TAG, "Failed due to foreign key constraint violations.", e)
|
Log.w(TAG, "Failed due to foreign key constraint violations.", e)
|
||||||
return@withContext BackupImportResult.FAILURE_FOREIGN_KEY
|
return@withContext BackupImportResult.FAILURE_FOREIGN_KEY
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
Log.w(TAG, e)
|
Log.w(TAG, "Restore failed due to unknown error!", e)
|
||||||
return@withContext BackupImportResult.FAILURE_UNKNOWN
|
return@withContext BackupImportResult.FAILURE_UNKNOWN
|
||||||
} finally {
|
} finally {
|
||||||
DataRestoreConstraint.isRestoringData = false
|
DataRestoreConstraint.isRestoringData = false
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ class RestoreLocalBackupFragment : LoggingFragment(R.layout.fragment_restore_loc
|
|||||||
binding.restoreButton.setOnClickListener { presentBackupPassPhrasePromptDialog() }
|
binding.restoreButton.setOnClickListener { presentBackupPassPhrasePromptDialog() }
|
||||||
|
|
||||||
binding.cancelLocalRestoreButton.setOnClickListener {
|
binding.cancelLocalRestoreButton.setOnClickListener {
|
||||||
|
Log.i(TAG, "Cancel clicked.")
|
||||||
findNavController().navigateUp()
|
findNavController().navigateUp()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,10 +147,21 @@ class RestoreLocalBackupFragment : LoggingFragment(R.layout.fragment_restore_loc
|
|||||||
|
|
||||||
private fun handleBackupImportError(importResult: RestoreRepository.BackupImportResult) {
|
private fun handleBackupImportError(importResult: RestoreRepository.BackupImportResult) {
|
||||||
when (importResult) {
|
when (importResult) {
|
||||||
RestoreRepository.BackupImportResult.FAILURE_VERSION_DOWNGRADE -> Toast.makeText(requireContext(), R.string.RegistrationActivity_backup_failure_downgrade, Toast.LENGTH_LONG).show()
|
RestoreRepository.BackupImportResult.FAILURE_VERSION_DOWNGRADE -> {
|
||||||
RestoreRepository.BackupImportResult.FAILURE_FOREIGN_KEY -> Toast.makeText(requireContext(), R.string.RegistrationActivity_backup_failure_foreign_key, Toast.LENGTH_LONG).show()
|
Log.i(TAG, "Notifying user of restore failure due to version downgrade.")
|
||||||
RestoreRepository.BackupImportResult.FAILURE_UNKNOWN -> Toast.makeText(requireContext(), R.string.RegistrationActivity_incorrect_backup_passphrase, Toast.LENGTH_LONG).show()
|
Toast.makeText(requireContext(), R.string.RegistrationActivity_backup_failure_downgrade, Toast.LENGTH_LONG).show()
|
||||||
RestoreRepository.BackupImportResult.SUCCESS -> Log.w(TAG, "Successful backup import should not be handled in this function.", IllegalStateException())
|
}
|
||||||
|
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())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user