diff options
author | Parménides GV <parmegv@sdf.org> | 2013-10-10 21:12:32 +0200 |
---|---|---|
committer | Parménides GV <parmegv@sdf.org> | 2013-12-10 18:08:52 +0100 |
commit | 3c1a4d2da2531b510fd01f921093f8c007bb4d5a (patch) | |
tree | f617cce816dc27bb7e02baecddf2895d36bda3ec /src/se/leap | |
parent | 50ad1c04cee7fe3409a1c2958d4dba98882cd45d (diff) |
Simplified the methods to add a new provider.
Adding a new provider is the same that selecting a new one, using the same methods and following the same workflow.
Diffstat (limited to 'src/se/leap')
-rw-r--r-- | src/se/leap/bitmaskclient/ConfigurationWizard.java | 74 | ||||
-rw-r--r-- | src/se/leap/bitmaskclient/NewProviderDialog.java | 4 | ||||
-rw-r--r-- | src/se/leap/bitmaskclient/ProviderAPI.java | 64 | ||||
-rw-r--r-- | src/se/leap/bitmaskclient/ProviderListContent.java | 18 | ||||
-rw-r--r-- | src/se/leap/bitmaskclient/ProviderListFragment.java | 3 |
5 files changed, 42 insertions, 121 deletions
diff --git a/src/se/leap/bitmaskclient/ConfigurationWizard.java b/src/se/leap/bitmaskclient/ConfigurationWizard.java index 6d088a85..43ac8dd8 100644 --- a/src/se/leap/bitmaskclient/ConfigurationWizard.java +++ b/src/se/leap/bitmaskclient/ConfigurationWizard.java @@ -238,7 +238,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn int provider_index = getProviderIndex(id);
startProgressBar(provider_index);
mSelectedProvider = selected_provider;
- updateProviderDotJson(mSelectedProvider.name(), mSelectedProvider.providerJsonUrl(), mSelectedProvider.completelyTrusted());
+ updateProviderDotJson(mSelectedProvider.providerMainUrl(), mSelectedProvider.completelyTrusted());
}
@Override
@@ -344,37 +344,6 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn }
/** - * Saves provider.json file associated with provider.
- *
- * If the provider is custom, the file has already been downloaded so we load it from memory.
- * If not, the file is updated using the provider's URL.
- * @param provider
- */
- private void saveProviderJson(ProviderItem provider) {
- JSONObject provider_json = new JSONObject();
- try {
- 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 = 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.completelyTrusted());
-
- mProgressBar.incrementProgressBy(1);
-
- downloadJSONFiles(provider_json, provider.completelyTrusted());
- }
- } catch (JSONException e) {
- setResult(RESULT_CANCELED);
- finish();
- }
- }
-
- /** * Asks ProviderAPI to download provider site's certificate and eip-service.json
*
* URLs are fetched from the provider parameter
@@ -471,34 +440,37 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn newFragment.show(fragment_transaction, ProviderDetailFragment.TAG);
}
- @Override
- public void saveAndSelectProvider(String provider_main_url, boolean danger_on) {
- Intent provider_API_command = new Intent(this, ProviderAPI.class);
-
- Bundle parameters = new Bundle();
- parameters.putString(Provider.MAIN_URL, provider_main_url);
- parameters.putBoolean(ProviderItem.DANGER_ON, danger_on);
-
- provider_API_command.setAction(ProviderAPI.DOWNLOAD_NEW_PROVIDER_DOTJSON);
- provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
- provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
-
- startService(provider_API_command);
+ public void showAndSelectProvider(String provider_main_url, boolean danger_on) {
+ showProvider(provider_main_url, danger_on);
+ updateProviderDotJson(provider_main_url, danger_on);
+ }
+
+ private void showProvider(final String provider_main_url, final boolean danger_on) {
+ String provider_name = provider_main_url.replaceFirst("http[s]?://", "").replaceFirst("\\/", "_");
+ boolean custom = true;
+ final ProviderItem added_provider = new ProviderItem(provider_name, provider_main_url, custom, danger_on);
+ runOnUiThread(new Runnable() {
+
+ @Override
+ public void run() {
+ // TODO Auto-generated method stub
+ ProviderListContent.addItem(added_provider);
+ ProviderListFragment provider_list_fragment = (ProviderListFragment) getFragmentManager().findFragmentByTag("providerlist");
+ provider_list_fragment.notifyAdapter();
+ }
+ });
}
/**
* Asks ProviderAPI to download a new provider.json file
* @param provider_name
- * @param provider_json_url
+ * @param provider_main_url
* @param danger_on tells if HTTPS client should bypass certificate errors
*/
- public void updateProviderDotJson(String provider_name, String provider_json_url, boolean danger_on) {
-
-
+ public void updateProviderDotJson(String provider_main_url, boolean danger_on) {
Intent provider_API_command = new Intent(this, ProviderAPI.class);
Bundle parameters = new Bundle();
- parameters.putString(Provider.NAME, provider_name);
- parameters.putString(Provider.DOT_JSON_URL, provider_json_url);
+ parameters.putString(Provider.MAIN_URL, provider_main_url);
parameters.putBoolean(ProviderItem.DANGER_ON, danger_on);
provider_API_command.setAction(ProviderAPI.UPDATE_PROVIDER_DOTJSON);
diff --git a/src/se/leap/bitmaskclient/NewProviderDialog.java b/src/se/leap/bitmaskclient/NewProviderDialog.java index a0b8a763..98686bd2 100644 --- a/src/se/leap/bitmaskclient/NewProviderDialog.java +++ b/src/se/leap/bitmaskclient/NewProviderDialog.java @@ -41,7 +41,7 @@ public class NewProviderDialog extends DialogFragment { final public static String TAG = "newProviderDialog"; public interface NewProviderDialogInterface { - public void saveAndSelectProvider(String url_provider, boolean danger_on); + public void showAndSelectProvider(String url_provider, boolean danger_on); } NewProviderDialogInterface interface_with_ConfigurationWizard; @@ -85,7 +85,7 @@ public class NewProviderDialog extends DialogFragment { } boolean danger_on = danger_checkbox.isChecked(); if(validURL(entered_url)) { - interface_with_ConfigurationWizard.saveAndSelectProvider(entered_url, danger_on); + interface_with_ConfigurationWizard.showAndSelectProvider(entered_url, danger_on); Toast.makeText(getActivity().getApplicationContext(), R.string.valid_url_entered, Toast.LENGTH_LONG).show(); } else { url_input_field.setText(""); diff --git a/src/se/leap/bitmaskclient/ProviderAPI.java b/src/se/leap/bitmaskclient/ProviderAPI.java index 871a20dd..268275e2 100644 --- a/src/se/leap/bitmaskclient/ProviderAPI.java +++ b/src/se/leap/bitmaskclient/ProviderAPI.java @@ -156,13 +156,6 @@ public class ProviderAPI extends IntentService { } else { receiver.send(INCORRECTLY_UPDATED_PROVIDER_DOT_JSON, Bundle.EMPTY); } - } else if (action.equalsIgnoreCase(DOWNLOAD_NEW_PROVIDER_DOTJSON)) { - Bundle result = downloadNewProviderDotJSON(parameters); - if(result.getBoolean(RESULT_KEY)) { - receiver.send(CORRECTLY_UPDATED_PROVIDER_DOT_JSON, result); - } else { - receiver.send(INCORRECTLY_DOWNLOADED_JSON_FILES, result); - } } else if (action.equalsIgnoreCase(SRP_AUTH)) { Bundle session_id_bundle = authenticateBySRP(parameters); if(session_id_bundle.getBoolean(RESULT_KEY)) { @@ -494,10 +487,8 @@ public class ProviderAPI extends IntentService { */ private Bundle updateProviderDotJSON(Bundle task) { Bundle result = new Bundle(); - boolean custom = task.getBoolean(ProviderItem.CUSTOM); boolean danger_on = task.getBoolean(ProviderItem.DANGER_ON); - String provider_json_url = task.getString(Provider.DOT_JSON_URL); - String provider_name = task.getString(Provider.NAME); + String provider_json_url = task.getString(Provider.MAIN_URL) + "/provider.json"; try { String provider_dot_json_string = downloadWithCommercialCA(provider_json_url, danger_on); @@ -512,56 +503,9 @@ public class ProviderAPI extends IntentService { } else { ConfigHelper.saveSharedPref(EIP.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIP.ALLOWED_ANON)); - //ProviderListContent.addItem(new ProviderItem(provider_name, provider_json_url, provider_json, custom, danger_on)); - result.putBoolean(RESULT_KEY, true); - result.putString(Provider.KEY, provider_json.toString()); - result.putBoolean(ProviderItem.DANGER_ON, danger_on); - } - } - } catch (JSONException e) { - result.putBoolean(RESULT_KEY, false); - } - - return result; - } - - /** - * Downloads a custom provider provider.json file - * @param task containing a boolean meaning if the user completely trusts this provider, and the provider main url entered in the new custom provider dialog. - * @return true if provider.json file was successfully parsed as a JSON object. - */ - private Bundle downloadNewProviderDotJSON(Bundle task) { - Bundle result = new Bundle(); - boolean custom = true; - boolean danger_on = task.getBoolean(ProviderItem.DANGER_ON); - - String provider_main_url = (String) task.get(Provider.MAIN_URL); - String provider_name = provider_main_url.replaceFirst("http[s]?://", "").replaceFirst("\\/", "_"); - String provider_json_url = guessProviderDotJsonURL(provider_main_url); - - String provider_json_string = downloadWithCommercialCA(provider_json_url, danger_on); - try { - if(provider_json_string.isEmpty()) { - result.putBoolean(RESULT_KEY, false); - } else { - JSONObject provider_json = new JSONObject(provider_json_string); - - if(provider_json.has(ERRORS)) { - String reason_to_fail = provider_json.getString(ERRORS); - result.putString(ERRORS, reason_to_fail); - result.putBoolean(RESULT_KEY, false); - } else { - ConfigHelper.saveSharedPref(Provider.KEY, provider_json); - ConfigHelper.saveSharedPref(ProviderItem.DANGER_ON, danger_on); - ConfigHelper.saveSharedPref(EIP.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIP.ALLOWED_ANON)); - ProviderItem added_provider = new ProviderItem(provider_name, provider_json_url, provider_json, custom, danger_on); - ProviderListContent.addItem(added_provider); - - result.putString(Provider.NAME, added_provider.getName()); - result.putBoolean(RESULT_KEY, true); - result.putString(Provider.KEY, provider_json.toString()); - result.putBoolean(ProviderItem.DANGER_ON, danger_on); - } + result.putBoolean(RESULT_KEY, true); + result.putString(Provider.KEY, provider_json.toString()); + result.putBoolean(ProviderItem.DANGER_ON, danger_on); } } catch (JSONException e) { result.putBoolean(RESULT_KEY, false); diff --git a/src/se/leap/bitmaskclient/ProviderListContent.java b/src/se/leap/bitmaskclient/ProviderListContent.java index a6da5620..3695066c 100644 --- a/src/se/leap/bitmaskclient/ProviderListContent.java +++ b/src/se/leap/bitmaskclient/ProviderListContent.java @@ -28,6 +28,8 @@ import java.net.MalformedURLException; import org.json.JSONException;
import org.json.JSONObject;
+import android.app.Activity;
+
/**
* Models the provider list shown in the ConfigurationWizard.
*
@@ -60,7 +62,7 @@ public class ProviderListContent { final public static String CUSTOM = "custom";
final public static String DANGER_ON = "danger_on";
private boolean custom = false;
- private String provider_json_url;
+ private String provider_main_url;
private String name;
private boolean danger_on = false; @@ -77,7 +79,7 @@ public class ProviderListContent { 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); - provider_json_url = file_contents.getString(Provider.DOT_JSON_URL);
+ provider_main_url = file_contents.getString(Provider.MAIN_URL);
this.name = name; this.custom = custom;
this.danger_on = danger_on;
@@ -92,14 +94,14 @@ public class ProviderListContent { /**
* @param name of the provider
- * @param provider_json_url used to download provider.json file of the provider
+ * @param provider_main_url used to download provider.json file of the provider
* @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, boolean custom, boolean danger_on) {
+ public ProviderItem(String name, String provider_main_url, boolean custom, boolean danger_on) {
this.name = name;
- this.provider_json_url = provider_json_url;
+ this.provider_main_url = provider_main_url;
this.custom = custom;
this.danger_on = danger_on; }
@@ -108,13 +110,13 @@ public class ProviderListContent { public boolean custom() { return custom; }
- public String providerJsonUrl() { return provider_json_url; }
+ public String providerMainUrl() { return provider_main_url; }
public String domain() {
try {
- return new URL(provider_json_url).getHost();
+ return new URL(provider_main_url).getHost();
} catch (MalformedURLException e) {
- return provider_json_url.replaceFirst("http[s]?://", "").replaceFirst("/.*", "");
+ return provider_main_url.replaceFirst("http[s]?://", "").replaceFirst("/.*", "");
}
}
diff --git a/src/se/leap/bitmaskclient/ProviderListFragment.java b/src/se/leap/bitmaskclient/ProviderListFragment.java index ca66d295..62dcef7a 100644 --- a/src/se/leap/bitmaskclient/ProviderListFragment.java +++ b/src/se/leap/bitmaskclient/ProviderListFragment.java @@ -172,6 +172,9 @@ public class ProviderListFragment extends ListFragment { }
}
+ public void notifyAdapter() {
+ content_adapter.notifyDataSetChanged();
+ }
/**
* Turns on activate-on-click mode. When this mode is on, list items will be
* given the 'activated' state when touched.
|