VpnService: Avoid duplicating file check
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
eb5fdf200a
commit
2b88150fd8
@ -261,6 +261,17 @@ public class VpnService extends Service
|
|||||||
|
|
||||||
private class ConfigEnabler extends AsyncTask<Void, Void, Integer> {
|
private class ConfigEnabler extends AsyncTask<Void, Void, Integer> {
|
||||||
private final Config config;
|
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) {
|
private ConfigEnabler(final Config config) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
@ -270,23 +281,18 @@ public class VpnService extends Service
|
|||||||
protected Integer doInBackground(final Void... voids) {
|
protected Integer doInBackground(final Void... voids) {
|
||||||
if (!new File("/sys/module/wireguard").exists())
|
if (!new File("/sys/module/wireguard").exists())
|
||||||
return -0xfff0001;
|
return -0xfff0001;
|
||||||
if (!existsInUsualSuspects("wg") || !existsInUsualSuspects("wg-quick"))
|
if (!existsInPath("wg") || !existsInPath("wg-quick"))
|
||||||
return -0xfff0002;
|
return -0xfff0002;
|
||||||
Log.i(TAG, "Running wg-quick up for " + config.getName());
|
Log.i(TAG, "Running wg-quick up for " + config.getName());
|
||||||
final File configFile = new File(getFilesDir(), config.getName() + ".conf");
|
final File configFile = new File(getFilesDir(), config.getName() + ".conf");
|
||||||
return rootShell.run(null, "wg-quick up '" + configFile.getPath() + "'");
|
return rootShell.run(null, "wg-quick up '" + configFile.getPath() + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean existsInUsualSuspects(final String file) {
|
private boolean existsInPath(final String file) {
|
||||||
return new File("/system/xbin/" + file).exists() ||
|
for (final String path : paths)
|
||||||
new File("/system/sbin/" + file).exists() ||
|
if (new File(path, file).exists())
|
||||||
new File("/system/bin/" + file).exists() ||
|
return true;
|
||||||
new File("/sbin/" + file).exists() ||
|
return false;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user