Don't unblock numbers not reported by SIA

This commit is contained in:
moezbhatti
2019-08-30 16:54:05 +02:00
parent 03af81336c
commit e1b1a6c8db
11 changed files with 69 additions and 66 deletions
@@ -34,9 +34,9 @@ class BlockingManager @Inject constructor(
override fun isAvailable(): Boolean = client.isAvailable()
override fun getClientCapability(): BlockingClientCapability = client.getClientCapability()
override fun getClientCapability(): BlockingClient.Capability = client.getClientCapability()
override fun isBlocked(address: String): Single<Boolean> = client.isBlocked(address)
override fun getAction(address: String): Single<BlockingClient.Action> = client.getAction(address)
override fun block(addresses: List<String>): Completable = client.block(addresses)
@@ -46,16 +46,19 @@ class CallControlBlockingClient @Inject constructor(
override fun isAvailable(): Boolean = context.isInstalled("com.flexaspect.android.everycallcontrol")
override fun getClientCapability() = BlockingClientCapability.BLOCK_WITH_PERMISSION
override fun getClientCapability() = BlockingClient.Capability.BLOCK_WITH_PERMISSION
override fun isBlocked(address: String): Single<Boolean> {
override fun getAction(address: String): Single<BlockingClient.Action> = Single.fromCallable {
val uri = Uri.withAppendedPath(CallControl.LOOKUP_TEXT_URI, address)
return Single.fromCallable {
tryOrNull {
context.contentResolver.query(uri, projection, null, null, null) // Query URI
?.use { cursor -> cursor.map(::LookupResult) } // Map to Result object
?.any { result -> result.blockReason != null } // Check if any are blocked
} == true // If none are blocked or we errored at some point, return false
val blocked = tryOrNull {
context.contentResolver.query(uri, projection, null, null, null) // Query URI
?.use { cursor -> cursor.map(::LookupResult) } // Map to Result object
?.any { result -> result.blockReason != null } // Check if any are blocked
} == true // If none are blocked or we errored at some point, return false
when (blocked) {
true -> BlockingClient.Action.BLOCK
false -> BlockingClient.Action.UNBLOCK
}
}
@@ -29,10 +29,13 @@ class QksmsBlockingClient @Inject constructor(
override fun isAvailable(): Boolean = true
override fun getClientCapability() = BlockingClientCapability.BLOCK_WITHOUT_PERMISSION
override fun getClientCapability() = BlockingClient.Capability.BLOCK_WITHOUT_PERMISSION
override fun isBlocked(address: String): Single<Boolean> = Single.fromCallable {
blockingRepo.isBlocked(address)
override fun getAction(address: String): Single<BlockingClient.Action> = Single.fromCallable {
when (blockingRepo.isBlocked(address)) {
true -> BlockingClient.Action.BLOCK
false -> BlockingClient.Action.UNBLOCK
}
}
override fun block(addresses: List<String>): Completable = Completable.fromCallable {
@@ -53,13 +53,16 @@ class ShouldIAnswerBlockingClient @Inject constructor(
"org.mistergroup.muzutozvednout")
.any(context::isInstalled)
override fun getClientCapability() = BlockingClientCapability.CANT_BLOCK
override fun getClientCapability() = BlockingClient.Capability.CANT_BLOCK
/**
* Return a Single<Boolean> which emits whether or not the given [address] should be blocked
*/
override fun isBlocked(address: String): Single<Boolean> {
override fun getAction(address: String): Single<BlockingClient.Action> {
return Binder(context, address).isBlocked()
.map { blocked ->
when (blocked) {
true -> BlockingClient.Action.BLOCK
false -> BlockingClient.Action.DO_NOTHING
}
}
}
override fun block(addresses: List<String>): Completable = Completable.fromCallable { openSettings() }
@@ -355,7 +355,7 @@ class ConversationRepositoryImpl @Inject constructor(
}
conversation.blocked = recipients.any { recipient ->
blockingClient.isBlocked(recipient.address).blockingGet()
blockingClient.getAction(recipient.address).blockingGet() == BlockingClient.Action.BLOCK
}
conversation.recipients.clear()