warn user before build expires

Closes #4322
// FREEBIE
This commit is contained in:
Christian Ascheberg 2015-10-28 15:46:47 +01:00 committed by Moxie Marlinspike
parent b40f0ffeb0
commit 4696837f2f
6 changed files with 63 additions and 8 deletions

View File

@ -1118,8 +1118,14 @@
<string name="text_secure_normal__help">Help</string>
<!-- reminder_header -->
<string name="reminder_header_expired_build">Your build of Signal has expired!</string>
<string name="reminder_header_expired_build_details">Messages will no longer send successfully, please update to the most recent version.</string>
<string name="reminder_header_outdated_build">Your version of Signal is outdated</string>
<plurals name="reminder_header_outdated_build_details">
<item quantity="one">Your version of Signal will expire in 1 day. Tap to update to the most recent version.</item>
<item quantity="other">Your version of Signal will expire in %d days. Tap to update to the most recent version.</item>
</plurals>
<string name="reminder_header_outdated_build_details_today">Your version of Signal will expire today. Tap to update to the most recent version.</string>
<string name="reminder_header_expired_build">Your version of Signal has expired!</string>
<string name="reminder_header_expired_build_details">Messages will no longer send successfully. Tap to update to the most recent version.</string>
<string name="reminder_header_expired_build_button">UPDATE</string>
<string name="reminder_header_sms_default_title">Use as default SMS app</string>
<string name="reminder_header_sms_default_text">Tap to make Signal your default SMS app.</string>

View File

@ -54,6 +54,7 @@ import android.view.ViewGroup;
import org.thoughtcrime.securesms.ConversationListAdapter.ItemClickListener;
import org.thoughtcrime.securesms.components.reminder.DefaultSmsReminder;
import org.thoughtcrime.securesms.components.reminder.ExpiredBuildReminder;
import org.thoughtcrime.securesms.components.reminder.OutdatedBuildReminder;
import org.thoughtcrime.securesms.components.reminder.PushRegistrationReminder;
import org.thoughtcrime.securesms.components.reminder.Reminder;
import org.thoughtcrime.securesms.components.reminder.ReminderView;
@ -166,8 +167,10 @@ public class ConversationListFragment extends Fragment
new AsyncTask<Context, Void, Optional<? extends Reminder>>() {
@Override protected Optional<? extends Reminder> doInBackground(Context... params) {
final Context context = params[0];
if (ExpiredBuildReminder.isEligible(context)) {
if (ExpiredBuildReminder.isEligible()) {
return Optional.of(new ExpiredBuildReminder(context));
} else if (OutdatedBuildReminder.isEligible()) {
return Optional.of(new OutdatedBuildReminder(context));
} else if (DefaultSmsReminder.isEligible(context)) {
return Optional.of(new DefaultSmsReminder(context));
} else if (Util.isDefaultSmsProvider(context) && SystemSmsImportReminder.isEligible(context)) {

View File

@ -31,8 +31,8 @@ public class ExpiredBuildReminder extends Reminder {
return false;
}
public static boolean isEligible(Context context) {
return !Util.isBuildFresh();
public static boolean isEligible() {
return Util.getDaysTillBuildExpiry() <= 0;
}
}

View File

@ -0,0 +1,45 @@
package org.thoughtcrime.securesms.components.reminder;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.util.Util;
public class OutdatedBuildReminder extends Reminder {
public OutdatedBuildReminder(final Context context) {
super(context.getString(R.string.reminder_header_outdated_build),
getPluralsText(context));
setOkListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + context.getPackageName())));
} catch (android.content.ActivityNotFoundException anfe) {
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + context.getPackageName())));
}
}
});
}
private static CharSequence getPluralsText(final Context context) {
int days = Util.getDaysTillBuildExpiry() - 1;
if (days == 0) {
return context.getString(R.string.reminder_header_outdated_build_details_today);
}
return context.getResources().getQuantityString(R.plurals.reminder_header_outdated_build_details, days, days);
}
@Override
public boolean isDismissable() {
return false;
}
public static boolean isEligible() {
return Util.getDaysTillBuildExpiry() <= 10;
}
}

View File

@ -34,7 +34,7 @@ public abstract class SendJob extends MasterSecretJob {
@Override
public final void onRun(MasterSecret masterSecret) throws Exception {
if (!Util.isBuildFresh()) {
if (Util.getDaysTillBuildExpiry() <= 0) {
throw new TextSecureExpiredException(String.format("TextSecure expired (build %d, now %d)",
BuildConfig.BUILD_TIMESTAMP,
System.currentTimeMillis()));

View File

@ -327,8 +327,9 @@ public class Util {
}
}
public static boolean isBuildFresh() {
return BuildConfig.BUILD_TIMESTAMP + TimeUnit.DAYS.toMillis(90) > System.currentTimeMillis();
public static int getDaysTillBuildExpiry() {
int age = (int)TimeUnit.MILLISECONDS.toDays(System.currentTimeMillis() - BuildConfig.BUILD_TIMESTAMP);
return 90 - age;
}
@TargetApi(VERSION_CODES.LOLLIPOP)