From 58eedfd6d90a11aa803277b2bfd9eef6dd2258be Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Mon, 1 Jan 2018 02:15:34 -0600 Subject: [PATCH] TunnelManager: Clear primary tunnel when it's removed Signed-off-by: Samuel Holland --- .../java/com/wireguard/android/model/TunnelManager.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 5122f9bf..b6f6819d 100644 --- a/app/src/main/java/com/wireguard/android/model/TunnelManager.java +++ b/app/src/main/java/com/wireguard/android/model/TunnelManager.java @@ -70,7 +70,11 @@ public final class TunnelManager { Log.v(TAG, "Requested delete tunnel " + tunnel.getName() + " state=" + tunnel.getState()); return backend.setState(tunnel, State.DOWN) .thenCompose(x -> configStore.delete(tunnel.getName())) - .thenAccept(x -> tunnels.remove(tunnel.getName())); + .thenAccept(x -> { + tunnels.remove(tunnel.getName()); + if (tunnel.getName().equals(preferences.getString(KEY_PRIMARY_TUNNEL, null))) + preferences.edit().remove(KEY_PRIMARY_TUNNEL).apply(); + }); } public TunnelCollection getTunnels() {