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

View File

@ -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

View File

@ -88,7 +88,6 @@ class MainActivity : AppCompatActivity() {
private lateinit var restoreRequest: ActivityResultLauncher<Intent>
private lateinit var contactsRequest: ActivityResultLauncher<Intent>
private lateinit var callsRequest: ActivityResultLauncher<Intent>
private lateinit var callDetailsRequest: ActivityResultLauncher<Intent>
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

View File

@ -420,9 +420,10 @@
<string name="about">Tietoja</string>
<string name="restart">Käynnistä uudelleen</string>
<string name="quit">Lopeta</string>
<string name="outgoing_call_to_dots">Lähtevä puhelu</string>
<string name="incoming_call_from_dots">Tuleva puhelu</string>
<string name="transferring_call_to_dots">Siirtopuhelu …</string>
<string name="outgoing_call_to_dots">Puhelu ulos</string>
<string name="incoming_call_from_dots">Puhelu sisään</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="callee">Puhelun kohde</string>
<string name="hangup">Lopeta</string>

View File

@ -382,8 +382,9 @@
<string name="about">About</string>
<string name="restart">Restart</string>
<string name="quit">Quit</string>
<string name="outgoing_call_to_dots">Outgoing call to …</string>
<string name="incoming_call_from_dots">Incoming call from …</string>
<string name="outgoing_call_to_dots">Call to …</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="invalid_sip_uri">Invalid SIP URI \'%1$s\'</string>
<string name="callee">Callee</string>