From ac2571f0dd5a9abbe199f253d6b2edb4f420b4c8 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Sat, 19 Mar 2022 09:17:53 +0200 Subject: [PATCH] Added Anonymous and Unknown checks to friendlyUri --- .../com/tutpro/baresip/BaresipService.kt | 18 +++++++++--------- .../com/tutpro/baresip/CallListAdapter.kt | 2 +- .../kotlin/com/tutpro/baresip/CallsActivity.kt | 6 +++--- .../kotlin/com/tutpro/baresip/ChatActivity.kt | 2 +- .../com/tutpro/baresip/ChatListAdapter.kt | 2 +- .../kotlin/com/tutpro/baresip/ChatsActivity.kt | 2 +- .../kotlin/com/tutpro/baresip/MainActivity.kt | 12 ++++++------ .../main/kotlin/com/tutpro/baresip/Utils.kt | 9 +++++++-- app/src/main/res/values-fi/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ 10 files changed, 33 insertions(+), 24 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index ea763dfe..ae69e348 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -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) diff --git a/app/src/main/kotlin/com/tutpro/baresip/CallListAdapter.kt b/app/src/main/kotlin/com/tutpro/baresip/CallListAdapter.kt index 3fcb65c7..8a5c6028 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallListAdapter.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallListAdapter.kt @@ -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 diff --git a/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt index 4a34a596..0c6627c9 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt @@ -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() diff --git a/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt index fa0d0526..b9afa2f9 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt @@ -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) diff --git a/app/src/main/kotlin/com/tutpro/baresip/ChatListAdapter.kt b/app/src/main/kotlin/com/tutpro/baresip/ChatListAdapter.kt index 2c0e92ed..3a0e144e 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ChatListAdapter.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ChatListAdapter.kt @@ -56,7 +56,7 @@ class ChatListAdapter(private val ctx: Context, private val rows: ArrayList { 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 } diff --git a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt index 3eef0819..1879397f 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt @@ -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 } diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index fa7de9c5..601dc6f3 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -426,6 +426,8 @@ Virhe Apua Vahvistus + Anonyymi + Tuntematon Invalid SIP or tel URI \'%1$s\' baresip Android diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d9bb285c..2d19d296 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -384,6 +384,8 @@ Error Help Confirmation + Anonymous + Unknown \u2022 %1$s Invalid SIP or tel URI \'%1$s\'