Add internal setting to run KT.

This commit is contained in:
Michelle Tang
2026-02-03 15:14:38 -05:00
parent 0570aaeb6e
commit 989cda6662
5 changed files with 22 additions and 12 deletions

View File

@@ -262,7 +262,7 @@ public class ApplicationContext extends Application implements AppForegroundObse
checkFreeDiskSpace();
MemoryTracker.start();
BackupSubscriptionCheckJob.enqueueIfAble();
CheckKeyTransparencyJob.enqueueIfNecessary();
CheckKeyTransparencyJob.enqueueIfNecessary(true);
AppDependencies.getAuthWebSocket().registerKeepAliveToken(SignalWebSocket.FOREGROUND_KEEPALIVE);
AppDependencies.getUnauthWebSocket().registerKeepAliveToken(SignalWebSocket.FOREGROUND_KEEPALIVE);

View File

@@ -46,6 +46,7 @@ import org.thoughtcrime.securesms.database.model.InAppPaymentSubscriberRecord
import org.thoughtcrime.securesms.database.model.MessageRecord
import org.thoughtcrime.securesms.dependencies.AppDependencies
import org.thoughtcrime.securesms.jobmanager.JobTracker
import org.thoughtcrime.securesms.jobs.CheckKeyTransparencyJob
import org.thoughtcrime.securesms.jobs.DownloadLatestEmojiDataJob
import org.thoughtcrime.securesms.jobs.EmojiSearchIndexDownloadJob
import org.thoughtcrime.securesms.jobs.InAppPaymentKeepAliveJob
@@ -307,6 +308,15 @@ class InternalSettingsFragment : DSLSettingsFragment(R.string.preferences__inter
}
)
clickPref(
title = DSLSettingsText.from("Run self-check key transparency"),
summary = DSLSettingsText.from("Automatically enqueues a job to run KT against yourself without waiting for the elapsed time."),
onClick = {
SignalStore.misc.lastKeyTransparencyTime = 0
CheckKeyTransparencyJob.enqueueIfNecessary(addDelay = false)
}
)
dividerPref()
sectionHeaderPref(DSLSettingsText.from("Logging"))

View File

@@ -5,6 +5,7 @@ import org.signal.libsignal.keytrans.KeyTransparencyException
import org.signal.libsignal.keytrans.VerificationFailedException
import org.signal.libsignal.net.AppExpiredException
import org.signal.libsignal.net.BadRequestError
import org.signal.libsignal.net.ChatServiceException
import org.signal.libsignal.net.KeyTransparency
import org.signal.libsignal.net.NetworkException
import org.signal.libsignal.net.NetworkProtocolException
@@ -33,8 +34,13 @@ class KeyTransparencyApi(private val unauthWebSocket: SignalWebSocket.Unauthenti
onSuccess = { RequestResult.Success(Unit) },
onError = { throwable ->
when (throwable) {
is TimeoutException,
is ServerSideErrorException,
is VerificationFailedException,
is KeyTransparencyException,
is AppExpiredException,
is IllegalArgumentException -> {
RequestResult.NonSuccess(KeyTransparencyError(throwable))
}
is ChatServiceException,
is NetworkException,
is NetworkProtocolException -> {
RequestResult.RetryableNetworkError(throwable, null)
@@ -42,12 +48,6 @@ class KeyTransparencyApi(private val unauthWebSocket: SignalWebSocket.Unauthenti
is RetryLaterException -> {
RequestResult.RetryableNetworkError(throwable, throwable.duration)
}
is VerificationFailedException,
is KeyTransparencyException,
is AppExpiredException,
is IllegalArgumentException -> {
RequestResult.NonSuccess(KeyTransparencyError(throwable))
}
else -> {
RequestResult.ApplicationError(throwable)
}

View File

@@ -41,7 +41,7 @@ class CheckKeyTransparencyJob private constructor(
private val TIME_BETWEEN_CHECK = 7.days
@JvmStatic
fun enqueueIfNecessary() {
fun enqueueIfNecessary(addDelay: Boolean) {
if (!canRunJob()) {
return
}
@@ -54,7 +54,7 @@ class CheckKeyTransparencyJob private constructor(
showFailure = false,
parameters = Parameters.Builder()
.addConstraint(NetworkConstraint.KEY)
.setInitialDelay(5.minutes.inWholeMilliseconds)
.setInitialDelay(if (addDelay) 5.minutes.inWholeMilliseconds else 0.minutes.inWholeMilliseconds)
.setGlobalPriority(Parameters.PRIORITY_LOWER)
.setMaxInstancesForFactory(2)
.build()

View File

@@ -245,7 +245,7 @@ object RegistrationRepository {
PreKeysSyncJob.enqueue()
recipientTable.clearSelfKeyTransparencyData()
CheckKeyTransparencyJob.enqueueIfNecessary()
CheckKeyTransparencyJob.enqueueIfNecessary(addDelay = true)
val jobManager = AppDependencies.jobManager