From 5b4218922bcae594baaaa2a26c2094fc8c10d276 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Mon, 31 Jul 2017 21:18:14 -0500 Subject: ProfileService: Check for existing interfaces when loading profiles --- .../main/java/com/wireguard/android/ProfileService.java | 14 ++++++++++++-- 1 file changed, 12 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 c561c340..a459dba5 100644 --- a/app/src/main/java/com/wireguard/android/ProfileService.java +++ b/app/src/main/java/com/wireguard/android/ProfileService.java @@ -50,25 +50,35 @@ public class ProfileService extends Service { private class ProfileLoader extends AsyncTask> { @Override 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) { + interfaceNames.clear(); + Log.w(TAG, "Can't enumerate network interfaces. All profiles will appear down."); + } for (File file : files) { + if (isCancelled()) + return null; final String fileName = file.getName(); final String profileName = fileName.substring(0, fileName.length() - 5); final Profile profile = new Profile(profileName); + Log.v(TAG, "Attempting to load profile " + profileName); try { profile.parseFrom(openFileInput(fileName)); + profile.setIsConnected(interfaceNames.contains(profileName)); loadedProfiles.add(profile); } catch (IOException e) { Log.w(TAG, "Failed to load profile from " + fileName, e); } - if (isCancelled()) - break; } return loadedProfiles; } @Override protected void onPostExecute(List loadedProfiles) { + if (loadedProfiles == null) + return; profiles.addAll(loadedProfiles); } } -- cgit v1.2.3