summaryrefslogtreecommitdiff
path: root/app/src/insecure/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/insecure/java')
-rw-r--r--app/src/insecure/java/se/leap/bitmaskclient/ConfigurationWizard.java4
-rw-r--r--app/src/insecure/java/se/leap/bitmaskclient/NewProviderDialog.java35
-rw-r--r--app/src/insecure/java/se/leap/bitmaskclient/ProviderApiManager.java12
-rw-r--r--app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailActivity.java17
-rw-r--r--app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java110
5 files changed, 49 insertions, 129 deletions
diff --git a/app/src/insecure/java/se/leap/bitmaskclient/ConfigurationWizard.java b/app/src/insecure/java/se/leap/bitmaskclient/ConfigurationWizard.java
index 766b6c60..b14a239a 100644
--- a/app/src/insecure/java/se/leap/bitmaskclient/ConfigurationWizard.java
+++ b/app/src/insecure/java/se/leap/bitmaskclient/ConfigurationWizard.java
@@ -16,10 +16,10 @@
*/
package se.leap.bitmaskclient;
-import android.app.DialogFragment;
-import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
+import android.support.v4.app.DialogFragment;
+import android.support.v4.app.FragmentTransaction;
import java.net.MalformedURLException;
import java.net.URL;
diff --git a/app/src/insecure/java/se/leap/bitmaskclient/NewProviderDialog.java b/app/src/insecure/java/se/leap/bitmaskclient/NewProviderDialog.java
index c1426708..d7d9eec5 100644
--- a/app/src/insecure/java/se/leap/bitmaskclient/NewProviderDialog.java
+++ b/app/src/insecure/java/se/leap/bitmaskclient/NewProviderDialog.java
@@ -16,14 +16,22 @@
*/
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.CheckBox;
+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;
+import se.leap.bitmaskclient.ProviderListContent.ProviderItem;
/**
* Implements the new custom provider dialog.
@@ -36,27 +44,29 @@ public class NewProviderDialog extends DialogFragment {
@InjectView(R.id.new_provider_url)
EditText url_input_field;
+
@InjectView(R.id.danger_checkbox)
CheckBox danger_checkbox;
public interface NewProviderDialogInterface {
- public void showAndSelectProvider(String url_provider, boolean danger_on);
+ void showAndSelectProvider(String url_provider, boolean danger_on);
}
NewProviderDialogInterface interface_with_ConfigurationWizard;
@Override
- public void onAttach(Activity activity) {
- super.onAttach(activity);
+ public void onAttach(Context context) {
+ super.onAttach(context);
try {
- interface_with_ConfigurationWizard = (NewProviderDialogInterface) activity;
+ interface_with_ConfigurationWizard = (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();
@@ -100,7 +110,6 @@ public class NewProviderDialog extends DialogFragment {
url_input_field.setText("");
danger_checkbox.setChecked(false);
Toast.makeText(getActivity().getApplicationContext(), R.string.not_valid_url_entered, Toast.LENGTH_LONG).show();
- ;
}
}
diff --git a/app/src/insecure/java/se/leap/bitmaskclient/ProviderApiManager.java b/app/src/insecure/java/se/leap/bitmaskclient/ProviderApiManager.java
index 6105c4b7..8ca971e0 100644
--- a/app/src/insecure/java/se/leap/bitmaskclient/ProviderApiManager.java
+++ b/app/src/insecure/java/se/leap/bitmaskclient/ProviderApiManager.java
@@ -48,6 +48,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;
@@ -173,8 +177,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) {
@@ -202,7 +206,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) {
@@ -225,7 +229,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(), lastDangerOn);
diff --git a/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailActivity.java b/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailActivity.java
new file mode 100644
index 00000000..6977753f
--- /dev/null
+++ b/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailActivity.java
@@ -0,0 +1,17 @@
+package se.leap.bitmaskclient;
+
+import android.content.SharedPreferences;
+
+import static se.leap.bitmaskclient.Constants.PROVIDER_ALLOW_ANONYMOUS;
+import static se.leap.bitmaskclient.Constants.PROVIDER_KEY;
+
+public class ProviderDetailActivity extends AbstractProviderDetailActivity {
+
+ @Override
+ public void onBackPressed() {
+ SharedPreferences.Editor editor = preferences.edit();
+ editor.remove(Provider.KEY).remove(ProviderListContent.ProviderItem.DANGER_ON).remove(PROVIDER_ALLOW_ANONYMOUS).remove(PROVIDER_KEY).apply();
+ super.onBackPressed();
+ }
+
+}
diff --git a/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java b/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java
deleted file mode 100644
index 390d4aeb..00000000
--- a/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java
+++ /dev/null
@@ -1,110 +0,0 @@
-package se.leap.bitmaskclient;
-
-import org.json.*;
-
-import se.leap.bitmaskclient.ProviderListContent.ProviderItem;
-
-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(ProviderItem.DANGER_ON).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;
-}