diff options
author | Sean Leonard <meanderingcode@aetherislands.net> | 2013-07-10 11:23:21 -0600 |
---|---|---|
committer | Sean Leonard <meanderingcode@aetherislands.net> | 2013-07-19 15:09:14 -0600 |
commit | e85eb39a9cfa209eb5503657d9724d1eebd2be0b (patch) | |
tree | 8497184cd4a39fd3eaeefda77b066ca32752cb15 /src | |
parent | 6614dface821c5f975dba47bc6150783c25ee468 (diff) |
Only parse eip-services.json if the serial has incremented
Diffstat (limited to 'src')
-rw-r--r-- | src/se/leap/leapclient/ConfigHelper.java | 23 | ||||
-rw-r--r-- | src/se/leap/leapclient/Dashboard.java | 1 | ||||
-rw-r--r-- | src/se/leap/leapclient/EIP.java | 21 |
3 files changed, 41 insertions, 4 deletions
diff --git a/src/se/leap/leapclient/ConfigHelper.java b/src/se/leap/leapclient/ConfigHelper.java index c5a37be5..0c589c41 100644 --- a/src/se/leap/leapclient/ConfigHelper.java +++ b/src/se/leap/leapclient/ConfigHelper.java @@ -49,6 +49,7 @@ public class ConfigHelper { LOG_OUT = "logOut", DOWNLOAD_CERTIFICATE = "downloadUserAuthedCertificate", API_VERSION_KEY = "api_version", + API_RETURN_SERIAL_KEY = "serial", RESULT_KEY = "result", RECEIVER_KEY = "receiver", PROVIDER_KEY = "provider", @@ -58,6 +59,7 @@ public class ConfigHelper { CERT_KEY = "cert", KEY_KEY = "key", EIP_SERVICE_KEY = "eip", + EIP_PARSED_SERIAL = "eip_parsed_serial", TYPE_OF_CERTIFICATE = "type_of_certificate", ANON_CERTIFICATE = "anon_certificate", AUTHED_CERTIFICATE = "authed_certificate", @@ -162,6 +164,17 @@ public class ConfigHelper { } /** + * Saves an int into class scope Shared Preferences + * + * @param shared_preferences_key + * @param value + */ + protected static void saveSharedPref(String shared_preferences_key, int value) { + SharedPreferences.Editor shared_preferences_editor = shared_preferences.edit(); + shared_preferences_editor.putInt(shared_preferences_key, value).commit(); + } + + /** * Gets String object from class scope Shared Preferences * @param shared_preferences_key * @return the string correspondent to the key parameter @@ -199,6 +212,16 @@ public class ConfigHelper { } return value; } + + /** + * Get an int from SharedPreferences + * + * @param shared_preferences_key Key to retrieve + * @return The value for the key or 0 + */ + protected static int getIntFromSharedPref(String shared_preferences_key) { + return shared_preferences.getInt(shared_preferences_key, 0); + } /* * This method defaults to false. diff --git a/src/se/leap/leapclient/Dashboard.java b/src/se/leap/leapclient/Dashboard.java index b58f4952..6634479e 100644 --- a/src/se/leap/leapclient/Dashboard.java +++ b/src/se/leap/leapclient/Dashboard.java @@ -99,6 +99,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf protected void onActivityResult(int requestCode, int resultCode, Intent data){ if ( requestCode == CONFIGURE_LEAP ) { if ( resultCode == RESULT_OK ){ + startService( new Intent(EIP.ACTION_UPDATE_EIP_SERVICE) ); buildDashboard(); if(data != null && data.hasExtra(ConfigHelper.LOG_IN)) { View view = ((ViewGroup)findViewById(android.R.id.content)).getChildAt(0); diff --git a/src/se/leap/leapclient/EIP.java b/src/se/leap/leapclient/EIP.java index b86a2a4a..5057732e 100644 --- a/src/se/leap/leapclient/EIP.java +++ b/src/se/leap/leapclient/EIP.java @@ -54,6 +54,7 @@ public final class EIP extends IntentService { // Used to store actions to "resume" onServiceConnection private static String mPending = null; + private static int parsedEipSerial; private static JSONObject eipDefinition = null; private static OVPNGateway activeGateway = null; @@ -70,6 +71,7 @@ public final class EIP extends IntentService { try { eipDefinition = ConfigHelper.getJsonFromSharedPref(ConfigHelper.EIP_SERVICE_KEY); + parsedEipSerial = ConfigHelper.getIntFromSharedPref(ConfigHelper.EIP_PARSED_SERIAL); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -224,7 +226,8 @@ public final class EIP extends IntentService { // TODO Auto-generated catch block e.printStackTrace(); } - updateGateways(); + if (eipDefinition.optInt("serial") > parsedEipSerial) + updateGateways(); } /** @@ -274,6 +277,8 @@ public final class EIP extends IntentService { e.printStackTrace(); } } + + ConfigHelper.saveSharedPref(ConfigHelper.EIP_PARSED_SERIAL, eipDefinition.optInt(ConfigHelper.API_RETURN_SERIAL_KEY)); } /** @@ -287,6 +292,7 @@ public final class EIP extends IntentService { private String TAG = "OVPNGateway"; + private String mName; private VpnProfile mVpnProfile; private JSONObject mGateway; private HashMap<String,Vector<Vector<String>>> options = new HashMap<String, Vector<Vector<String>>>(); @@ -299,17 +305,24 @@ public final class EIP extends IntentService { * @param name The hostname of the gateway to inflate */ private OVPNGateway(String name){ + mName = name; + + this.loadVpnProfile(); + } + + private void loadVpnProfile() { ProfileManager vpl = ProfileManager.getInstance(context); try { - if ( name == "first" ) { - name = vpl.getProfiles().iterator().next().mName; + if ( mName == "first" ) { + mName = vpl.getProfiles().iterator().next().mName; } - mVpnProfile = vpl.getProfileByName(name); + mVpnProfile = vpl.getProfileByName(mName); } catch (NoSuchElementException e) { updateEIPService(); + this.loadVpnProfile(); // FIXME catch infinite loops } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); |