diff options
3 files changed, 7 insertions, 34 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt index e6256e2be6..bf3414b0e1 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt @@ -14,7 +14,6 @@ import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.flow.emptyFlow -import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.shareIn @@ -132,14 +131,10 @@ class ConnectViewModel( .debounce(UI_STATE_DEBOUNCE_DURATION_MILLIS) .stateIn(viewModelScope, SharingStarted.WhileSubscribed(), ConnectUiState.INITIAL) - private fun LocationInfoCache.locationCallbackFlow() = - callbackFlow { - onNewLocation = { this.trySend(it) } - awaitClose { onNewLocation = null } - } - // Filter out empty or short-name country representations. - // We want to keep null location to handle those situations - .filter { it?.let { location -> location.country.length > 2 } ?: true } + private fun LocationInfoCache.locationCallbackFlow() = callbackFlow { + onNewLocation = { this.trySend(it) } + awaitClose { onNewLocation = null } + } private fun RelayListListener.relayListCallbackFlow() = callbackFlow { onRelayCountriesChange = { _, item -> this.trySend(item) } diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModelTest.kt index 517281e6c2..a2a39e54c4 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModelTest.kt @@ -224,30 +224,6 @@ class ConnectViewModelTest { } @Test - fun testLocationUpdateFilteredCountry() = - // Arrange - runTest(testCoroutineRule.testDispatcher) { - val locationTestItem = - GeoIpLocation( - ipv4 = mockk(relaxed = true), - ipv6 = mockk(relaxed = true), - country = "SW", - city = "gb", - hostname = "Ho" - ) - - // Act, Assert - viewModel.uiState.test { - assertEquals(ConnectUiState.INITIAL, awaitItem()) - serviceConnectionState.value = - ServiceConnectionState.ConnectedReady(mockServiceConnectionContainer) - locationSlot.captured.invoke(locationTestItem) - relaySlot.captured.invoke(mockk(), mockk()) - expectNoEvents() - } - } - - @Test fun testLocationUpdateNullLocation() = // Arrange runTest(testCoroutineRule.testDispatcher) { diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/LocationInfoCache.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/LocationInfoCache.kt index fb3a8637f6..e050421699 100644 --- a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/LocationInfoCache.kt +++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/LocationInfoCache.kt @@ -63,7 +63,9 @@ class LocationInfoCache(private val endpoint: ServiceEndpoint) { when (newState.actionAfterDisconnect) { ActionAfterDisconnect.Nothing -> location = lastKnownRealLocation ActionAfterDisconnect.Block -> location = null - ActionAfterDisconnect.Reconnect -> location = selectedRelayLocation + ActionAfterDisconnect.Reconnect -> { + lastKnownRealLocation?.let { location = it } + } } } is TunnelState.Error -> location = null |
