summaryrefslogtreecommitdiffhomepage
path: root/app
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2017-08-16 04:36:12 -0500
committerSamuel Holland <samuel@sholland.org>2017-08-16 04:36:12 -0500
commitb753ae09ca88e60891e2b6da7022e0059b33baf6 (patch)
tree5a05374ed7b0c52e21e1e373a42fb2aee90ed342 /app
parent08992185ecfe359ae7607a779b984fc6c3b8b22b (diff)
VpnService: Remember and optionally restore enabled configs
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/com/wireguard/android/VpnService.java20
1 files changed, 20 insertions, 0 deletions
diff --git a/app/src/main/java/com/wireguard/android/VpnService.java b/app/src/main/java/com/wireguard/android/VpnService.java
index 057f1906..fd2aadc3 100644
--- a/app/src/main/java/com/wireguard/android/VpnService.java
+++ b/app/src/main/java/com/wireguard/android/VpnService.java
@@ -18,8 +18,10 @@ import java.io.FilenameFilter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
+import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
+import java.util.Set;
/**
* Service that handles config state coordination and all background processing for the application.
@@ -27,7 +29,9 @@ import java.util.List;
public class VpnService extends Service
implements SharedPreferences.OnSharedPreferenceChangeListener {
+ private static final String KEY_ENABLED_CONFIGS = "enabled_configs";
private static final String KEY_PRIMARY_CONFIG = "primary_config";
+ private static final String KEY_RESTORE_ON_BOOT = "restore_on_boot";
private static final String TAG = "VpnService";
private static VpnService instance;
@@ -38,6 +42,7 @@ public class VpnService extends Service
private final IBinder binder = new Binder();
private final ObservableArrayMap<String, Config> configurations = new ObservableArrayMap<>();
+ private final Set<String> enabledConfigs = new HashSet<>();
private SharedPreferences preferences;
private Config primaryConfig;
private RootShell rootShell;
@@ -205,6 +210,8 @@ public class VpnService extends Service
if (!result)
return;
config.setIsEnabled(false);
+ enabledConfigs.remove(config.getName());
+ preferences.edit().putStringSet(KEY_ENABLED_CONFIGS, enabledConfigs).apply();
}
}
@@ -227,6 +234,8 @@ public class VpnService extends Service
if (!result)
return;
config.setIsEnabled(true);
+ enabledConfigs.add(config.getName());
+ preferences.edit().putStringSet(KEY_ENABLED_CONFIGS, enabledConfigs).apply();
}
}
@@ -276,6 +285,17 @@ public class VpnService extends Service
if (primaryConfig != null)
primaryConfig.setIsPrimary(true);
}
+ if (preferences.getBoolean(KEY_RESTORE_ON_BOOT, false)) {
+ final Set<String> configsToEnable =
+ preferences.getStringSet(KEY_ENABLED_CONFIGS, null);
+ if (configsToEnable != null) {
+ for (final String name : configsToEnable) {
+ final Config config = configurations.get(name);
+ if (config != null && !config.isEnabled())
+ new ConfigEnabler(config).execute();
+ }
+ }
+ }
}
}