Respect wantBlock param from SIA

This commit is contained in:
moezbhatti
2019-06-06 19:43:59 -04:00
parent d6f6c66b63
commit 1215770898
@@ -22,6 +22,7 @@ import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.os.Bundle
import android.os.Handler
import android.os.IBinder
import android.os.Message
@@ -102,9 +103,10 @@ class ExternalBlockingManagerImpl @Inject constructor(
val message = Message().apply {
what = GET_NUMBER_RATING
data = bundleOf("number" to address)
replyTo = Messenger(IncomingHandler { rating ->
subject.onSuccess(rating == RATING_NEGATIVE)
Timber.v("Should block: ${rating == RATING_NEGATIVE}")
replyTo = Messenger(IncomingHandler { response ->
val shouldBlock = response.rating == RATING_NEGATIVE || response.wantBlock
subject.onSuccess(shouldBlock)
Timber.v("Should block: $shouldBlock")
// We're done, so unbind the service
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) {
when (msg.what) {
GET_NUMBER_RATING -> callback(msg.data.getInt("rating"))
GET_NUMBER_RATING -> callback(Response(msg.data))
else -> super.handleMessage(msg)
}
}