forked from upstream-mirrors/quik
Block number in android blocking manager
This commit is contained in:
@@ -19,11 +19,10 @@
|
||||
package com.moez.QKSMS.blocking
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.provider.BlockedNumberContract
|
||||
import android.telecom.TelecomManager
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import androidx.core.content.contentValuesOf
|
||||
import com.moez.QKSMS.extensions.anyOf
|
||||
import com.moez.QKSMS.model.BlockedNumber
|
||||
import io.reactivex.Completable
|
||||
@@ -44,15 +43,13 @@ class QkBlockingClient @Inject constructor(private val context: Context) : Block
|
||||
}
|
||||
}
|
||||
|
||||
override fun canBlock(): Boolean = Build.VERSION.SDK_INT < 24
|
||||
override fun canBlock(): Boolean = true
|
||||
|
||||
override fun block(addresses: List<String>): Completable = Completable.fromCallable {
|
||||
when {
|
||||
Build.VERSION.SDK_INT >= 24 -> {
|
||||
val telecomManager = context.getSystemService(Context.TELECOM_SERVICE) as TelecomManager
|
||||
val intent = telecomManager.createManageBlockedNumbersIntent()
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
context.startActivity(intent)
|
||||
Build.VERSION.SDK_INT >= 24 -> addresses.forEach { address ->
|
||||
val cv = contentValuesOf(BlockedNumberContract.BlockedNumbers.COLUMN_ORIGINAL_NUMBER to address)
|
||||
context.contentResolver.insert(BlockedNumberContract.BlockedNumbers.CONTENT_URI, cv)
|
||||
}
|
||||
|
||||
else -> Realm.getDefaultInstance().use { realm ->
|
||||
|
||||
Reference in New Issue
Block a user