diff --git a/app/src/main/java/nl/eduvpn/app/fragment/ConnectionStatusFragment.kt b/app/src/main/java/nl/eduvpn/app/fragment/ConnectionStatusFragment.kt index fee4747b..d4d7690b 100644 --- a/app/src/main/java/nl/eduvpn/app/fragment/ConnectionStatusFragment.kt +++ b/app/src/main/java/nl/eduvpn/app/fragment/ConnectionStatusFragment.kt @@ -23,6 +23,7 @@ import android.view.View import androidx.activity.OnBackPressedCallback import androidx.appcompat.app.AlertDialog import androidx.core.view.postDelayed +import androidx.fragment.app.activityViewModels import androidx.fragment.app.viewModels import androidx.lifecycle.Observer import androidx.lifecycle.asLiveData @@ -47,6 +48,7 @@ import nl.eduvpn.app.utils.ErrorDialog import nl.eduvpn.app.utils.FormattingUtils import nl.eduvpn.app.viewmodel.BaseConnectionViewModel import nl.eduvpn.app.viewmodel.ConnectionStatusViewModel +import nl.eduvpn.app.viewmodel.MainViewModel import org.eduvpn.common.Protocol /** @@ -62,11 +64,14 @@ class ConnectionStatusFragment : BaseFragment() private val viewModel by viewModels { viewModelFactory } + private val mainViewModel by activityViewModels { viewModelFactory } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) EduVPNApplication.get(view.context).component().inject(this) binding.viewModel = viewModel binding.isTcp = viewModel.isCurrentProtocolUsingTcp() + binding.failoverNeeded = mainViewModel.failoverResult.value ?: false binding.secondsConnected = viewModel.connectionTimeLiveData.map { secondsConnected -> val context = this@ConnectionStatusFragment.context ?: return@map null FormattingUtils.formatDurationSeconds( @@ -206,6 +211,9 @@ class ConnectionStatusFragment : BaseFragment() updateCertExpiryObserver?.let { obs -> viewModel.timer.removeObserver(obs) } } } + mainViewModel.failoverResult.observe(viewLifecycleOwner) { + binding.failoverNeeded = it + } viewModel.timer.observe(viewLifecycleOwner, updateCertExpiryObserver) viewModel.vpnStatus.observe(viewLifecycleOwner) { status -> binding.connectionStatus.setText(VPNConnectionService.vpnStatusToStringID(status)) diff --git a/app/src/main/java/nl/eduvpn/app/viewmodel/MainViewModel.kt b/app/src/main/java/nl/eduvpn/app/viewmodel/MainViewModel.kt index e27b3f03..21d73f0f 100644 --- a/app/src/main/java/nl/eduvpn/app/viewmodel/MainViewModel.kt +++ b/app/src/main/java/nl/eduvpn/app/viewmodel/MainViewModel.kt @@ -69,6 +69,9 @@ class MainViewModel @Inject constructor( val mainParentAction = _mainParentAction.toSingleEvent() val proxyGuardEnabled: Boolean get() = preferencesService.getCurrentProtocol() == Protocol.WireGuardWithTCP.nativeValue + private val _failoverResult = MutableLiveData(false) + val failoverResult = _failoverResult.toSingleEvent() + init { backendService.register( @@ -159,21 +162,7 @@ class MainViewModel @Inject constructor( // Waits a bit so that the network interface has been surely set up delay(1_000L) backendService.startFailOver(service) { - // Failover needed, request a new profile with TCP enforced. - preferencesService.getCurrentInstance()?.let { currentInstance -> - viewModelScope.launch { - // Disconnect first, otherwise we don't have any internet :) - service.disconnect() - // Wait a bit for the disconnection to finish - delay(500L) - // Fetch a new profile, now with TCP forced - try { - backendService.getConfig(currentInstance, preferTcp = true) - } catch (ex: Exception) { - Log.w(TAG, "Could not fetch new config!", ex) - } - } - } + _failoverResult.postValue(true) } } catch (ex: CommonException) { // These are just warnings, so we log them, but don't display to the user diff --git a/app/src/main/res/layout/fragment_connection_status.xml b/app/src/main/res/layout/fragment_connection_status.xml index 3b10d356..61277b3b 100644 --- a/app/src/main/res/layout/fragment_connection_status.xml +++ b/app/src/main/res/layout/fragment_connection_status.xml @@ -38,6 +38,10 @@ name="isTcp" type="boolean" /> + + @@ -209,7 +213,7 @@ android:layout_marginTop="16dp" android:textColor="@color/textColor" android:textSize="14sp" - android:visibility="@{isTcp ? View.GONE : View.VISIBLE}" + android:visibility="@{isTcp || !failoverNeeded ? View.GONE : View.VISIBLE}" android:text="@string/connection_status_connectivity_problems" android:layout_height="wrap_content"/> @@ -218,7 +222,7 @@ android:id="@+id/reconnect_tcp_button" android:layout_width="wrap_content" android:layout_marginTop="8dp" - android:visibility="@{isTcp ? View.GONE : View.VISIBLE}" + android:visibility="@{isTcp || !failoverNeeded ? View.GONE : View.VISIBLE}" android:text="@string/connection_status_reconnect_with_tcp" android:layout_height="wrap_content"/>