aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2020-04-01 10:27:43 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2020-04-10 00:09:25 +0530
commit62372f241cd1087c4ffa143ff93381e4da81c8ac (patch)
treeba7aeb9519318f274ff4d276d92aa3c2de3a624d
parentZipExporterPreference: switch to coroutines (diff)
downloadwireguard-android-62372f241cd1087c4ffa143ff93381e4da81c8ac.tar.xz
wireguard-android-62372f241cd1087c4ffa143ff93381e4da81c8ac.zip
IntentReceiver: switch to coroutines
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
-rw-r--r--ui/src/main/java/com/wireguard/android/model/TunnelManager.kt15
1 files changed, 11 insertions, 4 deletions
diff --git a/ui/src/main/java/com/wireguard/android/model/TunnelManager.kt b/ui/src/main/java/com/wireguard/android/model/TunnelManager.kt
index a201d26f..a6cd6dd4 100644
--- a/ui/src/main/java/com/wireguard/android/model/TunnelManager.kt
+++ b/ui/src/main/java/com/wireguard/android/model/TunnelManager.kt
@@ -27,9 +27,12 @@ import com.wireguard.config.Config
import java9.util.concurrent.CompletableFuture
import java9.util.concurrent.CompletionStage
import kotlinx.coroutines.CompletableDeferred
+import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.Job
import kotlinx.coroutines.async
+import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.ArrayList
@@ -214,7 +217,9 @@ class TunnelManager(private val configStore: ConfigStore) : BaseObservable() {
saveState()
}
- class IntentReceiver : BroadcastReceiver() {
+ class IntentReceiver : BroadcastReceiver(), CoroutineScope {
+ override val coroutineContext
+ get() = Job() + Dispatchers.Default
override fun onReceive(context: Context, intent: Intent?) {
val manager = getTunnelManager()
if (intent == null) return
@@ -232,9 +237,11 @@ class TunnelManager(private val configStore: ConfigStore) : BaseObservable() {
else -> return
}
val tunnelName = intent.getStringExtra("tunnel") ?: return
- manager.tunnels.thenAccept {
- val tunnel = it[tunnelName] ?: return@thenAccept
- manager.setTunnelState(tunnel, state)
+ launch {
+ manager.getTunnelsAsync().let {
+ val tunnel = it[tunnelName] ?: return@launch
+ manager.setTunnelState(tunnel, state)
+ }
}
}
}