mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-24 02:39:55 +01:00
Move restore messages out of durable job.
This commit is contained in:
@@ -311,7 +311,8 @@ private fun BackupAvailableContent(
|
||||
when (state.importState) {
|
||||
RemoteRestoreViewModel.ImportState.None -> Unit
|
||||
RemoteRestoreViewModel.ImportState.InProgress -> RestoreProgressDialog(state.restoreProgress)
|
||||
is RemoteRestoreViewModel.ImportState.Restored -> Unit
|
||||
RemoteRestoreViewModel.ImportState.Restored -> Unit
|
||||
RemoteRestoreViewModel.ImportState.NetworkFailure -> RestoreNetworkFailedDialog(onDismiss = onImportErrorDialogDismiss)
|
||||
RemoteRestoreViewModel.ImportState.Failed -> {
|
||||
if (SignalStore.backup.hasInvalidBackupVersion) {
|
||||
InvalidBackupVersionDialog(onUpdateSignal = onUpdateSignal, onDismiss = onImportErrorDialogDismiss)
|
||||
@@ -490,6 +491,19 @@ fun RestoreFailedDialog(
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun RestoreNetworkFailedDialog(
|
||||
onDismiss: () -> Unit = {}
|
||||
) {
|
||||
Dialogs.SimpleAlertDialog(
|
||||
title = stringResource(R.string.RemoteRestoreActivity__couldnt_transfer),
|
||||
body = stringResource(R.string.RegistrationActivity_error_connecting_to_service),
|
||||
confirm = stringResource(android.R.string.ok),
|
||||
onConfirm = onDismiss,
|
||||
onDismiss = onDismiss
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun TierRestoreFailedDialog(
|
||||
loadAttempts: Int = 0,
|
||||
|
||||
@@ -8,11 +8,9 @@ package org.thoughtcrime.securesms.registrationv3.ui.restore
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
@@ -21,12 +19,9 @@ import org.signal.core.util.bytes
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.thoughtcrime.securesms.backup.v2.BackupRepository
|
||||
import org.thoughtcrime.securesms.backup.v2.MessageBackupTier
|
||||
import org.thoughtcrime.securesms.backup.v2.RemoteRestoreResult
|
||||
import org.thoughtcrime.securesms.backup.v2.RestoreV2Event
|
||||
import org.thoughtcrime.securesms.database.model.databaseprotos.RestoreDecisionState
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies
|
||||
import org.thoughtcrime.securesms.jobmanager.JobTracker
|
||||
import org.thoughtcrime.securesms.jobs.BackupRestoreJob
|
||||
import org.thoughtcrime.securesms.jobs.BackupRestoreMediaJob
|
||||
import org.thoughtcrime.securesms.keyvalue.Completed
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.keyvalue.Skipped
|
||||
@@ -97,44 +92,25 @@ class RemoteRestoreViewModel(isOnlyRestoreOption: Boolean) : ViewModel() {
|
||||
withContext(Dispatchers.IO) {
|
||||
QuickRegistrationRepository.setRestoreMethodForOldDevice(RestoreMethod.REMOTE_BACKUP)
|
||||
|
||||
val jobStateFlow = callbackFlow {
|
||||
val listener = JobTracker.JobListener { _, jobState ->
|
||||
trySend(jobState)
|
||||
when (val result = BackupRepository.restoreRemoteBackup()) {
|
||||
RemoteRestoreResult.Success -> {
|
||||
Log.i(TAG, "Restore successful")
|
||||
SignalStore.registration.restoreDecisionState = RestoreDecisionState.Completed
|
||||
|
||||
StorageServiceRestore.restore()
|
||||
|
||||
store.update { it.copy(importState = ImportState.Restored) }
|
||||
}
|
||||
|
||||
AppDependencies
|
||||
.jobManager
|
||||
.startChain(BackupRestoreJob())
|
||||
.then(BackupRestoreMediaJob())
|
||||
.enqueue(listener)
|
||||
|
||||
awaitClose {
|
||||
AppDependencies.jobManager.removeListener(listener)
|
||||
RemoteRestoreResult.NetworkError -> {
|
||||
Log.w(TAG, "Restore failed to download")
|
||||
store.update { it.copy(importState = ImportState.NetworkFailure) }
|
||||
}
|
||||
}
|
||||
|
||||
jobStateFlow.collect { state ->
|
||||
when (state) {
|
||||
JobTracker.JobState.SUCCESS -> {
|
||||
Log.i(TAG, "Restore successful")
|
||||
SignalStore.registration.restoreDecisionState = RestoreDecisionState.Completed
|
||||
|
||||
StorageServiceRestore.restore()
|
||||
|
||||
store.update { it.copy(importState = ImportState.Restored) }
|
||||
}
|
||||
|
||||
JobTracker.JobState.PENDING,
|
||||
JobTracker.JobState.RUNNING -> {
|
||||
Log.i(TAG, "Restore job states updated: $state")
|
||||
}
|
||||
|
||||
JobTracker.JobState.FAILURE,
|
||||
JobTracker.JobState.IGNORED -> {
|
||||
Log.w(TAG, "Restore failed with $state")
|
||||
|
||||
store.update { it.copy(importState = ImportState.Failed) }
|
||||
}
|
||||
RemoteRestoreResult.Canceled,
|
||||
RemoteRestoreResult.Failure -> {
|
||||
Log.w(TAG, "Restore failed with $result")
|
||||
store.update { it.copy(importState = ImportState.Failed) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -195,6 +171,7 @@ class RemoteRestoreViewModel(isOnlyRestoreOption: Boolean) : ViewModel() {
|
||||
data object None : ImportState
|
||||
data object InProgress : ImportState
|
||||
data object Restored : ImportState
|
||||
data object NetworkFailure : ImportState
|
||||
data object Failed : ImportState
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user