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())

View file

@ -13,7 +13,7 @@
<action
android:id="@+id/action_restore"
app:destination="@id/restoreBackupFragment"
app:destination="@id/restoreBackupFragmentV2"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
@ -60,7 +60,7 @@
<action
android:id="@+id/action_restore"
app:destination="@id/restoreBackupFragment"
app:destination="@id/restoreBackupFragmentV2"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
@ -96,7 +96,7 @@
<action
android:id="@+id/action_restore"
app:destination="@id/restoreBackupFragment"
app:destination="@id/restoreBackupFragmentV2"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
@ -284,7 +284,7 @@
tools:layout="@layout/fragment_registration_captcha" />
<fragment
android:id="@+id/restoreBackupFragment"
android:id="@+id/restoreBackupFragmentV2"
android:name="org.thoughtcrime.securesms.registration.fragments.RestoreBackupFragment"
android:label="fragment_restore_backup"
tools:layout="@layout/fragment_registration_restore_backup">
@ -296,7 +296,7 @@
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim"
app:popUpTo="@id/restoreBackupFragment"
app:popUpTo="@id/restoreBackupFragmentV2"
app:popUpToInclusive="true" />
<action
@ -314,7 +314,7 @@
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim"
app:popUpTo="@id/restoreBackupFragment"
app:popUpTo="@id/restoreBackupFragmentV2"
app:popUpToInclusive="true" />
<action
@ -324,7 +324,7 @@
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim"
app:popUpTo="@+id/restoreBackupFragment"
app:popUpTo="@+id/restoreBackupFragmentV2"
app:popUpToInclusive="true" />
<argument

View file

@ -58,32 +58,6 @@
</fragment>
<fragment
android:id="@+id/chooseBackupV2Fragment"
android:name="org.thoughtcrime.securesms.registration.fragments.ChooseBackupFragment"
android:label="fragment_choose_backup"
tools:layout="@layout/fragment_registration_choose_backup">
<action
android:id="@+id/action_restore"
app:destination="@id/restoreBackupV2Fragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim"
app:popUpTo="@id/chooseBackupV2Fragment"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_skip"
app:destination="@id/enterPhoneNumberV2Fragment"
app:enterAnim="@anim/slide_from_end"
app:exitAnim="@anim/slide_to_start"
app:popEnterAnim="@anim/slide_from_start"
app:popExitAnim="@anim/slide_to_end" />
</fragment>
<fragment
android:id="@+id/enterPhoneNumberV2Fragment"
android:name="org.thoughtcrime.securesms.registration.v2.ui.phonenumber.EnterPhoneNumberV2Fragment"
@ -245,58 +219,6 @@
android:label="fragment_captcha"
tools:layout="@layout/fragment_registration_captcha" />
<fragment
android:id="@+id/restoreBackupV2Fragment"
android:name="org.thoughtcrime.securesms.registration.fragments.RestoreBackupFragment"
android:label="fragment_restore_backup"
tools:layout="@layout/fragment_registration_restore_backup">
<action
android:id="@+id/action_backupRestored"
app:destination="@id/enterPhoneNumberV2Fragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim"
app:popUpTo="@id/restoreBackupV2Fragment"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_skip"
app:destination="@id/enterPhoneNumberV2Fragment"
app:enterAnim="@anim/slide_from_end"
app:exitAnim="@anim/slide_to_start"
app:popEnterAnim="@anim/slide_from_start"
app:popExitAnim="@anim/slide_to_end" />
<action
android:id="@+id/action_noBackupFound"
app:destination="@id/enterPhoneNumberV2Fragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim"
app:popUpTo="@id/restoreBackupV2Fragment"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_skip_no_return"
app:destination="@id/enterPhoneNumberV2Fragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim"
app:popUpTo="@+id/restoreBackupV2Fragment"
app:popUpToInclusive="true" />
<argument
android:name="uri"
android:defaultValue="@null"
app:argType="android.net.Uri"
app:nullable="true" />
</fragment>
<fragment
android:id="@+id/registrationCompletePlaceHolderV2Fragment"
android:name="org.thoughtcrime.securesms.registration.fragments.RegistrationCompleteFragment"
@ -309,137 +231,6 @@
android:label="fragment_registration_edit_proxy"
tools:layout="@layout/edit_proxy_fragment" />
<fragment
android:id="@+id/transferOrRestore"
android:name="org.thoughtcrime.securesms.devicetransfer.newdevice.TransferOrRestoreFragment"
tools:layout="@layout/fragment_transfer_restore">
<action
android:id="@+id/action_choose_backup"
app:destination="@id/chooseBackupV2Fragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
<action
android:id="@+id/action_new_device_transfer_instructions"
app:destination="@id/newDeviceTransferInstructions"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
<action
android:id="@+id/action_transferOrRestore_to_moreOptions"
app:destination="@+id/transferOrRestoreMoreOptionsDialog" />
</fragment>
<fragment
android:id="@+id/restoreFromBackupV2Fragment"
android:name="org.thoughtcrime.securesms.backup.v2.ui.restore.RestoreFromBackupFragment">
<action
android:id="@+id/action_restoreFromBacakupFragment_to_moreOptions"
app:destination="@+id/transferOrRestoreMoreOptionsDialog" />
<argument
android:name="cancelable"
app:argType="boolean" />
</fragment>
<dialog
android:id="@+id/transferOrRestoreMoreOptionsDialog"
android:name="org.thoughtcrime.securesms.devicetransfer.moreoptions.MoreTransferOrRestoreOptionsSheet">
<argument
android:name="mode"
app:argType="org.thoughtcrime.securesms.devicetransfer.moreoptions.MoreTransferOrRestoreOptionsMode" />
</dialog>
<fragment
android:id="@+id/newDeviceTransferInstructions"
android:name="org.thoughtcrime.securesms.devicetransfer.newdevice.NewDeviceTransferInstructionsFragment"
tools:layout="@layout/new_device_transfer_instructions_fragment">
<action
android:id="@+id/action_device_transfer_setup"
app:destination="@id/deviceTransferSetup"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</fragment>
<fragment
android:id="@+id/deviceTransferSetup"
android:name="org.thoughtcrime.securesms.devicetransfer.newdevice.NewDeviceTransferSetupFragment"
tools:layout="@layout/device_transfer_setup_fragment">
<action
android:id="@+id/action_new_device_transfer"
app:destination="@id/newDeviceTransfer"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
<action
android:id="@+id/action_deviceTransferSetup_to_transferOrRestore"
app:destination="@id/transferOrRestore"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim"
app:popUpTo="@id/transferOrRestore"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="@+id/newDeviceTransfer"
android:name="org.thoughtcrime.securesms.devicetransfer.newdevice.NewDeviceTransferFragment"
tools:layout="@layout/device_transfer_fragment">
<action
android:id="@+id/action_newDeviceTransfer_to_newDeviceTransferInstructions"
app:destination="@id/newDeviceTransferInstructions"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim"
app:popUpTo="@id/newDeviceTransferInstructions"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_newDeviceTransfer_to_newDeviceTransferComplete"
app:destination="@id/newDeviceTransferComplete"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim"
app:popUpTo="@id/welcomeV2Fragment" />
</fragment>
<fragment
android:id="@+id/newDeviceTransferComplete"
android:name="org.thoughtcrime.securesms.devicetransfer.newdevice.NewDeviceTransferCompleteFragment"
tools:layout="@layout/new_device_transfer_complete_fragment">
<action
android:id="@+id/action_newDeviceTransferComplete_to_enterPhoneNumberV2Fragment"
app:destination="@id/enterPhoneNumberV2Fragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</fragment>
<action
android:id="@+id/action_restart_to_welcomeV2Fragment"
app:destination="@id/welcomeV2Fragment"

View file

@ -7,17 +7,33 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/restore"
app:startDestination="@id/transfer_or_restore_v2_fragment">
app:startDestination="@id/transferOrRestore">
<fragment
android:id="@+id/transfer_or_restore_v2_fragment"
android:id="@+id/transferOrRestore"
android:name="org.thoughtcrime.securesms.restore.transferorrestore.TransferOrRestoreV2Fragment"
android:label="transfer_or_restore"
tools:layout="@layout/fragment_transfer_restore_v2">
<action
android:id="@+id/action_new_device_transfer_instructions"
app:destination="@id/newDeviceTransferInstructions"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
<action
android:id="@+id/action_transferOrRestore_to_moreOptions"
app:destination="@+id/transferOrRestoreMoreOptionsDialog" />
<action
android:id="@+id/action_transfer_or_restore_to_restore"
app:destination="@id/choose_local_backup_fragment" />
app:destination="@id/choose_local_backup_fragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim"/>
</fragment>
<fragment
@ -37,5 +53,158 @@
android:label="restore_local_backup"
tools:layout="@layout/fragment_restore_local_backup_v2">
<action
android:id="@id/action_backupRestored"
app:destination="@id/restoreCompleteFragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim"
app:popUpTo="@id/restoreBackupV2Fragment"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_skip"
app:destination="@id/restoreCompleteFragment"
app:enterAnim="@anim/slide_from_end"
app:exitAnim="@anim/slide_to_start"
app:popEnterAnim="@anim/slide_from_start"
app:popExitAnim="@anim/slide_to_end" />
<action
android:id="@+id/action_noBackupFound"
app:destination="@id/restoreCompleteFragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim"
app:popUpTo="@id/restoreBackupV2Fragment"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_skip_no_return"
app:destination="@id/restoreCompleteFragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim"
app:popUpTo="@+id/restoreBackupV2Fragment"
app:popUpToInclusive="true" />
<argument
android:name="uri"
android:defaultValue="@null"
app:argType="android.net.Uri"
app:nullable="true" />
</fragment>
<dialog
android:id="@+id/transferOrRestoreMoreOptionsDialog"
android:name="org.thoughtcrime.securesms.devicetransfer.moreoptions.MoreTransferOrRestoreOptionsSheet">
<argument
android:name="mode"
app:argType="org.thoughtcrime.securesms.devicetransfer.moreoptions.MoreTransferOrRestoreOptionsMode" />
</dialog>
<fragment
android:id="@+id/newDeviceTransferInstructions"
android:name="org.thoughtcrime.securesms.devicetransfer.newdevice.NewDeviceTransferInstructionsFragment"
tools:layout="@layout/new_device_transfer_instructions_fragment">
<action
android:id="@+id/action_device_transfer_setup"
app:destination="@id/deviceTransferSetup"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</fragment>
<fragment
android:id="@+id/deviceTransferSetup"
android:name="org.thoughtcrime.securesms.devicetransfer.newdevice.NewDeviceTransferSetupFragment"
tools:layout="@layout/device_transfer_setup_fragment">
<action
android:id="@+id/action_new_device_transfer"
app:destination="@id/newDeviceTransfer"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
<action
android:id="@+id/action_deviceTransferSetup_to_transferOrRestore"
app:destination="@id/transferOrRestore"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim"
app:popUpTo="@id/transferOrRestore"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="@+id/newDeviceTransfer"
android:name="org.thoughtcrime.securesms.devicetransfer.newdevice.NewDeviceTransferFragment"
tools:layout="@layout/device_transfer_fragment">
<action
android:id="@+id/action_newDeviceTransfer_to_newDeviceTransferInstructions"
app:destination="@id/newDeviceTransferInstructions"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim"
app:popUpTo="@id/newDeviceTransferInstructions"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_newDeviceTransfer_to_newDeviceTransferComplete"
app:destination="@id/newDeviceTransferComplete"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim"
app:popUpTo="@id/welcomeV2Fragment" />
</fragment>
<fragment
android:id="@+id/newDeviceTransferComplete"
android:name="org.thoughtcrime.securesms.devicetransfer.newdevice.NewDeviceTransferCompleteFragment"
tools:layout="@layout/new_device_transfer_complete_fragment">
<action
android:id="@+id/action_newDeviceTransferComplete_to_enterPhoneNumberFragment"
app:destination="@id/restoreCompleteFragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</fragment>
<fragment
android:id="@+id/restoreFromBackupFragment"
android:name="org.thoughtcrime.securesms.backup.v2.ui.restore.RestoreFromBackupFragment">
<action
android:id="@+id/action_restoreFromBacakupFragment_to_moreOptions"
app:destination="@+id/transferOrRestoreMoreOptionsDialog" />
<argument
android:name="cancelable"
app:argType="boolean" />
</fragment>
<fragment
android:id="@+id/restoreCompleteFragment"
android:name="org.thoughtcrime.securesms.restore.restorecomplete.RestoreCompleteV2Fragment" />
</navigation>