Fix checks in backup subscription check job.

This commit is contained in:
Alex Hart
2025-03-07 11:25:50 -04:00
committed by Michelle Tang
parent c38342e2fb
commit 3fee68e33e
3 changed files with 17 additions and 7 deletions

View File

@@ -259,6 +259,7 @@ class MessageBackupsFlowViewModel(
val inAppPayment = SignalDatabase.inAppPayments.getById(inAppPaymentId)!!
SignalDatabase.inAppPayments.update(
inAppPayment.copy(
state = InAppPaymentTable.State.PENDING,
subscriberId = InAppPaymentsRepository.requireSubscriber(InAppPaymentSubscriberRecord.Type.BACKUP).subscriberId,
data = inAppPayment.data.copy(
redemption = inAppPayment.data.redemption!!.copy(

View File

@@ -78,12 +78,6 @@ class BackupSubscriptionCheckJob private constructor(parameters: Parameters) : C
return Result.success()
}
if (!SignalStore.backup.areBackupsEnabled) {
Log.i(TAG, "Backups are not enabled on this device. Clearing mismatch value and exiting.")
SignalStore.backup.subscriptionStateMismatchDetected = false
return Result.success()
}
if (!AppDependencies.billingApi.isApiAvailable()) {
Log.i(TAG, "Google Play Billing API is not available on this device. Clearing mismatch value and exiting.")
SignalStore.backup.subscriptionStateMismatchDetected = false
@@ -91,6 +85,8 @@ class BackupSubscriptionCheckJob private constructor(parameters: Parameters) : C
}
val purchase: BillingPurchaseResult = AppDependencies.billingApi.queryPurchases()
Log.i(TAG, "Retrieved purchase result from Billing api: $purchase")
val hasActivePurchase = purchase is BillingPurchaseResult.Success && purchase.isAcknowledged && purchase.isWithinTheLastMonth()
val product: BillingProduct? = AppDependencies.billingApi.queryProduct()

View File

@@ -29,7 +29,20 @@ sealed interface BillingPurchaseResult {
val oneMonthAgo = now - 31.days
val purchaseTime = this.purchaseTime.milliseconds
return oneMonthAgo >= purchaseTime
return oneMonthAgo < purchaseTime
}
override fun toString(): String {
return """
BillingPurchaseResult {
purchaseState: $purchaseState
purchaseToken: <redacted>
purchaseTime: $purchaseTime
isAcknowledged: $isAcknowledged
isAutoRenewing: $isAutoRenewing
isWithinTheLastMonth: ${isWithinTheLastMonth()}
}
""".trimIndent()
}
}
data object UserCancelled : BillingPurchaseResult