diff options
author | Samuel Holland <samuel@sholland.org> | 2018-01-08 23:26:39 -0600 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2018-01-08 23:39:32 -0600 |
commit | c806e655faeebd3e409a053f6c14678a037ce135 (patch) | |
tree | 745bb3b7887e8110f33e764a3e792d199976a9dc /app/src | |
parent | 5201c7f8492ea5e77267d3e45f4a4c1285e8f10b (diff) |
WgQuickBackend: Ensure tools are available before use
Signed-off-by: Samuel Holland <samuel@sholland.org>
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/com/wireguard/android/Application.java | 5 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java | 8 |
2 files changed, 10 insertions, 3 deletions
diff --git a/app/src/main/java/com/wireguard/android/Application.java b/app/src/main/java/com/wireguard/android/Application.java index aaa6a246..4676e0bc 100644 --- a/app/src/main/java/com/wireguard/android/Application.java +++ b/app/src/main/java/com/wireguard/android/Application.java @@ -81,8 +81,9 @@ public class Application extends android.app.Application { @ApplicationScope @Provides public static Backend getBackend(@ApplicationContext final Context context, - final RootShell rootShell) { - return new WgQuickBackend(context, rootShell); + final RootShell rootShell, + final ToolsInstaller toolsInstaller) { + return new WgQuickBackend(context, rootShell, toolsInstaller); } @ApplicationScope 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 ed55f097..b067db0b 100644 --- a/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java +++ b/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java @@ -9,6 +9,7 @@ import com.wireguard.android.model.Tunnel; import com.wireguard.android.model.Tunnel.State; import com.wireguard.android.model.Tunnel.Statistics; import com.wireguard.android.util.RootShell; +import com.wireguard.android.util.ToolsInstaller; import com.wireguard.config.Config; import java.io.File; @@ -29,10 +30,13 @@ public final class WgQuickBackend implements Backend { private final Context context; private final RootShell rootShell; + private final ToolsInstaller toolsInstaller; - public WgQuickBackend(final Context context, final RootShell rootShell) { + public WgQuickBackend(final Context context, final RootShell rootShell, + final ToolsInstaller toolsInstaller) { this.context = context; this.rootShell = rootShell; + this.toolsInstaller = toolsInstaller; } @Override @@ -47,6 +51,7 @@ public final class WgQuickBackend implements Backend { final List<String> output = new ArrayList<>(); // Don't throw an exception here or nothing will show up in the UI. try { + toolsInstaller.ensureToolsAvailable(); if (rootShell.run(output, "wg show interfaces") != 0 || output.isEmpty()) return Collections.emptySet(); } catch (final Exception ignored) { @@ -75,6 +80,7 @@ public final class WgQuickBackend implements Backend { state = originalState == State.UP ? State.DOWN : State.UP; if (state == originalState) return originalState; + toolsInstaller.ensureToolsAvailable(); final int result; if (state == State.UP) { if (!new File("/sys/module/wireguard").exists()) |