summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2013-09-06 12:54:24 +0200
committerParménides GV <parmegv@sdf.org>2013-12-09 18:53:00 +0100
commit5ceb82f87fb4f94984d3720f68187bf6ba00d1e0 (patch)
treecc7e326f83c19eaee33db984427f6978e59a468c /src
parentb1dacaa6f0131193e04c10327a07f778a67b6d12 (diff)
Removing unnecessary fields from ProviderItem.
I'm targeting to refactor the whole ProviderItem class because I've not used the Provider class so far and I should not duplicate information from "Provider" into "ProviderItem".
Diffstat (limited to 'src')
-rw-r--r--src/se/leap/bitmaskclient/ConfigurationWizard.java27
-rw-r--r--src/se/leap/bitmaskclient/ProviderListContent.java77
2 files changed, 35 insertions, 69 deletions
diff --git a/src/se/leap/bitmaskclient/ConfigurationWizard.java b/src/se/leap/bitmaskclient/ConfigurationWizard.java
index 4a3bb12b..532debfd 100644
--- a/src/se/leap/bitmaskclient/ConfigurationWizard.java
+++ b/src/se/leap/bitmaskclient/ConfigurationWizard.java
@@ -175,13 +175,14 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
//Toast.makeText(this, getResources().getString(R.string.config_error_parsing), Toast.LENGTH_LONG);
setResult(RESULT_CANCELED, mConfigState);
}
- }
+ }
else if(resultCode == ProviderAPI.INCORRECTLY_UPDATED_PROVIDER_DOT_JSON) {
String reason_to_fail = resultData.getString(ProviderAPI.ERRORS);
showDownloadFailedDialog(getCurrentFocus(), reason_to_fail);
refreshProviderList(0);
mProgressBar.setVisibility(ProgressBar.GONE);
progressbar_description.setVisibility(TextView.GONE);
+ ConfigHelper.removeFromSharedPref(Provider.KEY);
setResult(RESULT_CANCELED, mConfigState);
}
else if(resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_JSON_FILES) {
@@ -237,8 +238,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
int provider_index = getProviderIndex(id);
startProgressBar(provider_index);
mSelectedProvider = selected_provider;
-
- saveProviderJson(mSelectedProvider);
+ updateProviderDotJson(mSelectedProvider.name(), mSelectedProvider.providerJsonUrl(), mSelectedProvider.completelyTrusted());
}
@Override
@@ -265,7 +265,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
Iterator<ProviderItem> providers_iterator = ProviderListContent.ITEMS.iterator();
while(providers_iterator.hasNext()) {
ProviderItem provider = providers_iterator.next();
- if(provider.id.equalsIgnoreCase(id)) {
+ if(provider.name().equalsIgnoreCase(id)) {
return provider;
}
}
@@ -343,7 +343,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
return loaded_preseeded_providers;
}
- /**
+ /**
* Saves provider.json file associated with provider.
*
* If the provider is custom, the file has already been downloaded so we load it from memory.
@@ -353,18 +353,19 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
private void saveProviderJson(ProviderItem provider) {
JSONObject provider_json = new JSONObject();
try {
- if(!provider.custom) {
- updateProviderDotJson(provider.name, provider.provider_json_url, provider.danger_on);
+ if(!provider.custom()) {
+ updateProviderDotJson(mSelectedProvider.name(), provider.providerJsonUrl(), provider.completelyTrusted());
} else {
// FIXME!! We should we be updating our seeded providers list at ConfigurationWizard onStart() ?
// I think yes, but if so, where does this list live? leap.se, as it's the non-profit project for the software?
// If not, we should just be getting names/urls, and fetching the provider.json like in custom entries
- provider_json = provider.provider_json;
+ provider_json = ConfigHelper.getJsonFromSharedPref(Provider.KEY);
ConfigHelper.saveSharedPref(Provider.KEY, provider_json);
ConfigHelper.saveSharedPref(EIP.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIP.ALLOWED_ANON));
- ConfigHelper.saveSharedPref(ProviderItem.DANGER_ON, provider.danger_on);
+ ConfigHelper.saveSharedPref(ProviderItem.DANGER_ON, provider.completelyTrusted());
mProgressBar.incrementProgressBy(1);
+
downloadJSONFiles(mSelectedProvider);
}
} catch (JSONException e) {
@@ -373,7 +374,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
}
}
- /**
+ /**
* Asks ProviderAPI to download provider site's certificate and eip-service.json
*
* URLs are fetched from the provider parameter
@@ -382,12 +383,12 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
private void downloadJSONFiles(ProviderItem provider) {
Intent provider_API_command = new Intent(this, ProviderAPI.class);
- Bundle parameters = new Bundle();
+ Bundle parameters = new Bundle();
- parameters.putString(Provider.KEY, provider.name);
+ parameters.putString(Provider.KEY, provider.name());
parameters.putString(Provider.CA_CERT, provider.cert_json_url);
parameters.putString(EIP.KEY, provider.eip_service_json_url);
- parameters.putBoolean(ProviderItem.DANGER_ON, provider.danger_on);
+ parameters.putBoolean(ProviderItem.DANGER_ON, provider.completelyTrusted());
provider_API_command.setAction(ProviderAPI.DOWNLOAD_JSON_FILES_BUNDLE_EXTRA);
provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
diff --git a/src/se/leap/bitmaskclient/ProviderListContent.java b/src/se/leap/bitmaskclient/ProviderListContent.java
index 75d91733..42cac792 100644
--- a/src/se/leap/bitmaskclient/ProviderListContent.java
+++ b/src/se/leap/bitmaskclient/ProviderListContent.java
@@ -55,23 +55,14 @@ public class ProviderListContent {
/**
* A provider item.
- */
+ */
public static class ProviderItem {
-
-
final public static String CUSTOM = "custom";
final public static String DANGER_ON = "danger_on";
-
- public boolean custom = false;
- public String id;
- public String name;
- public String domain;
- public String provider_json_url;
- public JSONObject provider_json;
- public String provider_json_filename;
- public String eip_service_json_url;
- public String cert_json_url;
- public boolean danger_on = false;
+ private boolean custom = false;
+ private String provider_json_url;
+ private String name;
+ private boolean danger_on = false;
/**
* @param name of the provider
@@ -85,19 +76,11 @@ public class ProviderListContent {
byte[] urls_file_bytes = new byte[urls_file_input_stream.available()];
urls_file_input_stream.read(urls_file_bytes);
String urls_file_content = new String(urls_file_bytes);
- JSONObject file_contents = new JSONObject(urls_file_content);
- id = name;
- this.name = name;
+ JSONObject file_contents = new JSONObject(urls_file_content);
provider_json_url = file_contents.getString(Provider.DOT_JSON_URL);
- domain = new URL(provider_json_url).getHost();
- //provider_json_filename = file_contents.getString("assets_json_provider");
- eip_service_json_url = file_contents.getString("json_eip_service");
- cert_json_url = file_contents.getString(EIP.CERTIFICATE);
+ this.name = name;
this.custom = custom;
this.danger_on = danger_on;
- } catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -113,38 +96,20 @@ public class ProviderListContent {
* @param provider_json already downloaded
* @param custom if it's a new provider entered by the user or not
* @param danger_on if the user trusts completely the new provider
- */
- public ProviderItem(String name, String provider_json_url, JSONObject provider_json, boolean custom, boolean danger_on) {
-
- try {
- id = name;
- //this.name = name;
- this.provider_json_url = provider_json_url;
- this.provider_json = provider_json;
- this.name = provider_json.getJSONObject("name").getString("en");
- domain = new URL(provider_json_url).getHost();
- eip_service_json_url = provider_json.getString(Provider.API_URL) + "/" + provider_json.getString(Provider.API_VERSION) + "/" + EIP.SERVICE_API_PATH;
- cert_json_url = provider_json.getString("ca_cert_uri");
- this.custom = custom;
- this.danger_on = danger_on;
- if(custom)
- provider_json_filename = name + "_provider.json".replaceFirst("__", "_");
- } catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- @Override
- public String toString() {
- return name;
- }
-
- public String getName() {
- return id;
+ */
+ public ProviderItem(String name, String provider_json_url, boolean custom, boolean danger_on) {
+ this.name = name;
+ this.provider_json_url = provider_json_url;
+ this.custom = custom;
+ this.danger_on = danger_on;
}
+
+ public String name() { return name; }
+
+ public boolean custom() { return custom; }
+
+ public String providerJsonUrl() { return provider_json_url; }
+
+ public boolean completelyTrusted() { return danger_on; }
}
}