mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-20 02:58:45 +00:00
Clear auth credentials post restore and when a user disables backups.
This commit is contained in:
committed by
Cody Henthorne
parent
9fd9760264
commit
962375e422
@@ -229,7 +229,7 @@ object BackupRepository {
|
||||
BackupMessagesJob.enqueue()
|
||||
}
|
||||
|
||||
private fun resetInitializedStateAndAuthCredentials() {
|
||||
fun resetInitializedStateAndAuthCredentials() {
|
||||
SignalStore.backup.backupsInitialized = false
|
||||
SignalStore.backup.messageCredentials.clearAll()
|
||||
SignalStore.backup.mediaCredentials.clearAll()
|
||||
|
||||
@@ -56,6 +56,7 @@ class BackupDeleteJob private constructor(
|
||||
|
||||
if (result.isFailure) {
|
||||
clearLocalBackupStateOnFailure()
|
||||
BackupRepository.resetInitializedStateAndAuthCredentials()
|
||||
}
|
||||
|
||||
return result
|
||||
@@ -110,6 +111,7 @@ class BackupDeleteJob private constructor(
|
||||
val result = checkResults(results)
|
||||
if (result.isSuccess) {
|
||||
Log.i(TAG, "Backup deletion was successful.")
|
||||
BackupRepository.resetInitializedStateAndAuthCredentials()
|
||||
SignalStore.backup.deletionState = DeletionState.COMPLETE
|
||||
}
|
||||
|
||||
|
||||
@@ -237,7 +237,8 @@ class InAppPaymentRecurringContextJob private constructor(
|
||||
}
|
||||
|
||||
if (tier != MessageBackupTier.PAID) {
|
||||
warning("ZK credential does not align with entitlement. Forcing a redemption.")
|
||||
warning("ZK credential does not align with entitlement. Clearing backup credentials and forcing a redemption.")
|
||||
BackupRepository.resetInitializedStateAndAuthCredentials()
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.whispersystems.signalservice.internal.push.SubscriptionsConfiguration
|
||||
import java.math.BigDecimal
|
||||
import java.util.Currency
|
||||
import java.util.Locale
|
||||
import kotlin.concurrent.withLock
|
||||
|
||||
/**
|
||||
* Runs after registration to make sure we are on the backup level we expect on this device.
|
||||
@@ -107,6 +108,12 @@ class PostRegistrationBackupRedemptionJob : CoroutineJob {
|
||||
warning("Could not resolve price, using empty price.")
|
||||
}
|
||||
|
||||
InAppPaymentSubscriberRecord.Type.BACKUP.lock.withLock {
|
||||
if (SignalDatabase.inAppPayments.hasPendingBackupRedemption()) {
|
||||
warning("Backup is already pending redemption. Exiting.")
|
||||
return Result.success()
|
||||
}
|
||||
|
||||
info("Creating a pending payment...")
|
||||
val id = SignalDatabase.inAppPayments.insert(
|
||||
type = InAppPaymentType.RECURRING_BACKUP,
|
||||
@@ -129,6 +136,7 @@ class PostRegistrationBackupRedemptionJob : CoroutineJob {
|
||||
InAppPaymentPurchaseTokenJob.createJobChain(
|
||||
inAppPayment = SignalDatabase.inAppPayments.getById(id)!!
|
||||
).enqueue()
|
||||
}
|
||||
|
||||
return Result.success()
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package org.thoughtcrime.securesms.registration.util;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.backup.v2.BackupRepository;
|
||||
import org.thoughtcrime.securesms.backup.v2.MessageBackupTier;
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies;
|
||||
import org.thoughtcrime.securesms.jobs.ArchiveBackupIdReservationJob;
|
||||
@@ -53,14 +54,13 @@ public final class RegistrationUtil {
|
||||
.then(new DirectoryRefreshJob(false))
|
||||
.enqueue();
|
||||
|
||||
if (SignalStore.backup().getBackupTier() == MessageBackupTier.PAID) {
|
||||
AppDependencies.getJobManager().add(new PostRegistrationBackupRedemptionJob());
|
||||
}
|
||||
|
||||
SignalStore.emoji().clearSearchIndexMetadata();
|
||||
EmojiSearchIndexDownloadJob.scheduleImmediately();
|
||||
|
||||
|
||||
BackupRepository.INSTANCE.resetInitializedStateAndAuthCredentials();
|
||||
AppDependencies.getJobManager().add(new ArchiveBackupIdReservationJob());
|
||||
AppDependencies.getJobManager().add(new PostRegistrationBackupRedemptionJob());
|
||||
|
||||
} else if (!SignalStore.registration().isRegistrationComplete()) {
|
||||
Log.i(TAG, "Registration is not yet complete.", new Throwable());
|
||||
|
||||
@@ -13,6 +13,7 @@ import assertk.assertions.hasSize
|
||||
import assertk.assertions.isEmpty
|
||||
import assertk.assertions.isEqualTo
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.mockkObject
|
||||
import io.mockk.mockkStatic
|
||||
import io.mockk.unmockkAll
|
||||
@@ -57,6 +58,14 @@ class RegistrationUtilTest {
|
||||
initialize(logRecorder)
|
||||
|
||||
every { SignalStore.backup.backupTier } returns null
|
||||
every { SignalStore.backup.backupsInitialized = any() } answers { }
|
||||
every { SignalStore.backup.cachedMediaCdnPath = any() } answers { }
|
||||
every { SignalStore.backup.mediaCredentials } returns mockk {
|
||||
every { clearAll() } answers {}
|
||||
}
|
||||
every { SignalStore.backup.messageCredentials } returns mockk {
|
||||
every { clearAll() } answers {}
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
|
||||
Reference in New Issue
Block a user