summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorFup Duck <fupduck@sacknagel.com>2018-02-06 17:43:37 +0100
committerFup Duck <fupduck@sacknagel.com>2018-02-06 17:43:37 +0100
commit8bb96b0116994897ca75ad8eb1d6c412e7d3ce40 (patch)
treef8c8f9ad407a2fbbed8c592b06fb289e6b34208d /app/src/main
parent268a7f205fa09edc145aace8bed30f75270a801f (diff)
8827 add EipCommand
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EipCommand.java66
1 files changed, 66 insertions, 0 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EipCommand.java b/app/src/main/java/se/leap/bitmaskclient/eip/EipCommand.java
new file mode 100644
index 00000000..35599ab4
--- /dev/null
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipCommand.java
@@ -0,0 +1,66 @@
+package se.leap.bitmaskclient.eip;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.ResultReceiver;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import static se.leap.bitmaskclient.Constants.EIP_ACTION_START;
+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;
+
+/**
+ * Use this class to send commands to EIP
+ */
+
+public class EipCommand {
+
+ public static void execute(@NotNull Context context, @NotNull String action) {
+ execute(context, action, null);
+ }
+
+ /**
+ * Send a command to EIP
+ * @param context the context to start the command from
+ * @param action A valid String constant from EIP class representing an Intent
+ * filter for the EIP class
+ * @param resultReceiver The resultreceiver to reply to
+ */
+ public static void execute(@NotNull Context context, @NotNull String action, @Nullable ResultReceiver resultReceiver) {
+ // TODO validate "action"...how do we get the list of intent-filters for a class via Android API?
+ Intent vpnIntent = new Intent(context.getApplicationContext(), EIP.class);
+ vpnIntent.setAction(action);
+ if (resultReceiver != null)
+ vpnIntent.putExtra(EIP_RECEIVER, resultReceiver);
+ context.startService(vpnIntent);
+ }
+
+ public static void updateEipService(Context context, ResultReceiver resultReceiver) {
+ execute(context, EIP_ACTION_UPDATE, resultReceiver);
+ }
+
+ public static void updateEipService(Context context) {
+ execute(context, EIP_ACTION_UPDATE);
+ }
+
+ public static void startVPN(Context context) {
+ execute(context, EIP_ACTION_START);
+ }
+
+ public static void startVPN(Context context, ResultReceiver resultReceiver) {
+ execute(context, EIP_ACTION_START, resultReceiver);
+ }
+
+
+ public static void stopVPN(Context context) {
+ execute(context, EIP_ACTION_STOP);
+ }
+
+ public static void stopVPN(Context context, ResultReceiver resultReceiver) {
+ execute(context, EIP_ACTION_STOP, resultReceiver);
+ }
+
+}