Added Anonymous and Unknown checks to friendlyUri

This commit is contained in:
Juha Heinanen
2022-03-19 09:17:53 +02:00
parent 9632740c5b
commit ac2571f0dd
10 changed files with 33 additions and 24 deletions

View File

@ -553,17 +553,17 @@ class BaresipService: Service() {
if (!isServiceRunning) return
val ev = event.split(",")
val ua = UserAgent.ofUap(uap)
val aor = ua?.account?.aor
Log.d(TAG, "got uaEvent $event/$aor/$callp")
if (ua == null) {
Log.w(TAG, "uaEvent $event did not find ua $uap")
return
}
val ev = event.split(",")
val aor = ua.account.aor
Log.d(TAG, "got uaEvent $event/$aor/$callp")
val call = Call.ofCallp(callp)
if (call == null && callp != 0L && ev[0] != "call incoming" && ev[0] != "call rejected") {
Log.w(TAG, "uaEvent $event did not find call $callp")
@ -681,7 +681,7 @@ class BaresipService: Service() {
PendingIntent.getActivity(applicationContext, CALL_REQ_CODE, intent,
PendingIntent.FLAG_UPDATE_CURRENT)
val nb = NotificationCompat.Builder(this, HIGH_CHANNEL_ID)
val caller = Utils.friendlyUri(Contact.contactName(peerUri), Utils.aorDomain(aor))
val caller = Utils.friendlyUri(this, Contact.contactName(peerUri), Utils.aorDomain(aor))
nb.setSmallIcon(R.drawable.ic_stat_call)
.setColor(ContextCompat.getColor(this, R.color.colorBaresip))
.setContentIntent(pi)
@ -788,7 +788,7 @@ class BaresipService: Service() {
PendingIntent.getActivity(applicationContext, TRANSFER_REQ_CODE,
intent, PendingIntent.FLAG_UPDATE_CURRENT)
val nb = NotificationCompat.Builder(this, HIGH_CHANNEL_ID)
val target = Utils.friendlyUri(Contact.contactName(ev[1]), Utils.aorDomain(aor))
val target = Utils.friendlyUri(this, Contact.contactName(ev[1]), Utils.aorDomain(aor))
nb.setSmallIcon(R.drawable.ic_stat_call)
.setColor(ContextCompat.getColor(this, R.color.colorBaresip))
.setContentIntent(pi)
@ -869,7 +869,7 @@ class BaresipService: Service() {
}
if (!Utils.isVisible()) {
if (missed) {
val caller = Utils.friendlyUri(Contact.contactName(call.peerUri), Utils.aorDomain(aor))
val caller = Utils.friendlyUri(this, Contact.contactName(call.peerUri), Utils.aorDomain(aor))
val intent = Intent(applicationContext, MainActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or
Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
@ -976,7 +976,7 @@ class BaresipService: Service() {
PendingIntent.getActivity(applicationContext, MESSAGE_REQ_CODE, intent,
PendingIntent.FLAG_UPDATE_CURRENT)
val nb = NotificationCompat.Builder(this, HIGH_CHANNEL_ID)
val sender = Utils.friendlyUri(Contact.contactName(peer), Utils.aorDomain(ua.account.aor))
val sender = Utils.friendlyUri(this, Contact.contactName(peer), Utils.aorDomain(ua.account.aor))
nb.setSmallIcon(R.drawable.ic_stat_message)
.setColor(ContextCompat.getColor(this, R.color.colorBaresip))
.setContentIntent(pi)

View File

@ -64,7 +64,7 @@ class CallListAdapter(private val ctx: Context, private val aor: String, private
val contactName = Contact.contactName(callRow.peerUri)
if (contactName.startsWith("sip:"))
viewHolder.peerURIView.text = Utils.friendlyUri(contactName, Utils.aorDomain(callRow.aor))
viewHolder.peerURIView.text = Utils.friendlyUri(ctx, contactName, Utils.aorDomain(callRow.aor))
else
viewHolder.peerURIView.text = contactName

View File

@ -48,7 +48,7 @@ class CallsActivity : AppCompatActivity() {
val peerUri = uaHistory[pos].peerUri
var peerName = Contact.contactName(peerUri)
if (peerName.startsWith("sip:"))
peerName = Utils.friendlyUri(peerName, Utils.aorDomain(aor))
peerName = Utils.friendlyUri(this, peerName, Utils.aorDomain(aor))
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
when (which) {
DialogInterface.BUTTON_POSITIVE, DialogInterface.BUTTON_NEGATIVE -> {
@ -121,7 +121,7 @@ class CallsActivity : AppCompatActivity() {
with (builder) {
setTitle(R.string.confirmation)
setMessage(String.format(getString(R.string.calls_add_delete_question),
Utils.friendlyUri(peerName, Utils.aorDomain(aor)), callText))
Utils.friendlyUri(this@CallsActivity, peerName, Utils.aorDomain(aor)), callText))
setNeutralButton(getString(R.string.cancel), dialogClickListener)
setPositiveButton(String.format(getString(R.string.delete), callText), dialogClickListener)
setNegativeButton(getString(R.string.add_contact), dialogClickListener)
@ -131,7 +131,7 @@ class CallsActivity : AppCompatActivity() {
with (builder) {
setTitle(R.string.confirmation)
setMessage(String.format(getString(R.string.calls_delete_question),
Utils.friendlyUri(peerName, Utils.aorDomain(aor)), callText))
Utils.friendlyUri(this@CallsActivity, peerName, Utils.aorDomain(aor)), callText))
setNeutralButton(getString(R.string.cancel), dialogClickListener)
setPositiveButton(String.format(getString(R.string.delete), callText), dialogClickListener)
show()

View File

@ -68,7 +68,7 @@ class ChatActivity : AppCompatActivity() {
var chatPeer = Contact.contactName(peerUri)
if (chatPeer.startsWith("sip:"))
chatPeer = Utils.friendlyUri(chatPeer, Utils.aorDomain(aor))
chatPeer = Utils.friendlyUri(this, chatPeer, Utils.aorDomain(aor))
title = String.format(getString(R.string.chat_with), chatPeer)

View File

@ -56,7 +56,7 @@ class ChatListAdapter(private val ctx: Context, private val rows: ArrayList<Mess
viewHolder.peerView.text = if (peerName !=message.peerUri )
peerName
else
Utils.friendlyUri(message.peerUri, message.aor)
Utils.friendlyUri(ctx, message.peerUri, message.aor)
val cal = GregorianCalendar()
cal.timeInMillis = message.timeStamp

View File

@ -101,7 +101,7 @@ class ChatsActivity: AppCompatActivity() {
with (builder) {
setTitle(R.string.confirmation)
setMessage(String.format(getString(R.string.long_chat_question),
Utils.friendlyUri(peer, Utils.aorDomain(aor))))
Utils.friendlyUri(this@ChatsActivity, peer, Utils.aorDomain(aor))))
setNeutralButton(getText(R.string.cancel), dialogClickListener)
setNegativeButton(getText(R.string.delete), dialogClickListener)
setPositiveButton(getText(R.string.add_contact), dialogClickListener)

View File

@ -1090,7 +1090,7 @@ class MainActivity : AppCompatActivity() {
return
}
val call = Call.ofCallp(callp)!!
val target = Utils.friendlyUri(Contact.contactName(ev[1]), Utils.aorDomain(aor))
val target = Utils.friendlyUri(this, Contact.contactName(ev[1]), Utils.aorDomain(aor))
with(MaterialAlertDialogBuilder(this, R.style.AlertDialogTheme)) {
setTitle(R.string.transfer_request)
setMessage(String.format(getString(R.string.transfer_request_query),
@ -1774,7 +1774,7 @@ class MainActivity : AppCompatActivity() {
} else {
val latest = NewCallHistory.aorLatestHistory(aor)
if (latest != null)
callUri.setText(Utils.friendlyUri(Contact.contactName(latest.peerUri),
callUri.setText(Utils.friendlyUri(this, Contact.contactName(latest.peerUri),
Utils.aorDomain(aor)))
}
}
@ -1819,7 +1819,7 @@ class MainActivity : AppCompatActivity() {
else
getString(R.string.outgoing_call_to_dots)
callTimer.visibility = View.INVISIBLE
callUri.setText(Utils.friendlyUri(Contact.contactName(call.peerUri),
callUri.setText(Utils.friendlyUri(this, Contact.contactName(call.peerUri),
Utils.aorDomain(ua.account.aor)))
securityButton.visibility = View.INVISIBLE
callButton.visibility = View.INVISIBLE
@ -1834,7 +1834,7 @@ class MainActivity : AppCompatActivity() {
"incoming" -> {
callTitle.text = getString(R.string.incoming_call_from_dots)
callTimer.visibility = View.INVISIBLE
callUri.setText(Utils.friendlyUri(Contact.contactName(call.peerUri),
callUri.setText(Utils.friendlyUri(this, Contact.contactName(call.peerUri),
Utils.aorDomain(ua.account.aor)))
callUri.setAdapter(null)
securityButton.visibility = View.INVISIBLE
@ -1854,7 +1854,7 @@ class MainActivity : AppCompatActivity() {
}
if (call.referTo != "") {
callTitle.text = getString(R.string.transferring_call_to_dots)
callUri.setText(Utils.friendlyUri(Contact.contactName(call.referTo),
callUri.setText(Utils.friendlyUri(this, Contact.contactName(call.referTo),
Utils.aorDomain(ua.account.aor)))
transferButton.isEnabled = false
} else {
@ -1862,7 +1862,7 @@ class MainActivity : AppCompatActivity() {
callTitle.text = getString(R.string.outgoing_call_to_dots)
else
callTitle.text = getString(R.string.incoming_call_from_dots)
callUri.setText(Utils.friendlyUri(Contact.contactName(call.peerUri),
callUri.setText(Utils.friendlyUri(this, Contact.contactName(call.peerUri),
Utils.aorDomain(ua.account.aor)))
transferButton.isEnabled = true
}

View File

@ -118,7 +118,7 @@ object Utils {
return if (params.size == 1) listOf() else params.subList(1, params.size)
}
fun friendlyUri(uri: String, domain: String): String {
fun friendlyUri(ctx: Context, uri: String, domain: String): String {
var u = uri
val params = uriParams(u)
if (uri.startsWith("<") && (uri.endsWith(">")))
@ -135,7 +135,12 @@ object Utils {
if (isTelNumber(user) || host == domain)
user
else
"$user@$host"
if (host == "anonymous.invalid")
ctx.getString(R.string.anonymous)
else if (host == "unknown.invalid")
ctx.getString(R.string.unknown)
else
"$user@$host"
} else {
u
}

View File

@ -426,6 +426,8 @@
<string name="error">Virhe</string>
<string name="help">Apua</string>
<string name="confirmation">Vahvistus</string>
<string name="anonymous">Anonyymi</string>
<string name="unknown">Tuntematon</string>
<string name="invalid_sip_or_tel_uri">Invalid SIP or tel URI \'%1$s\'</string>
<string name="baresip" translatable="false">baresip</string>
<string name="android" translatable="false">Android</string>

View File

@ -384,6 +384,8 @@
<string name="error">Error</string>
<string name="help">Help</string>
<string name="confirmation">Confirmation</string>
<string name="anonymous">Anonymous</string>
<string name="unknown">Unknown</string>
<string name="dots" translatable="false"></string>
<string name="bullet_item" translatable="false">\u2022 %1$s</string>
<string name="invalid_sip_or_tel_uri">Invalid SIP or tel URI \'%1$s\'</string>