summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/eip/EIP.java')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EIP.java47
1 files changed, 28 insertions, 19 deletions
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 39dd133f..a84ab941 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
@@ -26,7 +26,17 @@ import org.json.*;
import de.blinkt.openvpn.*;
import se.leap.bitmaskclient.*;
-import static se.leap.bitmaskclient.eip.Constants.*;
+import static se.leap.bitmaskclient.Constants.EIP_ACTION_CHECK_CERT_VALIDITY;
+import static se.leap.bitmaskclient.Constants.EIP_ACTION_IS_RUNNING;
+import static se.leap.bitmaskclient.Constants.EIP_ACTION_START;
+import static se.leap.bitmaskclient.Constants.EIP_ACTION_START_ALWAYS_ON_EIP;
+import static se.leap.bitmaskclient.Constants.EIP_ACTION_STOP;
+import static se.leap.bitmaskclient.Constants.EIP_ACTION_UPDATE;
+import static se.leap.bitmaskclient.Constants.EIP_RECEIVER;
+import static se.leap.bitmaskclient.Constants.EIP_REQUEST;
+import static se.leap.bitmaskclient.Constants.PROVIDER_KEY;
+import static se.leap.bitmaskclient.Constants.PROVIDER_VPN_CERTIFICATE;
+import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES;
/**
* EIP is the abstract base class for interacting with and managing the Encrypted
@@ -59,7 +69,7 @@ public final class EIP extends IntentService {
public void onCreate() {
super.onCreate();
context = getApplicationContext();
- preferences = getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE);
+ preferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
eip_definition = eipDefinitionFromPreferences();
if (gateways_manager.isEmpty())
gatewaysFromPreferences();
@@ -68,19 +78,19 @@ public final class EIP extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
String action = intent.getAction();
- mReceiver = intent.getParcelableExtra(RECEIVER_TAG);
+ mReceiver = intent.getParcelableExtra(EIP_RECEIVER);
- if (action.equals(ACTION_START_EIP))
+ if (action.equals(EIP_ACTION_START))
startEIP();
- else if (action.equals(ACTION_START_ALWAYS_ON_EIP))
+ else if (action.equals(EIP_ACTION_START_ALWAYS_ON_EIP))
startAlwaysOnEIP();
- else if (action.equals(ACTION_STOP_EIP))
+ else if (action.equals(EIP_ACTION_STOP))
stopEIP();
- else if (action.equals(ACTION_IS_EIP_RUNNING))
+ else if (action.equals(EIP_ACTION_IS_RUNNING))
isRunning();
- else if (action.equals(ACTION_UPDATE_EIP_SERVICE))
+ else if (action.equals(EIP_ACTION_UPDATE))
updateEIPService();
- else if (action.equals(ACTION_CHECK_CERT_VALIDITY))
+ else if (action.equals(EIP_ACTION_CHECK_CERT_VALIDITY))
checkCertValidity();
}
@@ -90,7 +100,6 @@ public final class EIP extends IntentService {
* It also sets up early routes.
*/
private void startEIP() {
- Log.d(TAG, "startEIP vpn");
if (gateways_manager.isEmpty())
updateEIPService();
if (!EipStatus.getInstance().isBlockingVpnEstablished()) {
@@ -101,9 +110,9 @@ public final class EIP extends IntentService {
if (gateway != null && gateway.getProfile() != null) {
mReceiver = VpnFragment.getReceiver();
launchActiveGateway();
- tellToReceiver(ACTION_START_EIP, Activity.RESULT_OK);
+ tellToReceiver(EIP_ACTION_START, Activity.RESULT_OK);
} else
- tellToReceiver(ACTION_START_EIP, Activity.RESULT_CANCELED);
+ tellToReceiver(EIP_ACTION_START, Activity.RESULT_CANCELED);
}
/**
@@ -152,7 +161,7 @@ public final class EIP extends IntentService {
if (eip_status.isConnected() || eip_status.isConnecting())
result_code = Activity.RESULT_OK;
- tellToReceiver(ACTION_STOP_EIP, result_code);
+ tellToReceiver(EIP_ACTION_STOP, result_code);
}
/**
@@ -165,7 +174,7 @@ public final class EIP extends IntentService {
int resultCode = (eip_status.isConnected()) ?
Activity.RESULT_OK :
Activity.RESULT_CANCELED;
- tellToReceiver(ACTION_IS_EIP_RUNNING, resultCode);
+ tellToReceiver(EIP_ACTION_IS_RUNNING, resultCode);
}
/**
@@ -176,13 +185,13 @@ public final class EIP extends IntentService {
eip_definition = eipDefinitionFromPreferences();
if (eip_definition.length() > 0)
updateGateways();
- tellToReceiver(ACTION_UPDATE_EIP_SERVICE, Activity.RESULT_OK);
+ tellToReceiver(EIP_ACTION_UPDATE, Activity.RESULT_OK);
}
private JSONObject eipDefinitionFromPreferences() {
JSONObject result = new JSONObject();
try {
- String eip_definition_string = preferences.getString(KEY, "");
+ String eip_definition_string = preferences.getString(PROVIDER_KEY, "");
if (!eip_definition_string.isEmpty()) {
result = new JSONObject(eip_definition_string);
}
@@ -212,17 +221,17 @@ public final class EIP extends IntentService {
}
private void checkCertValidity() {
- VpnCertificateValidator validator = new VpnCertificateValidator(preferences.getString(VPN_CERTIFICATE, ""));
+ VpnCertificateValidator validator = new VpnCertificateValidator(preferences.getString(PROVIDER_VPN_CERTIFICATE, ""));
int resultCode = validator.isValid() ?
Activity.RESULT_OK :
Activity.RESULT_CANCELED;
- tellToReceiver(ACTION_CHECK_CERT_VALIDITY, resultCode);
+ tellToReceiver(EIP_ACTION_CHECK_CERT_VALIDITY, resultCode);
}
private void tellToReceiver(String action, int resultCode) {
if (mReceiver != null) {
Bundle resultData = new Bundle();
- resultData.putString(REQUEST_TAG, action);
+ resultData.putString(EIP_REQUEST, action);
mReceiver.send(resultCode, resultData);
}
}