diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-01-10 23:38:39 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-01-10 23:47:13 +0100 |
commit | 7e06768f752f6ac44d0f33f4d8de5a6cadb4fa7c (patch) | |
tree | f4b778b55abe2afe79e619528975753a9bd8e9ec /app/src/main/java/com | |
parent | 7a618c1463341adc6d4ad0b6aa4c589cc4c0004d (diff) |
ToolsInstaller: symlink tools always
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com')
-rw-r--r-- | app/src/main/java/com/wireguard/android/util/ToolsInstaller.java | 36 |
1 files changed, 14 insertions, 22 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 46dc43a4..dca410f0 100644 --- a/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java +++ b/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java @@ -73,32 +73,15 @@ public final class ToolsInstaller { } } - public int areSymlinked() throws NoRootException { - 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).append(';'); - try { - return rootShell.run(null, script.toString()); - } catch (final IOException ignored) { - return OsConstants.EXIT_FAILURE; - } - } - public void ensureToolsAvailable() throws FileNotFoundException, NoRootException { if (areToolsAvailable == null) { synchronized (this) { if (areToolsAvailable == null) { - if (areInstalled() == OsConstants.EALREADY) { - Log.d(TAG, "Tools are installed to the system partition"); - areToolsAvailable = true; - } else if (areSymlinked() == OsConstants.EALREADY) { + int ret = symlink(); + if (ret == OsConstants.EALREADY) { Log.d(TAG, "Tools were already symlinked into our private binary dir"); areToolsAvailable = true; - } else if (symlink() == OsConstants.EXIT_SUCCESS) { + } else if (ret == OsConstants.EXIT_SUCCESS) { Log.d(TAG, "Tools are now symlinked into our private binary dir"); areToolsAvailable = true; } else { @@ -115,7 +98,7 @@ public final class ToolsInstaller { public int install() throws NoRootException { if (INSTALL_DIR == null) return OsConstants.ENOENT; - final StringBuilder script = new StringBuilder("set -ex;"); + final StringBuilder script = new StringBuilder("set -ex; "); script.append("trap 'mount -o ro,remount /system' EXIT; mount -o rw,remount /system; "); for (final String[] names : EXECUTABLES) { final File destination = new File(INSTALL_DIR, names[1]); @@ -130,12 +113,21 @@ public final class ToolsInstaller { } public int symlink() throws NoRootException { - final StringBuilder script = new StringBuilder("set -ex;"); + final StringBuilder script = new StringBuilder("set -x; "); + 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).append("; set -e; "); + for (final String[] names : EXECUTABLES) { script.append(String.format("ln -fns '%s' '%s'; ", new File(nativeLibraryDir, names[0]), new File(localBinaryDir, names[1]))); } + script.append("exit ").append(OsConstants.EXIT_SUCCESS).append(';'); + try { return rootShell.run(null, script.toString()); } catch (final IOException ignored) { |