From 544812b2a7e888e1cb16a6ea02c6035b050119be Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Mon, 31 Jul 2017 23:11:18 -0500 Subject: ProfileService: Use wg to enumerate interfaces Signed-off-by: Jason A. Donenfeld --- app/src/main/java/com/wireguard/android/ProfileService.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'app/src') 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 doInBackground(File... files) { final List interfaceNames = new LinkedList<>(); final List 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."); } -- cgit v1.2.3