diff options
author | Samuel Holland <samuel@sholland.org> | 2018-01-06 05:09:05 -0600 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2018-01-06 05:18:34 -0600 |
commit | df7d18fb5d332a2aa341e97274dc6e53cc4ffe11 (patch) | |
tree | 86079d8d32b4019a9b8d72bb510178ecb3a77927 /app/src/main | |
parent | 1c2239ae910de143658b35d3a53d13305d8b4c9e (diff) |
Tunnel: Require passing a state to the constructor
Signed-off-by: Samuel Holland <samuel@sholland.org>
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/com/wireguard/android/model/Tunnel.java | 5 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/android/model/TunnelManager.java | 9 |
2 files changed, 8 insertions, 6 deletions
diff --git a/app/src/main/java/com/wireguard/android/model/Tunnel.java b/app/src/main/java/com/wireguard/android/model/Tunnel.java index 8152381b..e1a80456 100644 --- a/app/src/main/java/com/wireguard/android/model/Tunnel.java +++ b/app/src/main/java/com/wireguard/android/model/Tunnel.java @@ -31,15 +31,16 @@ public class Tunnel extends BaseObservable implements Keyed<String> { private final ConfigStore configStore; private final String name; private Config config; - private State state = State.UNKNOWN; + private State state; private Statistics statistics; Tunnel(@NonNull final Backend backend, @NonNull final ConfigStore configStore, - @NonNull final String name, @Nullable final Config config) { + @NonNull final String name, @Nullable final Config config, @NonNull final State state) { this.backend = backend; this.configStore = configStore; this.name = name; this.config = config; + this.state = state; } public static boolean isNameValid(final CharSequence name) { diff --git a/app/src/main/java/com/wireguard/android/model/TunnelManager.java b/app/src/main/java/com/wireguard/android/model/TunnelManager.java index 53322ab4..eaf8c0d6 100644 --- a/app/src/main/java/com/wireguard/android/model/TunnelManager.java +++ b/app/src/main/java/com/wireguard/android/model/TunnelManager.java @@ -48,14 +48,14 @@ public final class TunnelManager { this.preferences = preferences; } - private Tunnel add(final String name, final Config config) { - final Tunnel tunnel = new Tunnel(backend, configStore, name, config); + private Tunnel add(final String name, final Config config, final State state) { + final Tunnel tunnel = new Tunnel(backend, configStore, name, config, state); tunnels.add(tunnel); return tunnel; } private Tunnel add(final String name) { - return add(name, null); + return add(name, null, State.UNKNOWN); } public CompletionStage<Tunnel> create(final String name, final Config config) { @@ -66,7 +66,8 @@ public final class TunnelManager { final String message = "Tunnel " + name + " already exists"; return CompletableFuture.failedFuture(new IllegalArgumentException(message)); } - return configStore.create(name, config).thenApply(savedConfig -> add(name, savedConfig)); + return configStore.create(name, config) + .thenApply(savedConfig -> add(name, savedConfig, State.DOWN)); } public CompletionStage<Void> delete(final Tunnel tunnel) { |