mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-03-23 14:50:13 +01:00
Merge pull request #445 from Naveen3Singh/blocking_calls
Add the ability to block calls using pattern
This commit is contained in:
commit
890401b8c6
@ -62,7 +62,7 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:28e3b108e7'
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:15c753bd01'
|
||||
implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61'
|
||||
implementation 'me.grantland:autofittextview:0.2.1'
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.simplemobiletools.dialer.services
|
||||
|
||||
import android.app.KeyguardManager
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Context
|
||||
import android.telecom.Call
|
||||
import android.telecom.InCallService
|
||||
@ -36,8 +35,8 @@ class CallService : InCallService() {
|
||||
try {
|
||||
callNotificationManager.setupNotification(true)
|
||||
startActivity(CallActivity.getStartIntent(this))
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
// seems like startActivity can thrown AndroidRuntimeException and ActivityNotFoundException, not yet sure when and why, lets show a notification
|
||||
} catch (e: Exception) {
|
||||
// seems like startActivity can throw AndroidRuntimeException and ActivityNotFoundException, not yet sure when and why, lets show a notification
|
||||
callNotificationManager.setupNotification()
|
||||
}
|
||||
} else {
|
||||
|
@ -7,23 +7,25 @@ import android.telecom.CallScreeningService
|
||||
import androidx.annotation.RequiresApi
|
||||
import com.simplemobiletools.commons.extensions.baseConfig
|
||||
import com.simplemobiletools.commons.extensions.getMyContactsCursor
|
||||
import com.simplemobiletools.commons.extensions.isNumberBlocked
|
||||
import com.simplemobiletools.commons.extensions.normalizePhoneNumber
|
||||
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.N)
|
||||
class SimpleCallScreeningService : CallScreeningService() {
|
||||
|
||||
override fun onScreenCall(callDetails: Call.Details) {
|
||||
if (baseConfig.blockUnknownNumbers) {
|
||||
if (callDetails.handle != null) {
|
||||
val simpleContactsHelper = SimpleContactsHelper(this)
|
||||
val number = Uri.decode(callDetails.handle?.toString() ?: "").substringAfter("tel:")
|
||||
val privateCursor = getMyContactsCursor(false, true)
|
||||
simpleContactsHelper.exists(number, privateCursor) { exists ->
|
||||
respondToCall(callDetails, !exists)
|
||||
}
|
||||
val number = Uri.decode(callDetails.handle?.toString())?.substringAfter("tel:")
|
||||
if (number != null && isNumberBlocked(number.normalizePhoneNumber())) {
|
||||
respondToCall(callDetails, isBlocked = true)
|
||||
} else if (number != null && baseConfig.blockUnknownNumbers) {
|
||||
val simpleContactsHelper = SimpleContactsHelper(this)
|
||||
val privateCursor = getMyContactsCursor(favoritesOnly = false, withPhoneNumbersOnly = true)
|
||||
simpleContactsHelper.exists(number, privateCursor) { exists ->
|
||||
respondToCall(callDetails, isBlocked = !exists)
|
||||
}
|
||||
} else {
|
||||
respondToCall(callDetails, false)
|
||||
respondToCall(callDetails, isBlocked = false)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user