forked from upstream-mirrors/quik
Respect wantBlock param from SIA
This commit is contained in:
@@ -22,6 +22,7 @@ import android.content.ComponentName
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.ServiceConnection
|
import android.content.ServiceConnection
|
||||||
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.os.Message
|
import android.os.Message
|
||||||
@@ -102,9 +103,10 @@ class ExternalBlockingManagerImpl @Inject constructor(
|
|||||||
val message = Message().apply {
|
val message = Message().apply {
|
||||||
what = GET_NUMBER_RATING
|
what = GET_NUMBER_RATING
|
||||||
data = bundleOf("number" to address)
|
data = bundleOf("number" to address)
|
||||||
replyTo = Messenger(IncomingHandler { rating ->
|
replyTo = Messenger(IncomingHandler { response ->
|
||||||
subject.onSuccess(rating == RATING_NEGATIVE)
|
val shouldBlock = response.rating == RATING_NEGATIVE || response.wantBlock
|
||||||
Timber.v("Should block: ${rating == RATING_NEGATIVE}")
|
subject.onSuccess(shouldBlock)
|
||||||
|
Timber.v("Should block: $shouldBlock")
|
||||||
|
|
||||||
// We're done, so unbind the service
|
// We're done, so unbind the service
|
||||||
if (isBound && serviceMessenger != null) {
|
if (isBound && serviceMessenger != null) {
|
||||||
@@ -122,10 +124,15 @@ class ExternalBlockingManagerImpl @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class IncomingHandler(private val callback: (rating: Int) -> Unit) : Handler() {
|
private class IncomingHandler(private val callback: (response: Response) -> Unit) : Handler() {
|
||||||
|
class Response(bundle: Bundle) {
|
||||||
|
val rating: Int = bundle.getInt("rating")
|
||||||
|
val wantBlock = bundle.getInt("wantBlock") == 1
|
||||||
|
}
|
||||||
|
|
||||||
override fun handleMessage(msg: Message) {
|
override fun handleMessage(msg: Message) {
|
||||||
when (msg.what) {
|
when (msg.what) {
|
||||||
GET_NUMBER_RATING -> callback(msg.data.getInt("rating"))
|
GET_NUMBER_RATING -> callback(Response(msg.data))
|
||||||
else -> super.handleMessage(msg)
|
else -> super.handleMessage(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user