mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-06-05 21:49:23 +02:00
Merge pull request #630 from Merkost/block_hidden_numbers_feature
Added blocking calls from hidden numbers
This commit is contained in:
@@ -81,7 +81,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
launchSetDefaultDialerIntent()
|
launchSetDefaultDialerIntent()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isQPlus() && config.blockUnknownNumbers) {
|
if (isQPlus() && (config.blockUnknownNumbers || config.blockHiddenNumbers)) {
|
||||||
setDefaultCallerIdApp()
|
setDefaultCallerIdApp()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,6 +141,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
} else if (requestCode == REQUEST_CODE_SET_DEFAULT_CALLER_ID && resultCode != Activity.RESULT_OK) {
|
} else if (requestCode == REQUEST_CODE_SET_DEFAULT_CALLER_ID && resultCode != Activity.RESULT_OK) {
|
||||||
toast(R.string.must_make_default_caller_id_app, length = Toast.LENGTH_LONG)
|
toast(R.string.must_make_default_caller_id_app, length = Toast.LENGTH_LONG)
|
||||||
baseConfig.blockUnknownNumbers = false
|
baseConfig.blockUnknownNumbers = false
|
||||||
|
baseConfig.blockHiddenNumbers = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
package com.simplemobiletools.dialer.services
|
package com.simplemobiletools.dialer.services
|
||||||
|
|
||||||
import android.net.Uri
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.telecom.Call
|
import android.telecom.Call
|
||||||
import android.telecom.CallScreeningService
|
import android.telecom.CallScreeningService
|
||||||
@@ -15,17 +14,27 @@ import com.simplemobiletools.commons.helpers.SimpleContactsHelper
|
|||||||
class SimpleCallScreeningService : CallScreeningService() {
|
class SimpleCallScreeningService : CallScreeningService() {
|
||||||
|
|
||||||
override fun onScreenCall(callDetails: Call.Details) {
|
override fun onScreenCall(callDetails: Call.Details) {
|
||||||
val number = Uri.decode(callDetails.handle?.toString())?.substringAfter("tel:")
|
val number = callDetails.handle?.schemeSpecificPart
|
||||||
if (number != null && isNumberBlocked(number.normalizePhoneNumber())) {
|
when {
|
||||||
respondToCall(callDetails, isBlocked = true)
|
number != null && isNumberBlocked(number.normalizePhoneNumber()) -> {
|
||||||
} else if (number != null && baseConfig.blockUnknownNumbers) {
|
respondToCall(callDetails, isBlocked = true)
|
||||||
val simpleContactsHelper = SimpleContactsHelper(this)
|
}
|
||||||
val privateCursor = getMyContactsCursor(favoritesOnly = false, withPhoneNumbersOnly = true)
|
|
||||||
simpleContactsHelper.exists(number, privateCursor) { exists ->
|
number != null && baseConfig.blockUnknownNumbers -> {
|
||||||
respondToCall(callDetails, isBlocked = !exists)
|
val simpleContactsHelper = SimpleContactsHelper(this)
|
||||||
|
val privateCursor = getMyContactsCursor(favoritesOnly = false, withPhoneNumbersOnly = true)
|
||||||
|
simpleContactsHelper.exists(number, privateCursor) { exists ->
|
||||||
|
respondToCall(callDetails, isBlocked = !exists)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
number == null && baseConfig.blockHiddenNumbers -> {
|
||||||
|
respondToCall(callDetails, isBlocked = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
respondToCall(callDetails, isBlocked = false)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
respondToCall(callDetails, isBlocked = false)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user