summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2022-11-11 01:33:35 +0100
committercyberta <cyberta@riseup.net>2022-11-22 01:48:38 +0100
commit08ed7bcd70750b066af2a6d6845d6bd904981e2a (patch)
treeaf4b8f195c0dea852ad82aebac3b3868a6ae1197 /app/src/main/java/se/leap
parent0806936f2e2499b2cfa85a429f7926cd3dc6d142 (diff)
add MotdClient, a Java wrapper around golang's motd
Diffstat (limited to 'app/src/main/java/se/leap')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/motd/MotdClient.java47
1 files changed, 47 insertions, 0 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/motd/MotdClient.java b/app/src/main/java/se/leap/bitmaskclient/motd/MotdClient.java
new file mode 100644
index 00000000..d80a8992
--- /dev/null
+++ b/app/src/main/java/se/leap/bitmaskclient/motd/MotdClient.java
@@ -0,0 +1,47 @@
+package se.leap.bitmaskclient.motd;
+
+import androidx.annotation.WorkerThread;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import de.blinkt.openvpn.core.VpnStatus;
+import motd.IMessages;
+import motd.IMotd;
+import motd.Motd;
+import se.leap.bitmaskclient.base.models.Provider;
+
+public class MotdClient {
+ IMotd motd;
+
+ public MotdClient(Provider provider) {
+ motd = Motd.newMotd(provider.getMotdUrl().toString(), provider.getName(), "android");
+ }
+
+ @WorkerThread
+ public IMessages fetch() {
+ if (!VpnStatus.isVPNActive()) {
+ VpnStatus.logError("Tried to fetch Message of the Day while VPN was off.");
+ return null;
+ }
+
+ return Motd.newMessages(motd.fetchLatestAsJson());
+ }
+
+ @WorkerThread
+ public JSONObject fetchJson() {
+ if (!VpnStatus.isVPNActive()) {
+ VpnStatus.logError("Tried to fetch Message of the Day while VPN was off.");
+ return null;
+ }
+
+ try {
+ return new JSONObject(motd.fetchLatestAsJson());
+ } catch (NullPointerException | JSONException e) {
+ e.printStackTrace();
+ return null;
+ }
+
+ }
+
+}