From a83219301047c38283d76a6557799d4236d066fb Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 23 Mar 2020 18:13:04 -0600 Subject: [PATCH] TunnelManager: save settings before restart Otherwise these get lost and then the restored state is confusing. Signed-off-by: Jason A. Donenfeld --- .../java/com/wireguard/android/model/TunnelManager.java | 9 ++++++--- 1 file 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 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 setTunnelConfig(final ObservableTunnel tunnel, final Config config) {