Better fix for the possible crash

This commit is contained in:
Juha Heinanen
2025-05-02 20:28:47 +03:00
parent d389990b00
commit 700eec8dbc
@@ -1243,6 +1243,7 @@ class MainActivity : ComponentActivity() {
if (showHangupButton.value) { if (showHangupButton.value) {
var ua: UserAgent = userAgentOfSelectedAor() var ua: UserAgent = userAgentOfSelectedAor()
val call = ua.currentCall()!!
IconButton( IconButton(
modifier = Modifier.size(48.dp), modifier = Modifier.size(48.dp),
@@ -1285,7 +1286,6 @@ class MainActivity : ComponentActivity() {
modifier = Modifier.size(48.dp), modifier = Modifier.size(48.dp),
onClick = { onClick = {
val aor = ua.account.aor val aor = ua.account.aor
val call = ua.currentCall()!!
if (call.onhold) { if (call.onhold) {
Log.d(TAG, "AoR $aor resuming call ${call.callp} with ${callUri.value}") Log.d(TAG, "AoR $aor resuming call ${call.callp} with ${callUri.value}")
call.resume() call.resume()
@@ -1312,8 +1312,6 @@ class MainActivity : ComponentActivity() {
modifier = Modifier.size(48.dp), modifier = Modifier.size(48.dp),
enabled = transferButtonEnabled.value, enabled = transferButtonEnabled.value,
onClick = { onClick = {
val call = ua.currentCall()
if (call != null) {
if (call.onHoldCall != null) { if (call.onHoldCall != null) {
if (!call.executeTransfer()) { if (!call.executeTransfer()) {
alertTitle.value = getString(R.string.notice) alertTitle.value = getString(R.string.notice)
@@ -1323,7 +1321,6 @@ class MainActivity : ComponentActivity() {
} }
else else
showTransferDialog = true showTransferDialog = true
}
}, },
) { ) {
Icon( Icon(
@@ -1335,8 +1332,7 @@ class MainActivity : ComponentActivity() {
} }
if (showTransferDialog) { if (showTransferDialog) {
val call = ua.currentCall() val showDialog = remember { mutableStateOf(true) }
val showDialog = remember { mutableStateOf(call != null) }
val blindChecked = remember { mutableStateOf(true) } val blindChecked = remember { mutableStateOf(true) }
if (showDialog.value) if (showDialog.value)
BasicAlertDialog( BasicAlertDialog(
@@ -1461,7 +1457,7 @@ class MainActivity : ComponentActivity() {
} }
} }
} }
if (call!!.replaces()) if (call.replaces())
Row( Row(
modifier = Modifier modifier = Modifier
.fillMaxWidth(), .fillMaxWidth(),
@@ -1592,9 +1588,8 @@ class MainActivity : ComponentActivity() {
modifier = Modifier.size(48.dp), modifier = Modifier.size(48.dp),
onClick = { onClick = {
ua = UserAgent.ofAor(viewModel.selectedAor.value)!! ua = UserAgent.ofAor(viewModel.selectedAor.value)!!
val call = ua.currentCall() val stats = call.stats("audio")
val stats = call?.stats("audio") if (call.startTime != null && stats != "") {
if (stats != null && stats != "") {
val parts = stats.split(",") as java.util.ArrayList val parts = stats.split(",") as java.util.ArrayList
if (parts[2] == "0/0") { if (parts[2] == "0/0") {
parts[2] = "?/?" parts[2] = "?/?"
@@ -1732,9 +1727,6 @@ class MainActivity : ComponentActivity() {
Toast.makeText(applicationContext, R.string.audio_focus_denied, Toast.makeText(applicationContext, R.string.audio_focus_denied,
Toast.LENGTH_SHORT).show() Toast.LENGTH_SHORT).show()
} else { } else {
callUriEnabled.value = false
showCallButton.value = false
showHangupButton.value = true
if (Build.VERSION.SDK_INT < 31) { if (Build.VERSION.SDK_INT < 31) {
Log.d(TAG, "Setting audio mode to MODE_IN_COMMUNICATION") Log.d(TAG, "Setting audio mode to MODE_IN_COMMUNICATION")
am.mode = AudioManager.MODE_IN_COMMUNICATION am.mode = AudioManager.MODE_IN_COMMUNICATION
@@ -2832,6 +2824,10 @@ class MainActivity : ComponentActivity() {
showCallButton.value = true showCallButton.value = true
showHangupButton.value = false showHangupButton.value = false
} }
else {
showCallButton.value = false
showHangupButton.value = true
}
} }
callHandler.postDelayed(callRunnable!!, BaresipService.audioDelay) callHandler.postDelayed(callRunnable!!, BaresipService.audioDelay)
} }