Made blocking rules account specific
This commit is contained in:
@ -1074,7 +1074,7 @@ class BaresipService: Service() {
|
|||||||
blockedCall = true
|
blockedCall = true
|
||||||
getString(R.string.hidden_call_blocked)
|
getString(R.string.hidden_call_blocked)
|
||||||
}
|
}
|
||||||
else if (isBlocked(peerUri)) {
|
else if (isBlocked(ua.account.aor, peerUri)) {
|
||||||
blockedCall = true
|
blockedCall = true
|
||||||
String.format(
|
String.format(
|
||||||
getString(R.string.call_blocked),
|
getString(R.string.call_blocked),
|
||||||
@ -1523,7 +1523,7 @@ class BaresipService: Service() {
|
|||||||
|
|
||||||
if ((ua.account.blockUnknown && Contact.contactName(peerUri) == peerUri) ||
|
if ((ua.account.blockUnknown && Contact.contactName(peerUri) == peerUri) ||
|
||||||
(ua.account.blockHidden && peerUri.contains("anonymous")) ||
|
(ua.account.blockHidden && peerUri.contains("anonymous")) ||
|
||||||
isBlocked(peerUri)) {
|
isBlocked(aor, peerUri)) {
|
||||||
Log.d(TAG, "Auto-rejecting blocked message from $peerUri")
|
Log.d(TAG, "Auto-rejecting blocked message from $peerUri")
|
||||||
toast(
|
toast(
|
||||||
if (ua.account.blockHidden && peerUri.contains("anonymous"))
|
if (ua.account.blockHidden && peerUri.contains("anonymous"))
|
||||||
@ -2176,7 +2176,7 @@ class BaresipService: Service() {
|
|||||||
).add()
|
).add()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (isBlocked(uri)) {
|
if (isBlocked(ua.account.aor, uri)) {
|
||||||
Log.d(TAG, "Auto-rejecting incoming PSTN call from $uri by block rule")
|
Log.d(TAG, "Auto-rejecting incoming PSTN call from $uri by block rule")
|
||||||
telecomCall.disconnect()
|
telecomCall.disconnect()
|
||||||
toast(
|
toast(
|
||||||
@ -3188,9 +3188,9 @@ class BaresipService: Service() {
|
|||||||
var blocked = ArrayList<Blocked>()
|
var blocked = ArrayList<Blocked>()
|
||||||
var blockRules = mutableListOf<BlockRule>()
|
var blockRules = mutableListOf<BlockRule>()
|
||||||
|
|
||||||
fun isBlocked(uri: String): Boolean {
|
fun isBlocked(aor: String, uri: String): Boolean {
|
||||||
for (rule in blockRules)
|
for (rule in blockRules)
|
||||||
if (rule.matches(uri)) return true
|
if ((rule.aor == aor || rule.aor == "") && rule.matches(uri)) return true
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import java.io.File
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class BlockRule(
|
class BlockRule(
|
||||||
|
val aor: String = "",
|
||||||
val pattern: String
|
val pattern: String
|
||||||
) {
|
) {
|
||||||
fun matches(uri: String): Boolean {
|
fun matches(uri: String): Boolean {
|
||||||
@ -18,8 +19,8 @@ class BlockRule(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun exists(pattern: String): Boolean {
|
fun exists(aor: String, pattern: String): Boolean {
|
||||||
return BaresipService.blockRules.any { it.pattern == pattern }
|
return BaresipService.blockRules.any { it.aor == aor && it.pattern == pattern }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun save() {
|
fun save() {
|
||||||
|
|||||||
@ -77,7 +77,9 @@ fun NavGraphBuilder.blockingScreenRoute(navController: NavController) {
|
|||||||
@Composable
|
@Composable
|
||||||
fun BlockingScreen(navController: NavController, viewModel: AccountViewModel, ua: UserAgent) {
|
fun BlockingScreen(navController: NavController, viewModel: AccountViewModel, ua: UserAgent) {
|
||||||
val acc = ua.account
|
val acc = ua.account
|
||||||
var rules by remember { mutableStateOf(BaresipService.blockRules.toList()) }
|
var rules by remember {
|
||||||
|
mutableStateOf(BaresipService.blockRules.filter { it.aor == acc.aor || it.aor == "" })
|
||||||
|
}
|
||||||
|
|
||||||
remember {
|
remember {
|
||||||
viewModel.loadAccount(acc)
|
viewModel.loadAccount(acc)
|
||||||
@ -111,14 +113,14 @@ fun BlockingScreen(navController: NavController, viewModel: AccountViewModel, ua
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
bottomBar = { NewRule(onRuleAdded = { rules = BaresipService.blockRules.toList() }) },
|
bottomBar = { NewRule(acc.aor, onRuleAdded = { rules = BaresipService.blockRules.filter { it.aor == acc.aor || it.aor == "" } }) },
|
||||||
content = { contentPadding ->
|
content = { contentPadding ->
|
||||||
BlockingContent(
|
BlockingContent(
|
||||||
contentPadding,
|
contentPadding,
|
||||||
viewModel,
|
viewModel,
|
||||||
rules,
|
rules,
|
||||||
acc,
|
acc,
|
||||||
onRuleDeleted = { rules = BaresipService.blockRules.toList() }
|
onRuleDeleted = { rules = BaresipService.blockRules.filter { it.aor == acc.aor || it.aor == "" } }
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -294,7 +296,7 @@ fun BlockingContent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun NewRule(onRuleAdded: () -> Unit) {
|
fun NewRule(aor: String, onRuleAdded: () -> Unit) {
|
||||||
val alertTitle = remember { mutableStateOf("") }
|
val alertTitle = remember { mutableStateOf("") }
|
||||||
val alertMessage = remember { mutableStateOf("") }
|
val alertMessage = remember { mutableStateOf("") }
|
||||||
val showAlert = remember { mutableStateOf(false) }
|
val showAlert = remember { mutableStateOf(false) }
|
||||||
@ -353,8 +355,8 @@ fun NewRule(onRuleAdded: () -> Unit) {
|
|||||||
modifier = Modifier.offset(y = 2.dp),
|
modifier = Modifier.offset(y = 2.dp),
|
||||||
onClick = {
|
onClick = {
|
||||||
if (pattern.trim().isNotEmpty()) {
|
if (pattern.trim().isNotEmpty()) {
|
||||||
if (!BlockRule.exists(pattern.trim())) {
|
if (!BlockRule.exists(aor, pattern.trim())) {
|
||||||
BaresipService.blockRules.add(BlockRule(pattern.trim()))
|
BaresipService.blockRules.add(BlockRule(aor, pattern.trim()))
|
||||||
BlockRule.save()
|
BlockRule.save()
|
||||||
onRuleAdded()
|
onRuleAdded()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -444,8 +444,8 @@ private fun Calls(
|
|||||||
}
|
}
|
||||||
thirdButtonText.value = ctx.getString(R.string.block)
|
thirdButtonText.value = ctx.getString(R.string.block)
|
||||||
thirdAction.value = {
|
thirdAction.value = {
|
||||||
if (!BlockRule.exists(peerUri)) {
|
if (!BlockRule.exists(ua.account.aor, peerUri)) {
|
||||||
BaresipService.blockRules.add(BlockRule(peerUri))
|
BaresipService.blockRules.add(BlockRule(ua.account.aor, peerUri))
|
||||||
BlockRule.save()
|
BlockRule.save()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -376,8 +376,8 @@ private fun Chats(
|
|||||||
secondAction.value = { navController.navigate("contact/${message.peerUri}/new") }
|
secondAction.value = { navController.navigate("contact/${message.peerUri}/new") }
|
||||||
thirdButtonText.value = blockText
|
thirdButtonText.value = blockText
|
||||||
thirdAction.value = {
|
thirdAction.value = {
|
||||||
if (!BlockRule.exists(message.peerUri)) {
|
if (!BlockRule.exists(account.aor, message.peerUri)) {
|
||||||
BaresipService.blockRules.add(BlockRule(message.peerUri))
|
BaresipService.blockRules.add(BlockRule(account.aor, message.peerUri))
|
||||||
BlockRule.save()
|
BlockRule.save()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user