mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-04-02 20:41:16 +02:00
Move pattern call blocking logic to CallScreeningService
This commit is contained in:
parent
de5b080df4
commit
129d9e9f66
@ -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,6 +1,5 @@
|
|||||||
package com.simplemobiletools.dialer.extensions
|
package com.simplemobiletools.dialer.extensions
|
||||||
|
|
||||||
import android.net.Uri
|
|
||||||
import android.telecom.Call
|
import android.telecom.Call
|
||||||
import android.telecom.Call.STATE_CONNECTING
|
import android.telecom.Call.STATE_CONNECTING
|
||||||
import android.telecom.Call.STATE_DIALING
|
import android.telecom.Call.STATE_DIALING
|
||||||
@ -42,18 +41,3 @@ fun Call.isOutgoing(): Boolean {
|
|||||||
fun Call.hasCapability(capability: Int): Boolean = (details.callCapabilities and capability) != 0
|
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?.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.content.Context
|
||||||
import android.telecom.Call
|
import android.telecom.Call
|
||||||
import android.telecom.InCallService
|
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.activities.CallActivity
|
||||||
import com.simplemobiletools.dialer.extensions.*
|
import com.simplemobiletools.dialer.extensions.config
|
||||||
|
import com.simplemobiletools.dialer.extensions.isOutgoing
|
||||||
|
import com.simplemobiletools.dialer.extensions.powerManager
|
||||||
import com.simplemobiletools.dialer.helpers.CallManager
|
import com.simplemobiletools.dialer.helpers.CallManager
|
||||||
import com.simplemobiletools.dialer.helpers.CallNotificationManager
|
import com.simplemobiletools.dialer.helpers.CallNotificationManager
|
||||||
import com.simplemobiletools.dialer.helpers.NoCall
|
import com.simplemobiletools.dialer.helpers.NoCall
|
||||||
@ -27,27 +27,21 @@ class CallService : InCallService() {
|
|||||||
|
|
||||||
override fun onCallAdded(call: Call) {
|
override fun onCallAdded(call: Call) {
|
||||||
super.onCallAdded(call)
|
super.onCallAdded(call)
|
||||||
val number = call.getCallerNumber().orEmpty()
|
CallManager.onCallAdded(call)
|
||||||
if (!call.isOutgoing() && !call.isConference() && isNumberBlocked(number.normalizePhoneNumber())) {
|
CallManager.inCallService = this
|
||||||
call.reject(false, null)
|
call.registerCallback(callListener)
|
||||||
return
|
|
||||||
} else {
|
|
||||||
CallManager.onCallAdded(call)
|
|
||||||
CallManager.inCallService = this
|
|
||||||
call.registerCallback(callListener)
|
|
||||||
|
|
||||||
val isScreenLocked = (getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager).isDeviceLocked
|
val isScreenLocked = (getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager).isDeviceLocked
|
||||||
if (!powerManager.isInteractive || call.isOutgoing() || isScreenLocked || config.alwaysShowFullscreen) {
|
if (!powerManager.isInteractive || call.isOutgoing() || isScreenLocked || config.alwaysShowFullscreen) {
|
||||||
try {
|
try {
|
||||||
callNotificationManager.setupNotification(true)
|
callNotificationManager.setupNotification(true)
|
||||||
startActivity(CallActivity.getStartIntent(this))
|
startActivity(CallActivity.getStartIntent(this))
|
||||||
} catch (e: ActivityNotFoundException) {
|
} catch (e: ActivityNotFoundException) {
|
||||||
// seems like startActivity can thrown AndroidRuntimeException and ActivityNotFoundException, not yet sure when and why, lets show a notification
|
// seems like startActivity can thrown AndroidRuntimeException and ActivityNotFoundException, not yet sure when and why, lets show a notification
|
||||||
callNotificationManager.setupNotification()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
callNotificationManager.setupNotification()
|
callNotificationManager.setupNotification()
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
callNotificationManager.setupNotification()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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())) {
|
||||||
val simpleContactsHelper = SimpleContactsHelper(this)
|
respondToCall(callDetails, isBlocked = true)
|
||||||
val number = Uri.decode(callDetails.handle?.toString() ?: "").substringAfter("tel:")
|
} else if (number != null && baseConfig.blockUnknownNumbers) {
|
||||||
val privateCursor = getMyContactsCursor(false, true)
|
val simpleContactsHelper = SimpleContactsHelper(this)
|
||||||
simpleContactsHelper.exists(number, privateCursor) { exists ->
|
val privateCursor = getMyContactsCursor(favoritesOnly = false, withPhoneNumbersOnly = true)
|
||||||
respondToCall(callDetails, !exists)
|
simpleContactsHelper.exists(number, privateCursor) { exists ->
|
||||||
}
|
respondToCall(callDetails, isBlocked = !exists)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
respondToCall(callDetails, false)
|
respondToCall(callDetails, isBlocked = false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user