diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-02-04 18:08:16 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-02-04 18:08:16 -0300 |
| commit | 4a6d1af34e675f92baa53fa10559190906923a33 (patch) | |
| tree | 3d63169ad88bac8aed329b6c52705a47bb9bde53 /android/src | |
| parent | ef166a9f898eb9a98cc35d6b6dfb2fd410831892 (diff) | |
| parent | 8a8b3a601fb64f8dbffae59fead88ce2439012f1 (diff) | |
| download | mullvadvpn-4a6d1af34e675f92baa53fa10559190906923a33.tar.xz mullvadvpn-4a6d1af34e675f92baa53fa10559190906923a33.zip | |
Merge branch 'fix-wireguard-key-error'
Diffstat (limited to 'android/src')
3 files changed, 53 insertions, 13 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/KeyStatusListener.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/KeyStatusListener.kt index 74b10de728..a4fe30ff30 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/KeyStatusListener.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/KeyStatusListener.kt @@ -42,7 +42,7 @@ class KeyStatusListener(val daemon: MullvadDaemon) { val oldStatus = keyStatus val newStatus = daemon.generateWireguardKey() val newFailure = newStatus?.failure() - if (oldStatus is KeygenEvent.NewKey && newStatus != null) { + if (oldStatus is KeygenEvent.NewKey && newFailure != null) { keyStatus = KeygenEvent.NewKey(oldStatus.publicKey, oldStatus.verified, newFailure) diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/model/KeygenEvent.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/model/KeygenEvent.kt index 00764ce9dc..8f283bdfc9 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/model/KeygenEvent.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/model/KeygenEvent.kt @@ -2,7 +2,7 @@ package net.mullvad.mullvadvpn.model sealed class KeygenEvent { class NewKey(val publicKey: PublicKey) : KeygenEvent() { - var verified: Boolean? = false + var verified: Boolean? = null private set var replacementFailure: KeygenFailure? = null private set diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/WireguardKeyFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/WireguardKeyFragment.kt index 74c8b5882c..a44da07d27 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/WireguardKeyFragment.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/WireguardKeyFragment.kt @@ -18,6 +18,7 @@ import java.util.TimeZone 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 @@ -39,6 +40,18 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre private var generatingKey = false private var validatingKey = false + private var resetReconnectionExpectedJob: Job? = null + private var reconnectionExpected = false + set(value) { + field = value + + resetReconnectionExpectedJob?.cancel() + + if (value == true) { + resetReconnectionExpected() + } + } + private lateinit var publicKey: TextView private lateinit var publicKeyAge: TextView private lateinit var statusMessage: TextView @@ -48,6 +61,17 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre private lateinit var verifyButton: Button private lateinit var verifySpinner: ProgressBar + private fun resetReconnectionExpected() { + resetReconnectionExpectedJob = GlobalScope.launch(Dispatchers.Main) { + delay(20_000) + + if (reconnectionExpected) { + reconnectionExpected = false + updateViews() + } + } + } + override fun onSafelyCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -227,16 +251,16 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre when (tunnelState) { is TunnelState.Connecting, is TunnelState.Disconnecting -> { - statusMessage.setText(R.string.wireguard_key_connectivity) - statusMessage.visibility = View.VISIBLE - generateButton.visibility = View.GONE - generateSpinner.visibility = View.VISIBLE - verifyButton.visibility = View.GONE - verifySpinner.visibility = View.VISIBLE + if (!reconnectionExpected) { + setStatusMessage(R.string.wireguard_key_connectivity, R.color.red) + generateButton.visibility = View.GONE + generateSpinner.visibility = View.VISIBLE + verifyButton.visibility = View.GONE + verifySpinner.visibility = View.VISIBLE + } } is TunnelState.Error -> { - statusMessage.setText(R.string.wireguard_key_blocked_state_message) - statusMessage.visibility = View.VISIBLE + setStatusMessage(R.string.wireguard_key_blocked_state_message, R.color.red) generateButton.setClickable(false) generateButton.setAlpha(0.5f) verifyButton.setClickable(false) @@ -249,9 +273,15 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre private fun onGenerateKeyPress() { currentJob?.cancel() - generatingKey = true - validatingKey = false + + synchronized(this) { + generatingKey = true + validatingKey = false + reconnectionExpected = !(tunnelState is TunnelState.Disconnected) + } + updateViews() + currentJob = GlobalScope.launch(Dispatchers.Main) { keyStatusListener.generateKey().join() generatingKey = false @@ -288,6 +318,7 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre keyStatusListener.onKeyStatusChange = null currentJob?.cancel() updateViewsJob?.cancel() + resetReconnectionExpectedJob?.cancel() validatingKey = false generatingKey = false urlController.onPause() @@ -295,7 +326,16 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre override fun onSafelyResume() { tunnelStateListener = connectionProxy.onUiStateChange.subscribe { uiState -> - tunnelState = uiState + synchronized(this@WireguardKeyFragment) { + tunnelState = uiState + + if (generatingKey) { + reconnectionExpected = !(tunnelState is TunnelState.Disconnected) + } else if (tunnelState is TunnelState.Connected) { + reconnectionExpected = false + } + } + updateViewsJob?.cancel() updateViewsJob = updateViewJob() } |
