Add BackupSubscriptionCheckJob.

This commit is contained in:
Alex Hart
2024-10-04 10:39:26 -03:00
committed by Greyson Parrelli
parent 24209756e3
commit 5bc8435d25
10 changed files with 326 additions and 26 deletions

View File

@@ -27,7 +27,7 @@ interface BillingApi {
* Queries the user's current purchases. This enqueues a check and will
* propagate it to the normal callbacks in the api.
*/
suspend fun queryPurchases() = Unit
suspend fun queryPurchases(): BillingPurchaseResult = BillingPurchaseResult.None
suspend fun launchBillingFlow(activity: Activity) = Unit

View File

@@ -5,6 +5,9 @@
package org.signal.core.util.billing
import kotlin.time.Duration.Companion.days
import kotlin.time.Duration.Companion.milliseconds
/**
* Sealed class hierarchy representing the different success
* and error states of google play billing purchases.
@@ -13,8 +16,21 @@ sealed interface BillingPurchaseResult {
data class Success(
val purchaseToken: String,
val isAcknowledged: Boolean,
val purchaseTime: Long
) : BillingPurchaseResult
val purchaseTime: Long,
val isAutoRenewing: Boolean
) : BillingPurchaseResult {
/**
* @return true if purchaseTime is within the last month.
*/
fun isWithinTheLastMonth(): Boolean {
val now = System.currentTimeMillis().milliseconds
val oneMonthAgo = now - 31.days
val purchaseTime = this.purchaseTime.milliseconds
return oneMonthAgo >= purchaseTime
}
}
data object UserCancelled : BillingPurchaseResult
data object None : BillingPurchaseResult
data object TryAgainLater : BillingPurchaseResult