diff options
author | Samuel Holland <samuel@sholland.org> | 2017-08-16 00:56:53 -0500 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2017-08-16 00:56:53 -0500 |
commit | 3c48e2fc1221d9867daee4b4f20474bdaed37a4c (patch) | |
tree | 8b36c131bf08a5ee3e38e61df4450b16cd7d6d55 /app/src/main/java/com | |
parent | 0614006612dba5ab4a2305bfe7136d6acc26e959 (diff) |
VpnService: Tweaks for ConfigUpdater to fix adding
Diffstat (limited to 'app/src/main/java/com')
-rw-r--r-- | app/src/main/java/com/wireguard/android/VpnService.java | 13 |
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 |