diff options
author | Parménides GV <parmegv@sdf.org> | 2014-12-16 16:58:07 +0100 |
---|---|---|
committer | Parménides GV <parmegv@sdf.org> | 2014-12-16 16:58:07 +0100 |
commit | 132b62695b021b61d1774944a7bfa6e9166d3ea0 (patch) | |
tree | 6c451f16af153d0f7a72971ef3625da7f736cbe3 /app/src/debug | |
parent | 9f146deb3448815fccc1637c00588e0dfb23293e (diff) |
Update eip-service.json each EipFragment.onAttach
Diffstat (limited to 'app/src/debug')
-rw-r--r-- | app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java index f47510bc..886d70a0 100644 --- a/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java +++ b/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java @@ -46,6 +46,7 @@ import se.leap.bitmaskclient.eip.*; public class ProviderAPI extends IntentService { final public static String + TAG = ProviderAPI.class.getSimpleName(), SET_UP_PROVIDER = "setUpProvider", DOWNLOAD_NEW_PROVIDER_DOTJSON = "downloadNewProviderDotJSON", SRP_REGISTER = "srpRegister", @@ -58,7 +59,7 @@ public class ProviderAPI extends IntentService { ERRORS = "errors", UPDATE_PROGRESSBAR = "update_progressbar", CURRENT_PROGRESS = "current_progress", - TAG = ProviderAPI.class.getSimpleName() + DOWNLOAD_EIP_SERVICE = TAG + ".DOWNLOAD_EIP_SERVICE" ; final public static int @@ -71,7 +72,9 @@ public class ProviderAPI extends IntentService { CORRECTLY_DOWNLOADED_CERTIFICATE = 9, INCORRECTLY_DOWNLOADED_CERTIFICATE = 10, PROVIDER_OK = 11, - PROVIDER_NOK = 12 + PROVIDER_NOK = 12, + CORRECTLY_DOWNLOADED_EIP_SERVICE = 13, + INCORRECTLY_DOWNLOADED_EIP_SERVICE= 14 ; private static boolean @@ -82,12 +85,12 @@ public class ProviderAPI extends IntentService { private static String last_provider_main_url; private static boolean last_danger_on = false; - private static boolean setting_up_provider = true; + private static boolean go_ahead = true; private static SharedPreferences preferences; private static String provider_api_url; public static void stop() { - setting_up_provider = false; + go_ahead = false; } public ProviderAPI() { @@ -124,15 +127,15 @@ public class ProviderAPI extends IntentService { try { JSONObject provider_json = new JSONObject(preferences.getString(Provider.KEY, "no provider")); provider_api_url = provider_json.getString(Provider.API_URL) + "/" + provider_json.getString(Provider.API_VERSION); - setting_up_provider = true; + go_ahead = true; } catch (JSONException e) { - setting_up_provider = false; + go_ahead = false; } } if(action.equalsIgnoreCase(SET_UP_PROVIDER)) { Bundle result = setUpProvider(parameters); - if(setting_up_provider) { + if(go_ahead) { if(result.getBoolean(RESULT_KEY)) { receiver.send(PROVIDER_OK, result); } else { @@ -165,7 +168,14 @@ public class ProviderAPI extends IntentService { } else { receiver.send(INCORRECTLY_DOWNLOADED_CERTIFICATE, Bundle.EMPTY); } - } + } else if(action.equalsIgnoreCase(DOWNLOAD_EIP_SERVICE)) { + Bundle result = getAndSetEipServiceJson(); + if(result.getBoolean(RESULT_KEY)) { + receiver.send(CORRECTLY_DOWNLOADED_EIP_SERVICE, result); + } else { + receiver.send(INCORRECTLY_DOWNLOADED_EIP_SERVICE, result); + } + } } private Bundle tryToRegister(Bundle task) { @@ -487,7 +497,7 @@ public class ProviderAPI extends IntentService { last_danger_on = task.getBoolean(ProviderItem.DANGER_ON); last_provider_main_url = task.getString(Provider.MAIN_URL); CA_CERT_DOWNLOADED = PROVIDER_JSON_DOWNLOADED = EIP_SERVICE_JSON_DOWNLOADED = false; - setting_up_provider = true; + go_ahead = true; } if(!PROVIDER_JSON_DOWNLOADED) @@ -518,7 +528,7 @@ public class ProviderAPI extends IntentService { String ca_cert_url = provider_json.getString(Provider.CA_CERT_URI); String cert_string = downloadWithCommercialCA(ca_cert_url, danger_on); - if(validCertificate(cert_string) && setting_up_provider) { + if(validCertificate(cert_string) && go_ahead) { preferences.edit().putString(Provider.CA_CERT, cert_string).commit(); result.putBoolean(RESULT_KEY, true); } else { @@ -579,7 +589,7 @@ public class ProviderAPI extends IntentService { private Bundle getAndSetProviderJson(String provider_main_url, boolean danger_on) { Bundle result = new Bundle(); - if(setting_up_provider) { + if(go_ahead) { String provider_dot_json_string = downloadWithCommercialCA(provider_main_url + "/provider.json", danger_on); try { @@ -606,7 +616,7 @@ public class ProviderAPI extends IntentService { private Bundle getAndSetEipServiceJson() { Bundle result = new Bundle(); String eip_service_json_string = ""; - if(setting_up_provider) { + if(go_ahead) { try { JSONObject provider_json = new JSONObject(preferences.getString(Provider.KEY, "")); String eip_service_url = provider_json.getString(Provider.API_URL) + "/" + provider_json.getString(Provider.API_VERSION) + "/" + EIP.SERVICE_API_PATH; |