From 3d163de8d8a0967fdfda60347e57d3ce4ab42c3a Mon Sep 17 00:00:00 2001 From: Jonatan Rhodin Date: Thu, 19 Oct 2023 16:09:24 +0200 Subject: [PATCH] Add relay ownership enum to relay constraints --- .../ui/serviceconnection/RelayListListener.kt | 6 +++++- .../kotlin/net/mullvad/mullvadvpn/model/Ownership.kt | 10 ++++++++++ .../net/mullvad/mullvadvpn/model/RelayConstraints.kt | 3 ++- .../mullvad/mullvadvpn/model/RelayConstraintsUpdate.kt | 1 + .../mullvadvpn/service/endpoint/RelayListListener.kt | 8 +++++++- mullvad-jni/src/classes.rs | 1 + mullvad-types/src/relay_constraints.rs | 4 ++-- 7 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/Ownership.kt 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 574f7a2004df..fe68c63408bb 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 @@ -97,7 +97,11 @@ class RelayListListener( relaySettings = newRelaySettings ?: RelaySettings.Normal( - RelayConstraints(Constraint.Any(), WireguardConstraints(Constraint.Any())) + RelayConstraints( + location = Constraint.Any(), + ownership = Constraint.Any(), + wireguardConstraints = WireguardConstraints(Constraint.Any()), + ) ) if (relayCountries != null) { diff --git a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/Ownership.kt b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/Ownership.kt new file mode 100644 index 000000000000..43037be67624 --- /dev/null +++ b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/Ownership.kt @@ -0,0 +1,10 @@ +package net.mullvad.mullvadvpn.model + +import android.os.Parcelable +import kotlinx.parcelize.Parcelize + +@Parcelize +enum class Ownership : Parcelable { + MullvadOwned, + Rented +} diff --git a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraints.kt b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraints.kt index da2acb39f6cc..21b1575edca8 100644 --- a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraints.kt +++ b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraints.kt @@ -6,5 +6,6 @@ import kotlinx.parcelize.Parcelize @Parcelize data class RelayConstraints( val location: Constraint, - val wireguardConstraints: WireguardConstraints + val ownership: Constraint, + val wireguardConstraints: WireguardConstraints, ) : Parcelable diff --git a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraintsUpdate.kt b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraintsUpdate.kt index 991ae7dbdeef..9d07ba92c316 100644 --- a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraintsUpdate.kt +++ b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraintsUpdate.kt @@ -2,5 +2,6 @@ package net.mullvad.mullvadvpn.model data class RelayConstraintsUpdate( val location: Constraint?, + val ownership: Constraint?, val wireguardConstraints: WireguardConstraints? ) diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt index 09f90a44d5da..cb57e7585ded 100644 --- a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt +++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt @@ -95,7 +95,13 @@ class RelayListListener(endpoint: ServiceEndpoint) { val wireguardConstraints: WireguardConstraints? = selectedWireguardConstraints val update = - RelaySettingsUpdate.Normal(RelayConstraintsUpdate(location, wireguardConstraints)) + RelaySettingsUpdate.Normal( + RelayConstraintsUpdate( + location = location, + wireguardConstraints = wireguardConstraints, + ownership = Constraint.Any() + ) + ) daemon.await().updateRelaySettings(update) } diff --git a/mullvad-jni/src/classes.rs b/mullvad-jni/src/classes.rs index 56de8919db75..9bdec1669175 100644 --- a/mullvad-jni/src/classes.rs +++ b/mullvad-jni/src/classes.rs @@ -33,6 +33,7 @@ pub const CLASSES: &[&str] = &[ "net/mullvad/mullvadvpn/model/LocationConstraint$Location", "net/mullvad/mullvadvpn/model/LocationConstraint$CustomList", "net/mullvad/mullvadvpn/model/ObfuscationSettings", + "net/mullvad/mullvadvpn/model/Ownership", "net/mullvad/mullvadvpn/model/PlayPurchase", "net/mullvad/mullvadvpn/model/PlayPurchaseInitError", "net/mullvad/mullvadvpn/model/PlayPurchaseInitResult", diff --git a/mullvad-types/src/relay_constraints.rs b/mullvad-types/src/relay_constraints.rs index 014e84a5ff26..600a04646c3a 100644 --- a/mullvad-types/src/relay_constraints.rs +++ b/mullvad-types/src/relay_constraints.rs @@ -371,7 +371,6 @@ pub struct RelayConstraints { pub location: Constraint, #[cfg_attr(target_os = "android", jnix(skip))] pub providers: Constraint, - #[cfg_attr(target_os = "android", jnix(skip))] pub ownership: Constraint, #[cfg_attr(target_os = "android", jnix(skip))] pub tunnel_protocol: Constraint, @@ -560,6 +559,8 @@ impl Set>> /// Limits the set of servers to choose based on ownership. #[derive(Debug, Copy, Clone, Eq, PartialEq, Deserialize, Serialize)] +#[cfg_attr(target_os = "android", derive(IntoJava, FromJava))] +#[cfg_attr(target_os = "android", jnix(package = "net.mullvad.mullvadvpn.model"))] #[cfg_attr(feature = "clap", derive(clap::ValueEnum))] pub enum Ownership { MullvadOwned, @@ -987,7 +988,6 @@ pub struct RelayConstraintsUpdate { pub location: Option>, #[cfg_attr(target_os = "android", jnix(default))] pub providers: Option>, - #[cfg_attr(target_os = "android", jnix(default))] pub ownership: Option>, #[cfg_attr(target_os = "android", jnix(default))] pub tunnel_protocol: Option>,