diff --git a/app/src/main/kotlin/com/tutpro/baresip/Account.kt b/app/src/main/kotlin/com/tutpro/baresip/Account.kt
index a10ad8ac..105ded9d 100644
--- a/app/src/main/kotlin/com/tutpro/baresip/Account.kt
+++ b/app/src/main/kotlin/com/tutpro/baresip/Account.kt
@@ -28,6 +28,7 @@ class Account(val accp: Long) {
var dtmfMode = Api.account_dtmfmode(accp)
var answerMode = Api.account_answermode(accp)
var autoRedirect = Api.account_sip_autoredirect(accp)
+ var blockUnknown = false
var vmUri = Api.account_vm_uri(accp)
var vmNew = 0
var vmOld = 0
@@ -72,6 +73,7 @@ class Account(val accp: Long) {
if (Utils.paramExists(extra, "regint"))
configuredRegInt = Utils.paramValue(extra, "regint").toInt()
callHistory = Utils.paramValue(extra, "call_history") == ""
+ blockUnknown= Utils.paramExists(extra, "block_unknown")
if (Utils.paramExists(extra, "country_code"))
countryCode = Utils.paramValue(extra, "country_code")
if (Utils.paramExists(extra, "tel_provider"))
@@ -148,6 +150,9 @@ class Account(val accp: Long) {
if (autoRedirect)
res += ";sip_autoredirect=yes"
+ if (blockUnknown)
+ res += ";block_unknown=yes"
+
res += ";ptime=20;regint=${regint};regq=0.5;pubint=0;inreq_allowed=yes;call_transfer=yes"
var extra = ""
diff --git a/app/src/main/kotlin/com/tutpro/baresip/AccountScreen.kt b/app/src/main/kotlin/com/tutpro/baresip/AccountScreen.kt
index 39f0f265..52c3fee4 100644
--- a/app/src/main/kotlin/com/tutpro/baresip/AccountScreen.kt
+++ b/app/src/main/kotlin/com/tutpro/baresip/AccountScreen.kt
@@ -966,6 +966,31 @@ private fun AccountContent(
}
}
+ @Composable
+ fun BlockUnknown() {
+ val block by viewModel.blockUnknown.collectAsState()
+ Row(
+ Modifier.fillMaxWidth().padding(end = 10.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.Start
+ ) {
+ Text(text = stringResource(R.string.block_unknown),
+ modifier = Modifier
+ .weight(1f)
+ .clickable {
+ alertTitle.value = ctx.getString(R.string.block_unknown)
+ alertMessage.value = ctx.getString(R.string.block_unknown_help)
+ showAlert.value = true
+ },
+ fontSize = 18.sp
+ )
+ Switch(
+ checked = block,
+ onCheckedChange = { viewModel.blockUnknown.value = it }
+ )
+ }
+ }
+
@Composable
fun Voicemail() {
val vmUri by viewModel.vmUri.collectAsState()
@@ -1142,6 +1167,7 @@ private fun AccountContent(
Dtmf()
Answer()
Redirect()
+ BlockUnknown()
Voicemail()
CountryCode()
TelProvider()
@@ -1449,6 +1475,12 @@ private fun checkOnClick(ctx: Context, viewModel: AccountViewModel, ua: UserAgen
Log.d(TAG, "New autoRedirect is ${acc.autoRedirect}")
}
+ val newBlockUnknown = viewModel.blockUnknown.value
+ if (newBlockUnknown != acc.blockUnknown) {
+ acc.blockUnknown = newBlockUnknown
+ Log.d(TAG, "New blockUnknown is ${acc.blockUnknown}")
+ }
+
var newVmUri = viewModel.vmUri.value.trim()
if (newVmUri != acc.vmUri) {
if (newVmUri != "") {
diff --git a/app/src/main/kotlin/com/tutpro/baresip/AccountViewModel.kt b/app/src/main/kotlin/com/tutpro/baresip/AccountViewModel.kt
index 4c818ae9..23f8325f 100644
--- a/app/src/main/kotlin/com/tutpro/baresip/AccountViewModel.kt
+++ b/app/src/main/kotlin/com/tutpro/baresip/AccountViewModel.kt
@@ -23,6 +23,7 @@ class AccountViewModel: ViewModel() {
val dtmfMode = MutableStateFlow(0)
val answerMode = MutableStateFlow(0)
val autoRedirect = MutableStateFlow(false)
+ val blockUnknown = MutableStateFlow(false)
val vmUri = MutableStateFlow("")
val countryCode = MutableStateFlow("")
val telProvider = MutableStateFlow("")
@@ -54,6 +55,7 @@ class AccountViewModel: ViewModel() {
dtmfMode.value = acc.dtmfMode
answerMode.value = acc.answerMode
autoRedirect.value = acc.autoRedirect
+ blockUnknown.value = acc.blockUnknown
vmUri.value = acc.vmUri
countryCode.value = acc.countryCode
telProvider.value = acc.telProvider
diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt
index c6f6f758..565b4716 100644
--- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt
+++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt
@@ -850,34 +850,38 @@ class BaresipService: Service() {
"incoming call" -> {
val peerUri = ev[1]
val bevent = ev[2].toLong()
- val toastMsg = if (!Utils.checkPermissions(this, arrayOf(RECORD_AUDIO)))
+ val blockUnknown = ua.account.blockUnknown && Contact.contactName(peerUri) == peerUri
+ val toastMsg = if (Call.inCall() || blockUnknown)
+ String.format(getString(R.string.call_auto_rejected),
+ Utils.friendlyUri(this, peerUri, ua.account))
+ else if (!Utils.checkPermissions(this, arrayOf(RECORD_AUDIO)))
getString(R.string.no_calls)
else if (!requestAudioFocus(applicationContext))
// request fails if there is an active telephony call
getString(R.string.audio_focus_denied)
- else if (Call.inCall())
- String.format(getString(R.string.call_auto_rejected),
- Utils.friendlyUri(this, peerUri, ua.account))
else
""
if (toastMsg != "") {
- Log.d(TAG, "Auto-rejecting incoming call $uap/$peerUri")
+ Log.d(TAG, "Auto-rejecting incoming call to $uap from $peerUri")
Api.sip_treply(callp, 486, "Busy Here")
Api.bevent_stop(bevent)
toast(toastMsg)
- val name = "callwaiting_$toneCountry"
- val resourceId = applicationContext.resources.getIdentifier(
- name,
- "raw",
- applicationContext.packageName)
- if (resourceId != 0) {
- playUnInterrupted(resourceId, 1)
- } else {
- Log.e(TAG, "Callwaiting tone $name.wav not found\")")
- }
- if (ua.account.callHistory) {
- CallHistoryNew(aor, peerUri, "in").add()
- ua.account.missedCalls = true
+ if (!blockUnknown) {
+ val name = "callwaiting_$toneCountry"
+ val resourceId = applicationContext.resources.getIdentifier(
+ name,
+ "raw",
+ applicationContext.packageName
+ )
+ if (resourceId != 0) {
+ playUnInterrupted(resourceId, 1)
+ } else {
+ Log.e(TAG, "Callwaiting tone $name.wav not found\")")
+ }
+ if (ua.account.callHistory) {
+ CallHistoryNew(aor, peerUri, "in").add()
+ ua.account.missedCalls = true
+ }
}
return
}
@@ -1207,6 +1211,18 @@ class BaresipService: Service() {
return
}
+ if (ua.account.blockUnknown && Contact.contactName(peerUri) == peerUri) {
+ Log.d(TAG, "Auto-rejecting incoming message by $uap from $peerUri")
+ toast(String.format(
+ getString(R.string.message_auto_rejected),
+ Utils.friendlyUri(this, peerUri, ua.account)
+ )
+ )
+ // Api.sip_treply(callp, 486, "Busy Here")
+ // Api.bevent_stop(bevent)
+ return
+ }
+
val charsetString = Utils.paramValue(cType.replace(" ", ""), "charset")
val charset = try {
Charset.forName(charsetString)
diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml
index bb745032..bbcb2f24 100644
--- a/app/src/main/res/values-fi/strings.xml
+++ b/app/src/main/res/values-fi/strings.xml
@@ -207,6 +207,8 @@
Valitsee tulevien puheluiden vastaustavan.
Manuaalinen
Automaattinen
+ Estä tuntemattomat
+ Estä puhelut ja viestit, joiden lähdettä ei löydy yhteystiedoista.
Uudelleenohjaustapa
Valitsee toteutetaanko puhelun uudelleenohjauspyyntö
automaattisesti vai kysytäänkö vahvistusta.
@@ -543,9 +545,9 @@
Puhelu epäonnistui
Puhelu on päättynyt
Tämä puhelu EI ole turvallinen!
- Tämä puhelu on turvallinen, mutta kohdetta ei ole
+ Tämä puhelu on turvallinen, mutta puhelun toista osapuolta ei ole
todennettu!
- Tämä puhelu on turvallinen ja kohde on
+ Tämä puhelu on turvallinen ja puhelun toinen osapuoli on
todennettu! Haluatko poistaa todennuksen\?
Poista todennus
Sovelluksen tiedot (äänityksiä lukuunottamatta)
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 15397fa6..fd93ed61 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -201,6 +201,8 @@
if confirmation is requested.
Manual
Automatic
+ Block Unknown
+ Block calls and messages from peers that are not found in contacts.
Voicemail URI
SIP URI for checking of voicemail messages. If left empty, voicemail
messages (Message Waiting Indications) are not subscribed to.
@@ -248,6 +250,7 @@
%1$d missed calls
Call transfer request to
Auto-rejected call from \`%1$s\`
+ Auto-rejected message from \`%1$s\`
Call History
Call Details