summaryrefslogtreecommitdiff
path: root/src/se/leap/bitmaskclient
diff options
context:
space:
mode:
Diffstat (limited to 'src/se/leap/bitmaskclient')
-rw-r--r--src/se/leap/bitmaskclient/Dashboard.java70
-rw-r--r--src/se/leap/bitmaskclient/EIP.java73
-rw-r--r--src/se/leap/bitmaskclient/ProviderAPI.java2
3 files changed, 84 insertions, 61 deletions
diff --git a/src/se/leap/bitmaskclient/Dashboard.java b/src/se/leap/bitmaskclient/Dashboard.java
index 3fddfed5..d50aa7e0 100644
--- a/src/se/leap/bitmaskclient/Dashboard.java
+++ b/src/se/leap/bitmaskclient/Dashboard.java
@@ -54,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;
@@ -263,7 +259,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);
}
@@ -294,7 +290,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);
@@ -351,71 +349,73 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
authed_eip = true;
ConfigHelper.saveSharedPref(EIP.AUTHED_EIP, authed_eip);
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);
+ ConfigHelper.saveSharedPref(EIP.AUTHED_EIP, authed_eip);
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);
}
/**
diff --git a/src/se/leap/bitmaskclient/EIP.java b/src/se/leap/bitmaskclient/EIP.java
index 2b7fd39f..ecb7498f 100644
--- a/src/se/leap/bitmaskclient/EIP.java
+++ b/src/se/leap/bitmaskclient/EIP.java
@@ -35,13 +35,13 @@ import se.leap.openvpn.OpenVpnService;
import se.leap.openvpn.OpenVpnService.LocalBinder;
import se.leap.openvpn.ProfileManager;
import se.leap.openvpn.VpnProfile;
-
import android.app.Activity;
import android.app.IntentService;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
+import android.drm.DrmStore.Action;
import android.os.Bundle;
import android.os.IBinder;
import android.os.ResultReceiver;
@@ -72,6 +72,7 @@ public final class EIP extends IntentService {
public final static String SERVICE_API_PATH = "config/eip-service.json";
public final static String RECEIVER_TAG = "receiverTag";
public final static String REQUEST_TAG = "requestTag";
+ public final static String TAG = "se.leap.bitmaskclient.EIP";
private static Context context;
@@ -141,7 +142,6 @@ public final class EIP extends IntentService {
}
private static ServiceConnection mVpnServiceConn = new ServiceConnection() {
-
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
LocalBinder binder = (LocalBinder) service;
@@ -149,17 +149,22 @@ public final class EIP extends IntentService {
mBound = true;
if (mReceiver != null && mPending != null) {
-
+
boolean running = mVpnService.isRunning();
+
int resultCode = Activity.RESULT_CANCELED;
- if (mPending.equals(ACTION_IS_EIP_RUNNING))
+ if (mPending.equals(ACTION_IS_EIP_RUNNING)){
resultCode = (running) ? Activity.RESULT_OK : Activity.RESULT_CANCELED;
- if (mPending.equals(ACTION_START_EIP))
+
+ }
+ else if (mPending.equals(ACTION_START_EIP)){
resultCode = (running) ? Activity.RESULT_OK : Activity.RESULT_CANCELED;
- else if (mPending.equals(ACTION_STOP_EIP))
+ }
+ else if (mPending.equals(ACTION_STOP_EIP)){
resultCode = (running) ? Activity.RESULT_CANCELED
: Activity.RESULT_OK;
+ }
Bundle resultData = new Bundle();
resultData.putString(REQUEST_TAG, ACTION_IS_EIP_RUNNING);
mReceiver.send(resultCode, resultData);
@@ -178,6 +183,7 @@ public final class EIP extends IntentService {
mReceiver.send(Activity.RESULT_CANCELED, resultData);
}
}
+
};
@@ -190,25 +196,42 @@ public final class EIP extends IntentService {
* Note: If the request to bind OpenVpnService is successful, the ResultReceiver
* will be notified in {@link onServiceConnected()}
*/
- private void isRunning() {
- Bundle resultData = new Bundle();
- resultData.putString(REQUEST_TAG, ACTION_IS_EIP_RUNNING);
- int resultCode = Activity.RESULT_CANCELED;
- if (mBound) {
- resultCode = (mVpnService.isRunning()) ? Activity.RESULT_OK : Activity.RESULT_CANCELED;
-
- if (mReceiver != null){
- mReceiver.send(resultCode, resultData);
- }
- } else {
- mPending = ACTION_IS_EIP_RUNNING;
- boolean retrieved_vpn_service = retreiveVpnService();
- if(!retrieved_vpn_service && mReceiver != null) {
- mReceiver.send(resultCode, resultData);
- }
- }
- }
-
+
+ private void isRunning() {
+ Bundle resultData = new Bundle();
+ resultData.putString(REQUEST_TAG, ACTION_IS_EIP_RUNNING);
+ int resultCode = Activity.RESULT_CANCELED;
+ if (mBound) {
+ resultCode = (mVpnService.isRunning()) ? Activity.RESULT_OK : Activity.RESULT_CANCELED;
+
+ if (mReceiver != null){
+ mReceiver.send(resultCode, resultData);
+ }
+ } else {
+ mPending = ACTION_IS_EIP_RUNNING;
+ boolean retrieved_vpn_service = retreiveVpnService();
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ boolean running = false;
+ try {
+ running = mVpnService.isRunning();
+ } catch (NullPointerException e){
+ e.printStackTrace();
+ }
+
+ if (retrieved_vpn_service && running && mReceiver != null){
+ mReceiver.send(Activity.RESULT_OK, resultData);
+ }
+ else{
+ mReceiver.send(Activity.RESULT_CANCELED, resultData);
+ }
+ }
+ }
+
/**
* Initiates an EIP connection by selecting a gateway and preparing and sending an
* Intent to {@link se.leap.openvpn.LaunchVPN}
diff --git a/src/se/leap/bitmaskclient/ProviderAPI.java b/src/se/leap/bitmaskclient/ProviderAPI.java
index ff6dd852..8116f244 100644
--- a/src/se/leap/bitmaskclient/ProviderAPI.java
+++ b/src/se/leap/bitmaskclient/ProviderAPI.java
@@ -778,7 +778,7 @@ public class ProviderAPI extends IntentService {
int responseCode = urlConnection.getResponseCode();
broadcast_progress(progress++);
LeapSRPSession.setToken("");
- Log.d("logout", Integer.toString(responseCode));
+ Log.d(TAG, Integer.toString(responseCode));
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();