Skip to content

Commit a82eece

Browse files
committed
new: CallEvent + ModifyNumber
1 parent 3e42dd4 commit a82eece

63 files changed

Lines changed: 1327 additions & 365 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/src/main/java/spam/blocker/db/BotTable.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.core.database.getStringOrNull
1212
import kotlinx.serialization.Serializable
1313
import spam.blocker.R
1414
import spam.blocker.service.bot.CalendarEvent
15+
import spam.blocker.service.bot.CallEvent
1516
import spam.blocker.service.bot.IAction
1617
import spam.blocker.service.bot.ISchedule
1718
import spam.blocker.service.bot.MyWorkManager
@@ -37,8 +38,10 @@ data class Bot(
3738
val lastLogTime: Long = 0,
3839
) {
3940

41+
// TODO: refactor this ..
42+
4043
// This is shown as the Bot summary on main UI
41-
// 3 types: Scheduled / Manual / CalendarEvent / SmsEvent
44+
// 3 types: Scheduled / Manual / CalendarEvent / SmsEvent / Call_or_SMS
4245
@Composable
4346
fun TriggerType(modifier: Modifier) {
4447
val ctx = LocalContext.current
@@ -58,6 +61,8 @@ data class Bot(
5861
firstAction.TriggerType(modifier)
5962
} else if (firstAction is SmsEvent) {
6063
firstAction.TriggerType(modifier)
64+
} else if (firstAction is CallEvent) {
65+
firstAction.TriggerType(modifier)
6166
} else {
6267
// Manual
6368
GreyLabel(
@@ -78,6 +83,8 @@ data class Bot(
7883
return firstAction.isActivated()
7984
} else if (firstAction is SmsEvent) {
8085
return firstAction.isActivated()
86+
} else if (firstAction is CallEvent) {
87+
return firstAction.isActivated()
8188
}
8289
return false // manually trigger
8390
}

app/src/main/java/spam/blocker/service/SmsReceiver.kt

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@ import android.content.Context
66
import android.content.Intent
77
import android.provider.Telephony
88
import spam.blocker.Events
9-
import spam.blocker.db.BotTable
109
import spam.blocker.db.HistoryRecord
1110
import spam.blocker.db.SmsTable
12-
import spam.blocker.service.bot.ActionContext
13-
import spam.blocker.service.bot.SmsEvent
14-
import spam.blocker.service.bot.executeAll
1511
import spam.blocker.service.checker.Checker
1612
import spam.blocker.service.checker.ICheckResult
1713
import spam.blocker.ui.NotificationTrampolineActivity
@@ -50,41 +46,17 @@ open class SmsReceiver : BroadcastReceiver() {
5046
processSms(ctx, logger = null, rawNumber, messageBody)
5147
}
5248

53-
// Run all workflows that have `SMS Event` as the first action
54-
fun triggerSmsEventWorkflows(
55-
ctx: Context,
56-
logger: ILogger?,
57-
rawNumber: String,
58-
messageBody: String,
59-
) {
60-
BotTable.listAll(ctx)
61-
.filter {
62-
val firstAction = it.actions.firstOrNull()
63-
firstAction is SmsEvent && firstAction.isActivated()
64-
}
65-
.forEach {
66-
val aCtx = ActionContext(
67-
logger = logger,
68-
rawNumber = rawNumber,
69-
smsContent = messageBody,
70-
)
71-
it.actions.executeAll(ctx, aCtx)
72-
}
73-
}
74-
7549
fun processSms(
7650
ctx: Context,
7751
logger: ILogger?,
7852
rawNumber: String,
7953
messageBody: String
8054
): ICheckResult {
8155

82-
triggerSmsEventWorkflows(ctx, logger, rawNumber, messageBody)
83-
8456
val r = Checker.checkSms(ctx, logger, rawNumber, messageBody)
8557

8658
run {
87-
// 1. log to db
59+
// 1. log to history db
8860
val spf = spf.HistoryOptions(ctx)
8961
val isLogEnabled = spf.isLoggingEnabled()
9062
val recordId = if (isLogEnabled)

app/src/main/java/spam/blocker/service/bot/Action.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import kotlinx.coroutines.runBlocking
1313
import kotlinx.coroutines.yield
1414
import kotlinx.serialization.PolymorphicSerializer
1515
import kotlinx.serialization.builtins.ListSerializer
16+
import spam.blocker.service.checker.CheckContext
1617
import spam.blocker.util.ILogger
1718
import spam.blocker.util.Permission
1819
import spam.blocker.util.PermissionWrapper
@@ -24,13 +25,15 @@ import spam.blocker.util.PermissionWrapper
2425

2526
val botActions = listOf(
2627
HttpDownload(),
27-
CalendarEvent(),
2828
SmsEvent(),
29+
CallEvent(),
30+
CalendarEvent(),
2931
ImportToSpamDB(),
3032
CleanupSpamDB(),
3133
ImportAsRegexRule(),
3234
FindRules(),
3335
ModifyRules(),
36+
ModifyNumber(),
3437
ReadFile(),
3538
WriteFile(),
3639
ParseCSV(),
@@ -100,6 +103,12 @@ data class ActionContext(
100103
// to simulate the "priority" of positive/negative identifiers.
101104
// (e.g.: add two `ParseQueryResult` actions, one for positive, one for negative)
102105
var lastParsedQueryData: ByteArray? = null,
106+
107+
// For altering rules on the fly, e.g. temporarily enable a rule for some ongoing calendar event.
108+
// Changes happens in memory and won't persist to the configuration.
109+
var cCtx: CheckContext? = null,
110+
var isInMemory: Boolean = false,
111+
103112
)
104113

105114
interface IAction {

0 commit comments

Comments
 (0)