From a0108776dd88af62314b858ecad80f0cd85c7849 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Tue, 25 Mar 2025 16:54:19 +0100 Subject: [PATCH] Keep newly created account disabled until SMS code validation is done --- .../viewmodel/AccountCreationViewModel.kt | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/linphone/ui/assistant/viewmodel/AccountCreationViewModel.kt b/app/src/main/java/org/linphone/ui/assistant/viewmodel/AccountCreationViewModel.kt index db9ba778e..2681eda1c 100644 --- a/app/src/main/java/org/linphone/ui/assistant/viewmodel/AccountCreationViewModel.kt +++ b/app/src/main/java/org/linphone/ui/assistant/viewmodel/AccountCreationViewModel.kt @@ -142,14 +142,7 @@ class AccountCreationViewModel goToSmsCodeConfirmationViewEvent.postValue(Event(true)) } AccountManagerServicesRequest.Type.LinkPhoneNumberUsingCode -> { - val account = accountCreated - if (account != null) { - Log.i( - "$TAG Account [${account.params.identityAddress?.asStringUriOnly()}] has been created & activated, setting it as default" - ) - coreContext.core.defaultAccount = account - } - accountCreatedEvent.postValue(Event(true)) + enableAccountAndSetItAsDefault() } else -> { } } @@ -496,6 +489,9 @@ class AccountCreationViewModel ) accountParams.internationalPrefix = dialPlan.internationalCallPrefix accountParams.internationalPrefixIsoCountryCode = dialPlan.isoCountryCode + + // Do not enable account just yet, wait for it to be activated using SMS code + accountParams.isRegisterEnabled = false } val account = core.createAccount(accountParams) core.addAccount(account) @@ -507,6 +503,21 @@ class AccountCreationViewModel lockUsernameAndPassword.postValue(true) } + @WorkerThread + private fun enableAccountAndSetItAsDefault() { + val account = accountCreated ?: return + Log.i( + "$TAG Account [${account.params.identityAddress?.asStringUriOnly()}] has been created & activated, enable it & setting it as default" + ) + + val newParams = account.params.clone() + newParams.isRegisterEnabled = true + account.params = newParams + + coreContext.core.defaultAccount = account + accountCreatedEvent.postValue(Event(true)) + } + @WorkerThread private fun requestFlexiApiToken() { if (!coreContext.core.isPushNotificationAvailable) {