summaryrefslogtreecommitdiff
path: root/src/se/leap/bitmaskclient/Dashboard.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/se/leap/bitmaskclient/Dashboard.java')
-rw-r--r--src/se/leap/bitmaskclient/Dashboard.java97
1 files changed, 46 insertions, 51 deletions
diff --git a/src/se/leap/bitmaskclient/Dashboard.java b/src/se/leap/bitmaskclient/Dashboard.java
index 44cf8247..07039a78 100644
--- a/src/se/leap/bitmaskclient/Dashboard.java
+++ b/src/se/leap/bitmaskclient/Dashboard.java
@@ -21,7 +21,6 @@ import org.json.JSONObject;
import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.ProviderAPIResultReceiver.Receiver;
-import se.leap.openvpn.MainActivity;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DialogFragment;
@@ -55,15 +54,11 @@ 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";
-
-
-
private ProgressBar mProgressBar;
private TextView eipStatus;
@@ -90,11 +85,10 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
mProgressBar = (ProgressBar) findViewById(R.id.eipProgress);
- ConfigHelper.setSharedPreferences(getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE));
- preferences = ConfigHelper.shared_preferences;
+ preferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
- authed_eip = ConfigHelper.getBoolFromSharedPref(EIP.AUTHED_EIP);
- if (ConfigHelper.getStringFromSharedPref(Provider.KEY).isEmpty())
+ authed_eip = preferences.getBoolean(EIP.AUTHED_EIP, false);
+ if (preferences.getString(Provider.KEY, "").isEmpty())
startActivityForResult(new Intent(this,ConfigurationWizard.class),CONFIGURE_LEAP);
else
buildDashboard();
@@ -110,9 +104,8 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
if ( requestCode == CONFIGURE_LEAP || requestCode == SWITCH_PROVIDER) {
// It should be equivalent: if ( (requestCode == CONFIGURE_LEAP) || (data!= null && data.hasExtra(STOP_FIRST))) {
if ( resultCode == RESULT_OK ){
- ConfigHelper.saveSharedPref(EIP.PARSED_SERIAL, 0);
- ConfigHelper.saveSharedPref(EIP.AUTHED_EIP, authed_eip);
-
+ getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).edit().putInt(EIP.PARSED_SERIAL, 0).commit();
+ getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).edit().putBoolean(EIP.AUTHED_EIP, authed_eip).commit();
startService( new Intent(EIP.ACTION_UPDATE_EIP_SERVICE) );
buildDashboard();
@@ -181,8 +174,9 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
public boolean onPrepareOptionsMenu(Menu menu) {
JSONObject provider_json;
try {
- provider_json = ConfigHelper.getJsonFromSharedPref(Provider.KEY);
+ provider_json = new JSONObject(getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE).getString(Provider.KEY, ""));
JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE);
+
if(service_description.getBoolean(Provider.ALLOW_REGISTRATION)) {
if(authed_eip) {
menu.findItem(R.id.login_button).setVisible(false);
@@ -213,18 +207,14 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
intent = new Intent(this, AboutActivity.class);
startActivity(intent);
return true;
- case R.id.legacy_interface:
- intent = new Intent(this,MainActivity.class);
- startActivity(intent);
- return true;
case R.id.switch_provider:
if (Provider.getInstance().hasEIP()){
- if (ConfigHelper.getBoolFromSharedPref(EIP.AUTHED_EIP)){
+ if (getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).getBoolean(EIP.AUTHED_EIP, false)){
logOut();
}
eipStop();
}
- ConfigHelper.removeFromSharedPref(Provider.KEY);
+ getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).edit().remove(Provider.KEY).commit();
startActivityForResult(new Intent(this,ConfigurationWizard.class), SWITCH_PROVIDER);
return true;
case R.id.login_button:
@@ -268,7 +258,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
mProgressBar.setVisibility(ProgressBar.VISIBLE);
- eipStatus.setText("Starting to login");
+ eipStatus.setText(R.string.authenticating_message);
//mProgressBar.setMax(4);
startService(provider_API_command);
}
@@ -299,7 +289,9 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
if(mProgressBar == null) mProgressBar = (ProgressBar) findViewById(R.id.eipProgress);
mProgressBar.setVisibility(ProgressBar.VISIBLE);
if(eipStatus == null) eipStatus = (TextView) findViewById(R.id.eipStatus);
- eipStatus.setText("Starting to logout");
+ eipStatus.setText(R.string.logout_message);
+ // eipStatus.setText("Starting to logout");
+
startService(provider_API_command);
//mProgressBar.setMax(1);
@@ -354,73 +346,76 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
setResult(RESULT_OK);
authed_eip = true;
- ConfigHelper.saveSharedPref(EIP.AUTHED_EIP, authed_eip);
- invalidateOptionsMenu();
+ getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).edit().putBoolean(EIP.AUTHED_EIP, authed_eip).commit();
+ invalidateOptionsMenu();
mProgressBar.setVisibility(ProgressBar.GONE);
+ changeStatusMessage(resultCode);
//Cookie session_id = new BasicClientCookie(session_id_cookie_key, session_id_string);
downloadAuthedUserCertificate(/*session_id*/);
} else if(resultCode == ProviderAPI.SRP_AUTHENTICATION_FAILED) {
logInDialog(getCurrentFocus(), resultData);
- eipStatus.setText("Login failed");
- mProgressBar.setVisibility(ProgressBar.GONE);
} else if(resultCode == ProviderAPI.LOGOUT_SUCCESSFUL) {
authed_eip = false;
- ConfigHelper.saveSharedPref(EIP.AUTHED_EIP, authed_eip);
-
- changeStatusMessage(resultCode);
+ getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).edit().putBoolean(EIP.AUTHED_EIP, authed_eip).commit();
mProgressBar.setVisibility(ProgressBar.GONE);
mProgressBar.setProgress(0);
invalidateOptionsMenu();
setResult(RESULT_OK);
+ changeStatusMessage(resultCode);
+
} else if(resultCode == ProviderAPI.LOGOUT_FAILED) {
setResult(RESULT_CANCELED);
- eipStatus.setText("Didn't log out");
+ changeStatusMessage(resultCode);
mProgressBar.setVisibility(ProgressBar.GONE);
- //mProgressBar.setProgress(0);
- Toast.makeText(getApplicationContext(), R.string.log_out_failed_message, Toast.LENGTH_LONG).show();
} else if(resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE) {
setResult(RESULT_OK);
+ changeStatusMessage(resultCode);
mProgressBar.setVisibility(ProgressBar.GONE);
- changeStatusMessage(resultCode);
- //mProgressBar.setProgress(0);
- Toast.makeText(getApplicationContext(), R.string.successful_authed_cert_downloaded_message, Toast.LENGTH_LONG).show();
} else if(resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) {
setResult(RESULT_CANCELED);
+ changeStatusMessage(resultCode);
mProgressBar.setVisibility(ProgressBar.GONE);
- //mProgressBar.setProgress(0);
- changeStatusMessage(resultCode);
- Toast.makeText(getApplicationContext(), R.string.authed_cert_download_failed_message, Toast.LENGTH_LONG).show();
- }
+ }
}
private void changeStatusMessage(final int previous_result_code) {
// TODO Auto-generated method stub
ResultReceiver eip_status_receiver = new ResultReceiver(new Handler()){
- @Override
- protected void onReceiveResult(int resultCode, Bundle resultData) {
+ protected void onReceiveResult(int resultCode, Bundle resultData){
super.onReceiveResult(resultCode, resultData);
String request = resultData.getString(EIP.REQUEST_TAG);
- if(resultCode == RESULT_OK) {
- if(request.equalsIgnoreCase(EIP.ACTION_IS_EIP_RUNNING)) {
- switch (previous_result_code) {
- case ProviderAPI.LOGOUT_SUCCESSFUL: eipStatus.setText(R.string.anonymous_secured_status); break;
+ if (request.equalsIgnoreCase(EIP.ACTION_IS_EIP_RUNNING)){
+ if (resultCode == Activity.RESULT_OK){
+
+ switch(previous_result_code){
+ case ProviderAPI.SRP_AUTHENTICATION_SUCCESSFUL: eipStatus.setText(R.string.succesful_authentication_message); break;
+ case ProviderAPI.SRP_AUTHENTICATION_FAILED: eipStatus.setText(R.string.authentication_failed_message); break;
case ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE: eipStatus.setText(R.string.authed_secured_status); break;
- }
+ case ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE: eipStatus.setText(R.string.incorrectly_downloaded_certificate_message); break;
+ case ProviderAPI.LOGOUT_SUCCESSFUL: eipStatus.setText(R.string.anonymous_secured_status); break;
+ case ProviderAPI.LOGOUT_FAILED: eipStatus.setText(R.string.log_out_failed_message); break;
+
+ }
}
- } else {
- if(request.equalsIgnoreCase(EIP.ACTION_IS_EIP_RUNNING)) {
- switch (previous_result_code) {
- case ProviderAPI.LOGOUT_SUCCESSFUL: eipStatus.setText(R.string.future_anonymous_secured_status); break;
+ else if(resultCode == Activity.RESULT_CANCELED){
+
+ switch(previous_result_code){
+
+ case ProviderAPI.SRP_AUTHENTICATION_SUCCESSFUL: eipStatus.setText(R.string.succesful_authentication_message); break;
+ case ProviderAPI.SRP_AUTHENTICATION_FAILED: eipStatus.setText(R.string.authentication_failed_message); break;
case ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE: eipStatus.setText(R.string.future_authed_secured_status); break;
+ case ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE: eipStatus.setText(R.string.incorrectly_downloaded_certificate_message); break;
+ case ProviderAPI.LOGOUT_SUCCESSFUL: eipStatus.setText(R.string.future_anonymous_secured_status); break;
+ case ProviderAPI.LOGOUT_FAILED: eipStatus.setText(R.string.log_out_failed_message); break;
}
}
}
+
}
};
- eipIsRunning(eip_status_receiver);
-
+ eipIsRunning(eip_status_receiver);
}
/**