summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorAlbin <albin@mullvad.net>2022-12-01 08:20:17 +0100
committerAlbin <albin@mullvad.net>2022-12-01 08:20:17 +0100
commit6efde79b1ad73f235f56c17d2753343540c3da66 (patch)
treeffb30a70931bb53aa3ef269c726f3cc6fadea56b /android
parent1e7eabbc591ffe554b531c9655b032e5072d22a9 (diff)
parent2214e8dff957539b193f9c7c6373d05dc2b9eef9 (diff)
downloadmullvadvpn-6efde79b1ad73f235f56c17d2753343540c3da66.tar.xz
mullvadvpn-6efde79b1ad73f235f56c17d2753343540c3da66.zip
Merge branch 'add-transition-on-auth-failed-expiry'
Diffstat (limited to 'android')
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt37
-rw-r--r--android/app/src/main/kotlin/net/mullvad/talpid/tunnel/ErrorStateCause.kt8
2 files changed, 15 insertions, 30 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt
index 79c0783fcd..5dc832eaa1 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt
@@ -12,7 +12,6 @@ import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.awaitClose
-import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.collect
@@ -20,7 +19,6 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
-import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.shareIn
import kotlinx.coroutines.launch
import net.mullvad.mullvadvpn.R
@@ -44,7 +42,7 @@ import net.mullvad.mullvadvpn.util.JobTracker
import net.mullvad.mullvadvpn.util.appVersionCallbackFlow
import net.mullvad.mullvadvpn.util.callbackFlowFromNotifier
import net.mullvad.mullvadvpn.viewmodel.ConnectViewModel
-import org.joda.time.DateTime
+import net.mullvad.talpid.tunnel.ErrorStateCause
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.viewModel
@@ -145,7 +143,6 @@ class ConnectFragment : BaseFragment(), NavigationBarPainter {
private fun CoroutineScope.launchUiSubscriptionsOnResume() = launch {
repeatOnLifecycle(Lifecycle.State.RESUMED) {
- launchScheduledExpiryCheck()
launchLocationSubscription()
launchRelayLocationSubscription()
launchTunnelStateSubscription()
@@ -155,17 +152,6 @@ class ConnectFragment : BaseFragment(), NavigationBarPainter {
}
}
- private fun CoroutineScope.launchScheduledExpiryCheck() = launch {
- accountRepository.accountExpiryState
- .map { state -> state.date() }
- .collect { expiryDate ->
- if (expiryDate?.isBeforeNow == true) {
- openOutOfTimeScreen()
- } else if (expiryDate != null)
- scheduleNextAccountExpiryCheck(expiryDate)
- }
- }
-
private fun CoroutineScope.launchLocationSubscription() = launch {
shared
.flatMapLatest { it.locationInfoCache.locationCallbackFlow() }
@@ -235,6 +221,10 @@ class ConnectFragment : BaseFragment(), NavigationBarPainter {
actionButton.tunnelState = uiState
switchLocationButton.tunnelState = uiState
+
+ if (realState.isTunnelErrorStateDueToExpiredAccount()) {
+ openOutOfTimeScreen()
+ }
}
private fun openSwitchLocationScreen() {
@@ -260,19 +250,8 @@ class ConnectFragment : BaseFragment(), NavigationBarPainter {
}
}
- private fun scheduleNextAccountExpiryCheck(expiration: DateTime) {
- jobTracker.newBackgroundJob("refetchAccountExpiry") {
- val millisUntilExpiration = expiration.millis - DateTime.now().millis
-
- delay(millisUntilExpiration)
- accountRepository.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()
- }
+ private fun TunnelState.isTunnelErrorStateDueToExpiredAccount(): Boolean {
+ return ((this as? TunnelState.Error)?.errorState?.cause as? ErrorStateCause.AuthFailed)
+ ?.isCausedByExpiredAccount() ?: false
}
}
diff --git a/android/app/src/main/kotlin/net/mullvad/talpid/tunnel/ErrorStateCause.kt b/android/app/src/main/kotlin/net/mullvad/talpid/tunnel/ErrorStateCause.kt
index f5b79bdfd5..b31f71f1fb 100644
--- a/android/app/src/main/kotlin/net/mullvad/talpid/tunnel/ErrorStateCause.kt
+++ b/android/app/src/main/kotlin/net/mullvad/talpid/tunnel/ErrorStateCause.kt
@@ -4,9 +4,15 @@ import android.os.Parcelable
import java.net.InetAddress
import kotlinx.parcelize.Parcelize
+private const val AUTH_FAILED_REASON_EXPIRED_ACCOUNT = "[EXPIRED_ACCOUNT]"
+
sealed class ErrorStateCause : Parcelable {
@Parcelize
- class AuthFailed(val reason: String?) : ErrorStateCause()
+ class AuthFailed(private val reason: String?) : ErrorStateCause() {
+ fun isCausedByExpiredAccount(): Boolean {
+ return reason == AUTH_FAILED_REASON_EXPIRED_ACCOUNT
+ }
+ }
@Parcelize
object Ipv6Unavailable : ErrorStateCause()