fix(document_scanner): prevent 'Reply already submitted' on duplicate activity result#858
Closed
MilanJa wants to merge 1 commit into
Closed
Conversation
… activity result `DocumentScanner` stored `MethodChannel.Result` in `pendingResult` and invoked `.success(...)` / `.error(...)` on it without ever clearing the field. When the platform delivers `onActivityResult` more than once for `START_DOCUMENT_ACTIVITY` (observed on Oppo/ColorOS devices via Firebase Crashlytics), the second invocation re-submits on the already-completed reply and throws `IllegalStateException: Reply already submitted`, crashing the host app. Introduce `consumePendingResult()` which atomically returns the current `pendingResult` and nulls the field, and route every submission path (success, cancelled, unknown, invalid-options, intent-sender failures) through it. A redelivered activity result now short-circuits via the null receiver instead of crashing. Fixes flutter-ml#857
|
This PR is stale because it has been open for 14 days with no activity. |
|
This PR was closed because it has been inactive for 14 days since being marked as stale. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes
IllegalStateException: Reply already submittedthrown fromDocumentScanner.handleScanningResult(and the cancel/error paths) when the platform deliversonActivityResultmore than once for the sameSTART_DOCUMENT_ACTIVITYrequest code.Fixes #857.
Root cause
DocumentScannerstores the caller'sMethodChannel.ResultinpendingResultbut never clears the field after completing it:If the OS then redelivers the activity result — which ColorOS (Oppo) is observed to do across certain lifecycle transitions — the second
onActivityResultinvocation calls.success(...)/.error(...)on the already-completedMethodChannel.Result, andDartMessenger$Reply.replythrowsIllegalStateException: Reply already submitted, crashing the host app.Stack trace (abridged) from the linked issue:
Fix
Introduce a
consumePendingResult()helper that atomically returns the currentpendingResultand nulls the field, and route every submission site through it:handleScanningResult(success path)onActivityResultRESULT_CANCELED/ unknown result brancheshandleScannererror paths (invalid options, intent-sender failures)A redelivered activity result now short-circuits via the null receiver (
consumePendingResult()?.xxx(...)) instead of double-submitting.The change is confined to one file:
packages/google_mlkit_document_scanner/android/src/main/kotlin/com/google_mlkit_document_scanner/DocumentScanner.kt(+20/-6).Validation
flutter build apk --debugonpackages/examplecompiles cleanly against the patched Kotlin source..success()/.error(),pendingResultis null and any subsequent callback is a no-op.Suggested CHANGELOG entry (for maintainers)
I did not bump the package version in this PR — leaving that to the maintainer release cadence.
Test plan
flutter build apk --debugonpackages/example— passes.