summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/insecure/java/se/leap/bitmaskclient/ProviderListActivity.java1
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/DefaultedURL.java5
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java12
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipFragment.java8
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Provider.java8
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java112
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderListBaseActivity.java29
-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/ProviderListActivity.java1
13 files changed, 71 insertions, 170 deletions
diff --git a/app/src/insecure/java/se/leap/bitmaskclient/ProviderListActivity.java b/app/src/insecure/java/se/leap/bitmaskclient/ProviderListActivity.java
index 2fdb5b02..554085b1 100644
--- a/app/src/insecure/java/se/leap/bitmaskclient/ProviderListActivity.java
+++ b/app/src/insecure/java/se/leap/bitmaskclient/ProviderListActivity.java
@@ -105,7 +105,6 @@ public class ProviderListActivity extends ProviderListBaseActivity {
addAndSelectNewProvider(provider.getMainUrlString(), ProviderAPI.lastDangerOn());
} else {
showProgressBar();
- adapter.hideAllBut(adapter.indexOf(provider));
ProviderAPICommand.execute(this, SET_UP_PROVIDER, provider);
}
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/DownloadFailedDialog.java b/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java
index 9d413a8d..1a0c85ad 100644
--- a/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java
+++ b/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java
@@ -16,12 +16,12 @@
*/
package se.leap.bitmaskclient;
-import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
-import android.support.v4.app.DialogFragment;
+import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
+import android.support.v4.app.DialogFragment;
import org.json.JSONObject;
@@ -134,12 +134,12 @@ switch (downloadError) {
DownloadFailedDialogInterface interface_with_ConfigurationWizard;
@Override
- public void onAttach(Activity activity) {
- super.onAttach(activity);
+ public void onAttach(Context context) {
+ super.onAttach(context);
try {
- interface_with_ConfigurationWizard = (DownloadFailedDialogInterface) activity;
+ interface_with_ConfigurationWizard = (DownloadFailedDialogInterface) context;
} catch (ClassCastException e) {
- throw new ClassCastException(activity.toString()
+ throw new ClassCastException(context.toString()
+ " must implement NoticeDialogListener");
}
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
index 9726ebf2..a86afd78 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
@@ -154,7 +154,6 @@ public class EipFragment extends Fragment implements Observer {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
eipStatus = EipStatus.getInstance();
- eipStatus.addObserver(this);
eipReceiver = new EIPReceiver(new Handler());
eipBroadcastReceiver = new EIPBroadcastReceiver();
providerAPIResultReceiver = new ProviderAPIResultReceiver(new Handler(), new EipFragmentReceiver());
@@ -163,6 +162,7 @@ public class EipFragment extends Fragment implements Observer {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ eipStatus.addObserver(this);
View view = inflater.inflate(R.layout.eip_service_fragment, container, false);
ButterKnife.inject(this, view);
@@ -192,6 +192,12 @@ public class EipFragment extends Fragment implements Observer {
}
@Override
+ public void onDestroyView() {
+ super.onDestroyView();
+ eipStatus.deleteObserver(this);
+ }
+
+ @Override
public void onSaveInstanceState(Bundle outState) {
outState.putBoolean(IS_CONNECTED, eipStatus.isConnected());
super.onSaveInstanceState(outState);
diff --git a/app/src/main/java/se/leap/bitmaskclient/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java
index 711d0573..9595b147 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Provider.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java
@@ -366,4 +366,12 @@ public final class Provider implements Parcelable {
public String getEipServiceJsonString() {
return getEipServiceJson().toString();
}
+ 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/ProviderListBaseActivity.java b/app/src/main/java/se/leap/bitmaskclient/ProviderListBaseActivity.java
index ceb7a3c4..c89e7a49 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderListBaseActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderListBaseActivity.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;
@@ -170,7 +169,6 @@ public abstract class ProviderListBaseActivity 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();
@@ -267,10 +265,15 @@ public abstract class ProviderListBaseActivity 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
@@ -295,7 +298,6 @@ public abstract class ProviderListBaseActivity extends ConfigWizardBaseActivity
public void cancelSettingUpProvider() {
hideProgressBar();
mConfigState.setAction(PROVIDER_NOT_SET);
- adapter.showAllProviders();
}
@Override
@@ -397,24 +399,9 @@ public abstract class ProviderListBaseActivity 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/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 b5955a95..46b0ceda 100644
--- a/app/src/main/res/values-es/strings.xml
+++ b/app/src/main/res/values-es/strings.xml
@@ -18,7 +18,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 c1443138..515e1f37 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>
@@ -103,4 +103,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/ProviderListActivity.java b/app/src/production/java/se/leap/bitmaskclient/ProviderListActivity.java
index 921b42e1..67c04f13 100644
--- a/app/src/production/java/se/leap/bitmaskclient/ProviderListActivity.java
+++ b/app/src/production/java/se/leap/bitmaskclient/ProviderListActivity.java
@@ -73,7 +73,6 @@ public class ProviderListActivity extends ProviderListBaseActivity {
addAndSelectNewProvider(provider.getMainUrlString());
} else {
showProgressBar();
- adapter.hideAllBut(adapter.indexOf(provider));
ProviderAPICommand.execute(this, SET_UP_PROVIDER, provider);
}