summaryrefslogtreecommitdiff
path: root/app/src/release/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/release/java')
-rw-r--r--app/src/release/java/se/leap/bitmaskclient/ConfigurationWizard.java70
-rw-r--r--app/src/release/java/se/leap/bitmaskclient/ProviderListContent.java25
2 files changed, 42 insertions, 53 deletions
diff --git a/app/src/release/java/se/leap/bitmaskclient/ConfigurationWizard.java b/app/src/release/java/se/leap/bitmaskclient/ConfigurationWizard.java
index 15a135d2..a6b009e3 100644
--- a/app/src/release/java/se/leap/bitmaskclient/ConfigurationWizard.java
+++ b/app/src/release/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;
@@ -350,34 +352,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.
*/
diff --git a/app/src/release/java/se/leap/bitmaskclient/ProviderListContent.java b/app/src/release/java/se/leap/bitmaskclient/ProviderListContent.java
index 230c297f..a5402fd8 100644
--- a/app/src/release/java/se/leap/bitmaskclient/ProviderListContent.java
+++ b/app/src/release/java/se/leap/bitmaskclient/ProviderListContent.java
@@ -63,32 +63,7 @@ public class ProviderListContent {
/**
* @param name of the provider
- * @param urls_file_input_stream file input stream linking with the assets url file
- * @param custom if it's a new provider entered by the user or not
- */
- public ProviderItem(String name, InputStream urls_file_input_stream) {
-
- try {
- 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);
- provider_main_url = file_contents.getString(Provider.MAIN_URL);
- this.name = name;
- } catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- /**
- * @param name 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
*/
public ProviderItem(String name, String provider_main_url) {
this.name = name;