Allow account to block calls and message from peers not found in contacts
This commit is contained in:
@ -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 = ""
|
||||
|
||||
@ -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 != "") {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -207,6 +207,8 @@
|
||||
<string name="answer_mode_help">Valitsee tulevien puheluiden vastaustavan.</string>
|
||||
<string name="manual">Manuaalinen</string>
|
||||
<string name="auto">Automaattinen</string>
|
||||
<string name="block_unknown">Estä tuntemattomat</string>
|
||||
<string name="block_unknown_help">Estä puhelut ja viestit, joiden lähdettä ei löydy yhteystiedoista.</string>
|
||||
<string name="redirect_mode">Uudelleenohjaustapa</string>
|
||||
<string name="redirect_mode_help">Valitsee toteutetaanko puhelun uudelleenohjauspyyntö
|
||||
automaattisesti vai kysytäänkö vahvistusta.</string>
|
||||
@ -543,9 +545,9 @@
|
||||
<string name="call_failed">Puhelu epäonnistui</string>
|
||||
<string name="call_closed">Puhelu on päättynyt</string>
|
||||
<string name="call_not_secure">Tämä puhelu EI ole turvallinen!</string>
|
||||
<string name="peer_not_verified">Tämä puhelu on turvallinen, mutta kohdetta ei ole
|
||||
<string name="peer_not_verified">Tämä puhelu on turvallinen, mutta puhelun toista osapuolta ei ole
|
||||
todennettu!</string>
|
||||
<string name="call_is_secure">Tämä puhelu on turvallinen ja kohde on
|
||||
<string name="call_is_secure">Tämä puhelu on turvallinen ja puhelun toinen osapuoli on
|
||||
todennettu! Haluatko poistaa todennuksen\?</string>
|
||||
<string name="unverify">Poista todennus</string>
|
||||
<string name="backed_up">Sovelluksen tiedot (äänityksiä lukuunottamatta)
|
||||
|
||||
@ -201,6 +201,8 @@
|
||||
if confirmation is requested.</string>
|
||||
<string name="manual">Manual</string>
|
||||
<string name="auto">Automatic</string>
|
||||
<string name="block_unknown">Block Unknown</string>
|
||||
<string name="block_unknown_help">Block calls and messages from peers that are not found in contacts.</string>
|
||||
<string name="voicemail_uri">Voicemail URI</string>
|
||||
<string name="voicemain_uri_help">SIP URI for checking of voicemail messages. If left empty, voicemail
|
||||
messages (Message Waiting Indications) are not subscribed to.
|
||||
@ -248,6 +250,7 @@
|
||||
<string name="missed_calls_count">%1$d missed calls</string>
|
||||
<string name="transfer_request_to">Call transfer request to</string>
|
||||
<string name="call_auto_rejected">Auto-rejected call from \`%1$s\`</string>
|
||||
<string name="message_auto_rejected">Auto-rejected message from \`%1$s\`</string>
|
||||
<!-- Calls Activity -->
|
||||
<string name="call_history">Call History</string>
|
||||
<string name="call_details">Call Details</string>
|
||||
|
||||
Reference in New Issue
Block a user