Regularly run account consistency checks.

This commit is contained in:
Greyson Parrelli 2023-05-23 15:56:23 -04:00 committed by Nicholas
parent 242900e87f
commit 25779d04a6
3 changed files with 21 additions and 0 deletions

View file

@ -48,6 +48,7 @@ import org.thoughtcrime.securesms.dependencies.ApplicationDependencyProvider;
import org.thoughtcrime.securesms.emoji.EmojiSource;
import org.thoughtcrime.securesms.emoji.JumboEmoji;
import org.thoughtcrime.securesms.gcm.FcmJobService;
import org.thoughtcrime.securesms.jobs.AccountConsistencyWorkerJob;
import org.thoughtcrime.securesms.jobs.CheckServiceReachabilityJob;
import org.thoughtcrime.securesms.jobs.DownloadLatestEmojiDataJob;
import org.thoughtcrime.securesms.jobs.EmojiSearchIndexDownloadJob;
@ -211,6 +212,7 @@ public class ApplicationContext extends MultiDexApplication implements AppForegr
.addPostRender(PnpInitializeDevicesJob::enqueueIfNecessary)
.addPostRender(() -> ApplicationDependencies.getExoPlayerPool().getPoolStats().getMaxUnreserved())
.addPostRender(() -> ApplicationDependencies.getRecipientCache().warmUp())
.addPostRender(AccountConsistencyWorkerJob::enqueueIfNecessary)
.execute();
Log.d(TAG, "onCreate() took " + (System.currentTimeMillis() - startTime) + " ms");

View file

@ -1,6 +1,7 @@
package org.thoughtcrime.securesms.jobs
import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
import org.thoughtcrime.securesms.jobmanager.Job
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint
import org.thoughtcrime.securesms.keyvalue.SignalStore
@ -20,6 +21,13 @@ class AccountConsistencyWorkerJob private constructor(parameters: Parameters) :
private val TAG = Log.tag(AccountConsistencyWorkerJob::class.java)
const val KEY = "AccountConsistencyWorkerJob"
@JvmStatic
fun enqueueIfNecessary() {
if (System.currentTimeMillis() - SignalStore.misc().lastConsistencyCheckTime > 3.days.inWholeMilliseconds) {
ApplicationDependencies.getJobManager().add(AccountConsistencyWorkerJob())
}
}
}
constructor() : this(
@ -60,6 +68,8 @@ class AccountConsistencyWorkerJob private constructor(parameters: Parameters) :
} else {
Log.i(TAG, "Everything matched.")
}
SignalStore.misc().lastConsistencyCheckTime = System.currentTimeMillis()
}
override fun onShouldRetry(e: Exception): Boolean {

View file

@ -38,6 +38,7 @@ public final class MiscellaneousValues extends SignalStoreValues {
private static final String USERNAME_QR_CODE_COLOR = "mis.username_qr_color_scheme";
private static final String KEYBOARD_LANDSCAPE_HEIGHT = "misc.keyboard.landscape_height";
private static final String KEYBOARD_PORTRAIT_HEIGHT = "misc.keyboard.protrait_height";
private static final String LAST_CONSISTENCY_CHECK_TIME = "misc.last_consistency_check_time";
MiscellaneousValues(@NonNull KeyValueStore store) {
super(store);
@ -317,4 +318,12 @@ public final class MiscellaneousValues extends SignalStoreValues {
public void setKeyboardPortraitHeight(int height) {
putInteger(KEYBOARD_PORTRAIT_HEIGHT, height);
}
public long getLastConsistencyCheckTime() {
return getLong(LAST_CONSISTENCY_CHECK_TIME, 0);
}
public void setLastConsistencyCheckTime(long time) {
putLong(LAST_CONSISTENCY_CHECK_TIME, time);
}
}