summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard/android/backends
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-11-27 04:28:48 +0100
committerSamuel Holland <samuel@sholland.org>2017-11-27 04:28:48 +0100
commit6bc6aea2d0a73d866092d7cfb318caf5ff351437 (patch)
tree3747d314c02a85a151d2b3d21a96bddee096f997 /app/src/main/java/com/wireguard/android/backends
parentad16d2cc7b5a39c95450f9d7bd26a0895e8af76b (diff)
NotSupported: check if the module exists
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/backends')
-rw-r--r--app/src/main/java/com/wireguard/android/backends/VpnService.java51
1 files changed, 40 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 8f4ba5a6..b97f532c 100644
--- a/app/src/main/java/com/wireguard/android/backends/VpnService.java
+++ b/app/src/main/java/com/wireguard/android/backends/VpnService.java
@@ -17,7 +17,9 @@ import android.service.quicksettings.TileService;
import android.util.Log;
import android.widget.Toast;
+import com.wireguard.android.NotSupportedActivity;
import com.wireguard.android.QuickTileService;
+import com.wireguard.android.R;
import com.wireguard.android.bindings.ObservableSortedMap;
import com.wireguard.android.bindings.ObservableTreeMap;
import com.wireguard.config.Config;
@@ -245,8 +247,11 @@ public class VpnService extends Service
@Override
protected void onPostExecute(final Boolean result) {
config.setIsEnabled(!result);
- if (!result)
+ if (!result) {
+ Toast.makeText(getApplicationContext(), getString(R.string.error_down),
+ Toast.LENGTH_SHORT).show();
return;
+ }
enabledConfigs.remove(config.getName());
preferences.edit().putStringSet(KEY_ENABLED_CONFIGS, enabledConfigs).apply();
if (config.getName().equals(primaryName))
@@ -254,7 +259,7 @@ public class VpnService extends Service
}
}
- private class ConfigEnabler extends AsyncTask<Void, Void, Boolean> {
+ private class ConfigEnabler extends AsyncTask<Void, Void, Integer> {
private final Config config;
private ConfigEnabler(final Config config) {
@@ -262,17 +267,43 @@ public class VpnService extends Service
}
@Override
- protected Boolean doInBackground(final Void... voids) {
+ protected Integer doInBackground(final Void... voids) {
+ if (!new File("/sys/module/wireguard").exists())
+ return -0xfff0001;
+ if (!existsInUsualSuspects("wg") || !existsInUsualSuspects("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() + "'") == 0;
+ return rootShell.run(null, "wg-quick up '" + configFile.getPath() + "'");
+ }
+
+ private boolean existsInUsualSuspects(final String file) {
+ return new File("/system/bin/" + file).exists() ||
+ new File("/system/xbin/" + file).exists() ||
+ new File("/system/sbin/" + file).exists() ||
+ new File("/bin/" + file).exists() ||
+ new File("/xbin/" + file).exists() ||
+ new File("/sbin/" + file).exists() ||
+ new File("/usr/bin/" + file).exists() ||
+ new File("/usr/xbin/" + file).exists() ||
+ new File("/usr/sbin/" + file).exists();
}
@Override
- protected void onPostExecute(final Boolean result) {
- config.setIsEnabled(result);
- if (!result)
+ protected void onPostExecute(final Integer ret) {
+ config.setIsEnabled(ret == 0);
+ if (ret != 0) {
+ if (ret == -0xfff0001) {
+ startActivity(new Intent(getApplicationContext(), NotSupportedActivity.class));
+ } else if (ret == -0xfff0002) {
+ Toast.makeText(getApplicationContext(), getString(R.string.error_missing),
+ Toast.LENGTH_LONG).show();
+ } else {
+ Toast.makeText(getApplicationContext(), getString(R.string.error_up),
+ Toast.LENGTH_SHORT).show();
+ }
return;
+ }
enabledConfigs.add(config.getName());
preferences.edit().putStringSet(KEY_ENABLED_CONFIGS, enabledConfigs).apply();
if (config.getName().equals(primaryName))
@@ -378,10 +409,8 @@ public class VpnService extends Service
config.setName(configName);
configs.add(config);
} catch (IllegalArgumentException | IOException e) {
- try {
- file.delete();
- } catch (Exception e2) {
- Log.w(TAG, "Could not remove " + fileName, e2);
+ if (!file.delete()) {
+ Log.e(TAG, "Could not delete configuration for config " + configName);
}
Log.w(TAG, "Failed to load config from " + fileName, e);
publishProgress(fileName + ": " + e.getMessage());