summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorFup Duck <fupduck@sacknagel.com>2018-01-23 15:55:00 +0100
committerFup Duck <fupduck@sacknagel.com>2018-01-23 15:55:00 +0100
commit26db3cd2398e0ae80fcc53e7933f2de747c074b4 (patch)
tree4b99b9a2f558a18e1e516dfaf6bbc784e674adc7 /app/src
parent042e10b53b95d48ffbcce45213ebec5f0794fb01 (diff)
add custom provider option
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java31
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/DefaultedURL.java5
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Provider.java10
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java112
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderManager.java50
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java8
-rw-r--r--app/src/main/res/menu/configuration_wizard_activity.xml2
-rw-r--r--app/src/main/res/values-es/strings.xml2
-rw-r--r--app/src/main/res/values/strings.xml3
-rw-r--r--app/src/production/java/se/leap/bitmaskclient/ConfigurationWizard.java2
10 files changed, 60 insertions, 165 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java
index 0726a785..cb52eb48 100644
--- a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java
@@ -27,7 +27,6 @@ import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.Menu;
-import android.view.MenuItem;
import android.widget.ListView;
import com.pedrogomez.renderers.Renderer;
@@ -116,8 +115,6 @@ public abstract class BaseConfigurationWizard extends ConfigWizardBaseActivity
@Override
protected void onSaveInstanceState(@NotNull Bundle outState) {
- //if (progressbarDescription != null)
- // outState.putString(PROGRESSBAR_TEXT, progressbarDescription.getText().toString());
outState.putString(ACTIVITY_STATE, mConfigState.getAction());
outState.putParcelable(Provider.KEY, provider);
@@ -170,7 +167,6 @@ public abstract class BaseConfigurationWizard extends ConfigWizardBaseActivity
isActivityShowing = true;
if (SETTING_UP_PROVIDER.equals(mConfigState.getAction())) {
showProgressBar();
- adapter.hideAllBut(adapter.indexOf(provider));
checkProviderSetUp();
} else if (PENDING_SHOW_FAILED_DIALOG.equals(mConfigState.getAction())) {
showDownloadFailedDialog();
@@ -276,10 +272,15 @@ public abstract class BaseConfigurationWizard extends ConfigWizardBaseActivity
}
//TODO Code 2 pane view
- mConfigState.setAction(SETTING_UP_PROVIDER);
provider = adapter.getItem(position);
- showProgressBar();
- onItemSelectedLogic();
+ if (provider != null && !provider.isDefault()) {
+ //TODO Code 2 pane view
+ mConfigState.setAction(SETTING_UP_PROVIDER);
+ showProgressBar();
+ onItemSelectedLogic();
+ } else {
+ addAndSelectNewProvider();
+ }
}
@Override
@@ -304,7 +305,6 @@ public abstract class BaseConfigurationWizard extends ConfigWizardBaseActivity
public void cancelSettingUpProvider() {
hideProgressBar();
mConfigState.setAction(PROVIDER_NOT_SET);
- adapter.showAllProviders();
preferences.edit().remove(Provider.KEY).remove(PROVIDER_ALLOW_ANONYMOUS).remove(PROVIDER_KEY).apply();
}
@@ -412,24 +412,9 @@ public abstract class BaseConfigurationWizard extends ConfigWizardBaseActivity
return true;
}
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.about_leap:
- startActivityForResult(new Intent(this, AboutFragment.class), 0);
- return true;
- case R.id.new_provider:
- addAndSelectNewProvider();
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
- }
-
public void cancelAndShowAllProviders() {
mConfigState.setAction(PROVIDER_NOT_SET);
provider = null;
- adapter.showAllProviders();
}
public class ProviderAPIBroadcastReceiver extends BroadcastReceiver {
diff --git a/app/src/main/java/se/leap/bitmaskclient/DefaultedURL.java b/app/src/main/java/se/leap/bitmaskclient/DefaultedURL.java
index 52c797a4..57ff1fd8 100644
--- a/app/src/main/java/se/leap/bitmaskclient/DefaultedURL.java
+++ b/app/src/main/java/se/leap/bitmaskclient/DefaultedURL.java
@@ -1,6 +1,7 @@
package se.leap.bitmaskclient;
-import java.net.*;
+import java.net.MalformedURLException;
+import java.net.URL;
public class DefaultedURL {
private URL DEFAULT_URL;
@@ -8,7 +9,7 @@ public class DefaultedURL {
private URL url;
- public DefaultedURL() {
+ DefaultedURL() {
try {
DEFAULT_URL = new URL(default_url);
url = DEFAULT_URL;
diff --git a/app/src/main/java/se/leap/bitmaskclient/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java
index 30504080..4d8c741d 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Provider.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java
@@ -306,4 +306,14 @@ public final class Provider implements Parcelable {
putString(Provider.MAIN_URL, getMainUrl().toString()).
putString(Provider.KEY, getDefinition().toString()).apply();
}
+
+ public boolean isDefault() {
+ return getMainUrl().isDefault() &&
+ getApiUrl().isDefault() &&
+ certificatePin.isEmpty() &&
+ certificatePinEncoding.isEmpty() &&
+ caCert.isEmpty();
+
+ }
+
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java b/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java
index 4a34caa0..6672c575 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java
@@ -1,119 +1,15 @@
package se.leap.bitmaskclient;
-import android.view.*;
+import android.view.LayoutInflater;
-import com.pedrogomez.renderers.*;
-
-import java.util.*;
+import com.pedrogomez.renderers.AdapteeCollection;
+import com.pedrogomez.renderers.RendererAdapter;
+import com.pedrogomez.renderers.RendererBuilder;
public class ProviderListAdapter extends RendererAdapter<Provider> {
- private static boolean[] hidden = null;
-
- public void hide(int position) {
- hidden[getRealPosition(position)] = true;
- notifyDataSetChanged();
- notifyDataSetInvalidated();
- }
-
- public void unHide(int position) {
- hidden[getRealPosition(position)] = false;
- notifyDataSetChanged();
- notifyDataSetInvalidated();
- }
-
- public void showAllProviders() {
- for (int i = 0; i < hidden.length; i++)
- hidden[i] = false;
- notifyDataSetChanged();
- notifyDataSetInvalidated();
- }
-
- public void hideAllBut(int position) {
- for (int i = 0; i < hidden.length; i++) {
- if (i != position)
- hidden[i] = true;
- else
- hidden[i] = false;
- }
- notifyDataSetChanged();
- notifyDataSetInvalidated();
- }
-
- private int getRealPosition(int position) {
- int hElements = getHiddenCountUpTo(position);
- int diff = 0;
- for (int i = 0; i < hElements; i++) {
- diff++;
- if (hidden[position + diff])
- i--;
- }
- return (position + diff);
- }
-
- private int getHiddenCount() {
- int count = 0;
- for (int i = 0; i < hidden.length; i++)
- if (hidden[i])
- count++;
- return count;
- }
-
- private int getHiddenCountUpTo(int location) {
- int count = 0;
- for (int i = 0; i <= location; i++) {
- if (hidden[i])
- count++;
- }
- return count;
- }
-
- @Override
- public int getCount() {
- return (hidden.length - getHiddenCount());
- }
-
public ProviderListAdapter(LayoutInflater layoutInflater, RendererBuilder rendererBuilder,
AdapteeCollection<Provider> collection) {
super(layoutInflater, rendererBuilder, collection);
- hidden = new boolean[collection.size()];
- for (int i = 0; i < collection.size(); i++)
- hidden[i] = false;
- }
-
- @Override
- public void add(Provider item) {
- super.add(item);
- if (getCollection().size() > hidden.length) {
- boolean[] new_hidden = new boolean[hidden.length + 1];
- System.arraycopy(hidden, 0, new_hidden, 0, hidden.length);
- new_hidden[hidden.length] = false;
- hidden = new_hidden;
- }
- }
-
- @Override
- public void remove(Provider item) {
- super.remove(item);
- boolean[] new_hidden = new boolean[hidden.length - 1];
- System.arraycopy(hidden, 0, new_hidden, 0, hidden.length - 1);
- hidden = new_hidden;
- }
-
- protected int indexOf(Provider item) {
- int index = 0;
- ProviderManager provider_manager = (ProviderManager) getCollection();
- Set<Provider> providers = provider_manager.providers();
- for (Provider provider : providers) {
- if (provider.equals(item)) {
- break;
- } else index++;
- }
- return index;
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- return super.getView(getRealPosition(position), convertView, parent);
}
public void saveProviders() {
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java b/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java
index 62c04c1a..ed41be67 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java
@@ -15,9 +15,11 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Set;
/**
@@ -25,15 +27,14 @@ import java.util.Set;
*/
public class ProviderManager implements AdapteeCollection<Provider> {
- private static final String TAG = ProviderManager.class.getName();
- private AssetManager assets_manager;
+ private AssetManager assetsManager;
private File externalFilesDir;
private Set<Provider> defaultProviders;
private Set<Provider> customProviders;
private static ProviderManager instance;
- final protected static String URLS = "urls";
+ final private static String URLS = "urls";
public static ProviderManager getInstance(AssetManager assetsManager, File externalFilesDir) {
if (instance == null)
@@ -42,8 +43,8 @@ public class ProviderManager implements AdapteeCollection<Provider> {
return instance;
}
- public ProviderManager(AssetManager assetManager, File externalFilesDir) {
- this.assets_manager = assetManager;
+ private ProviderManager(AssetManager assetManager, File externalFilesDir) {
+ this.assetsManager = assetManager;
addDefaultProviders(assetManager);
addCustomProviders(externalFilesDir);
}
@@ -57,7 +58,7 @@ public class ProviderManager implements AdapteeCollection<Provider> {
}
private Set<Provider> providersFromAssets(String directory, String[] relativeFilePaths) {
- Set<Provider> providers = new HashSet<Provider>();
+ Set<Provider> providers = new HashSet<>();
for (String file : relativeFilePaths) {
String mainUrl = null;
@@ -65,10 +66,10 @@ public class ProviderManager implements AdapteeCollection<Provider> {
String providerDefinition = null;
try {
String provider = file.substring(0, file.length() - ".url".length());
- InputStream provider_file = assets_manager.open(directory + "/" + file);
+ InputStream provider_file = assetsManager.open(directory + "/" + file);
mainUrl = extractMainUrlFromInputStream(provider_file);
- certificate = ConfigHelper.loadInputStreamAsString(assets_manager.open(provider + ".pem"));
- providerDefinition = ConfigHelper.loadInputStreamAsString(assets_manager.open(provider + ".json"));
+ certificate = ConfigHelper.loadInputStreamAsString(assetsManager.open(provider + ".pem"));
+ providerDefinition = ConfigHelper.loadInputStreamAsString(assetsManager.open(provider + ".json"));
} catch (IOException e) {
e.printStackTrace();
}
@@ -91,11 +92,11 @@ public class ProviderManager implements AdapteeCollection<Provider> {
}
private Set<Provider> providersFromFiles(String[] files) {
- Set<Provider> providers = new HashSet<Provider>();
+ Set<Provider> providers = new HashSet<>();
try {
for (String file : files) {
- String main_url = extractMainUrlFromInputStream(new FileInputStream(externalFilesDir.getAbsolutePath() + "/" + file));
- providers.add(new Provider(new URL(main_url)));
+ String mainUrl = extractMainUrlFromInputStream(new FileInputStream(externalFilesDir.getAbsolutePath() + "/" + file));
+ providers.add(new Provider(new URL(mainUrl)));
}
} catch (MalformedURLException | FileNotFoundException e) {
e.printStackTrace();
@@ -104,12 +105,12 @@ public class ProviderManager implements AdapteeCollection<Provider> {
return providers;
}
- private String extractMainUrlFromInputStream(InputStream input_stream) {
+ private String extractMainUrlFromInputStream(InputStream inputStream) {
String mainUrl = "";
- JSONObject file_contents = inputStreamToJson(input_stream);
- if (file_contents != null)
- mainUrl = file_contents.optString(Provider.MAIN_URL);
+ JSONObject fileContents = inputStreamToJson(inputStream);
+ if (fileContents != null)
+ mainUrl = fileContents.optString(Provider.MAIN_URL);
return mainUrl;
}
@@ -126,12 +127,13 @@ public class ProviderManager implements AdapteeCollection<Provider> {
return json;
}
- public Set<Provider> providers() {
- Set<Provider> all_providers = new HashSet<Provider>();
- all_providers.addAll(defaultProviders);
+ public List<Provider> providers() {
+ List<Provider> allProviders = new ArrayList<>();
+ allProviders.addAll(defaultProviders);
if(customProviders != null)
- all_providers.addAll(customProviders);
- return all_providers;
+ allProviders.addAll(customProviders);
+ allProviders.add(new Provider());
+ return allProviders;
}
@Override
@@ -151,9 +153,7 @@ public class ProviderManager implements AdapteeCollection<Provider> {
@Override
public boolean add(Provider element) {
- if (!defaultProviders.contains(element))
- return customProviders.add(element);
- else return true;
+ return !defaultProviders.contains(element) || customProviders.add(element);
}
@Override
@@ -179,7 +179,7 @@ public class ProviderManager implements AdapteeCollection<Provider> {
customProviders.clear();
}
- protected void saveCustomProvidersToFile() {
+ void saveCustomProvidersToFile() {
try {
for (Provider provider : customProviders) {
File providerFile = new File(externalFilesDir, provider.getName() + ".json");
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java b/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java
index 4a5d0db1..5b3e5728 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java
@@ -45,7 +45,11 @@ public class ProviderRenderer extends Renderer<Provider> {
@Override
public void render() {
Provider provider = getContent();
- name.setText(provider.getName());
- domain.setText(provider.getDomain());
+ if (!provider.isDefault()) {
+ name.setText(provider.getName());
+ domain.setText(provider.getDomain());
+ } else {
+ domain.setText(R.string.add_provider);
+ }
}
}
diff --git a/app/src/main/res/menu/configuration_wizard_activity.xml b/app/src/main/res/menu/configuration_wizard_activity.xml
index 9936b6dc..21591547 100644
--- a/app/src/main/res/menu/configuration_wizard_activity.xml
+++ b/app/src/main/res/menu/configuration_wizard_activity.xml
@@ -8,7 +8,7 @@
<item
android:id="@+id/new_provider"
android:orderInCategory="210"
- android:title="@string/new_provider_button"
+ android:title="@string/add_provider"
android:showAsAction="ifRoom|withText"
android:icon="@drawable/ic_menu_add"
/>
diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml
index 6355ce62..cd55531c 100644
--- a/app/src/main/res/values-es/strings.xml
+++ b/app/src/main/res/values-es/strings.xml
@@ -19,7 +19,7 @@
<string name="status_unknown">Estado no definido.</string>
<string name="eip_service_label">Acceso a Internet Encriptado con VPN</string>
<string name="configuration_wizard_title">Elige un proveedor</string>
- <string name="new_provider_button">Nuevo proveedor</string>
+ <string name="add_provider">Nuevo proveedor</string>
<string name="introduce_new_provider">AƱadir un nuevo proveedor</string>
<string name="save">Guardar</string>
<string name="new_provider_uri">Dominio</string>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 01715c32..c681f861 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -17,7 +17,7 @@
<string name="status_unknown">Status unknown.</string>
<string name="eip_service_label">Encrypted VPN Internet Access</string>
<string name="configuration_wizard_title">Select a service provider</string>
- <string name="new_provider_button">Add new Provider</string>
+ <string name="add_provider">Add new Provider</string>
<string name="introduce_new_provider">Add a new service provider</string>
<string name="save">Save</string>
<string name="new_provider_uri">Domain name</string>
@@ -102,4 +102,5 @@
<string name="warning_corrupted_provider_details">Stored provider details are corrupted. You can either update Bitmask (recommended) or update the provider details using a commercial CA certificate.</string>
<string name="warning_corrupted_provider_cert">Stored provider certificate is invalid. You can either update Bitmask (recommended) or update the provider certificate using a commercial CA certificate.</string>
<string name="warning_expired_provider_cert">Stored provider certificate is expired. You can either update Bitmask (recommended) or update the provider certificate using a commercial CA certificate.</string>
+
</resources>
diff --git a/app/src/production/java/se/leap/bitmaskclient/ConfigurationWizard.java b/app/src/production/java/se/leap/bitmaskclient/ConfigurationWizard.java
index f7102508..4e16647a 100644
--- a/app/src/production/java/se/leap/bitmaskclient/ConfigurationWizard.java
+++ b/app/src/production/java/se/leap/bitmaskclient/ConfigurationWizard.java
@@ -86,8 +86,6 @@ public class ConfigurationWizard extends BaseConfigurationWizard {
addAndSelectNewProvider(ProviderAPI.lastProviderMainUrl());
} else {
showProgressBar();
- adapter.hideAllBut(adapter.indexOf(provider));
-
Intent providerApiCommand = new Intent(this, ProviderAPI.class);
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);