mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-03-14 02:10:10 +01:00
add service to block unknown numbers
This commit is contained in:
parent
389f08f174
commit
b24f2455dc
@ -61,6 +61,6 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:55c3180f98'
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:59f709a2a8'
|
||||
implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61'
|
||||
}
|
||||
|
@ -168,6 +168,15 @@
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<service
|
||||
android:name=".services.SimpleCallScreeningService"
|
||||
android:exported="true"
|
||||
android:permission="android.permission.BIND_SCREENING_SERVICE">
|
||||
<intent-filter>
|
||||
<action android:name="android.telecom.CallScreeningService" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<receiver
|
||||
android:name=".receivers.CallActionReceiver"
|
||||
android:enabled="true"
|
||||
|
@ -4,6 +4,7 @@ import android.telecom.Call
|
||||
import android.telecom.Call.STATE_CONNECTING
|
||||
import android.telecom.Call.STATE_DIALING
|
||||
import android.telecom.Call.STATE_SELECT_PHONE_ACCOUNT
|
||||
import com.simplemobiletools.commons.helpers.isQPlus
|
||||
import com.simplemobiletools.commons.helpers.isSPlus
|
||||
|
||||
private val OUTGOING_CALL_STATES = arrayOf(STATE_CONNECTING, STATE_DIALING, STATE_SELECT_PHONE_ACCOUNT)
|
||||
@ -32,7 +33,11 @@ fun Call?.getCallDuration(): Int {
|
||||
}
|
||||
|
||||
fun Call.isOutgoing(): Boolean {
|
||||
return OUTGOING_CALL_STATES.contains(getStateCompat())
|
||||
return if (isQPlus()) {
|
||||
details.callDirection == Call.Details.DIRECTION_OUTGOING
|
||||
} else {
|
||||
OUTGOING_CALL_STATES.contains(getStateCompat())
|
||||
}
|
||||
}
|
||||
|
||||
fun Call.hasCapability(capability: Int): Boolean = (details.callCapabilities and capability) != 0
|
||||
|
@ -0,0 +1,26 @@
|
||||
package com.simplemobiletools.dialer.services
|
||||
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.telecom.Call
|
||||
import android.telecom.CallScreeningService
|
||||
import androidx.annotation.RequiresApi
|
||||
import com.simplemobiletools.commons.extensions.baseConfig
|
||||
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.N)
|
||||
class SimpleCallScreeningService : CallScreeningService() {
|
||||
|
||||
override fun onScreenCall(callDetails: Call.Details) {
|
||||
val simpleContactsHelper = SimpleContactsHelper(this)
|
||||
val number = Uri.decode(callDetails.handle.toString()).substringAfter("tel:").replace("+", "")
|
||||
val isBlocked = baseConfig.blockUnknownNumbers && !simpleContactsHelper.exists(number)
|
||||
val response = CallResponse.Builder()
|
||||
.setDisallowCall(isBlocked)
|
||||
.setRejectCall(isBlocked)
|
||||
.setSkipCallLog(isBlocked)
|
||||
.setSkipNotification(isBlocked)
|
||||
.build()
|
||||
respondToCall(callDetails, response)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user