diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index a189326d..19ed349e 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -538,12 +538,21 @@ class BaresipService: Service() { @SuppressLint("UnspecifiedImmutableFlag") @Keep fun uaEvent(event: String, uap: String, callp: String) { + if (!isServiceRunning) return + val ua = UserAgent.ofUap(uap) if (ua == null) { - Log.w(TAG, "uaEvent did not find ua $uap") + Log.w(TAG, "uaEvent $event did not find ua $uap") return } + + val call = Call.ofCallp(callp) + if (call == null && callp != "0" && event != "call incoming") { + Log.w(TAG, "uaEvent $event did not find call $callp") + return + } + Log.d(TAG, "got uaEvent $event/${ua.account.aor}/$callp") val aor = ua.account.aor @@ -580,12 +589,7 @@ class BaresipService: Service() { return } "call outgoing" -> { - val call = Call.ofCallp(callp) - if (call == null) { - Log.w(TAG, "Call $callp that is outgoing is not found") - return - } - if (call.status == "transferring") + if (call!!.status == "transferring") break stopMediaPlayer() if (am.mode != AudioManager.MODE_IN_COMMUNICATION) @@ -700,17 +704,12 @@ class BaresipService: Service() { } "call answered" -> { stopMediaPlayer() - return + call!!.status = "answered" } "call established" -> { nm.cancel(CALL_NOTIFICATION_ID) - val call = Call.ofCallp(callp) - if (call == null) { - Log.w(TAG, "Call $callp that is established is not found") - return - } Log.d(TAG, "AoR $aor call $callp established") - call.status = "connected" + call!!.status = "connected" call.onhold = false if (ua.account.callHistory) call.startTime = GregorianCalendar() @@ -718,37 +717,22 @@ class BaresipService: Service() { return } "call update" -> { - val call = Call.ofCallp(callp) - if (call == null) { - Log.w("Baresip", "Call $callp that is updated is not found") - return - } when (ev[1]) { - "0", "1" -> call.held = true - "2", "3" -> call.held = false + "0", "1" -> call!!.held = true + "2", "3" -> call!!.held = false } } "call verified", "call secure" -> { - val call = Call.ofCallp(callp) - if (call == null) { - Log.w("Baresip", "Call $callp that is verified is not found") - return - } if (ev[0] == "call secure") { - call.security = R.drawable.box_yellow + call!!.security = R.drawable.box_yellow } else { - call.security = R.drawable.box_green + call!!.security = R.drawable.box_green call.zid = ev[1] } if (!Utils.isVisible()) return } "call transfer" -> { - val call = Call.ofCallp(callp) - if (call == null) { - Log.w(TAG, "Call $callp to be transferred is not found") - return - } if (!Utils.isVisible()) { val intent = Intent(applicationContext, MainActivity::class.java) intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or @@ -802,20 +786,11 @@ class BaresipService: Service() { "transfer failed" -> { Log.d(TAG, "AoR $aor call $callp transfer failed: ${ev[1]}") stopMediaPlayer() - val call = Call.ofCallp(callp) - if (call == null) - Log.w(TAG, "Call $callp with failed transfer is not found") - else - call.referTo = "" + call!!.referTo = "" if (!Utils.isVisible()) return } "call closed" -> { nm.cancel(CALL_NOTIFICATION_ID) - val call = Call.ofCallp(callp) - if (call == null) { - Log.d(TAG, "AoR $aor call $callp that is closed is not found") - return - } Log.d(TAG, "AoR $aor call $callp is closed") stopRinging() stopMediaPlayer() @@ -825,7 +800,7 @@ class BaresipService: Service() { "error" -> playMedia(R.raw.error, 1) } - call.remove() + call!!.remove() if (Call.calls().size == 0) { resetCallVolume() am.isSpeakerphoneOn = false diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt index abf03fe2..5194a07f 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt @@ -88,7 +88,6 @@ class MainActivity : AppCompatActivity() { private lateinit var restoreRequest: ActivityResultLauncher private lateinit var contactsRequest: ActivityResultLauncher private lateinit var callsRequest: ActivityResultLauncher - private lateinit var callDetailsRequest: ActivityResultLauncher private var downloadsInputStream: FileInputStream? = null private var downloadsOutputStream: FileOutputStream? = null @@ -333,9 +332,12 @@ class MainActivity : AppCompatActivity() { val aor = ua.account.aor val uaCalls = Call.uaCalls(ua, "") if (uaCalls.size > 0) { - val callp = uaCalls[uaCalls.size - 1].callp + val call = uaCalls[uaCalls.size - 1] + val callp = call.callp Log.d(TAG, "AoR $aor hanging up call $callp with ${callUri.text}") hangupButton.isEnabled = false + if (call.status == "answered") + call.rejected = true Api.ua_hangup(ua.uap, callp, 0, "") } } @@ -967,6 +969,9 @@ class MainActivity : AppCompatActivity() { startActivity(i) } } + "call answered" -> { + showCall(ua) + } "call established" -> { if (aor == aorSpinner.tag) { dtmf.setText("") @@ -1724,8 +1729,11 @@ class MainActivity : AppCompatActivity() { val call = showCall ?: Call.uaCalls(ua, "")[0] callUri.isFocusable = false when (call.status) { - "outgoing", "transferring" -> { - callTitle.text = getString(R.string.outgoing_call_to_dots) + "outgoing", "transferring", "answered" -> { + callTitle.text = if (call.status == "answered") + getString(R.string.answering_call_from_dots) + else + getString(R.string.outgoing_call_to_dots) callUri.setText(Utils.friendlyUri(ContactsActivity.contactName(call.peerUri), Utils.aorDomain(ua.account.aor))) securityButton.visibility = View.INVISIBLE diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 47883596..bdaf5bfe 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -420,9 +420,10 @@ Tietoja Käynnistä uudelleen Lopeta - Lähtevä puhelu … - Tuleva puhelu … - Siirtopuhelu … + Puhelu ulos … + Puhelu sisään … + Vastattu puhelu … + Puhelun siirto … Virheellinen SIP URI \'%1$s\' Puhelun kohde Lopeta diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b69de576..753c1bc4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -382,8 +382,9 @@ About Restart Quit - Outgoing call to … - Incoming call from … + Call to … + Call from … + Answering call from … Transferring call to … Invalid SIP URI \'%1$s\' Callee