summaryrefslogtreecommitdiff
path: root/src/se/leap/bitmaskclient
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2013-12-04 17:24:42 +0100
committerParménides GV <parmegv@sdf.org>2013-12-04 17:24:42 +0100
commit90732260daaba438f49e510ed987284bcb419f4d (patch)
treeee30a40be65e993a9f886b47fd57d41717bf4222 /src/se/leap/bitmaskclient
parentdc417fbfc67d8edaad58effde3a6a73fbeeab1da (diff)
parentd004c5535c75540600d6670e86300872651fc7bf (diff)
Merge branch 'bug/fix-switch-provider' into develop
Diffstat (limited to 'src/se/leap/bitmaskclient')
-rw-r--r--src/se/leap/bitmaskclient/ConfigurationWizard.java14
-rw-r--r--src/se/leap/bitmaskclient/Dashboard.java43
-rw-r--r--src/se/leap/bitmaskclient/EIP.java12
-rw-r--r--src/se/leap/bitmaskclient/EipServiceFragment.java15
-rw-r--r--src/se/leap/bitmaskclient/Provider.java2
-rw-r--r--src/se/leap/bitmaskclient/ProviderAPI.java5
6 files changed, 72 insertions, 19 deletions
diff --git a/src/se/leap/bitmaskclient/ConfigurationWizard.java b/src/se/leap/bitmaskclient/ConfigurationWizard.java
index 28a8a44a..4a3bb12b 100644
--- a/src/se/leap/bitmaskclient/ConfigurationWizard.java
+++ b/src/se/leap/bitmaskclient/ConfigurationWizard.java
@@ -25,7 +25,6 @@ import org.json.JSONObject;
import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.ProviderAPIResultReceiver.Receiver;
import se.leap.bitmaskclient.ProviderListContent.ProviderItem;
-
import android.app.Activity;
import android.app.DialogFragment;
import android.app.Fragment;
@@ -37,6 +36,7 @@ import android.content.Intent;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.os.Handler;
+import android.util.Log;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
@@ -68,6 +68,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
private ProviderListFragment provider_list_fragment;
private Intent mConfigState = new Intent();
+ final public static String TAG = "se.leap.bitmaskclient.ConfigurationWizard";
final public static String TYPE_OF_CERTIFICATE = "type_of_certificate";
final public static String ANON_CERTIFICATE = "anon_certificate";
final public static String AUTHED_CERTIFICATE = "authed_certificate";
@@ -231,10 +232,12 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
@Override
public void onItemSelected(String id) {
//TODO Code 2 pane view
+ // resetOldConnection();
ProviderItem selected_provider = getProvider(id);
int provider_index = getProviderIndex(id);
startProgressBar(provider_index);
mSelectedProvider = selected_provider;
+
saveProviderJson(mSelectedProvider);
}
@@ -484,8 +487,9 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
* @param danger_on tells if HTTPS client should bypass certificate errors
*/
public void updateProviderDotJson(String provider_name, String provider_json_url, boolean danger_on) {
+
+
Intent provider_API_command = new Intent(this, ProviderAPI.class);
-
Bundle parameters = new Bundle();
parameters.putString(Provider.NAME, provider_name);
parameters.putString(Provider.DOT_JSON_URL, provider_json_url);
@@ -494,10 +498,10 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
provider_API_command.setAction(ProviderAPI.UPDATE_PROVIDER_DOTJSON);
provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
-
+
startService(provider_API_command);
}
-
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.configuration_wizard_activity, menu);
@@ -534,7 +538,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
fragment_transaction.replace(R.id.configuration_wizard_layout, newFragment, AboutFragment.TAG).commit();
}
}
-
+
public void showAllProviders() {
provider_list_fragment = (ProviderListFragment) getFragmentManager().findFragmentByTag(ProviderListFragment.TAG);
if(provider_list_fragment != null)
diff --git a/src/se/leap/bitmaskclient/Dashboard.java b/src/se/leap/bitmaskclient/Dashboard.java
index ca619e9f..65ff2800 100644
--- a/src/se/leap/bitmaskclient/Dashboard.java
+++ b/src/se/leap/bitmaskclient/Dashboard.java
@@ -40,6 +40,7 @@ import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.ResultReceiver;
+import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -63,12 +64,16 @@ 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;
private ProviderAPIBroadcastReceiver_Update providerAPI_broadcast_receiver_update;
@@ -89,8 +94,9 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
app = this;
PRNGFixes.apply();
- //mProgressBar = (ProgressBar) findViewById(R.id.progressbar_dashboard);
-
+ // mProgressBar = (ProgressBar) findViewById(R.id.progressbar_dashboard);
+ // mProgressBar = (ProgressBar) findViewById(R.id.eipProgress);
+ // eipStatus = (TextView) findViewById(R.id.eipStatus);
providerAPI_broadcast_receiver_update = new ProviderAPIBroadcastReceiver_Update();
IntentFilter update_intent_filter = new IntentFilter(ProviderAPI.UPDATE_ACTION);
@@ -99,7 +105,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
ConfigHelper.setSharedPreferences(getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE));
preferences = ConfigHelper.shared_preferences;
-
+
authed_eip = ConfigHelper.getBoolFromSharedPref(EIP.AUTHED_EIP);
if (ConfigHelper.getStringFromSharedPref(Provider.KEY).isEmpty())
startActivityForResult(new Intent(this,ConfigurationWizard.class),CONFIGURE_LEAP);
@@ -116,10 +122,13 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if ( requestCode == CONFIGURE_LEAP || requestCode == SWITCH_PROVIDER) {
- if ( resultCode == RESULT_OK ){
+ // 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);
startService( new Intent(EIP.ACTION_UPDATE_EIP_SERVICE) );
buildDashboard();
+
if(data != null && data.hasExtra(LogInDialog.VERB)) {
View view = ((ViewGroup)findViewById(android.R.id.content)).getChildAt(0);
logInDialog(view, Bundle.EMPTY);
@@ -130,7 +139,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
configErrorDialog();
}
}
-
+
/**
* Dialog shown when encountering a configuration error. Such errors require
* reconfiguring LEAP or aborting the application.
@@ -228,6 +237,12 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
startActivity(intent);
return true;
case R.id.switch_provider:
+ if (Provider.getInstance().hasEIP()){
+ if (ConfigHelper.getBoolFromSharedPref(EIP.AUTHED_EIP)){
+ logOut();
+ }
+ eipStop();
+ }
startActivityForResult(new Intent(this,ConfigurationWizard.class), SWITCH_PROVIDER);
return true;
case R.id.login_button:
@@ -299,14 +314,13 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
- //if(mProgressDialog != null) mProgressDialog.dismiss();
- //mProgressDialog = ProgressDialog.show(this, getResources().getString(R.string.logout_title), getResources().getString(R.string.logout_message), true);
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");
- //mProgressBar.setMax(1);
startService(provider_API_command);
+ //mProgressBar.setMax(1);
+
}
/**
@@ -456,7 +470,20 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
eip_intent.putExtra(EIP.RECEIVER_TAG, eip_receiver);
startService(eip_intent);
}
+
+ /**
+ * Send a command to EIP
+ *
+ */
+ private void eipStop(){
+ // TODO validate "action"...how do we get the list of intent-filters for a class via Android API?
+ Intent eip_intent = new Intent(this, EIP.class);
+ eip_intent.setAction(EIP.ACTION_STOP_EIP);
+ // eip_intent.putExtra(EIP.RECEIVER_TAG, eip_receiver);
+ startService(eip_intent);
+ }
+
public class ProviderAPIBroadcastReceiver_Update extends BroadcastReceiver {
@Override
diff --git a/src/se/leap/bitmaskclient/EIP.java b/src/se/leap/bitmaskclient/EIP.java
index 22f7558d..ec2f6972 100644
--- a/src/se/leap/bitmaskclient/EIP.java
+++ b/src/se/leap/bitmaskclient/EIP.java
@@ -214,8 +214,7 @@ public final class EIP extends IntentService {
* Intent to {@link se.leap.openvpn.LaunchVPN}
*/
private void startEIP() {
- if (activeGateway==null)
- activeGateway = selectGateway();
+ activeGateway = selectGateway();
Intent intent = new Intent(this,LaunchVPN.class);
intent.setAction(Intent.ACTION_MAIN);
@@ -252,10 +251,19 @@ public final class EIP extends IntentService {
private void updateEIPService() {
try {
eipDefinition = ConfigHelper.getJsonFromSharedPref(EIP.KEY);
+ parsedEipSerial = ConfigHelper.getIntFromSharedPref(PARSED_SERIAL);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
+ if(parsedEipSerial == 0) {
+ // Delete all vpn profiles
+ ProfileManager vpl = ProfileManager.getInstance(context);
+ Collection<VpnProfile> profiles = vpl.getProfiles();
+ for (VpnProfile profile : profiles){
+ vpl.removeProfile(context, profile);
+ }
+ }
if (eipDefinition.optInt("serial") > parsedEipSerial)
updateGateways();
}
diff --git a/src/se/leap/bitmaskclient/EipServiceFragment.java b/src/se/leap/bitmaskclient/EipServiceFragment.java
index 4d778b1a..e182b3fd 100644
--- a/src/se/leap/bitmaskclient/EipServiceFragment.java
+++ b/src/se/leap/bitmaskclient/EipServiceFragment.java
@@ -12,6 +12,7 @@ import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.ResultReceiver;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@@ -38,6 +39,9 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli
private EIPReceiver mEIPReceiver;
+
+ public static String TAG = "se.leap.bitmask.EipServiceFragment";
+
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@@ -57,6 +61,8 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli
eipStatus.setOnClickListener(this);
eipSwitch = (Switch) eipFragment.findViewById(R.id.eipSwitch);
+
+
eipSwitch.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
@@ -66,6 +72,7 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli
});
eipSwitch.setOnCheckedChangeListener(this);
+
return eipFragment;
}
@@ -152,6 +159,8 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli
eipAutoSwitched = true;
}
+
+
/**
* Send a command to EIP
*
@@ -186,15 +195,14 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli
statusMessage = getString(R.string.eip_state_connected); getActivity().findViewById(R.id.eipProgress).setVisibility(View.GONE);
mEipStartPending = false;
- } else if ( (state.equals("NOPROCESS") && !mEipStartPending ) || state.equals("EXITING")) {
+ } else if ( (state.equals("NOPROCESS") && !mEipStartPending ) || state.equals("EXITING") || state.equals("FATAL")) {
statusMessage = getString(R.string.eip_state_not_connected);
getActivity().findViewById(R.id.eipProgress).setVisibility(View.GONE);
mEipStartPending = false;
switchState = false;
} else if (state.equals("NOPROCESS")){
statusMessage = logmessage;
- }
- else {
+ } else {
statusMessage = prefix + " " + logmessage;
}
@@ -207,6 +215,7 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli
});
}
+
/**
* Inner class for handling messages related to EIP status and control requests
*
diff --git a/src/se/leap/bitmaskclient/Provider.java b/src/se/leap/bitmaskclient/Provider.java
index e462829f..f36e5946 100644
--- a/src/se/leap/bitmaskclient/Provider.java
+++ b/src/se/leap/bitmaskclient/Provider.java
@@ -166,6 +166,8 @@ public final class Provider implements Serializable {
// Walk the EIP types array looking for matches in provider's service definitions
if ( Arrays.asList(API_EIP_TYPES).contains( services.getString(i) ) )
return true;
+ } catch (NullPointerException e){
+ e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
diff --git a/src/se/leap/bitmaskclient/ProviderAPI.java b/src/se/leap/bitmaskclient/ProviderAPI.java
index a553851b..871a20dd 100644
--- a/src/se/leap/bitmaskclient/ProviderAPI.java
+++ b/src/se/leap/bitmaskclient/ProviderAPI.java
@@ -229,7 +229,10 @@ public class ProviderAPI extends IntentService {
result.putString(ERRORS, reason_to_fail);
result.putBoolean(RESULT_KEY, false);
}
- else ConfigHelper.saveSharedPref(EIP.KEY, eip_service_json);
+ else {
+ ConfigHelper.saveSharedPref(EIP.KEY, eip_service_json);
+ ConfigHelper.saveSharedPref(EIP.PARSED_SERIAL, 0);
+ }
result.putBoolean(RESULT_KEY, true);
} catch (JSONException e) {