Skip to content

Commit 60f97bf

Browse files
committed
Update MyCallReceiver to block already spam local numbers
1 parent 76813e8 commit 60f97bf

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

app/src/main/java/com/addev/listaspam/MyCallReceiver.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ import androidx.annotation.RequiresApi
1919
@RequiresApi(Build.VERSION_CODES.P)
2020
class MyCallReceiver : BroadcastReceiver() {
2121

22+
companion object {
23+
private const val SPAM_PREFS = "SPAM_PREFS"
24+
private const val BLOCK_NUMBERS_KEY = "BLOCK_NUMBERS"
25+
}
26+
2227
private val spamUtils = SpamUtils()
2328

2429
/**
@@ -44,6 +49,15 @@ class MyCallReceiver : BroadcastReceiver() {
4449
* @param incomingNumber The incoming phone number.
4550
*/
4651
private fun handleIncomingCall(context: Context, incomingNumber: String) {
52+
val sharedPreferences = context.getSharedPreferences(SPAM_PREFS, Context.MODE_PRIVATE)
53+
val blockedNumbers = sharedPreferences.getStringSet(BLOCK_NUMBERS_KEY, null)
54+
55+
// End call if the number is already blocked
56+
if (blockedNumbers?.contains(incomingNumber) == true) {
57+
endCall(context)
58+
return
59+
}
60+
4761
spamUtils.checkSpamNumber(context, incomingNumber) { isSpam ->
4862
if (isSpam) {
4963
endCall(context)

0 commit comments

Comments
 (0)