summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-11-13 19:22:35 +0100
committerParménides GV <parmegv@sdf.org>2014-11-26 12:29:44 +0100
commitba3362c6779e3b89533b1a132d67b4916a9976d8 (patch)
tree065ae2dd9e8856ae6fa452e64daec89bae4537c9 /app/src/main/java
parent1fcf003abf27b58047d59a3f8ac4787987de2ecd (diff)
GatewaySelector is back.
Had to rewrite the class, forgot to add the java file to git.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java2
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/Constants.java1
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EIP.java82
3 files changed, 36 insertions, 49 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index e4e575e4..395e9987 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -97,7 +97,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
case 101: // 0.8.0
if(!preferences.getString(Constants.KEY, "").isEmpty()) {
Intent rebuildVpnProfiles = new Intent(getApplicationContext(), EIP.class);
- rebuildVpnProfiles.setAction(Constants.ACTION_REBUILD_PROFILES);
+ rebuildVpnProfiles.setAction(Constants.ACTION_UPDATE_EIP_SERVICE);
startService(rebuildVpnProfiles);
}
break;
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/Constants.java b/app/src/main/java/se/leap/bitmaskclient/eip/Constants.java
index 3b43282b..b710d780 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/Constants.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/Constants.java
@@ -33,7 +33,6 @@ public interface Constants {
public final static String ACTION_STOP_EIP = TAG + ".STOP_EIP";
public final static String ACTION_UPDATE_EIP_SERVICE = TAG + ".UPDATE_EIP_SERVICE";
public final static String ACTION_IS_EIP_RUNNING = TAG + ".IS_RUNNING";
- public final static String ACTION_REBUILD_PROFILES = TAG + ".REBUILD_PROFILES";
public final static String EIP_NOTIFICATION = TAG + ".EIP_NOTIFICATION";
public final static String STATUS = TAG + ".STATUS";
public final static String DATE_FROM_CERTIFICATE = TAG + ".DATE_FROM_CERTIFICATE";
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
index 94027491..2b9f120d 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
@@ -101,8 +101,6 @@ public final class EIP extends IntentService {
updateEIPService();
else if ( action == ACTION_CHECK_CERT_VALIDITY )
checkCertValidity();
- else if ( action == ACTION_REBUILD_PROFILES )
- updateGateways();
}
/**
@@ -175,39 +173,28 @@ public final class EIP extends IntentService {
*/
private void isRunning() {
- int resultCode = Activity.RESULT_CANCELED;
- boolean is_connected = isConnected();
-
- resultCode = (is_connected) ? Activity.RESULT_OK : Activity.RESULT_CANCELED;
-
+ int resultCode = (isConnected()) ?
+ Activity.RESULT_OK :
+ Activity.RESULT_CANCELED;
tellToReceiver(ACTION_IS_EIP_RUNNING, resultCode);
}
public static boolean isConnected() {
- return lastConnectionStatusLevel != null && lastConnectionStatusLevel.equals(VpnStatus.ConnectionStatus.LEVEL_CONNECTED) && !mIsDisconnecting;
+ return lastConnectionStatusLevel != null
+ && lastConnectionStatusLevel.equals(VpnStatus.ConnectionStatus.LEVEL_CONNECTED)
+ && !mIsDisconnecting;
}
- /**
- * Loads eip-service.json from SharedPreferences and calls {@link updateGateways()}
- * to parse gateway definitions.
- * TODO Implement API call to refresh eip-service.json from the provider
- */
- private void updateEIPService() {
- try {
- String eip_definition_string = preferences.getString(KEY, "");
- if(eip_definition_string.isEmpty() == false) {
- eipDefinition = new JSONObject(eip_definition_string);
- }
- deleteAllVpnProfiles();
- updateGateways();
- if(mReceiver != null) mReceiver.send(Activity.RESULT_OK, Bundle.EMPTY);
- } catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- if (eip_definition != null && eip_definition.optInt("serial") >= parsedEipSerial)
- updateGateways();
+ /**
+ * Loads eip-service.json from SharedPreferences and calls {@link updateGateways()}
+ * to parse gateway definitions.
+ * TODO Implement API call to refresh eip-service.json from the provider
+ */
+ private void updateEIPService() {
+ refreshEipDefinition();
+ deleteAllVpnProfiles();
+ updateGateways();
+ if(mReceiver != null) mReceiver.send(Activity.RESULT_OK, Bundle.EMPTY);
}
private void refreshEipDefinition() {
@@ -233,29 +220,30 @@ public final class EIP extends IntentService {
* OVPNGateway objects.
* TODO Store the OVPNGateways (as Serializable) in SharedPreferences
*/
- private void updateGateways(){
- JSONArray gatewaysDefined = null;
- try {
- if(eip_definition == null) updateEIPService();
- gatewaysDefined = eip_definition.getJSONArray("gateways");
- for ( int i=0 ; i < gatewaysDefined.length(); i++ ){
- JSONObject gw = null;
- gw = gatewaysDefined.getJSONObject(i);
+ private void updateGateways(){
+ JSONArray gatewaysDefined = null;
+ try {
+ gatewaysDefined = eip_definition.getJSONArray("gateways");
+ for ( int i=0 ; i < gatewaysDefined.length(); i++ ){
+ JSONObject gw = null;
+ gw = gatewaysDefined.getJSONObject(i);
- if ( gw.getJSONObject("capabilities").getJSONArray("transport").toString().contains("openvpn") )
- new OVPNGateway(gw);
- }
- } catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- preferences.edit().putInt(PARSED_SERIAL, eip_definition.optInt(Provider.API_RETURN_SERIAL)).commit();
+ if ( gw.getJSONObject("capabilities").getJSONArray("transport").toString().contains("openvpn") )
+ new OVPNGateway(gw);
+ }
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
+ preferences.edit().putInt(PARSED_SERIAL, eip_definition.optInt(Provider.API_RETURN_SERIAL)).commit();
+ }
private void checkCertValidity() {
VpnCertificateValidator validator = new VpnCertificateValidator();
- boolean is_valid = validator.isValid(preferences.getString(CERTIFICATE, ""));
- tellToReceiver(ACTION_CHECK_CERT_VALIDITY, is_valid);
+ int resultCode = validator.isValid(preferences.getString(CERTIFICATE, "")) ?
+ Activity.RESULT_OK :
+ Activity.RESULT_CANCELED;
+ tellToReceiver(ACTION_CHECK_CERT_VALIDITY, resultCode);
}
/**