diff options
Diffstat (limited to 'android/app/src')
13 files changed, 87 insertions, 42 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt index b2af9c989d..3ab59000ae 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt @@ -5,7 +5,7 @@ import android.os.Messenger import java.net.InetAddress import kotlinx.parcelize.Parcelize import net.mullvad.mullvadvpn.model.DnsOptions -import net.mullvad.mullvadvpn.model.LocationConstraint +import net.mullvad.mullvadvpn.model.GeographicLocationConstraint import net.mullvad.mullvadvpn.model.ObfuscationSettings import net.mullvad.mullvadvpn.model.QuantumResistantState import net.mullvad.mullvadvpn.model.WireguardConstraints @@ -73,7 +73,8 @@ sealed class Request : Message.RequestMessage() { @Parcelize data class SetEnableSplitTunneling(val enable: Boolean) : Request() - @Parcelize data class SetRelayLocation(val relayLocation: LocationConstraint?) : Request() + @Parcelize + data class SetRelayLocation(val relayLocation: GeographicLocationConstraint?) : Request() @Parcelize data class SetWireGuardMtu(val mtu: Int?) : Request() diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/GeographicLocationConstraint.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/GeographicLocationConstraint.kt new file mode 100644 index 0000000000..04f92a72ac --- /dev/null +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/GeographicLocationConstraint.kt @@ -0,0 +1,28 @@ +package net.mullvad.mullvadvpn.model + +import android.os.Parcelable +import kotlinx.parcelize.Parcelize + +sealed class GeographicLocationConstraint : Parcelable { + abstract val location: GeoIpLocation + + @Parcelize + data class Country(val countryCode: String) : GeographicLocationConstraint() { + override val location: GeoIpLocation + get() = GeoIpLocation(null, null, countryCode, null, null) + } + + @Parcelize + data class City(val countryCode: String, val cityCode: String) : + GeographicLocationConstraint() { + override val location: GeoIpLocation + get() = GeoIpLocation(null, null, countryCode, cityCode, null) + } + + @Parcelize + data class Hostname(val countryCode: String, val cityCode: String, val hostname: String) : + GeographicLocationConstraint() { + override val location: GeoIpLocation + get() = GeoIpLocation(null, null, countryCode, cityCode, hostname) + } +} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/LocationConstraint.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/LocationConstraint.kt index 2820a449b8..de7dd4e99b 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/LocationConstraint.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/LocationConstraint.kt @@ -4,24 +4,7 @@ import android.os.Parcelable import kotlinx.parcelize.Parcelize sealed class LocationConstraint : Parcelable { - abstract val location: GeoIpLocation - - @Parcelize - data class Country(val countryCode: String) : LocationConstraint() { - override val location: GeoIpLocation - get() = GeoIpLocation(null, null, countryCode, null, null) - } - - @Parcelize - data class City(val countryCode: String, val cityCode: String) : LocationConstraint() { - override val location: GeoIpLocation - get() = GeoIpLocation(null, null, countryCode, cityCode, null) - } - @Parcelize - data class Hostname(val countryCode: String, val cityCode: String, val hostname: String) : - LocationConstraint() { - override val location: GeoIpLocation - get() = GeoIpLocation(null, null, countryCode, cityCode, hostname) - } + data class Location(val location: GeographicLocationConstraint) : LocationConstraint() + @Parcelize data class CustomList(val listId: String) : LocationConstraint() } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/Relay.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/Relay.kt index 7afb2249d2..6f7b6760b0 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/Relay.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/Relay.kt @@ -1,12 +1,13 @@ package net.mullvad.mullvadvpn.relaylist -import net.mullvad.mullvadvpn.model.LocationConstraint +import net.mullvad.mullvadvpn.model.GeographicLocationConstraint data class Relay(val city: RelayCity, override val name: String, override val active: Boolean) : RelayItem { override val code = name override val type = RelayItemType.Relay - override val location = LocationConstraint.Hostname(city.country.code, city.code, name) + override val location = + GeographicLocationConstraint.Hostname(city.country.code, city.code, name) override val hasChildren = false override val visibleChildCount = 0 diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCity.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCity.kt index 9500c43795..c6244101f6 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCity.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCity.kt @@ -1,6 +1,6 @@ package net.mullvad.mullvadvpn.relaylist -import net.mullvad.mullvadvpn.model.LocationConstraint +import net.mullvad.mullvadvpn.model.GeographicLocationConstraint class RelayCity( val country: RelayCountry, @@ -10,7 +10,7 @@ class RelayCity( val relays: List<Relay> ) : RelayItem { override val type = RelayItemType.City - override val location = LocationConstraint.City(country.code, code) + override val location = GeographicLocationConstraint.City(country.code, code) override val active get() = relays.any { relay -> relay.active } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCountry.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCountry.kt index 447cc25ff2..d8424cacad 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCountry.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCountry.kt @@ -1,6 +1,6 @@ package net.mullvad.mullvadvpn.relaylist -import net.mullvad.mullvadvpn.model.LocationConstraint +import net.mullvad.mullvadvpn.model.GeographicLocationConstraint class RelayCountry( override val name: String, @@ -9,7 +9,7 @@ class RelayCountry( val cities: List<RelayCity> ) : RelayItem { override val type = RelayItemType.Country - override val location = LocationConstraint.Country(code) + override val location = GeographicLocationConstraint.Country(code) override val active get() = cities.any { city -> city.active } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayItem.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayItem.kt index e5f28acee6..fde283fcdf 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayItem.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayItem.kt @@ -1,12 +1,12 @@ package net.mullvad.mullvadvpn.relaylist -import net.mullvad.mullvadvpn.model.LocationConstraint +import net.mullvad.mullvadvpn.model.GeographicLocationConstraint interface RelayItem { val type: RelayItemType val name: String val code: String - val location: LocationConstraint + val location: GeographicLocationConstraint val active: Boolean val hasChildren: Boolean val visibleChildCount: Int diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayList.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayList.kt index b5aaed028a..60cbdd46cf 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayList.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayList.kt @@ -1,7 +1,7 @@ package net.mullvad.mullvadvpn.relaylist import net.mullvad.mullvadvpn.model.Constraint -import net.mullvad.mullvadvpn.model.LocationConstraint +import net.mullvad.mullvadvpn.model.GeographicLocationConstraint class RelayList { val countries: List<RelayCountry> @@ -41,7 +41,7 @@ class RelayList { } fun findItemForLocation( - constraint: Constraint<LocationConstraint>, + constraint: Constraint<GeographicLocationConstraint>, expand: Boolean = false ): RelayItem? { when (constraint) { @@ -50,10 +50,10 @@ class RelayList { val location = constraint.value when (location) { - is LocationConstraint.Country -> { + is GeographicLocationConstraint.Country -> { return countries.find { country -> country.code == location.countryCode } } - is LocationConstraint.City -> { + is GeographicLocationConstraint.City -> { val country = countries.find { country -> country.code == location.countryCode } @@ -63,7 +63,7 @@ class RelayList { return country?.cities?.find { city -> city.code == location.cityCode } } - is LocationConstraint.Hostname -> { + is GeographicLocationConstraint.Hostname -> { val country = countries.find { country -> country.code == location.countryCode } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/LocationInfoCache.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/LocationInfoCache.kt index 7cc43925d7..7b0d419b45 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/LocationInfoCache.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/LocationInfoCache.kt @@ -19,6 +19,7 @@ import net.mullvad.mullvadvpn.model.GeoIpLocation import net.mullvad.mullvadvpn.model.RelaySettings import net.mullvad.mullvadvpn.model.TunnelState import net.mullvad.mullvadvpn.util.ExponentialBackoff +import net.mullvad.mullvadvpn.util.toGeographicLocationConstraint import net.mullvad.talpid.tunnel.ActionAfterDisconnect class LocationInfoCache(private val endpoint: ServiceEndpoint) { @@ -131,6 +132,6 @@ class LocationInfoCache(private val endpoint: ServiceEndpoint) { val settings = relaySettings as? RelaySettings.Normal val constraint = settings?.relayConstraints?.location as? Constraint.Only - selectedRelayLocation = constraint?.value?.location + selectedRelayLocation = constraint?.value?.toGeographicLocationConstraint()?.location } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt index 4fa531eeb4..7f4d274d6f 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt @@ -10,6 +10,7 @@ import kotlinx.coroutines.channels.trySendBlocking import net.mullvad.mullvadvpn.ipc.Event import net.mullvad.mullvadvpn.ipc.Request import net.mullvad.mullvadvpn.model.Constraint +import net.mullvad.mullvadvpn.model.GeographicLocationConstraint import net.mullvad.mullvadvpn.model.LocationConstraint import net.mullvad.mullvadvpn.model.RelayConstraintsUpdate import net.mullvad.mullvadvpn.model.RelayList @@ -29,7 +30,7 @@ class RelayListListener(endpoint: ServiceEndpoint) { private val daemon = endpoint.intermittentDaemon private var selectedRelayLocation by - observable<LocationConstraint?>(null) { _, _, _ -> + observable<GeographicLocationConstraint?>(null) { _, _, _ -> commandChannel.trySendBlocking(Command.SetRelayLocation) } private var selectedWireguardConstraints by @@ -93,7 +94,10 @@ class RelayListListener(endpoint: ServiceEndpoint) { private suspend fun updateRelayConstraints() { val location: Constraint<LocationConstraint> = - selectedRelayLocation?.let { location -> Constraint.Only(location) } ?: Constraint.Any() + selectedRelayLocation?.let { location -> + Constraint.Only(LocationConstraint.Location(location)) + } + ?: Constraint.Any() val wireguardConstraints: WireguardConstraints? = selectedWireguardConstraints val update = diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/RelayListListener.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/RelayListListener.kt index 46cf492d01..5efca2648c 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/RelayListListener.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/RelayListListener.kt @@ -5,6 +5,7 @@ import net.mullvad.mullvadvpn.ipc.Event import net.mullvad.mullvadvpn.ipc.EventDispatcher import net.mullvad.mullvadvpn.ipc.Request import net.mullvad.mullvadvpn.model.Constraint +import net.mullvad.mullvadvpn.model.GeographicLocationConstraint import net.mullvad.mullvadvpn.model.LocationConstraint import net.mullvad.mullvadvpn.model.PortRange import net.mullvad.mullvadvpn.model.RelayConstraints @@ -12,6 +13,7 @@ import net.mullvad.mullvadvpn.model.RelaySettings import net.mullvad.mullvadvpn.model.WireguardConstraints import net.mullvad.mullvadvpn.relaylist.RelayItem import net.mullvad.mullvadvpn.relaylist.RelayList +import net.mullvad.mullvadvpn.util.toGeographicLocationConstraint class RelayListListener( private val connection: Messenger, @@ -25,12 +27,12 @@ class RelayListListener( var selectedRelayItem: RelayItem? = null private set - var selectedRelayLocation: LocationConstraint? + var selectedRelayLocation: GeographicLocationConstraint? get() { val settings = relaySettings as? RelaySettings.Normal val location = settings?.relayConstraints?.location as? Constraint.Only - return location?.value + return location?.value?.toGeographicLocationConstraint() } set(value) { connection.send(Request.SetRelayLocation(value).message) @@ -119,7 +121,10 @@ class RelayListListener( is RelaySettings.Normal -> { val location = relaySettings.relayConstraints.location - return relayList?.findItemForLocation(location, true) + return relayList?.findItemForLocation( + location.toGeographicLocationConstraint(), + true + ) } else -> { /* NOOP */ diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/LocationConstraintExtensions.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/LocationConstraintExtensions.kt new file mode 100644 index 0000000000..2637028111 --- /dev/null +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/LocationConstraintExtensions.kt @@ -0,0 +1,22 @@ +package net.mullvad.mullvadvpn.util + +import net.mullvad.mullvadvpn.model.Constraint +import net.mullvad.mullvadvpn.model.GeographicLocationConstraint +import net.mullvad.mullvadvpn.model.LocationConstraint + +fun LocationConstraint.toGeographicLocationConstraint(): GeographicLocationConstraint? = + when (this) { + is LocationConstraint.Location -> this.location + is LocationConstraint.CustomList -> null + } + +fun Constraint<LocationConstraint>.toGeographicLocationConstraint(): + Constraint<GeographicLocationConstraint> = + when (this) { + is Constraint.Only -> + when (this.value) { + is LocationConstraint.Location -> Constraint.Only(this.value.location) + is LocationConstraint.CustomList -> Constraint.Any() + } + is Constraint.Any -> Constraint.Any() + } diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModelTest.kt index fbb5008eb7..ba7ea30c41 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModelTest.kt @@ -16,7 +16,7 @@ import kotlinx.coroutines.test.runTest import net.mullvad.mullvadvpn.TestCoroutineRule import net.mullvad.mullvadvpn.assertLists import net.mullvad.mullvadvpn.compose.state.SelectLocationUiState -import net.mullvad.mullvadvpn.model.LocationConstraint +import net.mullvad.mullvadvpn.model.GeographicLocationConstraint import net.mullvad.mullvadvpn.relaylist.RelayCountry import net.mullvad.mullvadvpn.relaylist.RelayItem import net.mullvad.mullvadvpn.relaylist.RelayList @@ -120,7 +120,7 @@ class SelectLocationViewModelTest { fun testSelectRelayAndClose() = runTest { // Arrange val mockRelayItem: RelayItem = mockk() - val mockLocation: LocationConstraint.Country = mockk(relaxed = true) + val mockLocation: GeographicLocationConstraint.Country = mockk(relaxed = true) val connectionProxyMock: ConnectionProxy = mockk(relaxUnitFun = true) every { mockRelayItem.location } returns mockLocation every { mockServiceConnectionManager.relayListListener() } returns mockRelayListListener |
