aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/src/main/java/com/wireguard/android/BootShutdownReceiver.kt
diff options
context:
space:
mode:
Diffstat (limited to 'ui/src/main/java/com/wireguard/android/BootShutdownReceiver.kt')
-rw-r--r--ui/src/main/java/com/wireguard/android/BootShutdownReceiver.kt13
1 files changed, 7 insertions, 6 deletions
diff --git a/ui/src/main/java/com/wireguard/android/BootShutdownReceiver.kt b/ui/src/main/java/com/wireguard/android/BootShutdownReceiver.kt
index 41aff76d..70899a0c 100644
--- a/ui/src/main/java/com/wireguard/android/BootShutdownReceiver.kt
+++ b/ui/src/main/java/com/wireguard/android/BootShutdownReceiver.kt
@@ -8,19 +8,20 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
-import com.wireguard.android.backend.Backend
import com.wireguard.android.backend.WgQuickBackend
-import com.wireguard.android.util.ExceptionLoggers
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.GlobalScope
+import kotlinx.coroutines.launch
class BootShutdownReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
- Application.getBackendAsync().thenAccept { backend: Backend? ->
- if (backend !is WgQuickBackend) return@thenAccept
- val action = intent.action ?: return@thenAccept
+ GlobalScope.launch(Dispatchers.Main.immediate) {
+ if (Application.getBackend() !is WgQuickBackend) return@launch
+ val action = intent.action ?: return@launch
val tunnelManager = Application.getTunnelManager()
if (Intent.ACTION_BOOT_COMPLETED == action) {
Log.i(TAG, "Broadcast receiver restoring state (boot)")
- tunnelManager.restoreState(false).whenComplete(ExceptionLoggers.D)
+ tunnelManager.restoreState(false)
} else if (Intent.ACTION_SHUTDOWN == action) {
Log.i(TAG, "Broadcast receiver saving state (shutdown)")
tunnelManager.saveState()