summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2018-01-08 23:25:49 -0600
committerSamuel Holland <samuel@sholland.org>2018-01-08 23:39:32 -0600
commit542f5cae7b4a15b53b8ee3d9a189f8cfc46161af (patch)
tree9edada3b737a82701bd089e3930b13a08e741d44 /app/src/main/java/com/wireguard
parent8cfaf737774c87b1ea63c0c81c87cc2829c8c982 (diff)
ToolsInstaller: Add a method to ensure tool availability
Signed-off-by: Samuel Holland <samuel@sholland.org>
Diffstat (limited to 'app/src/main/java/com/wireguard')
-rw-r--r--app/src/main/java/com/wireguard/android/util/ToolsInstaller.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java b/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java
index fddcf98b..5042abe6 100644
--- a/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java
+++ b/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java
@@ -3,12 +3,14 @@ package com.wireguard.android.util;
import android.content.Context;
import android.system.ErrnoException;
import android.system.OsConstants;
+import android.util.Log;
import com.wireguard.android.Application.ApplicationContext;
import com.wireguard.android.Application.ApplicationScope;
import com.wireguard.android.util.RootShell.NoRootException;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
@@ -30,10 +32,12 @@ public final class ToolsInstaller {
new File("/system/bin"),
};
private static final File INSTALL_DIR = getInstallDir();
+ private static final String TAG = "WireGuard/" + ToolsInstaller.class.getSimpleName();
private final File localBinaryDir;
private final File nativeLibraryDir;
private final RootShell rootShell;
+ private Boolean areToolsAvailable;
@Inject
public ToolsInstaller(@ApplicationContext final Context context, final RootShell rootShell) {
@@ -85,6 +89,30 @@ public final class ToolsInstaller {
}
}
+ public void ensureToolsAvailable() throws FileNotFoundException {
+ if (areToolsAvailable == null) {
+ synchronized (this) {
+ if (areToolsAvailable == null) {
+ if (areInstalled()) {
+ Log.d(TAG, "Tools are installed to /system");
+ areToolsAvailable = true;
+ } else if (areSymlinked()) {
+ Log.d(TAG, "Tools were already symlinked into our private binary dir");
+ areToolsAvailable = true;
+ } else if (symlink() == OsConstants.EXIT_SUCCESS) {
+ Log.d(TAG, "Tools are now symlinked into our private binary dir");
+ areToolsAvailable = true;
+ } else {
+ Log.e(TAG, "For some reason, wg and wg-quick are not available at all");
+ areToolsAvailable = false;
+ }
+ }
+ }
+ }
+ if (!areToolsAvailable)
+ throw new FileNotFoundException("Required tools unavailable");
+ }
+
public int install() {
if (INSTALL_DIR == null)
return OsConstants.ENOENT;