Improved check on prefix in assitant + fixed some logs missing assitant tag

This commit is contained in:
Sylvain Berfini 2023-07-20 13:27:11 +02:00
parent 7e694af88f
commit 35944bb3a1
16 changed files with 84 additions and 38 deletions

View file

@ -32,6 +32,7 @@ abstract class AbstractPhoneViewModel(accountCreator: AccountCreator) :
CountryPickerFragment.CountryPickedListener {
val prefix = MutableLiveData<String>()
val prefixError = MutableLiveData<String>()
val phoneNumber = MutableLiveData<String>()
val phoneNumberError = MutableLiveData<String>()
@ -48,7 +49,10 @@ abstract class AbstractPhoneViewModel(accountCreator: AccountCreator) :
}
fun isPhoneNumberOk(): Boolean {
return prefix.value.orEmpty().isNotEmpty() && phoneNumber.value.orEmpty().isNotEmpty() && phoneNumberError.value.orEmpty().isEmpty()
return prefix.value.orEmpty().length > 1 && // Not just '+' character
prefixError.value.orEmpty().isEmpty() &&
phoneNumber.value.orEmpty().isNotEmpty() &&
phoneNumberError.value.orEmpty().isEmpty()
}
fun updateFromPhoneNumberAndOrDialPlan(number: String?, dialPlan: DialPlan?) {

View file

@ -46,7 +46,7 @@ class AccountLoginViewModel(accountCreator: AccountCreator) : AbstractPhoneViewM
val password = MutableLiveData<String>()
val passwordError = MutableLiveData<String>()
val loginEnabled: MediatorLiveData<Boolean> = MediatorLiveData()
val loginEnabled = MediatorLiveData<Boolean>()
val waitForServerAnswer = MutableLiveData<Boolean>()
@ -140,6 +140,9 @@ class AccountLoginViewModel(accountCreator: AccountCreator) : AbstractPhoneViewM
loginEnabled.addSource(phoneNumberError) {
loginEnabled.value = isLoginButtonEnabled()
}
loginEnabled.addSource(prefixError) {
loginEnabled.value = isLoginButtonEnabled()
}
}
override fun onCleared() {
@ -149,6 +152,7 @@ class AccountLoginViewModel(accountCreator: AccountCreator) : AbstractPhoneViewM
override fun onFlexiApiTokenReceived() {
Log.i("[Assistant] [Account Login] Using FlexiAPI auth token [${accountCreator.token}]")
waitForServerAnswer.value = false
loginWithPhoneNumber()
}

View file

@ -51,16 +51,16 @@ class EchoCancellerCalibrationViewModel : ViewModel() {
coreContext.core.removeListener(listener)
when (status) {
EcCalibratorStatus.DoneNoEcho -> {
Log.i("[Echo Canceller Calibration] Done, no echo")
Log.i("[Assistant] [Echo Canceller Calibration] Done, no echo")
}
EcCalibratorStatus.Done -> {
Log.i("[Echo Canceller Calibration] Done, delay is ${delay}ms")
Log.i("[Assistant] [Echo Canceller Calibration] Done, delay is ${delay}ms")
}
EcCalibratorStatus.Failed -> {
Log.w("[Echo Canceller Calibration] Failed")
Log.w("[Assistant] [Echo Canceller Calibration] Failed")
}
EcCalibratorStatus.InProgress -> {
Log.i("[Echo Canceller Calibration] In progress")
Log.i("[Assistant] [Echo Canceller Calibration] In progress")
}
}
echoCalibrationTerminated.value = Event(true)

View file

@ -72,7 +72,7 @@ class EmailAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPu
status: AccountCreator.Status,
response: String?
) {
Log.i("[Account Creation] onIsAccountExist status is $status")
Log.i("[Assistant] [Account Creation] onIsAccountExist status is $status")
when (status) {
AccountCreator.Status.AccountExist, AccountCreator.Status.AccountExistWithAlias -> {
waitForServerAnswer.value = false
@ -99,7 +99,7 @@ class EmailAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPu
status: AccountCreator.Status,
response: String?
) {
Log.i("[Account Creation] onCreateAccount status is $status")
Log.i("[Assistant] [Account Creation] onCreateAccount status is $status")
waitForServerAnswer.value = false
when (status) {
@ -149,11 +149,11 @@ class EmailAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPu
}
override fun onFlexiApiTokenReceived() {
Log.i("[Account Creation] Using FlexiAPI auth token [${accountCreator.token}]")
Log.i("[Assistant] [Account Creation] Using FlexiAPI auth token [${accountCreator.token}]")
waitForServerAnswer.value = true
val status = accountCreator.isAccountExist
Log.i("[Account Creation] Account exists returned $status")
Log.i("[Assistant] [Account Creation] Account exists returned $status")
if (status != AccountCreator.Status.RequestOk) {
waitForServerAnswer.value = false
onErrorEvent.value = Event("Error: ${status.name}")
@ -161,7 +161,7 @@ class EmailAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPu
}
override fun onFlexiApiTokenRequestError() {
Log.e("[Account Creation] Failed to get an auth token from FlexiAPI")
Log.e("[Assistant] [Account Creation] Failed to get an auth token from FlexiAPI")
waitForServerAnswer.value = false
onErrorEvent.value = Event("Error: Failed to get an auth token from account manager server")
}
@ -175,11 +175,11 @@ class EmailAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPu
val token = accountCreator.token.orEmpty()
if (token.isNotEmpty()) {
Log.i(
"[Account Creation] We already have an auth token from FlexiAPI [$token], continue"
"[Assistant] [Account Creation] We already have an auth token from FlexiAPI [$token], continue"
)
onFlexiApiTokenReceived()
} else {
Log.i("[Account Creation] Requesting an auth token from FlexiAPI")
Log.i("[Assistant] [Account Creation] Requesting an auth token from FlexiAPI")
waitForServerAnswer.value = true
requestFlexiApiToken()
}

View file

@ -57,7 +57,7 @@ class EmailAccountValidationViewModel(val accountCreator: AccountCreator) : View
status: AccountCreator.Status,
response: String?
) {
Log.i("[Account Validation] onIsAccountActivated status is $status")
Log.i("[Assistant] [Account Validation] onIsAccountActivated status is $status")
waitForServerAnswer.value = false
when (status) {

View file

@ -152,6 +152,8 @@ class GenericLoginViewModel(private val accountCreator: AccountCreator) : ViewMo
}
private fun isLoginButtonEnabled(): Boolean {
return username.value.orEmpty().isNotEmpty() && domain.value.orEmpty().isNotEmpty() && password.value.orEmpty().isNotEmpty()
return username.value.orEmpty().isNotEmpty() &&
domain.value.orEmpty().isNotEmpty() &&
password.value.orEmpty().isNotEmpty()
}
}

View file

@ -68,7 +68,7 @@ class PhoneAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPh
status: AccountCreator.Status,
response: String?
) {
Log.i("[Phone Account Creation] onIsAccountExist status is $status")
Log.i("[Assistant] [Phone Account Creation] onIsAccountExist status is $status")
when (status) {
AccountCreator.Status.AccountExist, AccountCreator.Status.AccountExistWithAlias -> {
waitForServerAnswer.value = false
@ -92,7 +92,7 @@ class PhoneAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPh
status: AccountCreator.Status,
response: String?
) {
Log.i("[Phone Account Creation] onIsAliasUsed status is $status")
Log.i("[Assistant] [Phone Account Creation] onIsAliasUsed status is $status")
when (status) {
AccountCreator.Status.AliasExist -> {
waitForServerAnswer.value = false
@ -114,7 +114,9 @@ class PhoneAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPh
}
AccountCreator.Status.AliasNotExist -> {
val createAccountStatus = creator.createAccount()
Log.i("[Phone Account Creation] createAccount returned $createAccountStatus")
Log.i(
"[Assistant] [Phone Account Creation] createAccount returned $createAccountStatus"
)
if (createAccountStatus != AccountCreator.Status.RequestOk) {
waitForServerAnswer.value = false
onErrorEvent.value = Event("Error: ${status.name}")
@ -132,7 +134,7 @@ class PhoneAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPh
status: AccountCreator.Status,
response: String?
) {
Log.i("[Phone Account Creation] onCreateAccount status is $status")
Log.i("[Assistant] [Phone Account Creation] onCreateAccount status is $status")
waitForServerAnswer.value = false
when (status) {
AccountCreator.Status.AccountCreated -> {
@ -173,6 +175,9 @@ class PhoneAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPh
createEnabled.addSource(phoneNumberError) {
createEnabled.value = isCreateButtonEnabled()
}
createEnabled.addSource(prefixError) {
createEnabled.value = isCreateButtonEnabled()
}
}
override fun onCleared() {
@ -181,9 +186,22 @@ class PhoneAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPh
}
override fun onFlexiApiTokenReceived() {
Log.i("[Phone Account Creation] Using FlexiAPI auth token [${accountCreator.token}]")
Log.i(
"[Assistant] [Phone Account Creation] Using FlexiAPI auth token [${accountCreator.token}]"
)
accountCreator.displayName = displayName.value
accountCreator.setPhoneNumber(phoneNumber.value, prefix.value)
val result = AccountCreator.PhoneNumberStatus.fromInt(
accountCreator.setPhoneNumber(phoneNumber.value, prefix.value)
)
if (result != AccountCreator.PhoneNumberStatus.Ok) {
Log.e(
"[Assistant] [Phone Account Creation] Error [$result] setting the phone number: ${phoneNumber.value} with prefix: ${prefix.value}"
)
phoneNumberError.value = result.name
return
}
Log.i("[Assistant] [Phone Account Creation] Phone number is ${accountCreator.phoneNumber}")
if (useUsername.value == true) {
accountCreator.username = username.value
@ -199,14 +217,14 @@ class PhoneAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPh
}
override fun onFlexiApiTokenRequestError() {
Log.e("[Phone Account Creation] Failed to get an auth token from FlexiAPI")
Log.e("[Assistant] [Phone Account Creation] Failed to get an auth token from FlexiAPI")
waitForServerAnswer.value = false
onErrorEvent.value = Event("Error: Failed to get an auth token from account manager server")
}
private fun checkUsername() {
val status = accountCreator.isAccountExist
Log.i("[Phone Account Creation] isAccountExist returned $status")
Log.i("[Assistant] [Phone Account Creation] isAccountExist returned $status")
if (status != AccountCreator.Status.RequestOk) {
waitForServerAnswer.value = false
onErrorEvent.value = Event("Error: ${status.name}")
@ -215,7 +233,7 @@ class PhoneAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPh
private fun checkPhoneNumber() {
val status = accountCreator.isAliasUsed
Log.i("[Phone Account Creation] isAliasUsed returned $status")
Log.i("[Assistant] [Phone Account Creation] isAliasUsed returned $status")
if (status != AccountCreator.Status.RequestOk) {
waitForServerAnswer.value = false
onErrorEvent.value = Event("Error: ${status.name}")
@ -226,11 +244,11 @@ class PhoneAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPh
val token = accountCreator.token.orEmpty()
if (token.isNotEmpty()) {
Log.i(
"[Phone Account Creation] We already have an auth token from FlexiAPI [$token], continue"
"[Assistant] [Phone Account Creation] We already have an auth token from FlexiAPI [$token], continue"
)
onFlexiApiTokenReceived()
} else {
Log.i("[Phone Account Creation] Requesting an auth token from FlexiAPI")
Log.i("[Assistant] [Phone Account Creation] Requesting an auth token from FlexiAPI")
waitForServerAnswer.value = true
requestFlexiApiToken()
}

View file

@ -60,12 +60,12 @@ class PhoneAccountLinkingViewModel(accountCreator: AccountCreator) : AbstractPho
status: AccountCreator.Status,
response: String?
) {
Log.i("[Phone Account Linking] onIsAliasUsed status is $status")
Log.i("[Assistant] [Phone Account Linking] onIsAliasUsed status is $status")
when (status) {
AccountCreator.Status.AliasNotExist -> {
if (creator.linkAccount() != AccountCreator.Status.RequestOk) {
Log.e("[Phone Account Linking] linkAccount status is $status")
Log.e("[Assistant] [Phone Account Linking] linkAccount status is $status")
waitForServerAnswer.value = false
onErrorEvent.value = Event("Error: ${status.name}")
}
@ -86,7 +86,7 @@ class PhoneAccountLinkingViewModel(accountCreator: AccountCreator) : AbstractPho
status: AccountCreator.Status,
response: String?
) {
Log.i("[Phone Account Linking] onLinkAccount status is $status")
Log.i("[Assistant] [Phone Account Linking] onLinkAccount status is $status")
waitForServerAnswer.value = false
when (status) {
@ -113,6 +113,9 @@ class PhoneAccountLinkingViewModel(accountCreator: AccountCreator) : AbstractPho
linkEnabled.addSource(phoneNumberError) {
linkEnabled.value = isLinkButtonEnabled()
}
linkEnabled.addSource(prefixError) {
linkEnabled.value = isLinkButtonEnabled()
}
}
override fun onCleared() {
@ -123,10 +126,10 @@ class PhoneAccountLinkingViewModel(accountCreator: AccountCreator) : AbstractPho
override fun onFlexiApiTokenReceived() {
accountCreator.setPhoneNumber(phoneNumber.value, prefix.value)
accountCreator.username = username.value
Log.i("[Phone Account Linking] Phone number is ${accountCreator.phoneNumber}")
Log.i("[Assistant] [Phone Account Linking] Phone number is ${accountCreator.phoneNumber}")
val status: AccountCreator.Status = accountCreator.isAliasUsed
Log.i("[Phone Account Linking] isAliasUsed returned $status")
Log.i("[Assistant] [Phone Account Linking] isAliasUsed returned $status")
if (status != AccountCreator.Status.RequestOk) {
waitForServerAnswer.value = false
onErrorEvent.value = Event("Error: ${status.name}")
@ -134,12 +137,12 @@ class PhoneAccountLinkingViewModel(accountCreator: AccountCreator) : AbstractPho
}
override fun onFlexiApiTokenRequestError() {
Log.e("[Phone Account Linking] Failed to get an auth token from FlexiAPI")
Log.e("[Assistant] [Phone Account Linking] Failed to get an auth token from FlexiAPI")
waitForServerAnswer.value = false
}
fun link() {
Log.i("[Phone Account Linking] Requesting an auth token from FlexiAPI")
Log.i("[Assistant] [Phone Account Linking] Requesting an auth token from FlexiAPI")
waitForServerAnswer.value = true
requestFlexiApiToken()
}

View file

@ -34,7 +34,7 @@ class QrCodeViewModel : ViewModel() {
private val listener = object : CoreListenerStub() {
override fun onQrcodeFound(core: Core, result: String?) {
Log.i("[QR Code] Found [$result]")
Log.i("[Assistant] [QR Code] Found [$result]")
if (result != null) qrCodeFoundEvent.postValue(Event(result))
}
}
@ -54,7 +54,7 @@ class QrCodeViewModel : ViewModel() {
for (camera in coreContext.core.videoDevicesList) {
if (camera.contains("Back")) {
Log.i("[QR Code] Found back facing camera: $camera")
Log.i("[Assistant] [QR Code] Found back facing camera: $camera")
coreContext.core.videoDevice = camera
return
}
@ -62,7 +62,7 @@ class QrCodeViewModel : ViewModel() {
val first = coreContext.core.videoDevicesList.firstOrNull()
if (first != null) {
Log.i("[QR Code] Using first camera found: $first")
Log.i("[Assistant] [QR Code] Using first camera found: $first")
coreContext.core.videoDevice = first
}
}

View file

@ -73,7 +73,7 @@ class RemoteProvisioningViewModel : ViewModel() {
fun fetchAndApply() {
val url = urlToFetch.value.orEmpty()
coreContext.core.provisioningUri = url
Log.w("[Remote Provisioning] Url set to [$url], restarting Core")
Log.w("[Assistant] [Remote Provisioning] Url set to [$url], restarting Core")
fetchInProgress.value = true
coreContext.core.stop()
coreContext.core.start()

View file

@ -593,7 +593,17 @@ fun addPhoneNumberEditTextValidation(editText: EditText, enabled: Boolean) {
fun addPrefixEditTextValidation(editText: EditText, enabled: Boolean) {
if (!enabled) return
editText.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable?) {}
override fun afterTextChanged(s: Editable?) {
val dialPlan = PhoneNumberUtils.getDialPlanFromCountryCallingPrefix(
s.toString().substring(1)
)
if (dialPlan == null) {
editText.error =
editText.context.getString(
R.string.assistant_error_invalid_international_prefix
)
}
}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}

View file

@ -119,6 +119,7 @@
<com.google.android.material.textfield.TextInputEditText
assistantPhoneNumberPrefixValidation="@{true}"
errorMessage="@={viewModel.prefixError}"
android:text="@={viewModel.prefix}"
android:imeOptions="actionNext"
android:singleLine="true"

View file

@ -116,6 +116,7 @@
<com.google.android.material.textfield.TextInputEditText
assistantPhoneNumberPrefixValidation="@{true}"
errorMessage="@={viewModel.prefixError}"
android:text="@={viewModel.prefix}"
android:imeOptions="actionNext"
android:singleLine="true"

View file

@ -126,6 +126,7 @@
<com.google.android.material.textfield.TextInputEditText
assistantPhoneNumberPrefixValidation="@{true}"
errorMessage="@={viewModel.prefixError}"
android:text="@={viewModel.prefix}"
android:imeOptions="actionNext"
android:singleLine="true"

View file

@ -790,4 +790,5 @@
<string name="content_description_emoji_picker">Change la visibilité du selectionneur d\'emoji</string>
<string name="android_14_full_screen_intent_permission_not_granted">Permission requise pour afficher les appels entrant non accordée</string>
<string name="android_14_go_to_full_screen_intent_permission_setting">Afficher</string>
<string name="assistant_error_invalid_international_prefix">Préfixe international inconnu</string>
</resources>

View file

@ -422,6 +422,7 @@
<string name="assistant_error_invalid_email_address">Email address is invalid</string>
<string name="assistant_error_username_too_long">Username has too many characters</string>
<string name="assistant_error_invalid_credentials">Account does not exist or password does not match</string>
<string name="assistant_error_invalid_international_prefix">Wrong international prefix</string>
<!-- Assistant login -->
<string name="assistant_linphone_account">Use your &appName; account</string>