summaryrefslogtreecommitdiffhomepage
path: root/app/src
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
commit5201c7f8492ea5e77267d3e45f4a4c1285e8f10b (patch)
tree9edada3b737a82701bd089e3930b13a08e741d44 /app/src
parentba30d46e08d2c2186d99f1b398f10701dea86eba (diff)
ToolsInstaller: Add a method to ensure tool availability
Signed-off-by: Samuel Holland <samuel@sholland.org>
Diffstat (limited to 'app/src')
-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;