diff options
author | Samuel Holland <samuel@sholland.org> | 2018-01-08 23:49:14 -0600 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2018-01-08 23:49:14 -0600 |
commit | 204755d6892acdcfbeffbf7cf0e44b3083b2f631 (patch) | |
tree | ff44f69111d7847efeedb762e549f29368d8a85d /app | |
parent | c806e655faeebd3e409a053f6c14678a037ce135 (diff) |
RootShell: Simplify constructor
ToolsInstaller now takes care of installing the tools.
Signed-off-by: Samuel Holland <samuel@sholland.org>
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/com/wireguard/android/util/RootShell.java | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/app/src/main/java/com/wireguard/android/util/RootShell.java b/app/src/main/java/com/wireguard/android/util/RootShell.java index 6dda2d8f..947a6679 100644 --- a/app/src/main/java/com/wireguard/android/util/RootShell.java +++ b/app/src/main/java/com/wireguard/android/util/RootShell.java @@ -31,10 +31,6 @@ import javax.inject.Inject; public class RootShell { private static final Pattern ERRNO_EXTRACTOR = Pattern.compile("error=(\\d+)"); private static final String TAG = "WireGuard/" + RootShell.class.getSimpleName(); - private static final String[][] libraryNamedExecutables = { - {"libwg.so", "wg"}, - {"libwg-quick.so", "wg-quick"} - }; private final String exceptionMessage; private final String preamble; @@ -45,24 +41,15 @@ public class RootShell { @Inject public RootShell(@ApplicationContext final Context context) { - final String binDir = context.getCacheDir().getPath() + "/bin"; - final String tmpDir = context.getCacheDir().getPath() + "/tmp"; - final String libDir = context.getApplicationInfo().nativeLibraryDir; + final File binDir = new File(context.getCacheDir(), "bin"); + final File tmpDir = new File(context.getCacheDir(), "tmp"); - new File(binDir).mkdirs(); - new File(tmpDir).mkdirs(); - - StringBuilder builder = new StringBuilder(); - for (final String[] libraryNamedExecutable : libraryNamedExecutables) { - final String arg1 = "'" + libDir + "/" + libraryNamedExecutable[0] + "'"; - final String arg2 = "'" + binDir + "/" + libraryNamedExecutable[1] + "'"; - builder.append(String.format("[ %s -ef %s ] || ln -sf %s %s || exit 31;", arg1, arg2, arg1, arg2)); - } - builder.append(String.format("export PATH=\"%s:$PATH\" TMPDIR=\"%s\";", binDir, tmpDir)); - builder.append("id;\n"); + if (!(binDir.isDirectory() || binDir.mkdirs()) + || !(tmpDir.isDirectory() || tmpDir.mkdirs())) + throw new RuntimeException(new IOException("Cannot create binary dir/TMPDIR")); exceptionMessage = context.getString(R.string.error_root); - preamble = builder.toString(); + preamble = String.format("export PATH=\"%s:$PATH\" TMPDIR='%s'; id;\n", binDir, tmpDir); } private static boolean isExecutable(final String name) { |