From d7221a384b129e1876b6f781068abc57dfb48d5d Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Tue, 11 Feb 2025 16:15:38 -0400 Subject: [PATCH] Add check for authorized job. Fix issue with start external activity error propagation. --- .../donate/stripe/Stripe3DSDialogFragment.kt | 27 ++++++++----------- .../jobs/InAppPaymentAuthCheckJob.kt | 2 +- .../jobs/InAppPaymentOneTimeContextJob.kt | 4 +-- .../jobs/InAppPaymentRedemptionJob.kt | 14 +++++++--- app/src/main/protowire/JobData.proto | 1 + 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/donate/stripe/Stripe3DSDialogFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/donate/stripe/Stripe3DSDialogFragment.kt index 3243d78264..8e3e642725 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/donate/stripe/Stripe3DSDialogFragment.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/donate/stripe/Stripe3DSDialogFragment.kt @@ -20,10 +20,8 @@ import androidx.fragment.app.DialogFragment import androidx.fragment.app.setFragmentResult import androidx.navigation.fragment.navArgs import com.google.android.material.button.MaterialButton -import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers -import io.reactivex.rxjava3.core.Completable -import io.reactivex.rxjava3.schedulers.Schedulers import org.signal.core.util.concurrent.LifecycleDisposable +import org.signal.core.util.concurrent.SignalExecutors import org.signal.donations.StripeIntentAccessor import org.thoughtcrime.securesms.R import org.thoughtcrime.securesms.components.ViewBinderDelegate @@ -106,20 +104,17 @@ class Stripe3DSDialogFragment : DialogFragment(R.layout.donation_webview_fragmen } private fun handleLaunchExternal(intent: Intent) { - lifecycleDisposable += Completable - .fromAction { - SignalDatabase.inAppPayments.update(args.inAppPayment) - } - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe { - result = bundleOf( - LAUNCHED_EXTERNAL to true - ) + startActivity(intent) - startActivity(intent) - dismissAllowingStateLoss() - } + SignalExecutors.BOUNDED_IO.execute { + SignalDatabase.inAppPayments.update(args.inAppPayment) + } + + result = bundleOf( + LAUNCHED_EXTERNAL to true + ) + + dismissAllowingStateLoss() } private inner class Stripe3DSWebClient : WebViewClient() { diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/InAppPaymentAuthCheckJob.kt b/app/src/main/java/org/thoughtcrime/securesms/jobs/InAppPaymentAuthCheckJob.kt index 913cd675e8..0f8f5677d1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/InAppPaymentAuthCheckJob.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/InAppPaymentAuthCheckJob.kt @@ -173,7 +173,7 @@ class InAppPaymentAuthCheckJob private constructor(parameters: Parameters) : Bas Log.i(TAG, "Enqueuing job chain.") val updatedPayment = SignalDatabase.inAppPayments.getById(inAppPayment.id) - InAppPaymentOneTimeContextJob.createJobChain(updatedPayment!!).enqueue() + InAppPaymentOneTimeContextJob.createJobChain(updatedPayment!!, isFromAuthCheck = true).enqueue() return CheckResult.Success(Unit) } diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/InAppPaymentOneTimeContextJob.kt b/app/src/main/java/org/thoughtcrime/securesms/jobs/InAppPaymentOneTimeContextJob.kt index db6986d031..af35960523 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/InAppPaymentOneTimeContextJob.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/InAppPaymentOneTimeContextJob.kt @@ -57,12 +57,12 @@ class InAppPaymentOneTimeContextJob private constructor( ) } - fun createJobChain(inAppPayment: InAppPaymentTable.InAppPayment, makePrimary: Boolean = false): Chain { + fun createJobChain(inAppPayment: InAppPaymentTable.InAppPayment, makePrimary: Boolean = false, isFromAuthCheck: Boolean = false): Chain { return when (inAppPayment.type) { InAppPaymentType.ONE_TIME_DONATION -> { AppDependencies.jobManager .startChain(create(inAppPayment)) - .then(InAppPaymentRedemptionJob.create(inAppPayment, makePrimary)) + .then(InAppPaymentRedemptionJob.create(inAppPayment = inAppPayment, makePrimary = makePrimary, isFromAuthCheck = isFromAuthCheck)) .then(RefreshOwnProfileJob()) .then(MultiDeviceProfileContentUpdateJob()) } diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/InAppPaymentRedemptionJob.kt b/app/src/main/java/org/thoughtcrime/securesms/jobs/InAppPaymentRedemptionJob.kt index a2c7b1144a..a68753d5f9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/InAppPaymentRedemptionJob.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/InAppPaymentRedemptionJob.kt @@ -59,12 +59,14 @@ class InAppPaymentRedemptionJob private constructor( fun create( inAppPayment: InAppPaymentTable.InAppPayment? = null, - makePrimary: Boolean = false + makePrimary: Boolean = false, + isFromAuthCheck: Boolean = false ): Job { return create( inAppPayment = inAppPayment, giftMessageId = null, - makePrimary = makePrimary + makePrimary = makePrimary, + isFromAuthCheck = isFromAuthCheck ) } @@ -82,13 +84,15 @@ class InAppPaymentRedemptionJob private constructor( private fun create( inAppPayment: InAppPaymentTable.InAppPayment? = null, makePrimary: Boolean = false, + isFromAuthCheck: Boolean = false, giftMessageId: MessageId? = null ): Job { return InAppPaymentRedemptionJob( jobData = InAppPaymentRedemptionJobData( inAppPaymentId = inAppPayment?.id?.rowId, giftMessageId = giftMessageId?.id, - makePrimary = makePrimary + makePrimary = makePrimary, + isFromAuthCheck = isFromAuthCheck ), parameters = Parameters.Builder() .addConstraint(NetworkConstraint.KEY) @@ -243,9 +247,11 @@ class InAppPaymentRedemptionJob private constructor( ) } - Log.i(TAG, "InAppPayment with ID $inAppPaymentId was successfully redeemed. Response code: ${serviceResponse.status}") + Log.i(TAG, "InAppPayment with ID $inAppPaymentId was successfully redeemed. Response code: ${serviceResponse.status}, Will notify: ${jobData.isFromAuthCheck}") + SignalDatabase.inAppPayments.update( inAppPayment = inAppPayment.copy( + notified = !jobData.isFromAuthCheck, state = InAppPaymentTable.State.END, data = inAppPayment.data.copy( redemption = inAppPayment.data.redemption.copy( diff --git a/app/src/main/protowire/JobData.proto b/app/src/main/protowire/JobData.proto index 8b47990259..c8b40c4412 100644 --- a/app/src/main/protowire/JobData.proto +++ b/app/src/main/protowire/JobData.proto @@ -69,6 +69,7 @@ message InAppPaymentRedemptionJobData { } bool makePrimary = 3; + bool isFromAuthCheck = 4; } message DeleteSyncJobData {