Make build deprecation more resilient to clock skew.

This commit is contained in:
Greyson Parrelli
2024-06-06 10:14:09 -04:00
committed by Alex Hart
parent f572eb5322
commit 3ff218f9c6
11 changed files with 122 additions and 13 deletions

View File

@@ -19,12 +19,20 @@ public final class RemoteDeprecation {
private RemoteDeprecation() { }
/**
* @return The amount of time (in milliseconds) until this client version expires, or -1 if
* there's no pending expiration.
*/
public static long getTimeUntilDeprecation(long currentTime) {
return getTimeUntilDeprecation(FeatureFlags.clientExpiration(), currentTime, BuildConfig.VERSION_NAME);
}
/**
* @return The amount of time (in milliseconds) until this client version expires, or -1 if
* there's no pending expiration.
*/
public static long getTimeUntilDeprecation() {
return getTimeUntilDeprecation(FeatureFlags.clientExpiration(), System.currentTimeMillis(), BuildConfig.VERSION_NAME);
return getTimeUntilDeprecation(System.currentTimeMillis());
}
/**

View File

@@ -349,14 +349,14 @@ public class Util {
* @return The amount of time (in ms) until this build of Signal will be considered 'expired'.
* Takes into account both the build age as well as any remote deprecation values.
*/
public static long getTimeUntilBuildExpiry() {
public static long getTimeUntilBuildExpiry(long currentTime) {
if (SignalStore.misc().isClientDeprecated()) {
return 0;
}
long buildAge = System.currentTimeMillis() - BuildConfig.BUILD_TIMESTAMP;
long buildAge = currentTime - BuildConfig.BUILD_TIMESTAMP;
long timeUntilBuildDeprecation = BUILD_LIFESPAN - buildAge;
long timeUntilRemoteDeprecation = RemoteDeprecation.getTimeUntilDeprecation();
long timeUntilRemoteDeprecation = RemoteDeprecation.getTimeUntilDeprecation(currentTime);
if (timeUntilRemoteDeprecation != -1) {
long timeUntilDeprecation = Math.min(timeUntilBuildDeprecation, timeUntilRemoteDeprecation);

View File

@@ -24,7 +24,7 @@ object VersionTracker {
val lastVersionCode = TextSecurePreferences.getLastVersionCode(context)
if (currentVersionCode != lastVersionCode) {
Log.i(TAG, "Upgraded from $lastVersionCode to $currentVersionCode")
Log.i(TAG, "Upgraded from $lastVersionCode to $currentVersionCode. Clearing client deprecation.", true)
SignalStore.misc().isClientDeprecated = false
val jobChain = listOf(RemoteConfigRefreshJob(), RefreshAttributesJob())
AppDependencies.jobManager.startChain(jobChain).enqueue()