mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Show expiry warning when running on Android 4
After a set date a snackbar is shown, warning that Briar will stop working at a later set date.
This commit is contained in:
@@ -2,6 +2,7 @@ package org.briarproject.briar.android;
|
||||
|
||||
import org.briarproject.briar.BuildConfig;
|
||||
|
||||
import static android.os.Build.VERSION.SDK_INT;
|
||||
import static java.util.concurrent.TimeUnit.DAYS;
|
||||
|
||||
public interface TestingConstants {
|
||||
@@ -19,10 +20,15 @@ public interface TestingConstants {
|
||||
*/
|
||||
boolean PREVENT_SCREENSHOTS = !IS_DEBUG_BUILD;
|
||||
|
||||
boolean IS_OLD_ANDROID = SDK_INT <= 19;
|
||||
long OLD_ANDROID_WARN_DATE = 1659225600_000L; // 2022-07-31
|
||||
long OLD_ANDROID_EXPIRY_DATE = 1675123200_000L; // 2023-01-31
|
||||
|
||||
/**
|
||||
* Debug builds expire after 90 days. Release builds expire after 292
|
||||
* million years.
|
||||
* Debug builds expire after 90 days. Release builds running on Android 4
|
||||
* expire at a set date, otherwise they expire after 292 million years.
|
||||
*/
|
||||
long EXPIRY_DATE = IS_DEBUG_BUILD ?
|
||||
BuildConfig.BuildTimestamp + DAYS.toMillis(90) : Long.MAX_VALUE;
|
||||
BuildConfig.BuildTimestamp + DAYS.toMillis(90)
|
||||
: (IS_OLD_ANDROID ? OLD_ANDROID_EXPIRY_DATE : Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
@@ -75,12 +75,15 @@ import static org.briarproject.bramble.api.plugin.Plugin.State.ENABLING;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.STARTING_STOPPING;
|
||||
import static org.briarproject.briar.android.BriarService.EXTRA_STARTUP_FAILED;
|
||||
import static org.briarproject.briar.android.BriarService.EXTRA_START_RESULT;
|
||||
import static org.briarproject.briar.android.TestingConstants.EXPIRY_DATE;
|
||||
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_PASSWORD;
|
||||
import static org.briarproject.briar.android.navdrawer.IntentRouter.handleExternalIntent;
|
||||
import static org.briarproject.briar.android.util.UiUtils.formatDateFull;
|
||||
import static org.briarproject.briar.android.util.UiUtils.getDaysUntilExpiry;
|
||||
import static org.briarproject.briar.android.util.UiUtils.observeOnce;
|
||||
import static org.briarproject.briar.android.util.UiUtils.resolveColorAttribute;
|
||||
import static org.briarproject.briar.android.util.UiUtils.shouldWarnOldAndroidExpiry;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
@@ -137,9 +140,11 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
setContentView(R.layout.activity_nav_drawer);
|
||||
|
||||
BriarApplication app = (BriarApplication) getApplication();
|
||||
if (IS_DEBUG_BUILD && !app.isInstrumentationTest()) {
|
||||
navDrawerViewModel.showExpiryWarning()
|
||||
.observe(this, this::showExpiryWarning);
|
||||
if (!app.isInstrumentationTest()) {
|
||||
if (IS_DEBUG_BUILD || shouldWarnOldAndroidExpiry()) {
|
||||
navDrawerViewModel.showExpiryWarning()
|
||||
.observe(this, this::showExpiryWarning);
|
||||
}
|
||||
}
|
||||
navDrawerViewModel.shouldAskForDozeWhitelisting().observe(this, ask -> {
|
||||
if (ask) showDozeDialog(getString(R.string.setup_doze_intro));
|
||||
@@ -207,7 +212,9 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
lockManager.checkIfLockable();
|
||||
if (IS_DEBUG_BUILD) navDrawerViewModel.checkExpiryWarning();
|
||||
if (IS_DEBUG_BUILD || shouldWarnOldAndroidExpiry()) {
|
||||
navDrawerViewModel.checkExpiryWarning();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -377,14 +384,23 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
return;
|
||||
}
|
||||
|
||||
String text;
|
||||
if (IS_DEBUG_BUILD) {
|
||||
text = getResources().getQuantityString(
|
||||
R.plurals.expiry_warning, (int) daysUntilExpiry,
|
||||
(int) daysUntilExpiry);
|
||||
} else {
|
||||
text = getResources().getQuantityString(
|
||||
R.plurals.old_android_expiry_warning, (int) daysUntilExpiry,
|
||||
formatDateFull(this, EXPIRY_DATE),
|
||||
(int) daysUntilExpiry);
|
||||
}
|
||||
|
||||
ViewGroup expiryWarning = findViewById(R.id.expiryWarning);
|
||||
if (show) {
|
||||
// show expiry warning text
|
||||
TextView expiryWarningText =
|
||||
expiryWarning.findViewById(R.id.expiryWarningText);
|
||||
String text = getResources().getQuantityString(
|
||||
R.plurals.expiry_warning, (int) daysUntilExpiry,
|
||||
(int) daysUntilExpiry);
|
||||
expiryWarningText.setText(text);
|
||||
// make close button functional
|
||||
ImageView expiryWarningClose =
|
||||
|
||||
@@ -27,6 +27,7 @@ import static java.lang.System.currentTimeMillis;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.briar.android.BriarApplication.ENTRY_ACTIVITY;
|
||||
import static org.briarproject.briar.android.TestingConstants.EXPIRY_DATE;
|
||||
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
@@ -64,7 +65,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
int duration =
|
||||
getResources().getInteger(R.integer.splashScreenDuration);
|
||||
new Handler().postDelayed(() -> {
|
||||
if (currentTimeMillis() >= EXPIRY_DATE) {
|
||||
if (IS_DEBUG_BUILD && currentTimeMillis() >= EXPIRY_DATE) {
|
||||
LOG.info("Expired");
|
||||
startNextActivity(ExpiredActivity.class);
|
||||
} else {
|
||||
|
||||
@@ -110,6 +110,8 @@ import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.briar.BuildConfig.APPLICATION_ID;
|
||||
import static org.briarproject.briar.android.TestingConstants.EXPIRY_DATE;
|
||||
import static org.briarproject.briar.android.TestingConstants.IS_OLD_ANDROID;
|
||||
import static org.briarproject.briar.android.TestingConstants.OLD_ANDROID_WARN_DATE;
|
||||
import static org.briarproject.briar.android.reporting.CrashReportActivity.EXTRA_APP_LOGCAT;
|
||||
import static org.briarproject.briar.android.reporting.CrashReportActivity.EXTRA_APP_START_TIME;
|
||||
import static org.briarproject.briar.android.reporting.CrashReportActivity.EXTRA_INITIAL_COMMENT;
|
||||
@@ -197,6 +199,11 @@ public class UiUtils {
|
||||
return DateUtils.formatDateTime(ctx, time, flags);
|
||||
}
|
||||
|
||||
public static String formatDateFull(Context ctx, long time) {
|
||||
return DateUtils.formatDateTime(ctx, time,
|
||||
FORMAT_SHOW_DATE | FORMAT_SHOW_YEAR | FORMAT_ABBREV_ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the given duration in a human-friendly format. For example,
|
||||
* "7 days" or "1 hour 3 minutes".
|
||||
@@ -232,6 +239,11 @@ public class UiUtils {
|
||||
return (EXPIRY_DATE - now) / DAYS.toMillis(1);
|
||||
}
|
||||
|
||||
public static boolean shouldWarnOldAndroidExpiry() {
|
||||
return IS_OLD_ANDROID &&
|
||||
System.currentTimeMillis() >= OLD_ANDROID_WARN_DATE;
|
||||
}
|
||||
|
||||
public static SpannableStringBuilder getTeaser(Context ctx, Spanned text) {
|
||||
if (text.length() < TEASER_LENGTH)
|
||||
throw new IllegalArgumentException(
|
||||
|
||||
@@ -56,6 +56,10 @@
|
||||
<item quantity="one">This is a test version of Briar. Your account will expire in %d day and cannot be renewed.</item>
|
||||
<item quantity="other">This is a test version of Briar. Your account will expire in %d days and cannot be renewed.</item>
|
||||
</plurals>
|
||||
<plurals name="old_android_expiry_warning">
|
||||
<item quantity="one">Android 4 is no longer supported. Briar will stop working on %s (in %d day). Please install Briar on a newer device and create a new account.</item>
|
||||
<item quantity="other">Android 4 is no longer supported. Briar will stop working on %s (in %d days). Please install Briar on a newer device and create a new account.</item>
|
||||
</plurals>
|
||||
<string name="expiry_date_reached">This software has expired.\nThank you for testing!</string>
|
||||
<string name="download_briar">To continue using Briar, please download the latest release.</string>
|
||||
<string name="create_new_account">You will need to create a new account, but you can use the same nickname.</string>
|
||||
|
||||
Reference in New Issue
Block a user