Fix changing number flow in scenarios where service requires additional verification.

Fixes #12985, #13059.
This commit is contained in:
Nicholas Tinsley
2023-07-14 15:52:02 -04:00
committed by Clark Chen
parent e7e00bd428
commit fddfbd8d2d
3 changed files with 23 additions and 3 deletions

View File

@@ -81,7 +81,7 @@ class ChangeNumberVerifyFragment : LoggingFragment(R.layout.fragment_change_phon
val processor: RegistrationSessionProcessor = (result as RequestCodeResult.RequestedVerificationCode).processor
if (processor.hasResult()) {
if (processor.verificationCodeRequestSuccess()) {
Log.i(TAG, "Successfully requested SMS code.")
findNavController().safeNavigate(R.id.action_changePhoneNumberVerifyFragment_to_changeNumberEnterCodeFragment)
} else if (processor.captchaRequired(viewModel.excludedChallenges)) {

View File

@@ -88,6 +88,12 @@ sealed class RegistrationSessionProcessor(response: ServiceResponse<Registration
return 0 == result.body.nextVerificationAttempt
}
fun mustWaitToSubmitProof(): Boolean {
Preconditions.checkState(hasResult(), "This can only be called when result is present!")
val nextVerificationAttempt = result.body.nextVerificationAttempt
return nextVerificationAttempt != null && nextVerificationAttempt > 0
}
/**
* The soonest time at which the server will accept a submission of proof of ownership.
* @return a unix timestamp in milliseconds, or 0 to represent null
@@ -149,7 +155,17 @@ sealed class RegistrationSessionProcessor(response: ServiceResponse<Registration
}
fun cannotSubmitVerificationAttempt(): Boolean {
return !hasResult() || result.body.nextVerificationAttempt == null
if (!hasResult()) {
return true
}
val body = result.body
if (body.requestedInformation.isNotEmpty()) {
return false
}
return body.nextVerificationAttempt == null
}
/**

View File

@@ -389,12 +389,16 @@ public abstract class BaseEnterSmsCodeFragment<ViewModel extends BaseRegistratio
.observeOn(AndroidSchedulers.mainThread())
.subscribe(processor -> {
if (!processor.hasResult()) {
Log.d(TAG, "Network error.");
returnToPhoneEntryScreen();
} else if (processor.isInvalidSession()) {
Log.d(TAG, "Registration session is invalid.");
returnToPhoneEntryScreen();
} else if (processor.cannotSubmitVerificationAttempt()) {
Log.d(TAG, "Cannot submit any more verification attempts.");
returnToPhoneEntryScreen();
} else if (!processor.canSubmitProofImmediately()) {
} else if (processor.mustWaitToSubmitProof()) {
Log.d(TAG, "Blocked from submitting proof at this time.");
handleRateLimited();
}
// else session state is valid and server is ready to accept code