From b8aeb61756ccba19fe6c5e40efa96439be9d5c87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Fri, 4 Jul 2014 13:01:08 +0200 Subject: Refactor setting gateway name --- app/src/main/java/se/leap/bitmaskclient/EIP.java | 45 +++++++++++------------- 1 file 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 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(); } /** -- cgit v1.2.3