diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-01-08 19:46:51 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-01-08 19:46:51 +0100 |
commit | 31ba7e6593f3089a3700c800b2d3b1f2aad7648e (patch) | |
tree | 6e7ff0de24f3113077b9308baf0e69fcbc21ece4 /app/src/main/java/com/wireguard/android/backend | |
parent | Port over remaining error handling (diff) | |
download | wireguard-android-31ba7e6593f3089a3700c800b2d3b1f2aad7648e.tar.xz wireguard-android-31ba7e6593f3089a3700c800b2d3b1f2aad7648e.zip |
RootShell: multiplex commands
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/backend')
-rw-r--r-- | app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java b/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java index 5eaf437d..ab6a6199 100644 --- a/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java +++ b/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java @@ -52,8 +52,12 @@ public final class WgQuickBackend implements Backend { public Set<String> enumerate() { final List<String> output = new ArrayList<>(); // Don't throw an exception here or nothing will show up in the UI. - if (rootShell.run(output, "wg show interfaces") != 0 || output.isEmpty()) + try { + if (rootShell.run(output, "wg show interfaces") != 0 || output.isEmpty()) + return Collections.emptySet(); + } catch (Exception e) { return Collections.emptySet(); + } // wg puts all interface names on the same line. Split them into separate elements. return Stream.of(output.get(0).split(" ")).collect(Collectors.toUnmodifiableSet()); } @@ -86,11 +90,8 @@ public final class WgQuickBackend implements Backend { } else { result = rootShell.run(null, String.format("wg-quick down '%s'", tunnel.getName())); } - if (result != 0) { - final String message = result == OsConstants.EACCES ? - "Root access unavailable" : "wg-quick failed"; - throw new Exception(message); - } + if (result != 0) + throw new Exception("wg-quick failed"); return getState(tunnel); } } |