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.java33
1 files changed, 24 insertions, 9 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 eca5b881..e53d81d9 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
@@ -30,6 +30,9 @@ import org.json.JSONObject;
import de.blinkt.openvpn.LaunchVPN;
import se.leap.bitmaskclient.OnBootReceiver;
+import static se.leap.bitmaskclient.Constants.BROADCAST_EIP_EVENT;
+import static se.leap.bitmaskclient.Constants.BROADCAST_RESULT_CODE;
+import static se.leap.bitmaskclient.Constants.BROADCAST_RESULT_KEY;
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;
@@ -123,9 +126,9 @@ public final class EIP extends IntentService {
gateway = gatewaysManager.select();
if (gateway != null && gateway.getProfile() != null) {
launchActiveGateway();
- tellToReceiver(EIP_ACTION_START, Activity.RESULT_OK);
+ tellToReceiverOrBroadcast(EIP_ACTION_START, Activity.RESULT_OK);
} else
- tellToReceiver(EIP_ACTION_START, Activity.RESULT_CANCELED);
+ tellToReceiverOrBroadcast(EIP_ACTION_START, Activity.RESULT_CANCELED);
}
/**
@@ -173,7 +176,7 @@ public final class EIP extends IntentService {
if (eipStatus.isConnected() || eipStatus.isConnecting())
resultCode = Activity.RESULT_OK;
- tellToReceiver(EIP_ACTION_STOP, resultCode);
+ tellToReceiverOrBroadcast(EIP_ACTION_STOP, resultCode);
}
/**
@@ -186,7 +189,7 @@ public final class EIP extends IntentService {
int resultCode = (eipStatus.isConnected()) ?
Activity.RESULT_OK :
Activity.RESULT_CANCELED;
- tellToReceiver(EIP_ACTION_IS_RUNNING, resultCode);
+ tellToReceiverOrBroadcast(EIP_ACTION_IS_RUNNING, resultCode);
}
/**
@@ -197,7 +200,7 @@ public final class EIP extends IntentService {
eipDefinition = eipDefinitionFromPreferences();
if (eipDefinition.length() > 0)
updateGateways();
- tellToReceiver(EIP_ACTION_UPDATE, Activity.RESULT_OK);
+ tellToReceiverOrBroadcast(EIP_ACTION_UPDATE, Activity.RESULT_OK);
}
private JSONObject eipDefinitionFromPreferences() {
@@ -237,14 +240,26 @@ public final class EIP extends IntentService {
int resultCode = validator.isValid() ?
Activity.RESULT_OK :
Activity.RESULT_CANCELED;
- tellToReceiver(EIP_ACTION_CHECK_CERT_VALIDITY, resultCode);
+ tellToReceiverOrBroadcast(EIP_ACTION_CHECK_CERT_VALIDITY, resultCode);
}
- private void tellToReceiver(String action, int resultCode) {
+ private void tellToReceiverOrBroadcast(String action, int resultCode) {
+ Bundle resultData = new Bundle();
+ resultData.putString(EIP_REQUEST, action);
if (mReceiver != null) {
- Bundle resultData = new Bundle();
- resultData.putString(EIP_REQUEST, action);
mReceiver.send(resultCode, resultData);
+ } else {
+ broadcastEvent(resultCode, resultData);
}
}
+
+ private void broadcastEvent(int resultCode , Bundle resultData) {
+ Intent intentUpdate = new Intent(BROADCAST_EIP_EVENT);
+ intentUpdate.addCategory(Intent.CATEGORY_DEFAULT);
+ intentUpdate.putExtra(BROADCAST_RESULT_CODE, resultCode);
+ intentUpdate.putExtra(BROADCAST_RESULT_KEY, resultData);
+ Log.d(TAG, "sending broadcast");
+ sendBroadcast(intentUpdate);
+ }
+
}