mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-02-19 13:00:37 +01:00
Add the ability to block calls by pattern
This commit is contained in:
parent
6392a9266a
commit
de5b080df4
@ -1,5 +1,6 @@
|
||||
package com.simplemobiletools.dialer.extensions
|
||||
|
||||
import android.net.Uri
|
||||
import android.telecom.Call
|
||||
import android.telecom.Call.STATE_CONNECTING
|
||||
import android.telecom.Call.STATE_DIALING
|
||||
@ -41,3 +42,18 @@ fun Call.isOutgoing(): Boolean {
|
||||
fun Call.hasCapability(capability: Int): Boolean = (details.callCapabilities and capability) != 0
|
||||
|
||||
fun Call?.isConference(): Boolean = this?.details?.hasProperty(Call.Details.PROPERTY_CONFERENCE) == true
|
||||
|
||||
fun Call.getCallerNumber(): String? {
|
||||
val handle = try {
|
||||
details?.handle?.toString()
|
||||
} catch (e: NullPointerException) {
|
||||
null
|
||||
}
|
||||
if (handle != null) {
|
||||
val uri = Uri.decode(handle)
|
||||
if (uri.startsWith("tel:")) {
|
||||
return uri.substringAfter("tel:")
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
@ -5,10 +5,10 @@ import android.content.ActivityNotFoundException
|
||||
import android.content.Context
|
||||
import android.telecom.Call
|
||||
import android.telecom.InCallService
|
||||
import com.simplemobiletools.commons.extensions.isNumberBlocked
|
||||
import com.simplemobiletools.commons.extensions.normalizePhoneNumber
|
||||
import com.simplemobiletools.dialer.activities.CallActivity
|
||||
import com.simplemobiletools.dialer.extensions.config
|
||||
import com.simplemobiletools.dialer.extensions.isOutgoing
|
||||
import com.simplemobiletools.dialer.extensions.powerManager
|
||||
import com.simplemobiletools.dialer.extensions.*
|
||||
import com.simplemobiletools.dialer.helpers.CallManager
|
||||
import com.simplemobiletools.dialer.helpers.CallNotificationManager
|
||||
import com.simplemobiletools.dialer.helpers.NoCall
|
||||
@ -27,21 +27,27 @@ class CallService : InCallService() {
|
||||
|
||||
override fun onCallAdded(call: Call) {
|
||||
super.onCallAdded(call)
|
||||
CallManager.onCallAdded(call)
|
||||
CallManager.inCallService = this
|
||||
call.registerCallback(callListener)
|
||||
val number = call.getCallerNumber().orEmpty()
|
||||
if (!call.isOutgoing() && !call.isConference() && isNumberBlocked(number.normalizePhoneNumber())) {
|
||||
call.reject(false, null)
|
||||
return
|
||||
} else {
|
||||
CallManager.onCallAdded(call)
|
||||
CallManager.inCallService = this
|
||||
call.registerCallback(callListener)
|
||||
|
||||
val isScreenLocked = (getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager).isDeviceLocked
|
||||
if (!powerManager.isInteractive || call.isOutgoing() || isScreenLocked || config.alwaysShowFullscreen) {
|
||||
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
|
||||
val isScreenLocked = (getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager).isDeviceLocked
|
||||
if (!powerManager.isInteractive || call.isOutgoing() || isScreenLocked || config.alwaysShowFullscreen) {
|
||||
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
|
||||
callNotificationManager.setupNotification()
|
||||
}
|
||||
} else {
|
||||
callNotificationManager.setupNotification()
|
||||
}
|
||||
} else {
|
||||
callNotificationManager.setupNotification()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user