diff options
Diffstat (limited to 'app/src')
13 files changed, 94 insertions, 193 deletions
diff --git a/app/src/insecure/java/se/leap/bitmaskclient/ProviderListActivity.java b/app/src/insecure/java/se/leap/bitmaskclient/ProviderListActivity.java index 034c9752..823b5635 100644 --- a/app/src/insecure/java/se/leap/bitmaskclient/ProviderListActivity.java +++ b/app/src/insecure/java/se/leap/bitmaskclient/ProviderListActivity.java @@ -117,7 +117,6 @@ public class ProviderListActivity extends ProviderListBaseActivity { addAndSelectNewProvider(ProviderAPI.lastProviderMainUrl(), ProviderAPI.lastDangerOn()); } else { showProgressBar(); - adapter.hideAllBut(adapter.indexOf(provider)); Intent providerAPICommand = new Intent(this, ProviderAPI.class); 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 527ce1a7..dde71642 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 @@ public class DownloadFailedDialog extends DialogFragment { 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/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java index ae329cd1..5ff1949c 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Provider.java +++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java @@ -309,4 +309,12 @@ public final class Provider implements Parcelable { this.caCert = cert; } + public boolean isDefault() { + return getMainUrl().isDefault() && + getApiUrl().isDefault() && + certificatePin.isEmpty() && + certificatePinEncoding.isEmpty() && + caCert.isEmpty(); + } + } diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java b/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java index cfc6e49d..8117fb99 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java @@ -163,12 +163,16 @@ public abstract class ProviderApiManagerBase { if (action.equals(UPDATE_PROVIDER_DETAILS)) { resetProviderDetails(); Bundle task = new Bundle(); - task.putString(MAIN_URL, lastProviderMainUrl); + String mainUrl = parameters.getString(Provider.MAIN_URL); + if (mainUrl == null) { + mainUrl = lastProviderMainUrl; + } + task.putString(MAIN_URL, mainUrl); Bundle result = setUpProvider(task); if (result.getBoolean(RESULT_KEY)) { - receiver.send(PROVIDER_OK, result); + sendToReceiverOrBroadcast(receiver, PROVIDER_OK, result); } else { - receiver.send(PROVIDER_NOK, result); + sendToReceiverOrBroadcast(receiver, PROVIDER_NOK, result); } } else if (action.equalsIgnoreCase(SET_UP_PROVIDER)) { Bundle result = setUpProvider(parameters); @@ -222,7 +226,7 @@ public abstract class ProviderApiManagerBase { } else if (action.equalsIgnoreCase(PROVIDER_SET_UP)) { if(EIP_SERVICE_JSON_DOWNLOADED && CA_CERT_DOWNLOADED && PROVIDER_JSON_DOWNLOADED ) { if(receiver!= null) { - receiver.send(PROVIDER_OK, Bundle.EMPTY); + sendToReceiverOrBroadcast(receiver, PROVIDER_OK, Bundle.EMPTY); } } } 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 2b0c72db..aee00765 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; @@ -168,7 +167,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(); @@ -210,7 +208,6 @@ public abstract class ProviderListBaseActivity extends ConfigWizardBaseActivity private void setUpProviderAPIResultReceiver() { providerAPIResultReceiver = new ProviderAPIResultReceiver(new Handler(), this); providerAPIBroadcastReceiver = new ProviderAPIBroadcastReceiver(); - IntentFilter updateIntentFilter = new IntentFilter(PROVIDER_API_EVENT); updateIntentFilter.addCategory(Intent.CATEGORY_DEFAULT); registerReceiver(providerAPIBroadcastReceiver, updateIntentFilter); @@ -274,10 +271,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 @@ -302,7 +304,6 @@ public abstract class ProviderListBaseActivity 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(); } @@ -410,24 +411,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 { @@ -452,31 +438,35 @@ public abstract class ProviderListBaseActivity extends ConfigWizardBaseActivity String providerDomain = ConfigHelper.getProviderDomain(handledProvider); //FIXME: remove that lines as soon as Provider gets sent via broadcast + // and make sure providers are the same - remove providersMatch if (resultCode == PROVIDER_OK && handledProvider == null) { providerName = ConfigHelper.getProviderName(preferences); providerDomain = ConfigHelper.getProviderDomain(preferences); } + boolean providersMatch = true; + if (providerDomain != null) { + providersMatch = providerDomain.equalsIgnoreCase(provider.getDomain()); + } + if (providerName != null && !providersMatch) { + providersMatch = providerName.equalsIgnoreCase(provider.getName()); + } + - if (providerName != null && providerName.equalsIgnoreCase(provider.getName()) && - providerDomain != null && - providerDomain.equalsIgnoreCase(provider.getDomain())) { - switch (resultCode) { - case PROVIDER_OK: + switch (resultCode) { + case PROVIDER_OK: + if (providersMatch) handleProviderSetUp(); - break; - case PROVIDER_NOK: + break; + case PROVIDER_NOK: + if(providersMatch) handleProviderSetupFailed(resultData); - break; - } - } else { - switch (resultCode) { - case CORRECTLY_DOWNLOADED_CERTIFICATE: - handleCorrectlyDownloadedCertificate(); - break; - case INCORRECTLY_DOWNLOADED_CERTIFICATE: - handleIncorrectlyDownloadedCertificate(); - break; - } + break; + case CORRECTLY_DOWNLOADED_CERTIFICATE: + handleCorrectlyDownloadedCertificate(); + break; + case INCORRECTLY_DOWNLOADED_CERTIFICATE: + handleIncorrectlyDownloadedCertificate(); + break; } } } 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 8c008024..8403b046 100644 --- a/app/src/production/java/se/leap/bitmaskclient/ProviderListActivity.java +++ b/app/src/production/java/se/leap/bitmaskclient/ProviderListActivity.java @@ -87,8 +87,6 @@ public class ProviderListActivity extends ProviderListBaseActivity { addAndSelectNewProvider(ProviderAPI.lastProviderMainUrl()); } else { showProgressBar(); - adapter.hideAllBut(adapter.indexOf(provider)); - Intent providerApiCommand = new Intent(this, ProviderAPI.class); providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER); |