summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJonatan Rhodin <jonatan.rhodin@mullvad.net>2026-04-21 11:40:58 +0200
committerJonatan Rhodin <jonatan.rhodin@mullvad.net>2026-04-21 11:40:58 +0200
commitb6d3f17768ffdd7ecb8ddaaed1c781cf94d75e5a (patch)
tree02bbf543b44631fd7077f068afe535ca71735637
parent574b6a6e0345e74ba170ae4aabeb4e321a9b2ad4 (diff)
parent1a9be387f364f1b3d8d605763214dbf90c2e6b28 (diff)
downloadmullvadvpn-b6d3f17768ffdd7ecb8ddaaed1c781cf94d75e5a.tar.xz
mullvadvpn-b6d3f17768ffdd7ecb8ddaaed1c781cf94d75e5a.zip
Merge branch 'if-user-has-no-time-left-the-app-will-send-reminders-over-droid-2639'
-rw-r--r--android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/AccountExpiry.kt7
-rw-r--r--android/lib/push-notification/src/main/kotlin/net/mullvad/mullvadvpn/lib/pushnotification/ScheduleNotificationAlarmUseCase.kt20
-rw-r--r--android/lib/push-notification/src/test/kotlin/net/mullvad/mullvadvpn/lib/pushnotification/accountexpiry/AccountExpiryNotificationTriggerTest.kt4
3 files changed, 19 insertions, 12 deletions
diff --git a/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/AccountExpiry.kt b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/AccountExpiry.kt
index 28454f93fb..4876366822 100644
--- a/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/AccountExpiry.kt
+++ b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/AccountExpiry.kt
@@ -15,7 +15,7 @@ val ACCOUNT_EXPIRY_CLOSE_TO_EXPIRY_THRESHOLD: Duration = Duration.ofDays(3)
val ACCOUNT_EXPIRY_NOTIFICATION_UPDATE_INTERVAL: Duration = Duration.ofDays(1)
// Calculate when the alarm that triggers the account expiry notification should be set.
-fun accountExpiryNotificationTriggerAt(now: ZonedDateTime, expiry: ZonedDateTime): ZonedDateTime {
+fun accountExpiryNotificationTriggerAt(now: ZonedDateTime, expiry: ZonedDateTime): ZonedDateTime? {
val untilExpiry = Duration.between(now, expiry)
return if (untilExpiry > ACCOUNT_EXPIRY_CLOSE_TO_EXPIRY_THRESHOLD) {
@@ -24,7 +24,8 @@ fun accountExpiryNotificationTriggerAt(now: ZonedDateTime, expiry: ZonedDateTime
} else {
val wait = untilExpiry.toMillis() % ACCOUNT_EXPIRY_NOTIFICATION_UPDATE_INTERVAL.toMillis()
- // If the expiry is in the past we just return it as it is.
- if (wait >= 0) now + Duration.ofMillis(wait) else expiry
+ // If the expiry is in the past we will return null so that we do not schedule a
+ // notification in the past.
+ if (wait >= 0) now + Duration.ofMillis(wait) else null
}
}
diff --git a/android/lib/push-notification/src/main/kotlin/net/mullvad/mullvadvpn/lib/pushnotification/ScheduleNotificationAlarmUseCase.kt b/android/lib/push-notification/src/main/kotlin/net/mullvad/mullvadvpn/lib/pushnotification/ScheduleNotificationAlarmUseCase.kt
index 5b40970a67..65341ee82d 100644
--- a/android/lib/push-notification/src/main/kotlin/net/mullvad/mullvadvpn/lib/pushnotification/ScheduleNotificationAlarmUseCase.kt
+++ b/android/lib/push-notification/src/main/kotlin/net/mullvad/mullvadvpn/lib/pushnotification/ScheduleNotificationAlarmUseCase.kt
@@ -28,15 +28,21 @@ class ScheduleNotificationAlarmUseCase(
val triggerAt =
accountExpiryNotificationTriggerAt(now = ZonedDateTime.now(), expiry = accountExpiry)
- val triggerAtMillis = triggerAt.toInstant().toEpochMilli()
- val intent = alarmIntent(context)
- alarmManager.set(AlarmManager.RTC, triggerAtMillis, intent)
+ // If the triggerAt time is null, it means that the account has already expired, so we do
+ // not schedule a new notification.
+ if (triggerAt != null) {
+ val triggerAtMillis = triggerAt.toInstant().toEpochMilli()
+
+ val intent = alarmIntent(context)
+ alarmManager.set(AlarmManager.RTC, triggerAtMillis, intent)
+
+ // Change to UTC to avoid leaking the user's time zone in the logs
+ Logger.d(
+ "Scheduling next account expiry alarm for ${triggerAt.withZoneSameInstant(ZoneOffset.UTC)}"
+ )
+ }
- // Change to UTC to avoid leaking the user's time zone in the logs
- Logger.d(
- "Scheduling next account expiry alarm for ${triggerAt.withZoneSameInstant(ZoneOffset.UTC)}"
- )
userPreferencesRepository.setAccountExpiry(accountExpiry)
}
diff --git a/android/lib/push-notification/src/test/kotlin/net/mullvad/mullvadvpn/lib/pushnotification/accountexpiry/AccountExpiryNotificationTriggerTest.kt b/android/lib/push-notification/src/test/kotlin/net/mullvad/mullvadvpn/lib/pushnotification/accountexpiry/AccountExpiryNotificationTriggerTest.kt
index 89c3182772..451d437749 100644
--- a/android/lib/push-notification/src/test/kotlin/net/mullvad/mullvadvpn/lib/pushnotification/accountexpiry/AccountExpiryNotificationTriggerTest.kt
+++ b/android/lib/push-notification/src/test/kotlin/net/mullvad/mullvadvpn/lib/pushnotification/accountexpiry/AccountExpiryNotificationTriggerTest.kt
@@ -62,11 +62,11 @@ class AccountExpiryNotificationTriggerTest {
}
@Test
- fun `account expiry that is in the past should return the account expiry date`() {
+ fun `account expiry that is in the past should return null`() {
val now = ZonedDateTime.now()
val expiry = now.minusDays(1).minusHours(17).minusMinutes(3).minusSeconds(40)
val trigger = accountExpiryNotificationTriggerAt(now, expiry)
- assertEquals(expiry, trigger)
+ assertEquals(null, trigger)
}
}