mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 03:18:06 +00:00
Prevent fatal error due to changes in SDK preventing stopping Core from within iterate() loop, fixed leaving assistant after remote provisioning if no account was configured
This commit is contained in:
parent
f99b51d572
commit
08c72dbb8c
2 changed files with 32 additions and 13 deletions
|
|
@ -84,10 +84,12 @@ class QrCodeScannerFragment : GenericFragment() {
|
|||
goBack()
|
||||
}
|
||||
|
||||
viewModel.qrCodeFoundEvent.observe(viewLifecycleOwner) {
|
||||
it.consume { isValid ->
|
||||
if (isValid) {
|
||||
viewModel.remoteProvisioningSuccessfulEvent.observe(viewLifecycleOwner) {
|
||||
it.consume { atLeastOneAccountFound ->
|
||||
if (atLeastOneAccountFound) {
|
||||
requireActivity().finish()
|
||||
} else {
|
||||
goBack()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import org.linphone.core.tools.Log
|
|||
import org.linphone.ui.GenericViewModel
|
||||
import org.linphone.utils.Event
|
||||
import org.linphone.R
|
||||
import org.linphone.core.GlobalState
|
||||
|
||||
class QrCodeViewModel
|
||||
@UiThread
|
||||
|
|
@ -39,7 +40,7 @@ class QrCodeViewModel
|
|||
private const val TAG = "[Qr Code Scanner ViewModel]"
|
||||
}
|
||||
|
||||
val qrCodeFoundEvent = MutableLiveData<Event<Boolean>>()
|
||||
val remoteProvisioningSuccessfulEvent = MutableLiveData<Event<Boolean>>()
|
||||
|
||||
val onErrorEvent = MutableLiveData<Event<Boolean>>()
|
||||
|
||||
|
|
@ -47,15 +48,28 @@ class QrCodeViewModel
|
|||
@WorkerThread
|
||||
override fun onConfiguringStatus(core: Core, status: ConfiguringState, message: String?) {
|
||||
Log.i("$TAG Configuring state is [$status]")
|
||||
if (status == ConfiguringState.Successful) {
|
||||
qrCodeFoundEvent.postValue(Event(true))
|
||||
} else if (status == ConfiguringState.Failed) {
|
||||
if (status == ConfiguringState.Failed) {
|
||||
Log.e("$TAG Failure applying remote provisioning: $message")
|
||||
showRedToast(R.string.remote_provisioning_config_failed_toast, R.drawable.warning_circle)
|
||||
onErrorEvent.postValue(Event(true))
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
override fun onGlobalStateChanged(core: Core, state: GlobalState?, message: String) {
|
||||
if (state == GlobalState.On) {
|
||||
if (core.accountList.isEmpty()) {
|
||||
Log.w("$TAG Provisioning was successful but no account has been configured yet, staying in assistant")
|
||||
// Remote provisioning didn't contain any account
|
||||
// and there wasn't at least one configured before either
|
||||
remoteProvisioningSuccessfulEvent.postValue(Event(false))
|
||||
} else {
|
||||
Log.i("$TAG At least an account exists in Core, leaving assistant")
|
||||
remoteProvisioningSuccessfulEvent.postValue(Event(true))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
override fun onQrcodeFound(core: Core, result: String?) {
|
||||
Log.i("$TAG QR Code found: [$result]")
|
||||
|
|
@ -68,17 +82,20 @@ class QrCodeViewModel
|
|||
showRedToast(R.string.assistant_qr_code_invalid_toast, R.drawable.warning_circle)
|
||||
} else {
|
||||
Log.i(
|
||||
"$TAG QR code URL set, restarting the Core to apply configuration changes"
|
||||
"$TAG QR code URL set, restarting the Core outside of iterate() loop to apply configuration changes"
|
||||
)
|
||||
core.nativePreviewWindowId = null
|
||||
core.isVideoPreviewEnabled = false
|
||||
core.isQrcodeVideoPreviewEnabled = false
|
||||
|
||||
core.provisioningUri = result
|
||||
coreContext.core.stop()
|
||||
Log.i("$TAG Core has been stopped, restarting it")
|
||||
coreContext.core.start()
|
||||
Log.i("$TAG Core has been restarted")
|
||||
|
||||
coreContext.postOnCoreThread { core ->
|
||||
Log.i("$TAG Stopping Core")
|
||||
coreContext.core.stop()
|
||||
Log.i("$TAG Core has been stopped, restarting it")
|
||||
coreContext.core.start()
|
||||
Log.i("$TAG Core has been restarted")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue