mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 12:38:33 +00:00
Do not retry auth failures in Svr2MirrorJob.
This commit is contained in:
@@ -13,10 +13,12 @@ import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint
|
|||||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||||
import org.thoughtcrime.securesms.pin.SvrRepository
|
import org.thoughtcrime.securesms.pin.SvrRepository
|
||||||
import org.thoughtcrime.securesms.util.FeatureFlags
|
import org.thoughtcrime.securesms.util.FeatureFlags
|
||||||
|
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException
|
||||||
import org.whispersystems.signalservice.api.svr.SecureValueRecovery.BackupResponse
|
import org.whispersystems.signalservice.api.svr.SecureValueRecovery.BackupResponse
|
||||||
import org.whispersystems.signalservice.api.svr.SecureValueRecovery.PinChangeSession
|
import org.whispersystems.signalservice.api.svr.SecureValueRecovery.PinChangeSession
|
||||||
import org.whispersystems.signalservice.api.svr.SecureValueRecoveryV2
|
import org.whispersystems.signalservice.api.svr.SecureValueRecoveryV2
|
||||||
import kotlin.concurrent.withLock
|
import kotlin.concurrent.withLock
|
||||||
|
import kotlin.time.Duration.Companion.days
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures a user's SVR data is written to SVR2.
|
* Ensures a user's SVR data is written to SVR2.
|
||||||
@@ -34,7 +36,7 @@ class Svr2MirrorJob private constructor(parameters: Parameters, private var seri
|
|||||||
constructor() : this(
|
constructor() : this(
|
||||||
Parameters.Builder()
|
Parameters.Builder()
|
||||||
.addConstraint(NetworkConstraint.KEY)
|
.addConstraint(NetworkConstraint.KEY)
|
||||||
.setLifespan(Parameters.IMMORTAL)
|
.setLifespan(30.days.inWholeMilliseconds)
|
||||||
.setMaxAttempts(Parameters.UNLIMITED)
|
.setMaxAttempts(Parameters.UNLIMITED)
|
||||||
.setQueue("Svr2MirrorJob")
|
.setQueue("Svr2MirrorJob")
|
||||||
.setMaxInstancesForFactory(1)
|
.setMaxInstancesForFactory(1)
|
||||||
@@ -86,9 +88,14 @@ class Svr2MirrorJob private constructor(parameters: Parameters, private var seri
|
|||||||
Result.success()
|
Result.success()
|
||||||
}
|
}
|
||||||
is BackupResponse.ApplicationError -> {
|
is BackupResponse.ApplicationError -> {
|
||||||
|
if (response.exception.isUnauthorized()) {
|
||||||
|
Log.w(TAG, "Unauthorized! Giving up.", response.exception)
|
||||||
|
Result.success()
|
||||||
|
} else {
|
||||||
Log.w(TAG, "Hit an application error. Retrying.", response.exception)
|
Log.w(TAG, "Hit an application error. Retrying.", response.exception)
|
||||||
Result.retry(defaultBackoff())
|
Result.retry(defaultBackoff())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
BackupResponse.EnclaveNotFound -> {
|
BackupResponse.EnclaveNotFound -> {
|
||||||
Log.w(TAG, "Could not find the enclave. Giving up.")
|
Log.w(TAG, "Could not find the enclave. Giving up.")
|
||||||
Result.success()
|
Result.success()
|
||||||
@@ -109,6 +116,10 @@ class Svr2MirrorJob private constructor(parameters: Parameters, private var seri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Throwable.isUnauthorized(): Boolean {
|
||||||
|
return this is NonSuccessfulResponseCodeException && this.code == 401
|
||||||
|
}
|
||||||
|
|
||||||
override fun onFailure() = Unit
|
override fun onFailure() = Unit
|
||||||
|
|
||||||
class Factory : Job.Factory<Svr2MirrorJob> {
|
class Factory : Job.Factory<Svr2MirrorJob> {
|
||||||
|
|||||||
Reference in New Issue
Block a user