diff options
Diffstat (limited to 'app/src/main/java/com/wireguard')
3 files changed, 31 insertions, 32 deletions
diff --git a/app/src/main/java/com/wireguard/android/ProfileListFragment.java b/app/src/main/java/com/wireguard/android/ProfileListFragment.java index f794e54f..be9b8d42 100644 --- a/app/src/main/java/com/wireguard/android/ProfileListFragment.java +++ b/app/src/main/java/com/wireguard/android/ProfileListFragment.java @@ -36,9 +36,9 @@ public class ProfileListFragment extends ProfileActivityFragment { if (profile == null || service == null) return false; if (profile.getIsConnected()) - service.disconnectProfile(profile); + service.disconnectProfile(profile.getName()); else - service.connectProfile(profile); + service.connectProfile(profile.getName()); return true; } }); diff --git a/app/src/main/java/com/wireguard/android/ProfileService.java b/app/src/main/java/com/wireguard/android/ProfileService.java index ea97a613..96371d6c 100644 --- a/app/src/main/java/com/wireguard/android/ProfileService.java +++ b/app/src/main/java/com/wireguard/android/ProfileService.java @@ -215,26 +215,23 @@ public class ProfileService extends Service { private class ProfileServiceBinder extends Binder implements ProfileServiceInterface { @Override - public void connectProfile(Profile profile) { - if (profiles.get(profile.getName()) != profile) - return; - if (profile.getIsConnected()) + public void connectProfile(String name) { + final Profile profile = profiles.get(name); + if (profile == null || profile.getIsConnected()) return; new ProfileConnecter(profile).execute(); } @Override - public Profile copyProfileForEditing(Profile profile) { - if (profiles.get(profile.getName()) != profile) - return null; - return profile.copy(); + public Profile copyProfileForEditing(String name) { + final Profile profile = profiles.get(name); + return profile != null ? profile.copy() : null; } @Override - public void disconnectProfile(Profile profile) { - if (profiles.get(profile.getName()) != profile) - return; - if (!profile.getIsConnected()) + public void disconnectProfile(String name) { + final Profile profile = profiles.get(name); + if (profile == null || !profile.getIsConnected()) return; new ProfileDisconnecter(profile).execute(); } @@ -245,8 +242,9 @@ public class ProfileService extends Service { } @Override - public void removeProfile(Profile profile) { - if (profiles.get(profile.getName()) != profile) + public void removeProfile(String name) { + final Profile profile = profiles.get(name); + if (profile == null) return; if (profile.getIsConnected()) new ProfileDisconnecter(profile).execute(); @@ -254,9 +252,10 @@ public class ProfileService extends Service { } @Override - public void saveProfile(Profile oldProfile, Profile newProfile) { - if (oldProfile != null) { - if (profiles.get(oldProfile.getName()) != oldProfile) + public void saveProfile(String oldName, Profile newProfile) { + if (oldName != null) { + final Profile oldProfile = profiles.get(oldName); + if (oldProfile == null) return; final boolean wasConnected = oldProfile.getIsConnected(); if (wasConnected) diff --git a/app/src/main/java/com/wireguard/android/ProfileServiceInterface.java b/app/src/main/java/com/wireguard/android/ProfileServiceInterface.java index 0e94727b..54b32595 100644 --- a/app/src/main/java/com/wireguard/android/ProfileServiceInterface.java +++ b/app/src/main/java/com/wireguard/android/ProfileServiceInterface.java @@ -14,35 +14,35 @@ public interface ProfileServiceInterface { * will be updated if connection is successful. If this profile is already connected, or it is * not a known profile, no changes will be made. * - * @param profile The profile (in the list of known profiles) to use for this connection. + * @param name The profile (in the list of known profiles) to use for this connection. */ - void connectProfile(Profile profile); + void connectProfile(String name); /** * Creates a deep copy of an existing profile that can be modified and then passed to * saveProfile. If the given profile is not a known profile, or the profile cannot be copied, * this function returns null. * - * @param profile The existing profile (in the list of known profiles) to copy. + * @param name The existing profile (in the list of known profiles) to copy. * @return A copy of the profile that can be freely modified. */ - Profile copyProfileForEditing(Profile profile); + Profile copyProfileForEditing(String name); /** * Attempt to disable and tear down an interface for this profile. The profile's connection * state will be updated if disconnection is successful. If this profile is already * disconnected, or it is not a known profile, no changes will be made. * - * @param profile The profile (in the list of known profiles) to disconnect. + * @param name The profile (in the list of known profiles) to disconnect. */ - void disconnectProfile(Profile profile); + void disconnectProfile(String name); /** - * Retrieve a list of profiles known and managed by this service. Profiles in this list must not - * be modified directly. If a profile is to be updated, first create a copy of it by calling + * Retrieve the set of profiles known and managed by this service. Profiles in this list must + * not be modified directly. If a profile is to be updated, first create a copy of it by calling * copyProfileForEditing(). * - * @return The list of known profiles. + * @return The set of known profiles. */ ObservableArrayMap<String, Profile> getProfiles(); @@ -52,9 +52,9 @@ public interface ProfileServiceInterface { * will be removed from persistent storage. If the profile is not a known profile, no changes * will be made. * - * @param profile The profile (in the list of known profiles) to remove. + * @param name The profile (in the list of known profiles) to remove. */ - void removeProfile(Profile profile); + void removeProfile(String name); /** * Replace the given profile, or add a new profile if oldProfile is null. @@ -63,8 +63,8 @@ public interface ProfileServiceInterface { * it will be set to the disconnected state. If successful, configuration for this profile will * be saved to persistent storage. * - * @param oldProfile The existing profile to replace, or null to add the new profile. + * @param oldName The existing profile to replace, or null to add the new profile. * @param newProfile The profile to add, or a copy of the profile to replace. */ - void saveProfile(Profile oldProfile, Profile newProfile); + void saveProfile(String oldName, Profile newProfile); } |