aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-04-26 19:41:35 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-04-26 19:42:55 +0200
commit8a0dae6bc521417c31f4c404f390fc19c1b6f29e (patch)
treeb5a212b65a0cb7b55f38d3539be0ed9f65ea1c6e /app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
parentManifest: disable always-on VPN (diff)
downloadwireguard-android-8a0dae6bc521417c31f4c404f390fc19c1b6f29e.tar.xz
wireguard-android-8a0dae6bc521417c31f4c404f390fc19c1b6f29e.zip
WgQuickBackend: always create configuration file
It might be removed on an update.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java15
1 files changed, 5 insertions, 10 deletions
diff --git a/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java b/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
index a0371842..b91d8476 100644
--- a/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
+++ b/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
@@ -100,17 +100,12 @@ public final class WgQuickBackend implements Backend {
private void setStateInternal(final Tunnel tunnel, final Config config, final State state)
throws Exception {
final File tempFile = new File(localTemporaryDir, tunnel.getName() + ".conf");
- final int result;
- if (state == State.UP) {
- try (FileOutputStream stream = new FileOutputStream(tempFile, false)) {
- stream.write(config.toString().getBytes(StandardCharsets.UTF_8));
- }
- result = rootShell.run(null, "wg-quick up '" + tempFile.getAbsolutePath() + '\'');
- } else {
- result = rootShell.run(null, "wg-quick down '" + tempFile.getAbsolutePath() + '\'');
- if (result == 0 && !tempFile.delete())
- Log.w(TAG, "Couldn't delete temp config after bringing down " + tunnel.getName());
+ try (FileOutputStream stream = new FileOutputStream(tempFile, false)) {
+ stream.write(config.toString().getBytes(StandardCharsets.UTF_8));
}
+ final String command = String.format("wg-quick %s '%s'", state.toString().toLowerCase(), tempFile.getAbsolutePath());
+ final int result = rootShell.run(null, command);
+ tempFile.delete();
if (result != 0)
throw new Exception("Unable to configure tunnel (wg-quick returned " + result + ')');
}