Merge pull request #445 from Naveen3Singh/blocking_calls

Add the ability to block calls using pattern
This commit is contained in:
Tibor Kaputa 2022-09-14 11:31:24 +02:00 committed by GitHub
commit 890401b8c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 13 deletions

View File

@ -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'
}

View File

@ -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 {

View File

@ -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)
}
}