summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2018-01-08 23:12:50 -0600
committerSamuel Holland <samuel@sholland.org>2018-01-08 23:39:32 -0600
commit1cfb938dd18526b4d961dfc8ac374ac678724c18 (patch)
tree3099f3fc2e790faa5c71b66c8619efd56ccd7f3e /app/src/main/java/com
parent011d683c233dedf90a52b9edb59f311bcfa3e065 (diff)
ToolsInstaller: Add methods to check/make symlinks
Signed-off-by: Samuel Holland <samuel@sholland.org>
Diffstat (limited to 'app/src/main/java/com')
-rw-r--r--app/src/main/java/com/wireguard/android/util/ToolsInstaller.java35
1 files changed, 35 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 ebe69855..fddcf98b 100644
--- a/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java
+++ b/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java
@@ -31,11 +31,13 @@ public final class ToolsInstaller {
};
private static final File INSTALL_DIR = getInstallDir();
+ private final File localBinaryDir;
private final File nativeLibraryDir;
private final RootShell rootShell;
@Inject
public ToolsInstaller(@ApplicationContext final Context context, final RootShell rootShell) {
+ localBinaryDir = new File(context.getCacheDir(), "bin");
nativeLibraryDir = new File(context.getApplicationInfo().nativeLibraryDir);
this.rootShell = rootShell;
}
@@ -68,6 +70,21 @@ public final class ToolsInstaller {
}
}
+ public boolean areSymlinked() {
+ final StringBuilder script = new StringBuilder();
+ for (final String[] names : EXECUTABLES) {
+ script.append(String.format("test '%s' -ef '%s' && ",
+ new File(nativeLibraryDir, names[0]),
+ new File(localBinaryDir, names[1])));
+ }
+ script.append("exit ").append(OsConstants.EALREADY);
+ try {
+ return rootShell.run(null, script.toString()) == OsConstants.EALREADY;
+ } catch (final ErrnoException | IOException | NoRootException ignored) {
+ return false;
+ }
+ }
+
public int install() {
if (INSTALL_DIR == null)
return OsConstants.ENOENT;
@@ -88,4 +105,22 @@ public final class ToolsInstaller {
return OsConstants.EACCES;
}
}
+
+ public int symlink() {
+ final StringBuilder script = new StringBuilder("set -ex");
+ for (final String[] names : EXECUTABLES) {
+ script.append(String.format("; ln -fns '%s' '%s'",
+ new File(nativeLibraryDir, names[0]),
+ new File(localBinaryDir, names[1])));
+ }
+ try {
+ return rootShell.run(null, script.toString());
+ } catch (final ErrnoException e) {
+ return e.errno;
+ } catch (final IOException ignored) {
+ return OsConstants.EXIT_FAILURE;
+ } catch (final NoRootException ignored) {
+ return OsConstants.EACCES;
+ }
+ }
}