diff options
| author | Kalle Lindström <karl.lindstrom@mullvad.net> | 2025-06-09 17:16:45 +0200 |
|---|---|---|
| committer | Kalle Lindström <karl.lindstrom@mullvad.net> | 2025-06-19 09:36:26 +0200 |
| commit | cdc2c4d700cd41f37cf4b1607a0396019b1fbee5 (patch) | |
| tree | 10fbfcebf826159d515b5599634ce5b7be256f54 /android/test/mockapi/src | |
| parent | 1748d8a7b3e8044f6b2718d25903bf1b38afad4e (diff) | |
| download | mullvadvpn-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/test/mockapi/src')
| -rw-r--r-- | android/test/mockapi/src/main/kotlin/net/mullvad/mullvadvpn/test/mockapi/AccountExpiryMockApiTest.kt | 61 |
1 files changed, 45 insertions, 16 deletions
diff --git a/android/test/mockapi/src/main/kotlin/net/mullvad/mullvadvpn/test/mockapi/AccountExpiryMockApiTest.kt b/android/test/mockapi/src/main/kotlin/net/mullvad/mullvadvpn/test/mockapi/AccountExpiryMockApiTest.kt index 7aec8f4725..43020435df 100644 --- a/android/test/mockapi/src/main/kotlin/net/mullvad/mullvadvpn/test/mockapi/AccountExpiryMockApiTest.kt +++ b/android/test/mockapi/src/main/kotlin/net/mullvad/mullvadvpn/test/mockapi/AccountExpiryMockApiTest.kt @@ -2,6 +2,7 @@ package net.mullvad.mullvadvpn.test.mockapi import androidx.test.uiautomator.By import java.time.ZonedDateTime +import net.mullvad.mullvadvpn.test.common.constant.VERY_LONG_TIMEOUT import net.mullvad.mullvadvpn.test.common.extension.findObjectWithTimeout import net.mullvad.mullvadvpn.test.common.page.AccountPage import net.mullvad.mullvadvpn.test.common.page.ConnectPage @@ -18,14 +19,7 @@ class AccountExpiryMockApiTest : MockApiTest() { @Test fun testAccountExpiryDateUpdated() { // Arrange - val validAccountNumber = "1234123412341234" - val oldAccountExpiry = ZonedDateTime.now().plusMonths(1) - apiDispatcher.apply { - expectedAccountNumber = validAccountNumber - accountExpiry = oldAccountExpiry - devices = DEFAULT_DEVICE_LIST.toMutableMap() - devicePendingToGetCreated = DUMMY_ID_2 to DUMMY_DEVICE_NAME_2 - } + val (validAccountNumber, oldAccountExpiry) = configureAccount() // Act app.launchAndLogIn(validAccountNumber) @@ -45,14 +39,7 @@ class AccountExpiryMockApiTest : MockApiTest() { @Test fun testAccountTimeExpiredWhileUsingTheAppShouldShowOutOfTimeScreen() { // Arrange - val validAccountNumber = "1234123412341234" - val oldAccountExpiry = ZonedDateTime.now().plusMonths(1) - apiDispatcher.apply { - expectedAccountNumber = validAccountNumber - accountExpiry = oldAccountExpiry - devices = DEFAULT_DEVICE_LIST.toMutableMap() - devicePendingToGetCreated = DUMMY_ID_2 to DUMMY_DEVICE_NAME_2 - } + val (validAccountNumber, oldAccountExpiry) = configureAccount() // Act app.launchAndLogIn(validAccountNumber) @@ -75,4 +62,46 @@ class AccountExpiryMockApiTest : MockApiTest() { // Assert that we show the out of time screen on<OutOfTimePage>() } + + @Test + fun testAccountTimeExpiryNotificationIsShown() { + // Arrange + val (validAccountNumber, _) = configureAccount() + + // Act + app.launchAndLogIn(validAccountNumber) + + // Wait for us to be on connect page before changing expiry + on<ConnectPage>() + + // Set account time as expired + val newAccountExpiry = ZonedDateTime.now().plusDays(3).plusSeconds(5) + apiDispatcher.accountExpiry = newAccountExpiry + + on<ConnectPage> { clickAccount() } + + // Go to account page to update the account expiry + on<AccountPage>() + + // Go back to the main screen + device.openNotification() + + // Make sure the notification is shown + device.findObjectWithTimeout( + By.text("Account credit expires in 2 days"), + timeout = VERY_LONG_TIMEOUT, + ) + } + + private fun configureAccount(): Pair<String, ZonedDateTime> { + val validAccountNumber = "1234123412341234" + val oldAccountExpiry = ZonedDateTime.now().plusMonths(1) + apiDispatcher.apply { + expectedAccountNumber = validAccountNumber + accountExpiry = oldAccountExpiry + devices = DEFAULT_DEVICE_LIST.toMutableMap() + devicePendingToGetCreated = DUMMY_ID_2 to DUMMY_DEVICE_NAME_2 + } + return Pair(validAccountNumber, oldAccountExpiry) + } } |
