summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2017-08-16 00:56:53 -0500
committerSamuel Holland <samuel@sholland.org>2017-08-16 00:56:53 -0500
commitb60536222dc4be5154c57477d2746a1ea45384a1 (patch)
tree8b36c131bf08a5ee3e38e61df4450b16cd7d6d55 /app/src/main/java/com/wireguard
parentc3203ce90aa021955589165fc387c415442ff5ef (diff)
VpnService: Tweaks for ConfigUpdater to fix adding
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard')
-rw-r--r--app/src/main/java/com/wireguard/android/VpnService.java13
1 files changed, 9 insertions, 4 deletions
diff --git a/app/src/main/java/com/wireguard/android/VpnService.java b/app/src/main/java/com/wireguard/android/VpnService.java
index 2f3d97c8..920dd78e 100644
--- a/app/src/main/java/com/wireguard/android/VpnService.java
+++ b/app/src/main/java/com/wireguard/android/VpnService.java
@@ -288,8 +288,9 @@ public class VpnService extends Service {
this.oldConfig = oldConfig;
this.shouldConnect = shouldConnect;
newName = newConfig.getName();
- oldName = oldConfig.getName();
- if (isRename() && configurations.containsKey(newName))
+ // When adding a config, "old file" and "new file" are the same thing.
+ oldName = oldConfig != null ? oldConfig.getName() : newName;
+ if (isAddOrRename() && configurations.containsKey(newName))
throw new IllegalStateException("Config " + newName + " already exists");
}
@@ -298,7 +299,7 @@ public class VpnService extends Service {
Log.i(TAG, (oldConfig == null ? "Adding" : "Updating") + " config " + newName);
final File newFile = new File(getFilesDir(), newName + ".conf");
final File oldFile = new File(getFilesDir(), oldName + ".conf");
- if (isRename() && newFile.exists()) {
+ if (isAddOrRename() && newFile.exists()) {
Log.w(TAG, "Refusing to overwrite existing config configuration");
return false;
}
@@ -317,8 +318,12 @@ public class VpnService extends Service {
return true;
}
+ private boolean isAddOrRename() {
+ return oldConfig == null || !newName.equals(oldName);
+ }
+
private boolean isRename() {
- return oldConfig != null && !newConfig.getName().equals(oldConfig.getName());
+ return oldConfig != null && !newName.equals(oldName);
}
@Override