Allow cancelling of answered call that waits to be established

Simplified some call related strings
This commit is contained in:
Juha Heinanen
2022-01-21 19:17:44 +02:00
parent c15c00cb69
commit d173c929f1
4 changed files with 38 additions and 53 deletions
@@ -538,12 +538,21 @@ class BaresipService: Service() {
@SuppressLint("UnspecifiedImmutableFlag") @SuppressLint("UnspecifiedImmutableFlag")
@Keep @Keep
fun uaEvent(event: String, uap: String, callp: String) { fun uaEvent(event: String, uap: String, callp: String) {
if (!isServiceRunning) return if (!isServiceRunning) return
val ua = UserAgent.ofUap(uap) val ua = UserAgent.ofUap(uap)
if (ua == null) { if (ua == null) {
Log.w(TAG, "uaEvent did not find ua $uap") Log.w(TAG, "uaEvent $event did not find ua $uap")
return 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") Log.d(TAG, "got uaEvent $event/${ua.account.aor}/$callp")
val aor = ua.account.aor val aor = ua.account.aor
@@ -580,12 +589,7 @@ class BaresipService: Service() {
return return
} }
"call outgoing" -> { "call outgoing" -> {
val call = Call.ofCallp(callp) if (call!!.status == "transferring")
if (call == null) {
Log.w(TAG, "Call $callp that is outgoing is not found")
return
}
if (call.status == "transferring")
break break
stopMediaPlayer() stopMediaPlayer()
if (am.mode != AudioManager.MODE_IN_COMMUNICATION) if (am.mode != AudioManager.MODE_IN_COMMUNICATION)
@@ -700,17 +704,12 @@ class BaresipService: Service() {
} }
"call answered" -> { "call answered" -> {
stopMediaPlayer() stopMediaPlayer()
return call!!.status = "answered"
} }
"call established" -> { "call established" -> {
nm.cancel(CALL_NOTIFICATION_ID) 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") Log.d(TAG, "AoR $aor call $callp established")
call.status = "connected" call!!.status = "connected"
call.onhold = false call.onhold = false
if (ua.account.callHistory) if (ua.account.callHistory)
call.startTime = GregorianCalendar() call.startTime = GregorianCalendar()
@@ -718,37 +717,22 @@ class BaresipService: Service() {
return return
} }
"call update" -> { "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]) { when (ev[1]) {
"0", "1" -> call.held = true "0", "1" -> call!!.held = true
"2", "3" -> call.held = false "2", "3" -> call!!.held = false
} }
} }
"call verified", "call secure" -> { "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") { if (ev[0] == "call secure") {
call.security = R.drawable.box_yellow call!!.security = R.drawable.box_yellow
} else { } else {
call.security = R.drawable.box_green call!!.security = R.drawable.box_green
call.zid = ev[1] call.zid = ev[1]
} }
if (!Utils.isVisible()) if (!Utils.isVisible())
return return
} }
"call transfer" -> { "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()) { if (!Utils.isVisible()) {
val intent = Intent(applicationContext, MainActivity::class.java) val intent = Intent(applicationContext, MainActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or
@@ -802,20 +786,11 @@ class BaresipService: Service() {
"transfer failed" -> { "transfer failed" -> {
Log.d(TAG, "AoR $aor call $callp transfer failed: ${ev[1]}") Log.d(TAG, "AoR $aor call $callp transfer failed: ${ev[1]}")
stopMediaPlayer() stopMediaPlayer()
val call = Call.ofCallp(callp) call!!.referTo = ""
if (call == null)
Log.w(TAG, "Call $callp with failed transfer is not found")
else
call.referTo = ""
if (!Utils.isVisible()) return if (!Utils.isVisible()) return
} }
"call closed" -> { "call closed" -> {
nm.cancel(CALL_NOTIFICATION_ID) 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") Log.d(TAG, "AoR $aor call $callp is closed")
stopRinging() stopRinging()
stopMediaPlayer() stopMediaPlayer()
@@ -825,7 +800,7 @@ class BaresipService: Service() {
"error" -> "error" ->
playMedia(R.raw.error, 1) playMedia(R.raw.error, 1)
} }
call.remove() call!!.remove()
if (Call.calls().size == 0) { if (Call.calls().size == 0) {
resetCallVolume() resetCallVolume()
am.isSpeakerphoneOn = false am.isSpeakerphoneOn = false
@@ -88,7 +88,6 @@ class MainActivity : AppCompatActivity() {
private lateinit var restoreRequest: ActivityResultLauncher<Intent> private lateinit var restoreRequest: ActivityResultLauncher<Intent>
private lateinit var contactsRequest: ActivityResultLauncher<Intent> private lateinit var contactsRequest: ActivityResultLauncher<Intent>
private lateinit var callsRequest: ActivityResultLauncher<Intent> private lateinit var callsRequest: ActivityResultLauncher<Intent>
private lateinit var callDetailsRequest: ActivityResultLauncher<Intent>
private var downloadsInputStream: FileInputStream? = null private var downloadsInputStream: FileInputStream? = null
private var downloadsOutputStream: FileOutputStream? = null private var downloadsOutputStream: FileOutputStream? = null
@@ -333,9 +332,12 @@ class MainActivity : AppCompatActivity() {
val aor = ua.account.aor val aor = ua.account.aor
val uaCalls = Call.uaCalls(ua, "") val uaCalls = Call.uaCalls(ua, "")
if (uaCalls.size > 0) { 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}") Log.d(TAG, "AoR $aor hanging up call $callp with ${callUri.text}")
hangupButton.isEnabled = false hangupButton.isEnabled = false
if (call.status == "answered")
call.rejected = true
Api.ua_hangup(ua.uap, callp, 0, "") Api.ua_hangup(ua.uap, callp, 0, "")
} }
} }
@@ -967,6 +969,9 @@ class MainActivity : AppCompatActivity() {
startActivity(i) startActivity(i)
} }
} }
"call answered" -> {
showCall(ua)
}
"call established" -> { "call established" -> {
if (aor == aorSpinner.tag) { if (aor == aorSpinner.tag) {
dtmf.setText("") dtmf.setText("")
@@ -1724,8 +1729,11 @@ class MainActivity : AppCompatActivity() {
val call = showCall ?: Call.uaCalls(ua, "")[0] val call = showCall ?: Call.uaCalls(ua, "")[0]
callUri.isFocusable = false callUri.isFocusable = false
when (call.status) { when (call.status) {
"outgoing", "transferring" -> { "outgoing", "transferring", "answered" -> {
callTitle.text = getString(R.string.outgoing_call_to_dots) 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), callUri.setText(Utils.friendlyUri(ContactsActivity.contactName(call.peerUri),
Utils.aorDomain(ua.account.aor))) Utils.aorDomain(ua.account.aor)))
securityButton.visibility = View.INVISIBLE securityButton.visibility = View.INVISIBLE
+4 -3
View File
@@ -420,9 +420,10 @@
<string name="about">Tietoja</string> <string name="about">Tietoja</string>
<string name="restart">Käynnistä uudelleen</string> <string name="restart">Käynnistä uudelleen</string>
<string name="quit">Lopeta</string> <string name="quit">Lopeta</string>
<string name="outgoing_call_to_dots">Lähtevä puhelu</string> <string name="outgoing_call_to_dots">Puhelu ulos</string>
<string name="incoming_call_from_dots">Tuleva puhelu</string> <string name="incoming_call_from_dots">Puhelu sisään</string>
<string name="transferring_call_to_dots">Siirtopuhelu …</string> <string name="answering_call_from_dots">Vastattu puhelu …</string>
<string name="transferring_call_to_dots">Puhelun siirto …</string>
<string name="invalid_sip_uri">Virheellinen SIP URI \'%1$s\'</string> <string name="invalid_sip_uri">Virheellinen SIP URI \'%1$s\'</string>
<string name="callee">Puhelun kohde</string> <string name="callee">Puhelun kohde</string>
<string name="hangup">Lopeta</string> <string name="hangup">Lopeta</string>
+3 -2
View File
@@ -382,8 +382,9 @@
<string name="about">About</string> <string name="about">About</string>
<string name="restart">Restart</string> <string name="restart">Restart</string>
<string name="quit">Quit</string> <string name="quit">Quit</string>
<string name="outgoing_call_to_dots">Outgoing call to …</string> <string name="outgoing_call_to_dots">Call to …</string>
<string name="incoming_call_from_dots">Incoming call from …</string> <string name="incoming_call_from_dots">Call from …</string>
<string name="answering_call_from_dots">Answering call from …</string>
<string name="transferring_call_to_dots">Transferring call to …</string> <string name="transferring_call_to_dots">Transferring call to …</string>
<string name="invalid_sip_uri">Invalid SIP URI \'%1$s\'</string> <string name="invalid_sip_uri">Invalid SIP URI \'%1$s\'</string>
<string name="callee">Callee</string> <string name="callee">Callee</string>