summaryrefslogtreecommitdiff
path: root/app/src/main/java/se
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2022-11-11 18:50:23 +0100
committercyberta <cyberta@riseup.net>2022-11-22 01:48:38 +0100
commit7d5e33aeab1ba02148be041c29ad6b4220d83b27 (patch)
tree0daf62b8de6de8a04ba9b5065b0f7617a70125ee /app/src/main/java/se
parentc6435f2e9831b6c99836701b42a45a10ea81bb61 (diff)
stub implementation to start motd UI on app start if required
Diffstat (limited to 'app/src/main/java/se')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java74
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/utils/DateHelper.java11
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EipSetupObserver.java7
3 files changed, 75 insertions, 17 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java
index 8d11105f..537c6c91 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java
@@ -16,6 +16,17 @@
*/
package se.leap.bitmaskclient.base;
+import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_VPN_FRAGMENT;
+import static se.leap.bitmaskclient.base.models.Constants.APP_ACTION_CONFIGURE_ALWAYS_ON_PROFILE;
+import static se.leap.bitmaskclient.base.models.Constants.EIP_RESTART_ON_BOOT;
+import static se.leap.bitmaskclient.base.models.Constants.PREFERENCES_APP_VERSION;
+import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_EIP_DEFINITION;
+import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_KEY;
+import static se.leap.bitmaskclient.base.models.Constants.REQUEST_CODE_CONFIGURE_LEAP;
+import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES;
+import static se.leap.bitmaskclient.base.utils.ConfigHelper.isDefaultBitmask;
+import static se.leap.bitmaskclient.base.utils.PreferenceHelper.storeProviderInPreferences;
+
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -28,27 +39,22 @@ import androidx.annotation.Nullable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.util.Set;
import de.blinkt.openvpn.core.VpnStatus;
+import motd.IMessage;
+import motd.IMessages;
+import motd.IStringCollection;
+import motd.Motd;
import se.leap.bitmaskclient.BuildConfig;
-import se.leap.bitmaskclient.providersetup.ProviderListActivity;
-import se.leap.bitmaskclient.eip.EipCommand;
import se.leap.bitmaskclient.base.models.FeatureVersionCode;
import se.leap.bitmaskclient.base.models.Provider;
import se.leap.bitmaskclient.base.models.ProviderObservable;
-import se.leap.bitmaskclient.providersetup.activities.CustomProviderSetupActivity;
+import se.leap.bitmaskclient.base.utils.DateHelper;
import se.leap.bitmaskclient.base.utils.PreferenceHelper;
-
-import static se.leap.bitmaskclient.base.models.Constants.APP_ACTION_CONFIGURE_ALWAYS_ON_PROFILE;
-import static se.leap.bitmaskclient.base.models.Constants.EIP_RESTART_ON_BOOT;
-import static se.leap.bitmaskclient.base.models.Constants.PREFERENCES_APP_VERSION;
-import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_EIP_DEFINITION;
-import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_KEY;
-import static se.leap.bitmaskclient.base.models.Constants.REQUEST_CODE_CONFIGURE_LEAP;
-import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES;
-import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_VPN_FRAGMENT;
-import static se.leap.bitmaskclient.base.utils.ConfigHelper.isDefaultBitmask;
-import static se.leap.bitmaskclient.base.utils.PreferenceHelper.storeProviderInPreferences;
+import se.leap.bitmaskclient.eip.EipCommand;
+import se.leap.bitmaskclient.providersetup.ProviderListActivity;
+import se.leap.bitmaskclient.providersetup.activities.CustomProviderSetupActivity;
/**
* Activity shown at startup. Evaluates if App is started for the first time or has been upgraded
@@ -202,12 +208,13 @@ public class StartActivity extends Activity{
EipCommand.startVPN(this, true);
finish();
} else if (PreferenceHelper.getRestartOnUpdate(this.getApplicationContext())) {
+ // This is relevant for web build flavor apks
PreferenceHelper.restartOnUpdate(this.getApplicationContext(), false);
EipCommand.startVPN(this, false);
- showMainActivity();
+ showNextActivity(provider);
finish();
} else {
- showMainActivity();
+ showNextActivity(provider);
}
} else {
configureLeapProvider();
@@ -234,13 +241,46 @@ public class StartActivity extends Activity{
storeProviderInPreferences(preferences, provider);
ProviderObservable.getInstance().updateProvider(provider);
EipCommand.startVPN(this, false);
- showMainActivity();
+ showNextActivity(provider);
} else if (resultCode == RESULT_CANCELED) {
finish();
}
}
}
+ private void showNextActivity(Provider provider) {
+ if (provider.shouldShowMotdSeen()) {
+ try {
+ IMessages messages = Motd.newMessages(provider.getMotdJsonString());
+
+ IStringCollection stringCollection = Motd.newStringCollection(); //provider.getMotdLastSeenHashCollection();
+ String formattedDate = DateHelper.getFormattedDateWithTimezone(provider.getLastMotdSeen());
+ IMessage message = messages.getFirstMessage(formattedDate, stringCollection);
+ if (message != null) {
+ IMessage imessage = Motd.newMessage(message.toJson());
+ showMotd(provider, imessage);
+ return;
+ }
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Couldn't show Motd. Invalid timestamp.");
+ }
+ }
+ showMainActivity();
+ }
+
+ private void showMotd(Provider p, IMessage message) {
+ if (message.mType().equals(Motd.MESSAGE_TYPE_ONCE)) {
+ Set<String> lastSeenHashes = p.getMotdLastSeenHashes();
+ String hash = message.hash();
+ lastSeenHashes.add(hash);
+ p.setMotdLastSeenHashes(lastSeenHashes);
+ PreferenceHelper.persistProvider(this, p);
+ ProviderObservable.getInstance().updateProvider(p);
+ }
+ //TODO: show Motd Activity!
+ showMainActivity();
+ }
+
private void showMainActivity() {
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/DateHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/DateHelper.java
index 0476bf12..2e9c2b24 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/utils/DateHelper.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/DateHelper.java
@@ -12,6 +12,7 @@ import java.util.Locale;
*/
public class DateHelper {
private static final String DATE_PATTERN = "dd/MM/yyyy";
+ private static final String DATE_PATTERN_RFC822_NUMERIC_ZONE = "dd MMM yy hh:mm Z"; // RFC822 with numeric zone
private static final int ONE_DAY = 86400000; //1000*60*60*24
public static long getDateDiffToCurrentDateInDays(String startDate) throws ParseException {
@@ -26,4 +27,14 @@ public class DateHelper {
Date lastDate = new Date();
return sdf.format(lastDate);
}
+
+ /**
+ * Return date in a specific format bitmaskcore can handle.
+ * @param milliSeconds Date in milliseconds
+ * @return String representing date in specified format
+ */
+ public static String getFormattedDateWithTimezone(long milliSeconds) throws IllegalArgumentException {
+ SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN_RFC822_NUMERIC_ZONE, Locale.US);
+ return sdf.format(milliSeconds);
+ }
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EipSetupObserver.java b/app/src/main/java/se/leap/bitmaskclient/eip/EipSetupObserver.java
index 05991390..85cdb06c 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EipSetupObserver.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipSetupObserver.java
@@ -40,6 +40,7 @@ import static se.leap.bitmaskclient.providersetup.ProviderAPI.CORRECTLY_DOWNLOAD
import static se.leap.bitmaskclient.providersetup.ProviderAPI.CORRECTLY_DOWNLOADED_GEOIP_JSON;
import static se.leap.bitmaskclient.providersetup.ProviderAPI.CORRECTLY_UPDATED_INVALID_VPN_CERTIFICATE;
import static se.leap.bitmaskclient.providersetup.ProviderAPI.DELAY;
+import static se.leap.bitmaskclient.providersetup.ProviderAPI.DOWNLOAD_MOTD;
import static se.leap.bitmaskclient.providersetup.ProviderAPI.INCORRECTLY_DOWNLOADED_EIP_SERVICE;
import static se.leap.bitmaskclient.providersetup.ProviderAPI.INCORRECTLY_DOWNLOADED_GEOIP_JSON;
import static se.leap.bitmaskclient.providersetup.ProviderAPI.INCORRECTLY_DOWNLOADED_VPN_CERTIFICATE;
@@ -385,6 +386,12 @@ public class EipSetupObserver extends BroadcastReceiver implements VpnStatus.Sta
parameters.putLong(DELAY, 500);
ProviderAPICommand.execute(appContext, QUIETLY_UPDATE_VPN_CERTIFICATE, parameters, provider);
}
+
+ if (provider.shouldUpdateMotdJson()) {
+ Bundle parameters = new Bundle();
+ parameters.putLong(DELAY, 500);
+ ProviderAPICommand.execute(appContext, DOWNLOAD_MOTD, parameters, provider);
+ }
finishGatewaySetup(false);
} else if ("TCP_CONNECT".equals(state)) {
changingGateway.set(false);