From 4dc660a52d9a83293d9cf5af661ccafb005a1e37 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 11 Jan 2024 10:57:42 +0100 Subject: [PATCH] Handle possible null call in alerts --- .../ui/call/viewmodel/CurrentCallViewModel.kt | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt b/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt index 0a4b65ed7..d4f29d1a1 100644 --- a/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt +++ b/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt @@ -300,11 +300,19 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() { @WorkerThread override fun onNewAlertTriggered(core: Core, alert: Alert) { - val remote = alert.call.remoteAddress.asStringUriOnly() + val call = alert.call + if (call == null) { + Log.w( + "$TAG Alert of type [${alert.type}] triggered but with null call, ignoring..." + ) + return + } + + val remote = call.remoteAddress.asStringUriOnly() Log.w("$TAG Alert of type [${alert.type}] triggered for call from [$remote]") alert.addListener(alertListener) - if (alert.call != currentCall) { + if (call != currentCall) { Log.w("$TAG Terminated alert wasn't for current call, do not display it") return } @@ -352,11 +360,19 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() { private val alertListener = object : AlertListenerStub() { @WorkerThread override fun onTerminated(alert: Alert) { - val remote = alert.call.remoteAddress.asStringUriOnly() + val call = alert.call + if (call == null) { + Log.w( + "$TAG Alert of type [${alert.type}] dismissed but with null call, ignoring..." + ) + return + } + + val remote = call.remoteAddress.asStringUriOnly() Log.w("$TAG Alert of type [${alert.type}] dismissed for call from [$remote]") alert.removeListener(this) - if (alert.call != currentCall) { + if (call != currentCall) { Log.w("$TAG Terminated alert wasn't for current call, do not display it") return }