diff options
author | Samuel Holland <samuel@sholland.org> | 2017-11-28 20:40:58 -0600 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2017-11-28 20:42:25 -0600 |
commit | 2b88150fd8499eb79e834eaaae97b96dd1683c74 (patch) | |
tree | 63b8022910a9c3c8efe195ae82f8cc04edde921a /app/src/main/java/com/wireguard/android/backends/VpnService.java | |
parent | eb5fdf200a0c64eba73619dfd1058bff94bab1e3 (diff) |
VpnService: Avoid duplicating file check
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/backends/VpnService.java')
-rw-r--r-- | app/src/main/java/com/wireguard/android/backends/VpnService.java | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/app/src/main/java/com/wireguard/android/backends/VpnService.java b/app/src/main/java/com/wireguard/android/backends/VpnService.java index dbd08182..e255c245 100644 --- a/app/src/main/java/com/wireguard/android/backends/VpnService.java +++ b/app/src/main/java/com/wireguard/android/backends/VpnService.java @@ -261,6 +261,17 @@ public class VpnService extends Service private class ConfigEnabler extends AsyncTask<Void, Void, Integer> { private final Config config; + private final String[] paths = { + "/system/xbin", + "/system/sbin", + "/system/bin", + "/sbin", + "/bin", + "/xbin", + "/usr/sbin", + "/usr/bin", + "/usr/xbin", + }; private ConfigEnabler(final Config config) { this.config = config; @@ -270,23 +281,18 @@ public class VpnService extends Service protected Integer doInBackground(final Void... voids) { if (!new File("/sys/module/wireguard").exists()) return -0xfff0001; - if (!existsInUsualSuspects("wg") || !existsInUsualSuspects("wg-quick")) + if (!existsInPath("wg") || !existsInPath("wg-quick")) return -0xfff0002; Log.i(TAG, "Running wg-quick up for " + config.getName()); final File configFile = new File(getFilesDir(), config.getName() + ".conf"); return rootShell.run(null, "wg-quick up '" + configFile.getPath() + "'"); } - private boolean existsInUsualSuspects(final String file) { - return new File("/system/xbin/" + file).exists() || - new File("/system/sbin/" + file).exists() || - new File("/system/bin/" + file).exists() || - new File("/sbin/" + file).exists() || - new File("/bin/" + file).exists() || - new File("/xbin/" + file).exists() || - new File("/usr/sbin/" + file).exists() || - new File("/usr/bin/" + file).exists() || - new File("/usr/xbin/" + file).exists(); + private boolean existsInPath(final String file) { + for (final String path : paths) + if (new File(path, file).exists()) + return true; + return false; } @Override |