summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-07-04 13:01:08 +0200
committerParménides GV <parmegv@sdf.org>2014-07-10 09:00:34 +0200
commitb8aeb61756ccba19fe6c5e40efa96439be9d5c87 (patch)
tree7bbdc1b88de82dc2d008fced35fb5fc4b81c7ac7 /app/src/main/java/se/leap
parent5749b7ec95d9bb68548f6a002b5c5e91cb8a8f7a (diff)
Refactor setting gateway name
Diffstat (limited to 'app/src/main/java/se/leap')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EIP.java45
1 files changed, 20 insertions, 25 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/EIP.java b/app/src/main/java/se/leap/bitmaskclient/EIP.java
index 5c1336a1..0b43f9e1 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EIP.java
@@ -424,43 +424,38 @@ public final class EIP extends IntentService {
for (Iterator<VpnProfile> it = profiles.iterator(); it.hasNext(); ){
VpnProfile p = it.next();
- try {
- String name = eipDefinition.getJSONObject("locations").getJSONObject(mGateway.getString("location")).getString("name");
- if ( p.mName.equalsIgnoreCase( name ) ) {
- it.remove();
- vpl.removeProfile(context, p);
- }
- } catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ if ( p.mName.equalsIgnoreCase( mName ) ) {
+ it.remove();
+ vpl.removeProfile(context, p);
}
}
this.createVPNProfile();
- setUniqueProfileName(vpl);
+ setUniqueProfileName();
vpl.addProfile(mVpnProfile);
vpl.saveProfile(context, mVpnProfile);
vpl.saveProfileList(context);
}
+
+
+ public String locationAsName() {
+ try {
+ return eipDefinition.getJSONObject("locations").getJSONObject(mGateway.getString("location")).getString("name");
+ } catch (JSONException e) {
+ Log.v(TAG,"Couldn't read gateway name for profile creation! Returning original name = " + mName);
+ e.printStackTrace();
+ return mName;
+ }
+ }
+
/**
- * Attempts to create a unique profile name from the hostname of the gateway
- *
- * @param profileManager
+ * Attempts to create a unique profile name
+ * based on the location of the gateway.
*/
- private void setUniqueProfileName(ProfileManager profileManager) {
- int i=0;
-
- try {
- String newname = eipDefinition.getJSONObject("locations").getJSONObject(mGateway.getString("location")).getString("name");
- mVpnProfile.mName=newname;
- mName = newname;
- } catch (JSONException e) {
- // TODO Auto-generated catch block
- Log.v(TAG,"Couldn't read gateway name for profile creation!");
- e.printStackTrace();
- }
+ private void setUniqueProfileName() {
+ mVpnProfile.mName = mName = locationAsName();
}
/**