From aa16b68aa35f744ecc15b6b395709c280704d337 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Sat, 3 May 2025 16:59:56 +0300 Subject: [PATCH] Try to avoid call null pointer exeptions on call row --- .../kotlin/com/tutpro/baresip/MainActivity.kt | 73 +++++++++++-------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt index b5f79b69..b92f905b 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt @@ -1278,7 +1278,6 @@ class MainActivity : ComponentActivity() { if (showHangupButton.value) { var ua: UserAgent = userAgentOfSelectedAor() - val call = ua.currentCall()!! IconButton( modifier = Modifier.size(48.dp), @@ -1305,16 +1304,25 @@ class MainActivity : ComponentActivity() { modifier = Modifier.size(48.dp), onClick = { val aor = ua.account.aor - if (call.onhold) { - Log.d(TAG, "AoR $aor resuming call ${call.callp} with ${callUri.value}") - call.resume() - call.onhold = false - holdIcon.intValue = R.drawable.call_hold - } else { - Log.d(TAG, "AoR $aor holding call ${call.callp} with ${callUri.value}") - call.hold() - call.onhold = true - holdIcon.intValue = R.drawable.resume + val call = ua.currentCall() + if (call != null) { + if (call.onhold) { + Log.d( + TAG, + "AoR $aor resuming call ${call.callp} with ${callUri.value}" + ) + call.resume() + call.onhold = false + holdIcon.intValue = R.drawable.call_hold + } else { + Log.d( + TAG, + "AoR $aor holding call ${call.callp} with ${callUri.value}" + ) + call.hold() + call.onhold = true + holdIcon.intValue = R.drawable.resume + } } }, ) { @@ -1331,15 +1339,17 @@ class MainActivity : ComponentActivity() { modifier = Modifier.size(48.dp), enabled = transferButtonEnabled.value, onClick = { - if (call.onHoldCall != null) { - if (!call.executeTransfer()) { - alertTitle.value = getString(R.string.notice) - alertMessage.value = getString(R.string.transfer_failed) - showAlert.value = true - } + val call = ua.currentCall() + if (call != null) { + if (call.onHoldCall != null) { + if (!call.executeTransfer()) { + alertTitle.value = getString(R.string.notice) + alertMessage.value = getString(R.string.transfer_failed) + showAlert.value = true + } + } else + showTransferDialog = true } - else - showTransferDialog = true }, ) { Icon( @@ -1480,7 +1490,8 @@ class MainActivity : ComponentActivity() { } } } - if (call.replaces()) + val call = ua.currentCall() + if (call != null && call.replaces()) Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center, @@ -1583,8 +1594,7 @@ class MainActivity : ComponentActivity() { val char = it.last() if (char.isDigit() || char == '*' || char == '#') { Log.d(TAG, "Got DTMF digit '$char'") - ua = UserAgent.ofAor(viewModel.selectedAor.value)!! - ua.currentCall()!!.sendDigit(char) + ua.currentCall()?.sendDigit(char) } } dtmfText.value = it @@ -1608,9 +1618,9 @@ class MainActivity : ComponentActivity() { IconButton( modifier = Modifier.size(48.dp), onClick = { - ua = UserAgent.ofAor(viewModel.selectedAor.value)!! - val stats = call.stats("audio") - if (call.startTime != null && stats != "") { + val call = ua.currentCall() + val stats = call?.stats("audio") + if (stats != null && call.startTime != null && stats != "") { val parts = stats.split(",") as java.util.ArrayList if (parts[2] == "0/0") { parts[2] = "?/?" @@ -1810,12 +1820,13 @@ class MainActivity : ComponentActivity() { private fun reject() { val ua = UserAgent.ofAor(viewModel.selectedAor.value)!! - val aor = ua.account.aor - val call = ua.currentCall()!! - val callp = call.callp - Log.d(TAG, "AoR $aor rejecting call $callp from ${callUri.value}") - call.rejected = true - Api.ua_hangup(ua.uap, callp, 486, "Busy Here") + val call = ua.currentCall() + if (call != null) { + val callp = call.callp + Log.d(TAG, "AoR ${ua.account.aor} rejecting call $callp from ${callUri.value}") + call.rejected = true + Api.ua_hangup(ua.uap, callp, 486, "Busy Here") + } } @Composable