diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-05-11 14:21:32 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-05-12 17:32:45 +0000 |
| commit | cecbee01d0184b14c940f46b1fefbe8b59485073 (patch) | |
| tree | 375849e541b4b7fb6546a57df6a33202bab8d284 /android | |
| parent | e7446354e63288588519422a559f8c9def121d07 (diff) | |
| download | mullvadvpn-cecbee01d0184b14c940f46b1fefbe8b59485073.tar.xz mullvadvpn-cecbee01d0184b14c940f46b1fefbe8b59485073.zip | |
Recheck account time when expiry time is reached
Diffstat (limited to 'android')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt index 8a0953010a..22960d5e73 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt @@ -8,11 +8,13 @@ import android.widget.ImageButton import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.Job +import kotlinx.coroutines.delay import kotlinx.coroutines.launch import net.mullvad.mullvadvpn.R import net.mullvad.mullvadvpn.model.KeygenEvent import net.mullvad.mullvadvpn.model.TunnelState import net.mullvad.mullvadvpn.util.JobTracker +import org.joda.time.DateTime val KEY_IS_TUNNEL_INFO_EXPANDED = "is_tunnel_info_expanded" @@ -105,6 +107,8 @@ class ConnectFragment : ServiceDependentFragment(OnNoService.GoToLaunchScreen) { accountCache.onAccountDataChange = { _, expiry -> if (expiry?.isBeforeNow() ?: false) { openOutOfTimeScreen() + } else if (expiry != null) { + scheduleNextAccountExpiryCheck(expiry) } } } @@ -173,4 +177,20 @@ class ConnectFragment : ServiceDependentFragment(OnNoService.GoToLaunchScreen) { } } } + + private fun scheduleNextAccountExpiryCheck(expiration: DateTime) { + jobTracker.newBackgroundJob("refetchAccountExpiry") { + val millisUntilExpiration = expiration.millis - DateTime.now().millis + + delay(millisUntilExpiration) + accountCache.fetchAccountExpiry() + + // If the account ran out of time but is still connected, fetching the expiry again will + // fail. Therefore, after a timeout of 5 seconds the app will assume the account time + // really expired and move to the out of time screen. However, if fetching the expiry + // succeeds, this job is cancelled and replaced with a new scheduled check. + delay(5_000) + openOutOfTimeScreen() + } + } } |
