summaryrefslogtreecommitdiff
path: root/app/src/main/java/se
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/se')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java21
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipFragment.java54
2 files changed, 36 insertions, 39 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index 4e6120ab..94be7cd1 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -296,11 +296,14 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
providerApiCommand(Bundle.EMPTY, R.string.logout_message, ProviderAPI.LOG_OUT);
}
- private void downloadAuthedUserCertificate() {
- Bundle parameters = new Bundle();
- parameters.putString(ConfigurationWizard.TYPE_OF_CERTIFICATE, ConfigurationWizard.AUTHED_CERTIFICATE);
-
- providerApiCommand(parameters, R.string.downloading_certificate_message, ProviderAPI.DOWNLOAD_CERTIFICATE);
+ protected void downloadVpnCertificate() {
+ boolean is_authenticated = !LeapSRPSession.getToken().isEmpty();
+ boolean allowed_anon = preferences.getBoolean(Constants.ALLOWED_ANON, false);
+ if(allowed_anon || is_authenticated)
+ providerApiCommand(Bundle.EMPTY, R.string.downloading_certificate_message, ProviderAPI.DOWNLOAD_CERTIFICATE);
+ else
+ sessionDialog(Bundle.EMPTY);
+
}
private Bundle bundleParameters(String username, String password) {
@@ -312,8 +315,8 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
return parameters;
}
- private void providerApiCommand(Bundle parameters, int progressbar_message_resId, String providerApi_action) {
- if(eip_fragment != null) {
+ protected void providerApiCommand(Bundle parameters, int progressbar_message_resId, String providerApi_action) {
+ if(eip_fragment != null && progressbar_message_resId != 0) {
eip_fragment.progress_bar.setVisibility(ProgressBar.VISIBLE);
setStatusMessage(progressbar_message_resId);
}
@@ -322,7 +325,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
startService(command);
}
- protected Intent prepareProviderAPICommand(Bundle parameters, String action) {
+ private Intent prepareProviderAPICommand(Bundle parameters, String action) {
providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler());
providerAPI_result_receiver.setReceiver(this);
@@ -371,7 +374,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
preferences.edit().putBoolean(Constants.AUTHED_EIP, authed_eip).apply();
updateViewHidingProgressBar(resultCode);
- downloadAuthedUserCertificate();
+ downloadVpnCertificate();
} else if(resultCode == ProviderAPI.FAILED_LOGIN) {
updateViewHidingProgressBar(resultCode);
sessionDialog(resultData);
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
index 54432033..bbcaa577 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
@@ -45,7 +45,7 @@ public class EipFragment extends Fragment implements Observer {
@InjectView(R.id.eipProgress)
ProgressBar progress_bar;
- private static Activity parent_activity;
+ private static Dashboard dashboard;
private static EIPReceiver mEIPReceiver;
private static EipStatus eip_status;
private boolean is_starting_to_connect;
@@ -53,11 +53,9 @@ public class EipFragment extends Fragment implements Observer {
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
- parent_activity = activity;
- Dashboard dashboard = (Dashboard) parent_activity;
- Intent provider_API_command = dashboard.prepareProviderAPICommand(Bundle.EMPTY, ProviderAPI.DOWNLOAD_EIP_SERVICE);
- parent_activity.startService(provider_API_command);
+ dashboard = (Dashboard) activity;
+ dashboard.providerApiCommand(Bundle.EMPTY, 0, ProviderAPI.DOWNLOAD_EIP_SERVICE);
}
@Override
@@ -130,7 +128,6 @@ public class EipFragment extends Fragment implements Observer {
startEipFromScratch();
else if(canLogInToStartEIP()) {
Log.d(TAG, "Can Log In to start EIP");
- Dashboard dashboard = (Dashboard) parent_activity;
Bundle bundle = new Bundle();
bundle.putBoolean(IS_PENDING, true);
dashboard.sessionDialog(bundle);
@@ -160,16 +157,16 @@ public class EipFragment extends Fragment implements Observer {
}
private void askPendingStartCancellation() {
- AlertDialog.Builder alertBuilder = new AlertDialog.Builder(parent_activity);
- alertBuilder.setTitle(parent_activity.getString(R.string.eip_cancel_connect_title))
- .setMessage(parent_activity.getString(R.string.eip_cancel_connect_text))
+ AlertDialog.Builder alertBuilder = new AlertDialog.Builder(dashboard);
+ alertBuilder.setTitle(dashboard.getString(R.string.eip_cancel_connect_title))
+ .setMessage(dashboard.getString(R.string.eip_cancel_connect_text))
.setPositiveButton((R.string.yes), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
askToStopEIP();
}
})
- .setNegativeButton(parent_activity.getString(R.string.no), new DialogInterface.OnClickListener() {
+ .setNegativeButton(dashboard.getString(R.string.no), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
eip_switch.setChecked(true);
@@ -182,7 +179,7 @@ public class EipFragment extends Fragment implements Observer {
is_starting_to_connect = true;
progress_bar.setVisibility(View.VISIBLE);
eip_switch.setVisibility(View.VISIBLE);
- String status = parent_activity.getString(R.string.eip_status_start_pending);
+ String status = dashboard.getString(R.string.eip_status_start_pending);
status_message.setText(status);
if(!eip_switch.isChecked()) {
@@ -195,15 +192,15 @@ public class EipFragment extends Fragment implements Observer {
private void stopEIP() {
if(eip_status.isConnecting())
VoidVpnService.stop();
- Intent disconnect_vpn = new Intent(parent_activity, DisconnectVPN.class);
- parent_activity.startActivityForResult(disconnect_vpn, EIP.DISCONNECT);
+ Intent disconnect_vpn = new Intent(dashboard, DisconnectVPN.class);
+ dashboard.startActivityForResult(disconnect_vpn, EIP.DISCONNECT);
eip_status.setDisconnecting();
}
protected void askToStopEIP() {
hideProgressBar();
- String status = parent_activity.getString(R.string.eip_state_not_connected);
+ String status = dashboard.getString(R.string.eip_state_not_connected);
status_message.setText(status);
eipCommand(Constants.ACTION_STOP_EIP);
@@ -217,10 +214,10 @@ public class EipFragment extends Fragment implements Observer {
*/
private void eipCommand(String action){
// TODO validate "action"...how do we get the list of intent-filters for a class via Android API?
- Intent vpn_intent = new Intent(parent_activity.getApplicationContext(), EIP.class);
+ Intent vpn_intent = new Intent(dashboard.getApplicationContext(), EIP.class);
vpn_intent.setAction(action);
vpn_intent.putExtra(Constants.RECEIVER_TAG, mEIPReceiver);
- parent_activity.startService(vpn_intent);
+ dashboard.startService(vpn_intent);
}
@Override
@@ -228,7 +225,7 @@ public class EipFragment extends Fragment implements Observer {
if(observable instanceof EipStatus) {
eip_status = (EipStatus) observable;
final EipStatus eip_status = (EipStatus) observable;
- parent_activity.runOnUiThread(new Runnable() {
+ dashboard.runOnUiThread(new Runnable() {
@Override
public void run() {
handleNewState(eip_status);
@@ -254,13 +251,13 @@ public class EipFragment extends Fragment implements Observer {
Log.d(TAG, "setConnectedUi? " + eip_status.isConnected());
adjustSwitch();
is_starting_to_connect = false;
- status_message.setText(parent_activity.getString(R.string.eip_state_connected));
+ status_message.setText(dashboard.getString(R.string.eip_state_connected));
}
private void setDisconnectedUI(){
hideProgressBar();
adjustSwitch();
- status_message.setText(parent_activity.getString(R.string.eip_state_not_connected));
+ status_message.setText(dashboard.getString(R.string.eip_state_not_connected));
}
private void adjustSwitch() {
@@ -281,13 +278,18 @@ public class EipFragment extends Fragment implements Observer {
private void setInProgressUI(EipStatus eip_status) {
int localizedResId = eip_status.getLocalizedResId();
String logmessage = eip_status.getLogMessage();
- String prefix = parent_activity.getString(localizedResId);
+ String prefix = dashboard.getString(localizedResId);
status_message.setText(prefix + " " + logmessage);
is_starting_to_connect = false;
adjustSwitch();
}
+ private void updatingCertificateUI() {
+ progress_bar.setVisibility(View.VISIBLE);
+ status_message.setText(getString(R.string.updating_certificate_message));
+ }
+
private void hideProgressBar() {
if(progress_bar != null)
progress_bar.setVisibility(View.GONE);
@@ -333,16 +335,8 @@ public class EipFragment extends Fragment implements Observer {
case Activity.RESULT_OK:
break;
case Activity.RESULT_CANCELED:
- Dashboard dashboard = (Dashboard) parent_activity;
-
- progress_bar.setVisibility(View.VISIBLE);
- status_message.setText(getString(R.string.updating_certificate_message));
- if(LeapSRPSession.getToken().isEmpty() && !Dashboard.preferences.getBoolean(Constants.ALLOWED_ANON, false)) {
- dashboard.sessionDialog(Bundle.EMPTY);
- } else {
- Intent provider_API_command = dashboard.prepareProviderAPICommand(Bundle.EMPTY, ProviderAPI.DOWNLOAD_CERTIFICATE);
- parent_activity.startService(provider_API_command);
- }
+ updatingCertificateUI();
+ dashboard.downloadVpnCertificate();
break;
}
}