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