summaryrefslogtreecommitdiffhomepage
path: root/android/lib/shared/src
diff options
context:
space:
mode:
authorKalle Lindström <karl.lindstrom@mullvad.net>2025-06-09 17:16:45 +0200
committerKalle Lindström <karl.lindstrom@mullvad.net>2025-06-19 09:36:26 +0200
commitcdc2c4d700cd41f37cf4b1607a0396019b1fbee5 (patch)
tree10fbfcebf826159d515b5599634ce5b7be256f54 /android/lib/shared/src
parent1748d8a7b3e8044f6b2718d25903bf1b38afad4e (diff)
downloadmullvadvpn-cdc2c4d700cd41f37cf4b1607a0396019b1fbee5.tar.xz
mullvadvpn-cdc2c4d700cd41f37cf4b1607a0396019b1fbee5.zip
Use AlarmManager for notifications
Instead of scheduling system notifications from a flow we now schedule them independently from the app lifecycle via AlarmManager. This is done so that for example an expiry notification that the user dismissed won't get redisplayed if the app process gets killed and then restarted. When the account exiry time is fetched we schedule an alarm that will show a notification 3 days before the account time expires. This alarm then also schedules a new alarm to show the following notification and so on. To make this work this PR also introduces two new broadcast receivers; one on boot received listener and one on time time/timezone changed listener. Beause Android clears alarms when the devices is rebooted/the time is changed we need these listeners to re-trigger the alarm. To enable the broadcast receivers to re-trigger the alarm we also have to persist the expiry time in the DataStore preferences.
Diffstat (limited to 'android/lib/shared/src')
-rw-r--r--android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/AccountRepository.kt7
1 files changed, 5 insertions, 2 deletions
diff --git a/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/AccountRepository.kt b/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/AccountRepository.kt
index a0edc2faa6..2e922a0895 100644
--- a/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/AccountRepository.kt
+++ b/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/AccountRepository.kt
@@ -9,7 +9,6 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.distinctUntilChanged
-import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.stateIn
@@ -41,7 +40,7 @@ class AccountRepository(
val accountData: StateFlow<AccountData?> =
merge(
- managementService.deviceState.filterNotNull().map { deviceState ->
+ managementService.deviceState.map { deviceState ->
when (deviceState) {
is DeviceState.LoggedIn -> {
managementService.getAccountData(deviceState.accountNumber).getOrNull()
@@ -90,4 +89,8 @@ class AccountRepository(
internal suspend fun onVoucherRedeemed(newExpiry: ZonedDateTime) {
accountData.value?.copy(expiryDate = newExpiry)?.let { _mutableAccountDataCache.emit(it) }
}
+
+ fun resetIsNewAccount() {
+ _isNewAccount.value = false
+ }
}