summaryrefslogtreecommitdiff
path: root/src/se/leap/bitmaskclient
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-04-03 20:11:01 +0200
committerParménides GV <parmegv@sdf.org>2014-04-03 20:11:01 +0200
commitb799ea39c1ef8750ac21390e93fdc935a1ebc693 (patch)
tree3c54a975dd7853695b018d6aa3ea5f2e86dad754 /src/se/leap/bitmaskclient
parentcf286c03a4a263f9cebff7a1a81d4b4f5239d05b (diff)
parentf6447292f733df5085c7de138c1e9f05f4428a07 (diff)
Merge branch 'bug/disable-anonymous-connection-when-Service-doesn't-provide-it-#5317' into develop
Diffstat (limited to 'src/se/leap/bitmaskclient')
-rw-r--r--src/se/leap/bitmaskclient/Dashboard.java18
-rw-r--r--src/se/leap/bitmaskclient/EipServiceFragment.java44
-rw-r--r--src/se/leap/bitmaskclient/LogInDialog.java20
3 files changed, 73 insertions, 9 deletions
diff --git a/src/se/leap/bitmaskclient/Dashboard.java b/src/se/leap/bitmaskclient/Dashboard.java
index aa3cd4d9..b388b84a 100644
--- a/src/se/leap/bitmaskclient/Dashboard.java
+++ b/src/se/leap/bitmaskclient/Dashboard.java
@@ -55,7 +55,6 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
protected static final int CONFIGURE_LEAP = 0;
protected static final int SWITCH_PROVIDER = 1;
- private static final String TAG_EIP_FRAGMENT = "EIP_DASHBOARD_FRAGMENT";
final public static String SHARED_PREFERENCES = "LEAPPreferences";
final public static String ACTION_QUIT = "quit";
public static final String REQUEST_CODE = "request_code";
@@ -168,7 +167,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
FragmentManager fragMan = getFragmentManager();
if ( provider.hasEIP()){
EipServiceFragment eipFragment = new EipServiceFragment();
- fragMan.beginTransaction().replace(R.id.servicesCollection, eipFragment, TAG_EIP_FRAGMENT).commit();
+ fragMan.beginTransaction().replace(R.id.servicesCollection, eipFragment, EipServiceFragment.TAG).commit();
}
}
@@ -264,6 +263,11 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
//mProgressBar.setMax(4);
startService(provider_API_command);
}
+
+ public void cancelAuthedEipOn() {
+ EipServiceFragment eipFragment = (EipServiceFragment) getFragmentManager().findFragmentByTag(EipServiceFragment.TAG);
+ eipFragment.checkEipSwitch(false);
+ }
/**
* Asks ProviderAPI to log out.
@@ -375,6 +379,8 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
setResult(RESULT_OK);
changeStatusMessage(resultCode);
mProgressBar.setVisibility(ProgressBar.GONE);
+ if(EipServiceFragment.isEipSwitchChecked())
+ eipStart();
} else if(resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) {
setResult(RESULT_CANCELED);
changeStatusMessage(resultCode);
@@ -462,4 +468,12 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
startService(eip_intent);
}
+
+ private void eipStart(){
+ Intent eip_intent = new Intent(this, EIP.class);
+ eip_intent.setAction(EIP.ACTION_START_EIP);
+ eip_intent.putExtra(EIP.RECEIVER_TAG, EipServiceFragment.getReceiver());
+ startService(eip_intent);
+
+ }
}
diff --git a/src/se/leap/bitmaskclient/EipServiceFragment.java b/src/se/leap/bitmaskclient/EipServiceFragment.java
index 0534838d..b4cb541a 100644
--- a/src/se/leap/bitmaskclient/EipServiceFragment.java
+++ b/src/se/leap/bitmaskclient/EipServiceFragment.java
@@ -26,10 +26,10 @@ import android.widget.TextView;
public class EipServiceFragment extends Fragment implements StateListener, OnCheckedChangeListener {
- private static final String IS_EIP_PENDING = "is_eip_pending";
+ protected static final String IS_EIP_PENDING = "is_eip_pending";
private View eipFragment;
- private Switch eipSwitch;
+ private static Switch eipSwitch;
private View eipDetail;
private TextView eipStatus;
@@ -37,7 +37,9 @@ public class EipServiceFragment extends Fragment implements StateListener, OnChe
private boolean mEipStartPending = false;
- private EIPReceiver mEIPReceiver;
+ private boolean set_switch_off = false;
+
+ private static EIPReceiver mEIPReceiver;
public static String TAG = "se.leap.bitmask.EipServiceFragment";
@@ -90,8 +92,16 @@ public class EipServiceFragment extends Fragment implements StateListener, OnChe
super.onResume();
OpenVPN.addStateListener(this);
+ if(set_switch_off) {
+ eipSwitch.setChecked(false);
+ set_switch_off = false;
+ }
}
+ protected void setSwitchOff(boolean value) {
+ set_switch_off = value;
+ }
+
@Override
public void onPause() {
super.onPause();
@@ -108,6 +118,9 @@ public class EipServiceFragment extends Fragment implements StateListener, OnChe
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (buttonView.equals(eipSwitch) && !eipAutoSwitched){
+ boolean allowed_anon = getActivity().getSharedPreferences(Dashboard.SHARED_PREFERENCES, Activity.MODE_PRIVATE).getBoolean(EIP.ALLOWED_ANON, false);
+ String certificate = getActivity().getSharedPreferences(Dashboard.SHARED_PREFERENCES, Activity.MODE_PRIVATE).getString(EIP.CERTIFICATE, "");
+ if(allowed_anon || !certificate.isEmpty()) {
if (isChecked){
mEipStartPending = true;
eipFragment.findViewById(R.id.eipProgress).setVisibility(View.VISIBLE);
@@ -139,6 +152,17 @@ public class EipServiceFragment extends Fragment implements StateListener, OnChe
eipCommand(EIP.ACTION_STOP_EIP);
}
}
+ }
+ else {
+ Dashboard dashboard = (Dashboard)getActivity();
+ Bundle waiting_on_login = new Bundle();
+ waiting_on_login.putBoolean(IS_EIP_PENDING, true);
+ dashboard.logInDialog(getActivity().getCurrentFocus(), waiting_on_login);
+ }
+ }
+ else {
+ if(!eipSwitch.isChecked())
+ eipStatus.setText(R.string.state_noprocess);
}
eipAutoSwitched = true;
}
@@ -265,4 +289,18 @@ public class EipServiceFragment extends Fragment implements StateListener, OnChe
eipAutoSwitched = false;
}
}
+
+
+ public static EIPReceiver getReceiver() {
+ return mEIPReceiver;
+ }
+
+ public static boolean isEipSwitchChecked() {
+ return eipSwitch.isChecked();
+ }
+
+ public void checkEipSwitch(boolean checked) {
+ eipSwitch.setChecked(checked);
+ onCheckedChanged(eipSwitch, checked);
+ }
}
diff --git a/src/se/leap/bitmaskclient/LogInDialog.java b/src/se/leap/bitmaskclient/LogInDialog.java
index 81a3f764..a28c9049 100644
--- a/src/se/leap/bitmaskclient/LogInDialog.java
+++ b/src/se/leap/bitmaskclient/LogInDialog.java
@@ -51,7 +51,8 @@ public class LogInDialog extends DialogFragment {
final public static String PASSWORD = "password";
final public static String USERNAME_MISSING = "username missing";
final public static String PASSWORD_INVALID_LENGTH = "password_invalid_length";
-
+
+ private static boolean is_eip_pending = false;
public AlertDialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
@@ -79,8 +80,11 @@ public class LogInDialog extends DialogFragment {
password_field.requestFocus();
}
if (getArguments() != null && getArguments().containsKey(PASSWORD_INVALID_LENGTH)) {
- password_field.setError(getResources().getString(R.string.error_not_valid_password_user_message));
- }
+ password_field.setError(getResources().getString(R.string.error_not_valid_password_user_message));
+ }
+ if(getArguments() != null && getArguments().getBoolean(EipServiceFragment.IS_EIP_PENDING, false)) {
+ is_eip_pending = true;
+ }
builder.setView(log_in_dialog_view)
@@ -113,7 +117,8 @@ public class LogInDialog extends DialogFragment {
* @param username
* @param password
*/
- public void authenticate(String username, String password);
+ public void authenticate(String username, String password);
+ public void cancelAuthedEipOn();
}
LogInDialogInterface interface_with_Dashboard;
@@ -136,4 +141,11 @@ public class LogInDialog extends DialogFragment {
+ " must implement LogInDialogListener");
}
}
+
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ if(is_eip_pending)
+ interface_with_Dashboard.cancelAuthedEipOn();
+ super.onCancel(dialog);
+ }
}