diff options
author | Samuel Holland <samuel@sholland.org> | 2017-07-31 23:11:18 -0500 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2017-07-31 23:11:18 -0500 |
commit | 544812b2a7e888e1cb16a6ea02c6035b050119be (patch) | |
tree | fd14842018d0742588593a93ac852a3daae755ad | |
parent | b324e7b7f1908bbf95698191ed462191dd2a523c (diff) |
ProfileService: Use wg to enumerate interfaces
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | app/src/main/java/com/wireguard/android/ProfileService.java | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/app/src/main/java/com/wireguard/android/ProfileService.java b/app/src/main/java/com/wireguard/android/ProfileService.java index 2d0e55eb..d5c882db 100644 --- a/app/src/main/java/com/wireguard/android/ProfileService.java +++ b/app/src/main/java/com/wireguard/android/ProfileService.java @@ -16,6 +16,7 @@ import java.io.FileOutputStream; import java.io.FilenameFilter; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -132,8 +133,13 @@ public class ProfileService extends Service { protected List<Profile> doInBackground(File... files) { final List<String> interfaceNames = new LinkedList<>(); final List<Profile> loadedProfiles = new LinkedList<>(); - final String command = "ip -br link show type wireguard | cut -d' ' -f1"; - if (RootShell.run(interfaceNames, command) != 0) { + final String command = "wg show interfaces"; + if (RootShell.run(interfaceNames, command) == 0 && interfaceNames.size() == 1) { + // wg puts all interface names on the same line. Split them into separate elements. + final String nameList = interfaceNames.get(0); + Collections.addAll(interfaceNames, nameList.split(" ")); + interfaceNames.remove(0); + } else { interfaceNames.clear(); Log.w(TAG, "Can't enumerate network interfaces. All profiles will appear down."); } |