From 8d7bedaa40129ae809f3e1261228b00042872f62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Wed, 31 Dec 2014 16:51:56 +0100 Subject: Don't remove vpn profiles if possible. --- .../main/java/se/leap/bitmaskclient/eip/EIP.java | 20 +++++++++++------ .../java/se/leap/bitmaskclient/eip/Gateway.java | 25 ++++++++-------------- 2 files changed, 22 insertions(+), 23 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/eip') diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java index 3d3070c8..77d0cd82 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -101,7 +101,7 @@ public final class EIP extends IntentService { stopEIP(); else if (action.equals(ACTION_IS_EIP_RUNNING)) isRunning(); - else if (action.equals(ACTION_UPDATE_EIP_SERVICE)) + else if (action.equals(ACTION_UPDATE_EIP_SERVICE)) updateEIPService(); else if (action.equals(ACTION_CHECK_CERT_VALIDITY)) checkCertValidity(); @@ -174,8 +174,8 @@ public final class EIP extends IntentService { */ private void updateEIPService() { refreshEipDefinition(); - deleteAllVpnProfiles(); - updateGateways(); + if(eip_definition != null) + updateGateways(); tellToReceiver(ACTION_UPDATE_EIP_SERVICE, Activity.RESULT_OK); } @@ -204,15 +204,16 @@ public final class EIP extends IntentService { */ private void updateGateways(){ try { - if(eip_definition != null) { JSONArray gatewaysDefined = eip_definition.getJSONArray("gateways"); for (int i = 0; i < gatewaysDefined.length(); i++) { JSONObject gw = gatewaysDefined.getJSONObject(i); if (isOpenVpnGateway(gw)) { - addGateway(new Gateway(eip_definition, context, gw)); + Gateway gateway = new Gateway(eip_definition, context, gw); + if(!gateways.contains(gateway)) { + addGateway(gateway); + } } } - } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -229,8 +230,13 @@ public final class EIP extends IntentService { } private void addGateway(Gateway gateway) { - profile_manager.addProfile(gateway.getProfile()); + VpnProfile profile = gateway.getProfile(); + profile_manager.addProfile(profile); + profile_manager.saveProfile(context, profile); + profile_manager.saveProfileList(context); + gateways.add(gateway); + Log.d(TAG, "Gateway added: " + gateway.getProfile().getUUIDString()); } private void checkCertValidity() { diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java index 3ee9443c..79239308 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java @@ -68,24 +68,8 @@ public class Gateway { timezone = getTimezone(eip_definition); mName = locationAsName(eip_definition); - // Currently deletes VpnProfile for host, if there already is one, and builds new - ProfileManager vpl = ProfileManager.getInstance(context); - Collection profiles = vpl.getProfiles(); - for (Iterator it = profiles.iterator(); it.hasNext(); ){ - VpnProfile p = it.next(); - - if ( p.mName.equalsIgnoreCase( mName ) ) { - it.remove(); - vpl.removeProfile(context, p); - } - } - mVpnProfile = createVPNProfile(); mVpnProfile.mName = mName; - - vpl.addProfile(mVpnProfile); - vpl.saveProfile(context, mVpnProfile); - vpl.saveProfileList(context); } private JSONObject getGeneralConfiguration(JSONObject eip_definition) { @@ -153,4 +137,13 @@ public class Gateway { public int getTimezone() { return timezone; } + + @Override + public boolean equals(Object o) { + if(o instanceof Gateway) { + return ((Gateway) o).getProfile().mConnections.equals(mVpnProfile.mConnections); + } + else + return super.equals(o); + } } -- cgit v1.2.3