Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent multiple invocations of final result #5749

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## XX.XX.XX - 2022-XX-XX

* [FIXED][5749](https://github.com/stripe/stripe-android/pull/5749) Prevent multiple invocations to `/verify_frames`

## 20.15.2 - 2022-10-25

This release fixes a few bugs in `PaymentSession`, `PaymentSheet` and `CardScan`.
Expand Down Expand Up @@ -41,7 +43,7 @@ This release adds Link as a payment method to the SDK and fixes a minor issue wi

### CardScan

* [CHANGED][5679](https://github.com/stripe/stripe-android/pull/5679) Fix oversized verification_frames payloads leading to failed scans.
* [FIXED][5679](https://github.com/stripe/stripe-android/pull/5679) Fix oversized verification_frames payloads leading to failed scans.

## 20.14.1 - 2022-10-03

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import com.stripe.android.camera.framework.util.FrameRateTracker
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.withContext

/**
Expand Down Expand Up @@ -98,6 +100,8 @@ abstract class ResultAggregator<
) : StatefulResultHandler<DataFrame, State, AnalyzerResult, Boolean>(initialState),
LifecycleEventObserver {

private val finalResultMutex = Mutex()

private var isCanceled = false
private var isPaused = false
private var isFinished = false
Expand Down Expand Up @@ -178,16 +182,19 @@ abstract class ResultAggregator<
else -> withContext(Dispatchers.Default) {
frameRateTracker.trackFrameProcessed()

val (interimResult, finalResult) = aggregateResult(data, result)
finalResultMutex.withLock {
val (interimResult, finalResult) = aggregateResult(data, result)

launch { listener.onInterimResult(interimResult) }
aggregatorExecutionStats?.trackResult("frame_processed")

aggregatorExecutionStats?.trackResult("frame_processed")
launch { listener.onInterimResult(interimResult) }

finalResult?.also {
isFinished = true
launch { listener.onResult(it) }
} != null
if (!isFinished && finalResult != null) {
isFinished = true
launch { listener.onResult(finalResult) }
}
isFinished
}
}
}

Expand Down