summaryrefslogtreecommitdiffhomepage
path: root/android/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'android/app/src')
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/receiver/NotificationAlarmReceiver.kt7
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/BroadcastReceiverExtensions.kt23
2 files changed, 27 insertions, 3 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/receiver/NotificationAlarmReceiver.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/receiver/NotificationAlarmReceiver.kt
index 7b8ab4e04a..49bd290230 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/receiver/NotificationAlarmReceiver.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/receiver/NotificationAlarmReceiver.kt
@@ -6,9 +6,9 @@ import android.content.Intent
import co.touchlab.kermit.Logger
import java.time.Duration
import java.time.ZonedDateTime
-import kotlinx.coroutines.runBlocking
import net.mullvad.mullvadvpn.service.notifications.accountexpiry.AccountExpiryNotificationProvider
import net.mullvad.mullvadvpn.usecase.ScheduleNotificationAlarmUseCase
+import net.mullvad.mullvadvpn.util.goAsync
import net.mullvad.mullvadvpn.util.serializable
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
@@ -28,8 +28,9 @@ class NotificationAlarmReceiver : BroadcastReceiver(), KoinComponent {
Logger.d("Account expiry alarm triggered")
val untilExpiry = Duration.between(ZonedDateTime.now(), expiry)
- runBlocking {
- notificationProvider.showNotification(untilExpiry)
+ notificationProvider.showNotification(untilExpiry)
+
+ goAsync {
// Only schedule the next alarm if we still have time left on the account.
if (context != null && expiry > ZonedDateTime.now()) {
scheduleNotificationAlarmUseCase(context = context, accountExpiry = expiry)
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/BroadcastReceiverExtensions.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/BroadcastReceiverExtensions.kt
new file mode 100644
index 0000000000..9d835a96a7
--- /dev/null
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/BroadcastReceiverExtensions.kt
@@ -0,0 +1,23 @@
+package net.mullvad.mullvadvpn.util
+
+import android.content.BroadcastReceiver
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.DelicateCoroutinesApi
+import kotlinx.coroutines.GlobalScope
+import kotlinx.coroutines.launch
+
+@OptIn(DelicateCoroutinesApi::class)
+fun BroadcastReceiver.goAsync(
+ coroutineScope: CoroutineScope = GlobalScope,
+ block: suspend () -> Unit,
+) {
+ val result = goAsync()
+ coroutineScope.launch {
+ try {
+ block()
+ } finally {
+ // Always call finish(), even if the coroutineScope was cancelled
+ result.finish()
+ }
+ }
+}