summaryrefslogtreecommitdiffhomepage
path: root/app/src/main
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2017-07-31 21:18:14 -0500
committerSamuel Holland <samuel@sholland.org>2017-07-31 21:18:14 -0500
commit0451370caffa5e1fd70d50a842abdf58a63c7107 (patch)
treec7a57c747ca2bd071e038a243dc89caf71fe24e0 /app/src/main
parenta1e334efa647d6f4aa2c5a818f92be9376219c73 (diff)
ProfileService: Check for existing interfaces when loading profiles
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/com/wireguard/android/ProfileService.java14
1 files changed, 12 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 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<File, Void, List<Profile>> {
@Override
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) {
+ 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<Profile> loadedProfiles) {
+ if (loadedProfiles == null)
+ return;
profiles.addAll(loadedProfiles);
}
}