Support device transfers in restore flow v2.

This commit is contained in:
Nicholas Tinsley
2024-05-03 10:59:04 -04:00
committed by Alex Hart
parent 35232a3928
commit 0a3f96935a
8 changed files with 230 additions and 226 deletions

View File

@@ -12,9 +12,7 @@ package org.thoughtcrime.securesms.registration.v2.ui
enum class RegistrationCheckpoint {
INITIALIZATION,
PERMISSIONS_GRANTED,
BACKUP_DETECTED,
BACKUP_SELECTED,
BACKUP_RESTORED,
BACKUP_RESTORED_OR_SKIPPED,
PUSH_NETWORK_AUDITED,
PHONE_NUMBER_CONFIRMED,
PIN_CONFIRMED,

View File

@@ -99,7 +99,7 @@ class RegistrationV2ViewModel : ViewModel() {
fun onBackupSuccessfullyRestored() {
val recoveryPassword = SignalStore.svr().recoveryPassword
store.update {
it.copy(registrationCheckpoint = RegistrationCheckpoint.BACKUP_RESTORED, recoveryPassword = SignalStore.svr().recoveryPassword, canSkipSms = recoveryPassword != null)
it.copy(registrationCheckpoint = RegistrationCheckpoint.BACKUP_RESTORED_OR_SKIPPED, recoveryPassword = SignalStore.svr().recoveryPassword, canSkipSms = recoveryPassword != null)
}
}

View File

@@ -0,0 +1,40 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.thoughtcrime.securesms.restore.restorecomplete
import android.os.Bundle
import android.view.View
import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.LoggingFragment
import org.thoughtcrime.securesms.R
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.restore.RestoreActivity
/**
* This is a hack placeholder fragment so we can reuse the existing V1 device transfer fragments without changing their navigation calls.
* The original calls expect to be navigating from the [NewDeviceTransferCompleteFragment] to [EnterPhoneNumberFragment]
* This approximates that by taking the place of [EnterPhoneNumberFragment],
* then bridging us back to [RegistrationV2Activity] by immediately closing the [RestoreActivity].
*/
class RestoreCompleteV2Fragment : LoggingFragment(R.layout.fragment_registration_blank) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Log.d(TAG, "Finishing activity…")
onBackupCompletedSuccessfully()
}
private fun onBackupCompletedSuccessfully() {
Log.d(TAG, "onBackupCompletedSuccessfully()")
SignalStore.internalValues().setForceEnterRestoreV2Flow(false)
val activity = requireActivity() as RestoreActivity
activity.finishActivitySuccessfully()
}
companion object {
private val TAG = Log.tag(RestoreCompleteV2Fragment::class.java)
}
}

View File

@@ -55,6 +55,14 @@ class RestoreLocalBackupFragment : LoggingFragment(R.layout.fragment_restore_loc
binding.restoreButton.setOnClickListener { presentBackupPassPhrasePromptDialog() }
// TODO [regv2]: check for re-register and skip ahead to phone number entry
if (SignalStore.settings().isBackupEnabled) {
Log.i(TAG, "Backups enabled, so a backup must have been previously restored.")
onBackupCompletedSuccessfully()
return
}
restoreLocalBackupViewModel.uiState.observe(viewLifecycleOwner) { fragmentState ->
fragmentState.backupInfo?.let {
presentBackupFileInfo(backupSize = it.size, backupTimestamp = it.timestamp)

View File

@@ -66,9 +66,7 @@ class TransferOrRestoreV2Fragment : LoggingFragment(R.layout.fragment_transfer_r
private fun launchSelection(restorationType: BackupRestorationType) {
when (restorationType) {
BackupRestorationType.DEVICE_TRANSFER -> {
// TODO [regv2]
Log.w(TAG, "Not yet implemented!", NotImplementedError())
Toast.makeText(requireContext(), "Not yet implemented!", Toast.LENGTH_LONG).show()
NavHostFragment.findNavController(this).safeNavigate(TransferOrRestoreV2FragmentDirections.actionNewDeviceTransferInstructions())
}
BackupRestorationType.LOCAL_BACKUP -> {
NavHostFragment.findNavController(this).safeNavigate(TransferOrRestoreV2FragmentDirections.actionTransferOrRestoreToRestore())