mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 13:08:46 +00:00
Registration V2 restore tweaks.
This commit is contained in:
committed by
Cody Henthorne
parent
500a1e46ad
commit
9af1c72233
@@ -71,6 +71,7 @@ import org.whispersystems.signalservice.internal.push.AuthCredentials
|
||||
import org.whispersystems.signalservice.internal.push.PushServiceSocket
|
||||
import org.whispersystems.signalservice.internal.push.RegistrationSessionMetadataHeaders
|
||||
import org.whispersystems.signalservice.internal.push.RegistrationSessionMetadataResponse
|
||||
import org.whispersystems.signalservice.internal.push.VerifyAccountResponse
|
||||
import java.io.IOException
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.Locale
|
||||
@@ -159,6 +160,7 @@ object RegistrationRepository {
|
||||
@JvmStatic
|
||||
suspend fun registerAccountLocally(context: Context, registrationData: RegistrationData, response: AccountRegistrationResult, reglockEnabled: Boolean) =
|
||||
withContext(Dispatchers.IO) {
|
||||
Log.v(TAG, "registerAccountLocally()")
|
||||
val aciPreKeyCollection: PreKeyCollection = response.aciPreKeyCollection
|
||||
val pniPreKeyCollection: PreKeyCollection = response.pniPreKeyCollection
|
||||
val aci: ACI = ACI.parseOrThrow(response.uuid)
|
||||
@@ -422,7 +424,7 @@ object RegistrationRepository {
|
||||
val pniPreKeyCollection = org.thoughtcrime.securesms.registration.RegistrationRepository.generateSignedAndLastResortPreKeys(pniIdentity, SignalStore.account().pniPreKeys)
|
||||
|
||||
val result: NetworkResult<AccountRegistrationResult> = api.registerAccount(sessionId, registrationData.recoveryPassword, accountAttributes, aciPreKeyCollection, pniPreKeyCollection, registrationData.fcmToken, true)
|
||||
.map { accountRegistrationResponse ->
|
||||
.map { accountRegistrationResponse: VerifyAccountResponse ->
|
||||
AccountRegistrationResult(
|
||||
uuid = accountRegistrationResponse.uuid,
|
||||
pni = accountRegistrationResponse.pni,
|
||||
|
||||
@@ -494,7 +494,7 @@ class RegistrationV2ViewModel : ViewModel() {
|
||||
Log.v(TAG, "handleRegistrationResult()")
|
||||
when (registrationResult) {
|
||||
is RegisterAccountResult.Success -> {
|
||||
Log.i(TAG, "Register account result: Success!")
|
||||
Log.i(TAG, "Register account result: Success! Registration lock: $reglockEnabled")
|
||||
onSuccessfulRegistration(context, registrationData, registrationResult.accountRegistrationResult, reglockEnabled)
|
||||
return true
|
||||
}
|
||||
@@ -600,6 +600,7 @@ class RegistrationV2ViewModel : ViewModel() {
|
||||
}
|
||||
|
||||
private suspend fun verifyReRegisterInternal(context: Context, pin: String, masterKey: MasterKey, registrationErrorHandler: (RegisterAccountResult) -> Unit) {
|
||||
Log.v(TAG, "verifyReRegisterInternal()")
|
||||
updateFcmToken(context)
|
||||
|
||||
val registrationData = getRegistrationData()
|
||||
@@ -615,10 +616,12 @@ class RegistrationV2ViewModel : ViewModel() {
|
||||
* @return a [Pair] containing the server response and a boolean signifying whether the current account is registration locked.
|
||||
*/
|
||||
private suspend fun registerAccountInternal(context: Context, sessionId: String?, registrationData: RegistrationData, pin: String?, masterKey: MasterKey): Pair<RegisterAccountResult, Boolean> {
|
||||
Log.v(TAG, "registerAccountInternal()")
|
||||
val registrationResult: RegisterAccountResult = RegistrationRepository.registerAccount(context = context, sessionId = sessionId, registrationData = registrationData, pin = pin) { masterKey }
|
||||
|
||||
// Check if reg lock is enabled
|
||||
if (registrationResult !is RegisterAccountResult.RegistrationLocked) {
|
||||
Log.i(TAG, "Received a non-registration lock response to registration. Assuming registration lock as DISABLED")
|
||||
return Pair(registrationResult, false)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ import android.widget.EditText
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.navigation.fragment.navArgs
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
@@ -53,8 +55,18 @@ class RestoreLocalBackupFragment : LoggingFragment(R.layout.fragment_restore_loc
|
||||
setDebugLogSubmitMultiTapView(binding.verifyHeader)
|
||||
Log.i(TAG, "Backup restore.")
|
||||
|
||||
if (navigationViewModel.getBackupFileUri() == null) {
|
||||
Log.i(TAG, "No backup URI found, must navigate back to choose one.")
|
||||
findNavController().navigateUp()
|
||||
return
|
||||
}
|
||||
|
||||
binding.restoreButton.setOnClickListener { presentBackupPassPhrasePromptDialog() }
|
||||
|
||||
binding.cancelLocalRestoreButton.setOnClickListener {
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
|
||||
// TODO [regv2]: check for re-register and skip ahead to phone number entry
|
||||
|
||||
if (SignalStore.settings().isBackupEnabled) {
|
||||
@@ -73,9 +85,11 @@ class RestoreLocalBackupFragment : LoggingFragment(R.layout.fragment_restore_loc
|
||||
} else {
|
||||
presentProgressEnded()
|
||||
}
|
||||
}
|
||||
|
||||
if (fragmentState.backupRestoreComplete) {
|
||||
val importResult = fragmentState.backupImportResult
|
||||
restoreLocalBackupViewModel.backupComplete.observe(viewLifecycleOwner) {
|
||||
if (it.first) {
|
||||
val importResult = it.second
|
||||
if (importResult == null) {
|
||||
onBackupCompletedSuccessfully()
|
||||
} else {
|
||||
|
||||
@@ -11,6 +11,7 @@ import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.asLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import org.signal.core.util.logging.Log
|
||||
@@ -24,6 +25,8 @@ class RestoreLocalBackupViewModel(fileBackupUri: Uri) : ViewModel() {
|
||||
private val store = MutableStateFlow(RestoreLocalBackupState(fileBackupUri))
|
||||
val uiState = store.asLiveData()
|
||||
|
||||
val backupComplete = store.map { Pair(it.backupRestoreComplete, it.backupImportResult) }.asLiveData()
|
||||
|
||||
fun prepareRestore(context: Context) {
|
||||
val backupFileUri = store.value.uri
|
||||
viewModelScope.launch {
|
||||
|
||||
@@ -90,13 +90,6 @@
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user