summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard/android
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/com/wireguard/android')
-rw-r--r--app/src/main/java/com/wireguard/android/backends/RootShell.java6
-rw-r--r--app/src/main/java/com/wireguard/android/backends/VpnService.java10
2 files changed, 15 insertions, 1 deletions
diff --git a/app/src/main/java/com/wireguard/android/backends/RootShell.java b/app/src/main/java/com/wireguard/android/backends/RootShell.java
index 0b529065..9fd5020d 100644
--- a/app/src/main/java/com/wireguard/android/backends/RootShell.java
+++ b/app/src/main/java/com/wireguard/android/backends/RootShell.java
@@ -10,6 +10,8 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
/**
* Helper class for running commands as root.
@@ -22,6 +24,7 @@ class RootShell {
*/
private static final String SETUP_TEMPLATE = "export TMPDIR=%s\ntrap 'echo $?' EXIT\n";
private static final String TAG = "RootShell";
+ private static final Pattern ERRNO_EXTRACTOR = Pattern.compile("error=(\\d+)");
private final byte[] setupCommands;
private final String shell;
@@ -80,6 +83,9 @@ class RootShell {
Log.d(TAG, "Session completed with exit value " + exitValue);
} catch (IOException | InterruptedException | NumberFormatException e) {
Log.w(TAG, "Session failed with exception", e);
+ final Matcher match = ERRNO_EXTRACTOR.matcher(e.toString());
+ if (match.find())
+ exitValue = Integer.valueOf(match.group(1));
}
return exitValue;
}
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 e255c245..3a8f6597 100644
--- a/app/src/main/java/com/wireguard/android/backends/VpnService.java
+++ b/app/src/main/java/com/wireguard/android/backends/VpnService.java
@@ -283,9 +283,14 @@ public class VpnService extends Service
return -0xfff0001;
if (!existsInPath("wg") || !existsInPath("wg-quick"))
return -0xfff0002;
+ if (!existsInPath("su"))
+ return -0xfff0003;
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() + "'");
+ final int ret = rootShell.run(null, "wg-quick up '" + configFile.getPath() + "'");
+ if (ret == 13 /* EPERM */)
+ return -0xfff0003;
+ return ret;
}
private boolean existsInPath(final String file) {
@@ -304,6 +309,9 @@ public class VpnService extends Service
} else if (ret == -0xfff0002) {
Toast.makeText(getApplicationContext(), getString(R.string.error_missing),
Toast.LENGTH_LONG).show();
+ } else if (ret == -0xfff0003) {
+ Toast.makeText(getApplicationContext(), getString(R.string.error_su),
+ Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), getString(R.string.error_up),
Toast.LENGTH_SHORT).show();