summaryrefslogtreecommitdiff
path: root/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-04-09 18:43:29 +0200
committerParménides GV <parmegv@sdf.org>2014-04-09 18:43:29 +0200
commit4a8c2f34c3bbac63e0900f86bff53d11b7831151 (patch)
tree099e78c24a3c80374217c51970e0f7167ea026ee /app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java
parentc8fd9bdf99911ef6d717a6860f7b5cc754a6fcf2 (diff)
Bitmask loads all preseeded providers correctly.
If you choose one and then tap "Switch provider" button, no duplicated providers are shown.
Diffstat (limited to 'app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java')
-rw-r--r--app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java70
1 files changed, 42 insertions, 28 deletions
diff --git a/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java b/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java
index f0aac40b..fb63b47a 100644
--- a/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java
+++ b/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java
@@ -49,6 +49,7 @@ import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.io.IOException;
+import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
@@ -84,6 +85,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
final protected static String PROVIDER_SET = "PROVIDER SET";
final protected static String SERVICES_RETRIEVED = "SERVICES RETRIEVED";
+ final protected static String ASSETS_URL_FOLDER = "urls";
public ProviderAPIResultReceiver providerAPI_result_receiver;
private ProviderAPIBroadcastReceiver_Update providerAPI_broadcast_receiver_update;
@@ -353,34 +355,46 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
return listItem.getMeasuredHeight();
}
- /**
- * Loads providers data from url file contained in the project
- * @return true if the file was read correctly
- */
- private boolean loadPreseededProviders() {
- boolean loaded_preseeded_providers = false;
- AssetManager asset_manager = getAssets();
- String[] urls_filepaths = null;
- try {
- String url_files_folder = "urls";
- //TODO Put that folder in a better place (also inside the "for")
- urls_filepaths = asset_manager.list(url_files_folder);
- String provider_name = "";
- for(String url_filepath : urls_filepaths)
- {
- boolean custom = false;
- provider_name = url_filepath.subSequence(0, url_filepath.indexOf(".")).toString();
- if(ProviderListContent.ITEMS.isEmpty()) //TODO I have to implement a way of checking if a provider new or is already present in that ITEMS list
- ProviderListContent.addItem(new ProviderItem(provider_name, asset_manager.open(url_files_folder + "/" + url_filepath)));
- loaded_preseeded_providers = true;
- }
- } catch (IOException e) {
- loaded_preseeded_providers = false;
- }
-
- return loaded_preseeded_providers;
- }
-
+ /**
+ * Loads providers data from url files contained in the assets folder
+ * @return true if the files were correctly read
+ */
+ private boolean loadPreseededProviders() {
+ boolean loaded_preseeded_providers = false;
+ String[] urls_filepaths = null;
+ try {
+ //TODO Put that folder in a better place (also inside the "for")
+ urls_filepaths = getAssets().list(ASSETS_URL_FOLDER);
+ String provider_name = "";
+ for(String url_filepath : urls_filepaths) {
+ provider_name = url_filepath.subSequence(0, url_filepath.lastIndexOf(".")).toString();
+ String provider_main_url = extractProviderMainUrlFromAssetsFile(ASSETS_URL_FOLDER + "/" + url_filepath);
+ if(getId(provider_main_url).isEmpty())
+ ProviderListContent.addItem(new ProviderItem(provider_name, provider_main_url));
+ loaded_preseeded_providers = true;
+ }
+ } catch (IOException e) {
+ loaded_preseeded_providers = false;
+ }
+
+ return loaded_preseeded_providers;
+ }
+
+ private String extractProviderMainUrlFromAssetsFile(String filepath) {
+ String provider_main_url = "";
+ try {
+ InputStream input_stream_file_contents = getAssets().open(filepath);
+ byte[] urls_file_bytes = new byte[input_stream_file_contents.available()];
+ input_stream_file_contents.read(urls_file_bytes);
+ String urls_file_content = new String(urls_file_bytes);
+ JSONObject file_contents = new JSONObject(urls_file_content);
+ provider_main_url = file_contents.getString(Provider.MAIN_URL);
+ } catch (JSONException e) {
+ } catch (IOException e) {
+ }
+ return provider_main_url;
+ }
+
/**
* Asks ProviderAPI to download an anonymous (anon) VPN certificate.
*/