Quiet down auth check job.

This commit is contained in:
Alex Hart
2024-06-21 15:28:58 -03:00
committed by Greyson Parrelli
parent 16c8b88f0f
commit 57a70c3085
3 changed files with 16 additions and 2 deletions

View File

@@ -238,11 +238,11 @@ public class ApplicationContext extends MultiDexApplication implements AppForegr
AppDependencies.getMegaphoneRepository().onAppForegrounded(); AppDependencies.getMegaphoneRepository().onAppForegrounded();
AppDependencies.getDeadlockDetector().start(); AppDependencies.getDeadlockDetector().start();
InAppPaymentKeepAliveJob.enqueueAndTrackTimeIfNecessary(); InAppPaymentKeepAliveJob.enqueueAndTrackTimeIfNecessary();
AppDependencies.getJobManager().add(new InAppPaymentAuthCheckJob());
FcmFetchManager.onForeground(this); FcmFetchManager.onForeground(this);
startAnrDetector(); startAnrDetector();
SignalExecutors.BOUNDED.execute(() -> { SignalExecutors.BOUNDED.execute(() -> {
InAppPaymentAuthCheckJob.enqueueIfNeeded();
RemoteConfig.refreshIfNecessary(); RemoteConfig.refreshIfNecessary();
RetrieveProfileJob.enqueueRoutineFetchIfNecessary(); RetrieveProfileJob.enqueueRoutineFetchIfNecessary();
executePendingContactSync(); executePendingContactSync();

View File

@@ -162,6 +162,13 @@ class InAppPaymentTable(context: Context, databaseHelper: SignalDatabase) : Data
AppDependencies.databaseObserver.notifyInAppPaymentsObservers(inAppPayment) AppDependencies.databaseObserver.notifyInAppPaymentsObservers(inAppPayment)
} }
fun hasWaitingForAuth(): Boolean {
return readableDatabase
.exists(TABLE_NAME)
.where("$STATE = ?", State.serialize(State.WAITING_FOR_AUTHORIZATION))
.run()
}
fun getAllWaitingForAuth(): List<InAppPayment> { fun getAllWaitingForAuth(): List<InAppPayment> {
return readableDatabase.select() return readableDatabase.select()
.from(TABLE_NAME) .from(TABLE_NAME)

View File

@@ -39,7 +39,7 @@ import kotlin.time.Duration.Companion.days
*/ */
class InAppPaymentAuthCheckJob private constructor(parameters: Parameters) : BaseJob(parameters), StripeApi.PaymentIntentFetcher, StripeApi.SetupIntentHelper { class InAppPaymentAuthCheckJob private constructor(parameters: Parameters) : BaseJob(parameters), StripeApi.PaymentIntentFetcher, StripeApi.SetupIntentHelper {
constructor() : this( private constructor() : this(
Parameters.Builder() Parameters.Builder()
.addConstraint(NetworkConstraint.KEY) .addConstraint(NetworkConstraint.KEY)
.setMaxAttempts(Parameters.UNLIMITED) .setMaxAttempts(Parameters.UNLIMITED)
@@ -51,6 +51,13 @@ class InAppPaymentAuthCheckJob private constructor(parameters: Parameters) : Bas
companion object { companion object {
private val TAG = Log.tag(InAppPaymentAuthCheckJob::class.java) private val TAG = Log.tag(InAppPaymentAuthCheckJob::class.java)
const val KEY = "InAppPaymentAuthCheckJob" const val KEY = "InAppPaymentAuthCheckJob"
@JvmStatic
fun enqueueIfNeeded() {
if (SignalDatabase.inAppPayments.hasWaitingForAuth()) {
AppDependencies.jobManager.add(InAppPaymentAuthCheckJob())
}
}
} }
private val stripeApi = StripeApi(Environment.Donations.STRIPE_CONFIGURATION, this, this, AppDependencies.okHttpClient) private val stripeApi = StripeApi(Environment.Donations.STRIPE_CONFIGURATION, this, this, AppDependencies.okHttpClient)