summaryrefslogtreecommitdiff
path: root/app/src/production
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2018-01-17 14:35:48 +0100
committercyBerta <cyberta@riseup.net>2018-01-17 14:35:48 +0100
commit20582f79321627257d1b66b22af791e9e22817fd (patch)
tree0402daf13f51dcf7f9eba319eb8e26dcc2a79d10 /app/src/production
parent1bb789a9ee39ea8ef652855d8fc4add01848d88f (diff)
parent58f13c43e70cad2429c9fa10efbc0b6756798800 (diff)
Merge branch 'fupduck_drawer' into mirror_0xacab_0.9.8
Diffstat (limited to 'app/src/production')
-rw-r--r--app/src/production/java/se/leap/bitmaskclient/ConfigurationWizard.java45
-rw-r--r--app/src/production/java/se/leap/bitmaskclient/NewProviderDialog.java52
-rw-r--r--app/src/production/java/se/leap/bitmaskclient/ProviderApiManager.java18
-rw-r--r--app/src/production/java/se/leap/bitmaskclient/ProviderDetailActivity.java4
-rw-r--r--app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java108
5 files changed, 66 insertions, 161 deletions
diff --git a/app/src/production/java/se/leap/bitmaskclient/ConfigurationWizard.java b/app/src/production/java/se/leap/bitmaskclient/ConfigurationWizard.java
index 3f05b0a2..b1deae67 100644
--- a/app/src/production/java/se/leap/bitmaskclient/ConfigurationWizard.java
+++ b/app/src/production/java/se/leap/bitmaskclient/ConfigurationWizard.java
@@ -40,17 +40,17 @@ public class ConfigurationWizard extends BaseConfigurationWizard {
public void showAndSelectProvider(String provider_main_url) {
try {
- selected_provider = new Provider(new URL((provider_main_url)));
- adapter.add(selected_provider);
+ selectedProvider = new Provider(new URL((provider_main_url)));
+ adapter.add(selectedProvider);
adapter.saveProviders();
- autoSelectProvider(selected_provider);
+ autoSelectProvider(selectedProvider);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
private void autoSelectProvider(Provider provider) {
- selected_provider = provider;
+ selectedProvider = provider;
onItemSelectedUi();
onItemSelectedLogic();
}
@@ -61,24 +61,23 @@ public class ConfigurationWizard extends BaseConfigurationWizard {
*/
public void setUpProvider() {
mConfigState.setAction(SETTING_UP_PROVIDER);
- Intent provider_API_command = new Intent(this, ProviderAPI.class);
+ Intent providerApiCommand = new Intent(this, ProviderAPI.class);
Bundle parameters = new Bundle();
- parameters.putString(Provider.MAIN_URL, selected_provider.getMainUrl().toString());
- if (selected_provider.hasCertificatePin()){
- parameters.putString(Provider.CA_CERT_FINGERPRINT, selected_provider.certificatePin());
+ parameters.putString(Provider.MAIN_URL, selectedProvider.getMainUrl().toString());
+ if (selectedProvider.hasCertificatePin()){
+ parameters.putString(Provider.CA_CERT_FINGERPRINT, selectedProvider.certificatePin());
}
- if (selected_provider.hasCaCert()) {
- parameters.putString(Provider.CA_CERT, selected_provider.getCaCert());
+ if (selectedProvider.hasCaCert()) {
+ parameters.putString(Provider.CA_CERT, selectedProvider.getCaCert());
}
- if (selected_provider.hasDefinition()) {
- parameters.putString(Provider.KEY, selected_provider.getDefinition().toString());
+ if (selectedProvider.hasDefinition()) {
+ parameters.putString(Provider.KEY, selectedProvider.getDefinition().toString());
}
- provider_API_command.setAction(ProviderAPI.SET_UP_PROVIDER);
- provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
- provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
+ providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
+ providerApiCommand.putExtra(ProviderAPI.PARAMETERS, parameters);
- startService(provider_API_command);
+ startService(providerApiCommand);
}
@Override
@@ -88,17 +87,17 @@ public class ConfigurationWizard extends BaseConfigurationWizard {
addAndSelectNewProvider(ProviderAPI.lastProviderMainUrl());
} else {
showProgressBar();
- adapter.hideAllBut(adapter.indexOf(selected_provider));
+ adapter.hideAllBut(adapter.indexOf(selectedProvider));
- Intent provider_API_command = new Intent(this, ProviderAPI.class);
- provider_API_command.setAction(ProviderAPI.SET_UP_PROVIDER);
- provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
+ Intent providerApiCommand = new Intent(this, ProviderAPI.class);
+ providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
+ providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, providerAPIResultReceiver);
Bundle parameters = new Bundle();
- parameters.putString(Provider.MAIN_URL, selected_provider.getMainUrl().toString());
- provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
+ parameters.putString(Provider.MAIN_URL, selectedProvider.getMainUrl().toString());
+ providerApiCommand.putExtra(ProviderAPI.PARAMETERS, parameters);
- startService(provider_API_command);
+ startService(providerApiCommand);
}
}
diff --git a/app/src/production/java/se/leap/bitmaskclient/NewProviderDialog.java b/app/src/production/java/se/leap/bitmaskclient/NewProviderDialog.java
index 1823d3e3..025d5263 100644
--- a/app/src/production/java/se/leap/bitmaskclient/NewProviderDialog.java
+++ b/app/src/production/java/se/leap/bitmaskclient/NewProviderDialog.java
@@ -16,14 +16,20 @@
*/
package se.leap.bitmaskclient;
-import butterknife.*;
-import se.leap.bitmaskclient.ProviderListContent.ProviderItem;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.v4.app.DialogFragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.Toast;
-import android.app.*;
-import android.content.*;
-import android.os.*;
-import android.view.*;
-import android.widget.*;
+import butterknife.ButterKnife;
+import butterknife.InjectView;
/**
* Implements the new custom provider dialog.
@@ -35,26 +41,27 @@ public class NewProviderDialog extends DialogFragment {
final public static String TAG = "newProviderDialog";
@InjectView(R.id.new_provider_url)
- EditText url_input_field;
+ EditText urlInputField;
public interface NewProviderDialogInterface {
- public void showAndSelectProvider(String url_provider);
+ void showAndSelectProvider(String url_provider);
}
- NewProviderDialogInterface interface_with_ConfigurationWizard;
+ NewProviderDialogInterface interfaceWithConfigurationWizard;
@Override
- public void onAttach(Activity activity) {
- super.onAttach(activity);
+ public void onAttach(Context context) {
+ super.onAttach(context);
try {
- interface_with_ConfigurationWizard = (NewProviderDialogInterface) activity;
+ interfaceWithConfigurationWizard = (NewProviderDialogInterface) context;
} catch (ClassCastException e) {
- throw new ClassCastException(activity.toString()
+ throw new ClassCastException(context.toString()
+ " must implement NoticeDialogListener");
}
}
@Override
+ @NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
@@ -62,7 +69,7 @@ public class NewProviderDialog extends DialogFragment {
ButterKnife.inject(this, view);
Bundle arguments = getArguments();
if (arguments != null) {
- url_input_field.setText(arguments.getString(Provider.MAIN_URL, ""));
+ urlInputField.setText(arguments.getString(Provider.MAIN_URL, ""));
}
builder.setView(view)
@@ -82,7 +89,7 @@ public class NewProviderDialog extends DialogFragment {
}
private void saveProvider() {
- String entered_url = url_input_field.getText().toString().trim();
+ String entered_url = urlInputField.getText().toString().trim();
if (!entered_url.startsWith("https://")) {
if (entered_url.startsWith("http://")) {
entered_url = entered_url.substring("http://".length());
@@ -91,23 +98,22 @@ public class NewProviderDialog extends DialogFragment {
}
if (validURL(entered_url)) {
- interface_with_ConfigurationWizard.showAndSelectProvider(entered_url);
+ interfaceWithConfigurationWizard.showAndSelectProvider(entered_url);
Toast.makeText(getActivity().getApplicationContext(), R.string.valid_url_entered, Toast.LENGTH_LONG).show();
} else {
- url_input_field.setText("");
+ urlInputField.setText("");
Toast.makeText(getActivity().getApplicationContext(), R.string.not_valid_url_entered, Toast.LENGTH_LONG).show();
- ;
}
}
/**
* Checks if the entered url is valid or not.
*
- * @param entered_url
+ * @param enteredUrl
* @return true if it's not empty nor contains only the protocol.
*/
- boolean validURL(String entered_url) {
- //return !entered_url.isEmpty() && entered_url.matches("http[s]?://.+") && !entered_url.replaceFirst("http[s]?://", "").isEmpty();
- return android.util.Patterns.WEB_URL.matcher(entered_url).matches();
+ boolean validURL(String enteredUrl) {
+ //return !enteredUrl.isEmpty() && enteredUrl.matches("http[s]?://.+") && !enteredUrl.replaceFirst("http[s]?://", "").isEmpty();
+ return android.util.Patterns.WEB_URL.matcher(enteredUrl).matches();
}
}
diff --git a/app/src/production/java/se/leap/bitmaskclient/ProviderApiManager.java b/app/src/production/java/se/leap/bitmaskclient/ProviderApiManager.java
index b20a7759..a30c9615 100644
--- a/app/src/production/java/se/leap/bitmaskclient/ProviderApiManager.java
+++ b/app/src/production/java/se/leap/bitmaskclient/ProviderApiManager.java
@@ -33,6 +33,10 @@ import okhttp3.OkHttpClient;
import se.leap.bitmaskclient.eip.EIP;
import static android.text.TextUtils.isEmpty;
+import static se.leap.bitmaskclient.Constants.PROVIDER_ALLOWED_REGISTERED;
+import static se.leap.bitmaskclient.Constants.PROVIDER_ALLOW_ANONYMOUS;
+import static se.leap.bitmaskclient.Constants.PROVIDER_KEY;
+import static se.leap.bitmaskclient.Constants.PROVIDER_VPN_CERTIFICATE;
import static se.leap.bitmaskclient.DownloadFailedDialog.DOWNLOAD_ERRORS.ERROR_CERTIFICATE_PINNING;
import static se.leap.bitmaskclient.ProviderAPI.ERRORS;
import static se.leap.bitmaskclient.ProviderAPI.RESULT_KEY;
@@ -119,17 +123,17 @@ public class ProviderApiManager extends ProviderApiManagerBase {
if (!PROVIDER_JSON_DOWNLOADED)
currentDownload = getAndSetProviderJson(lastProviderMainUrl, providerCaCert, providerDefinition);
if (PROVIDER_JSON_DOWNLOADED || (currentDownload.containsKey(RESULT_KEY) && currentDownload.getBoolean(RESULT_KEY))) {
- broadcastProgress(progress++);
+ broadcastProgress(++progress);
PROVIDER_JSON_DOWNLOADED = true;
if (!CA_CERT_DOWNLOADED)
currentDownload = downloadCACert();
if (CA_CERT_DOWNLOADED || (currentDownload.containsKey(RESULT_KEY) && currentDownload.getBoolean(RESULT_KEY))) {
- broadcastProgress(progress++);
+ broadcastProgress(++progress);
CA_CERT_DOWNLOADED = true;
currentDownload = getAndSetEipServiceJson();
if (currentDownload.containsKey(RESULT_KEY) && currentDownload.getBoolean(RESULT_KEY)) {
- broadcastProgress(progress++);
+ broadcastProgress(++progress);
EIP_SERVICE_JSON_DOWNLOADED = true;
}
}
@@ -163,8 +167,8 @@ public class ProviderApiManager extends ProviderApiManagerBase {
//TODO setProviderName(name);
preferences.edit().putString(Provider.KEY, providerJson.toString()).
- putBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS, providerJson.getJSONObject(Provider.SERVICE).getBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS)).
- putBoolean(Constants.PROVIDER_ALLOWED_REGISTERED, providerJson.getJSONObject(Provider.SERVICE).getBoolean(Constants.PROVIDER_ALLOWED_REGISTERED)).
+ putBoolean(PROVIDER_ALLOW_ANONYMOUS, providerJson.getJSONObject(Provider.SERVICE).getBoolean(PROVIDER_ALLOW_ANONYMOUS)).
+ putBoolean(PROVIDER_ALLOWED_REGISTERED, providerJson.getJSONObject(Provider.SERVICE).getBoolean(PROVIDER_ALLOWED_REGISTERED)).
putString(Provider.KEY + "." + providerDomain, providerJson.toString()).commit();
result.putBoolean(RESULT_KEY, true);
} catch (JSONException e) {
@@ -192,7 +196,7 @@ public class ProviderApiManager extends ProviderApiManagerBase {
JSONObject eip_service_json = new JSONObject(eip_service_json_string);
eip_service_json.getInt(Provider.API_RETURN_SERIAL);
- preferences.edit().putString(Constants.PROVIDER_KEY, eip_service_json.toString()).commit();
+ preferences.edit().putString(PROVIDER_KEY, eip_service_json.toString()).commit();
result.putBoolean(RESULT_KEY, true);
} catch (NullPointerException | JSONException e) {
@@ -215,7 +219,7 @@ public class ProviderApiManager extends ProviderApiManagerBase {
JSONObject provider_json = new JSONObject(preferences.getString(Provider.KEY, ""));
String provider_main_url = provider_json.getString(Provider.API_URL);
- URL new_cert_string_url = new URL(provider_main_url + "/" + provider_json.getString(Provider.API_VERSION) + "/" + Constants.PROVIDER_VPN_CERTIFICATE);
+ URL new_cert_string_url = new URL(provider_main_url + "/" + provider_json.getString(Provider.API_VERSION) + "/" + PROVIDER_VPN_CERTIFICATE);
String cert_string = downloadWithProviderCA(new_cert_string_url.toString());
diff --git a/app/src/production/java/se/leap/bitmaskclient/ProviderDetailActivity.java b/app/src/production/java/se/leap/bitmaskclient/ProviderDetailActivity.java
new file mode 100644
index 00000000..e1815689
--- /dev/null
+++ b/app/src/production/java/se/leap/bitmaskclient/ProviderDetailActivity.java
@@ -0,0 +1,4 @@
+package se.leap.bitmaskclient;
+
+public class ProviderDetailActivity extends AbstractProviderDetailActivity {
+}
diff --git a/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java b/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java
deleted file mode 100644
index c7224ede..00000000
--- a/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java
+++ /dev/null
@@ -1,108 +0,0 @@
-package se.leap.bitmaskclient;
-
-import org.json.*;
-
-import android.app.*;
-import android.content.*;
-import android.os.*;
-import android.view.*;
-import android.widget.*;
-
-public class ProviderDetailFragment extends DialogFragment {
-
- final public static String TAG = "providerDetailFragment";
-
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
- try {
-
- LayoutInflater inflater = getActivity().getLayoutInflater();
- View provider_detail_view = inflater.inflate(R.layout.provider_detail_fragment, null);
-
- JSONObject provider_json = new JSONObject(getActivity().getSharedPreferences(Constants.SHARED_PREFERENCES, getActivity().MODE_PRIVATE).getString(Provider.KEY, ""));
-
- final TextView domain = (TextView) provider_detail_view.findViewById(R.id.provider_detail_domain);
- domain.setText(provider_json.getString(Provider.DOMAIN));
- final TextView name = (TextView) provider_detail_view.findViewById(R.id.provider_detail_name);
- name.setText(provider_json.getJSONObject(Provider.NAME).getString("en"));
- final TextView description = (TextView) provider_detail_view.findViewById(R.id.provider_detail_description);
- description.setText(provider_json.getJSONObject(Provider.DESCRIPTION).getString("en"));
-
- builder.setView(provider_detail_view);
- builder.setTitle(R.string.provider_details_fragment_title);
-
- if (anon_allowed(provider_json)) {
- builder.setPositiveButton(R.string.use_anonymously_button, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- interface_with_configuration_wizard.use_anonymously();
- }
- });
- }
-
- if (registration_allowed(provider_json)) {
- builder.setNegativeButton(R.string.signup_or_login_button, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- interface_with_configuration_wizard.login();
- }
- });
- }
-
- return builder.create();
- } catch (JSONException e) {
- return null;
- }
- }
-
- private boolean anon_allowed(JSONObject provider_json) {
- try {
- JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE);
- return service_description.has(Constants.PROVIDER_ALLOW_ANONYMOUS) && service_description.getBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS);
- } catch (JSONException e) {
- return false;
- }
- }
-
- private boolean registration_allowed(JSONObject provider_json) {
- try {
- JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE);
- return service_description.has(Provider.ALLOW_REGISTRATION) && service_description.getBoolean(Provider.ALLOW_REGISTRATION);
- } catch (JSONException e) {
- return false;
- }
- }
-
- @Override
- public void onCancel(DialogInterface dialog) {
- super.onCancel(dialog);
- SharedPreferences.Editor editor = getActivity().getSharedPreferences(Constants.SHARED_PREFERENCES, Activity.MODE_PRIVATE).edit();
- editor.remove(Provider.KEY).remove(Constants.PROVIDER_ALLOW_ANONYMOUS).remove(Constants.PROVIDER_KEY).commit();
- interface_with_configuration_wizard.cancelAndShowAllProviders();
- }
-
- public static DialogFragment newInstance() {
- ProviderDetailFragment provider_detail_fragment = new ProviderDetailFragment();
- return provider_detail_fragment;
- }
-
- @Override
- public void onAttach(Activity activity) {
- super.onAttach(activity);
- try {
- interface_with_configuration_wizard = (ProviderDetailFragmentInterface) activity;
- } catch (ClassCastException e) {
- throw new ClassCastException(activity.toString()
- + " must implement LogInDialogListener");
- }
- }
-
- public interface ProviderDetailFragmentInterface {
- public void login();
-
- public void use_anonymously();
-
- public void cancelAndShowAllProviders();
- }
-
- ProviderDetailFragmentInterface interface_with_configuration_wizard;
-}