summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap/bitmaskclient/eip
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-12-31 16:51:56 +0100
committerParménides GV <parmegv@sdf.org>2014-12-31 16:51:56 +0100
commit8d7bedaa40129ae809f3e1261228b00042872f62 (patch)
tree022a867957c29f26f28638cc0db93ff5bb8b49c8 /app/src/main/java/se/leap/bitmaskclient/eip
parent44b59b984f76da62d409b585047224cb1e958016 (diff)
Don't remove vpn profiles if possible.
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/eip')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EIP.java20
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java25
2 files changed, 22 insertions, 23 deletions
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<VpnProfile> profiles = vpl.getProfiles();
- for (Iterator<VpnProfile> 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);
+ }
}