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>
This commit is contained in:
parent
383659fb8a
commit
a832193010
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package com.wireguard.android.model;
|
package com.wireguard.android.model;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@ -189,23 +190,25 @@ public final class TunnelManager extends BaseObservable {
|
|||||||
.toArray(CompletableFuture[]::new));
|
.toArray(CompletableFuture[]::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("ApplySharedPref")
|
||||||
public void saveState() {
|
public void saveState() {
|
||||||
final Set<String> runningTunnels = StreamSupport.stream(tunnels)
|
final Set<String> runningTunnels = StreamSupport.stream(tunnels)
|
||||||
.filter(tunnel -> tunnel.getState() == State.UP)
|
.filter(tunnel -> tunnel.getState() == State.UP)
|
||||||
.map(ObservableTunnel::getName)
|
.map(ObservableTunnel::getName)
|
||||||
.collect(Collectors.toUnmodifiableSet());
|
.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) {
|
private void setLastUsedTunnel(@Nullable final ObservableTunnel tunnel) {
|
||||||
if (tunnel == lastUsedTunnel)
|
if (tunnel == lastUsedTunnel)
|
||||||
return;
|
return;
|
||||||
lastUsedTunnel = tunnel;
|
lastUsedTunnel = tunnel;
|
||||||
notifyPropertyChanged(BR.lastUsedTunnel);
|
notifyPropertyChanged(BR.lastUsedTunnel);
|
||||||
if (tunnel != null)
|
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
|
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) {
|
CompletionStage<Config> setTunnelConfig(final ObservableTunnel tunnel, final Config config) {
|
||||||
|
Loading…
Reference in New Issue
Block a user