diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-03-23 18:13:04 -0600 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-03-23 18:14:23 -0600 |
commit | a83219301047c38283d76a6557799d4236d066fb (patch) | |
tree | 969a7994ef05b562cd5f83e49c3d32a8862e253d /ui/src/main/java | |
parent | 383659fb8a8c92203c4906a5261a17d20cdaa7e0 (diff) |
TunnelManager: save settings before restart
Otherwise these get lost and then the restored state is confusing.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/src/main/java')
-rw-r--r-- | ui/src/main/java/com/wireguard/android/model/TunnelManager.java | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/ui/src/main/java/com/wireguard/android/model/TunnelManager.java b/ui/src/main/java/com/wireguard/android/model/TunnelManager.java index eb818791..9fe9bfb3 100644 --- a/ui/src/main/java/com/wireguard/android/model/TunnelManager.java +++ b/ui/src/main/java/com/wireguard/android/model/TunnelManager.java @@ -5,6 +5,7 @@ package com.wireguard.android.model; +import android.annotation.SuppressLint; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -189,23 +190,25 @@ public final class TunnelManager extends BaseObservable { .toArray(CompletableFuture[]::new)); } + @SuppressLint("ApplySharedPref") public void saveState() { final Set<String> runningTunnels = StreamSupport.stream(tunnels) .filter(tunnel -> tunnel.getState() == State.UP) .map(ObservableTunnel::getName) .collect(Collectors.toUnmodifiableSet()); - Application.getSharedPreferences().edit().putStringSet(KEY_RUNNING_TUNNELS, runningTunnels).apply(); + Application.getSharedPreferences().edit().putStringSet(KEY_RUNNING_TUNNELS, runningTunnels).commit(); } + @SuppressLint("ApplySharedPref") private void setLastUsedTunnel(@Nullable final ObservableTunnel tunnel) { if (tunnel == lastUsedTunnel) return; lastUsedTunnel = tunnel; notifyPropertyChanged(BR.lastUsedTunnel); if (tunnel != null) - Application.getSharedPreferences().edit().putString(KEY_LAST_USED_TUNNEL, tunnel.getName()).apply(); + Application.getSharedPreferences().edit().putString(KEY_LAST_USED_TUNNEL, tunnel.getName()).commit(); else - Application.getSharedPreferences().edit().remove(KEY_LAST_USED_TUNNEL).apply(); + Application.getSharedPreferences().edit().remove(KEY_LAST_USED_TUNNEL).commit(); } CompletionStage<Config> setTunnelConfig(final ObservableTunnel tunnel, final Config config) { |