mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-20 11:08:31 +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()
|
BackupMessagesJob.enqueue()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resetInitializedStateAndAuthCredentials() {
|
fun resetInitializedStateAndAuthCredentials() {
|
||||||
SignalStore.backup.backupsInitialized = false
|
SignalStore.backup.backupsInitialized = false
|
||||||
SignalStore.backup.messageCredentials.clearAll()
|
SignalStore.backup.messageCredentials.clearAll()
|
||||||
SignalStore.backup.mediaCredentials.clearAll()
|
SignalStore.backup.mediaCredentials.clearAll()
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ class BackupDeleteJob private constructor(
|
|||||||
|
|
||||||
if (result.isFailure) {
|
if (result.isFailure) {
|
||||||
clearLocalBackupStateOnFailure()
|
clearLocalBackupStateOnFailure()
|
||||||
|
BackupRepository.resetInitializedStateAndAuthCredentials()
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@@ -110,6 +111,7 @@ class BackupDeleteJob private constructor(
|
|||||||
val result = checkResults(results)
|
val result = checkResults(results)
|
||||||
if (result.isSuccess) {
|
if (result.isSuccess) {
|
||||||
Log.i(TAG, "Backup deletion was successful.")
|
Log.i(TAG, "Backup deletion was successful.")
|
||||||
|
BackupRepository.resetInitializedStateAndAuthCredentials()
|
||||||
SignalStore.backup.deletionState = DeletionState.COMPLETE
|
SignalStore.backup.deletionState = DeletionState.COMPLETE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -237,7 +237,8 @@ class InAppPaymentRecurringContextJob private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tier != MessageBackupTier.PAID) {
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import org.whispersystems.signalservice.internal.push.SubscriptionsConfiguration
|
|||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
import java.util.Currency
|
import java.util.Currency
|
||||||
import java.util.Locale
|
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.
|
* 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.")
|
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...")
|
info("Creating a pending payment...")
|
||||||
val id = SignalDatabase.inAppPayments.insert(
|
val id = SignalDatabase.inAppPayments.insert(
|
||||||
type = InAppPaymentType.RECURRING_BACKUP,
|
type = InAppPaymentType.RECURRING_BACKUP,
|
||||||
@@ -129,6 +136,7 @@ class PostRegistrationBackupRedemptionJob : CoroutineJob {
|
|||||||
InAppPaymentPurchaseTokenJob.createJobChain(
|
InAppPaymentPurchaseTokenJob.createJobChain(
|
||||||
inAppPayment = SignalDatabase.inAppPayments.getById(id)!!
|
inAppPayment = SignalDatabase.inAppPayments.getById(id)!!
|
||||||
).enqueue()
|
).enqueue()
|
||||||
|
}
|
||||||
|
|
||||||
return Result.success()
|
return Result.success()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
package org.thoughtcrime.securesms.registration.util;
|
package org.thoughtcrime.securesms.registration.util;
|
||||||
|
|
||||||
import org.signal.core.util.logging.Log;
|
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.backup.v2.MessageBackupTier;
|
||||||
import org.thoughtcrime.securesms.dependencies.AppDependencies;
|
import org.thoughtcrime.securesms.dependencies.AppDependencies;
|
||||||
import org.thoughtcrime.securesms.jobs.ArchiveBackupIdReservationJob;
|
import org.thoughtcrime.securesms.jobs.ArchiveBackupIdReservationJob;
|
||||||
@@ -53,14 +54,13 @@ public final class RegistrationUtil {
|
|||||||
.then(new DirectoryRefreshJob(false))
|
.then(new DirectoryRefreshJob(false))
|
||||||
.enqueue();
|
.enqueue();
|
||||||
|
|
||||||
if (SignalStore.backup().getBackupTier() == MessageBackupTier.PAID) {
|
|
||||||
AppDependencies.getJobManager().add(new PostRegistrationBackupRedemptionJob());
|
|
||||||
}
|
|
||||||
|
|
||||||
SignalStore.emoji().clearSearchIndexMetadata();
|
SignalStore.emoji().clearSearchIndexMetadata();
|
||||||
EmojiSearchIndexDownloadJob.scheduleImmediately();
|
EmojiSearchIndexDownloadJob.scheduleImmediately();
|
||||||
|
|
||||||
|
|
||||||
|
BackupRepository.INSTANCE.resetInitializedStateAndAuthCredentials();
|
||||||
AppDependencies.getJobManager().add(new ArchiveBackupIdReservationJob());
|
AppDependencies.getJobManager().add(new ArchiveBackupIdReservationJob());
|
||||||
|
AppDependencies.getJobManager().add(new PostRegistrationBackupRedemptionJob());
|
||||||
|
|
||||||
} else if (!SignalStore.registration().isRegistrationComplete()) {
|
} else if (!SignalStore.registration().isRegistrationComplete()) {
|
||||||
Log.i(TAG, "Registration is not yet complete.", new Throwable());
|
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.isEmpty
|
||||||
import assertk.assertions.isEqualTo
|
import assertk.assertions.isEqualTo
|
||||||
import io.mockk.every
|
import io.mockk.every
|
||||||
|
import io.mockk.mockk
|
||||||
import io.mockk.mockkObject
|
import io.mockk.mockkObject
|
||||||
import io.mockk.mockkStatic
|
import io.mockk.mockkStatic
|
||||||
import io.mockk.unmockkAll
|
import io.mockk.unmockkAll
|
||||||
@@ -57,6 +58,14 @@ class RegistrationUtilTest {
|
|||||||
initialize(logRecorder)
|
initialize(logRecorder)
|
||||||
|
|
||||||
every { SignalStore.backup.backupTier } returns null
|
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
|
@After
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ fun setupWebView(
|
|||||||
}
|
}
|
||||||
|
|
||||||
copyButton.setOnClickListener { // In Signal app, use Util.writeTextToClipboard(context, value) instead
|
copyButton.setOnClickListener { // In Signal app, use Util.writeTextToClipboard(context, value) instead
|
||||||
webview.evaluateJavascript ("editor.getValue();") { value ->
|
webview.evaluateJavascript("editor.getValue();") { value ->
|
||||||
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||||
val clip = ClipData.newPlainText(context.getString(R.string.app_name), value)
|
val clip = ClipData.newPlainText(context.getString(R.string.app_name), value)
|
||||||
clipboard.setPrimaryClip(clip)
|
clipboard.setPrimaryClip(clip)
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ object DebugLogsViewer {
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun onCopy(webview: WebView, context: Context, appName: String) {
|
fun onCopy(webview: WebView, context: Context, appName: String) {
|
||||||
webview.evaluateJavascript ("editor.getValue();") { value ->
|
webview.evaluateJavascript("editor.getValue();") { value ->
|
||||||
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||||
val clip = ClipData.newPlainText(appName, value)
|
val clip = ClipData.newPlainText(appName, value)
|
||||||
clipboard.setPrimaryClip(clip)
|
clipboard.setPrimaryClip(clip)
|
||||||
|
|||||||
Reference in New Issue
Block a user