Repository navigation
Commit c79bba3
authored
[in_app_purchase_android] Guard async billing callbacks against duplicate listener responses (#12640)
The Play Billing library can invoke the response listener of a single async
call more than once (observed in production via its internal watchdog/timeout
path, `zzaf.run → zzan.run`, with the real response also arriving). A pigeon
reply may only be submitted once; the second completion throws
`IllegalStateException: Reply already submitted` on the main thread and kills
the process.
`startConnection` already guards against a double `onBillingSetupFinished`
with its `alreadyFinished` flag; this PR extends the same protection to the
other 9 async methods via a `replyOnce(methodName, callback)` wrapper — an
`AtomicBoolean.getAndSet(true)` single-shot around the pigeon callback. The
first completion wins; duplicates are dropped with a `Log.d`. Call sites bind
the pigeon parameter as `rawCallback` and rebind `callback` to the wrapper, so
the method bodies are otherwise unchanged and every completion path
(null-client error, null-activity error, listener response, RuntimeException
catch) is single-shot. Listener side effects (`updateCachedProducts`) still
run on dropped duplicates, so if an error response lands first and the real
one second, the product cache still receives real data for a later
`launchBillingFlow`.
Two JUnit regression tests fire a captured listener twice with distinct
results and assert exactly one pigeon completion holding the first result.
*Developed with AI assistance; tested and verified by the submitter.*
Fixes flutter/flutter#191832
Related: flutter/flutter#103432, flutter/flutter#134967
## Pre-Review Checklist
Note: this PR and #12639 both bump the package to 0.5.3; whichever lands
second will be rebased and re-bumped.
[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.1 parent 63bc5cd commit c79bba3
4 files changed
Lines changed: 130 additions & 10 deletions
File tree
- packages/in_app_purchase/in_app_purchase_android
- android/src
- main/java/io/flutter/plugins/inapppurchase
- test/java/io/flutter/plugins/inapppurchase
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
1 | 7 | | |
2 | 8 | | |
3 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
117 | 118 | | |
118 | 119 | | |
119 | 120 | | |
120 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
121 | 124 | | |
122 | 125 | | |
123 | 126 | | |
| |||
141 | 144 | | |
142 | 145 | | |
143 | 146 | | |
144 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
145 | 150 | | |
146 | 151 | | |
147 | 152 | | |
| |||
161 | 166 | | |
162 | 167 | | |
163 | 168 | | |
164 | | - | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
165 | 172 | | |
166 | 173 | | |
167 | 174 | | |
| |||
179 | 186 | | |
180 | 187 | | |
181 | 188 | | |
182 | | - | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
183 | 192 | | |
184 | 193 | | |
185 | 194 | | |
| |||
204 | 213 | | |
205 | 214 | | |
206 | 215 | | |
207 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
208 | 219 | | |
209 | 220 | | |
210 | 221 | | |
| |||
243 | 254 | | |
244 | 255 | | |
245 | 256 | | |
246 | | - | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
247 | 260 | | |
248 | 261 | | |
249 | 262 | | |
| |||
384 | 397 | | |
385 | 398 | | |
386 | 399 | | |
387 | | - | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
388 | 403 | | |
389 | 404 | | |
390 | 405 | | |
| |||
408 | 423 | | |
409 | 424 | | |
410 | 425 | | |
411 | | - | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
412 | 429 | | |
413 | 430 | | |
414 | 431 | | |
| |||
487 | 504 | | |
488 | 505 | | |
489 | 506 | | |
490 | | - | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
491 | 510 | | |
492 | 511 | | |
493 | 512 | | |
| |||
514 | 533 | | |
515 | 534 | | |
516 | 535 | | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
517 | 558 | | |
518 | 559 | | |
519 | 560 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
635 | 635 | | |
636 | 636 | | |
637 | 637 | | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
638 | 680 | | |
639 | 681 | | |
640 | 682 | | |
| |||
1021 | 1063 | | |
1022 | 1064 | | |
1023 | 1065 | | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
1024 | 1092 | | |
1025 | 1093 | | |
1026 | 1094 | | |
| |||
1226 | 1294 | | |
1227 | 1295 | | |
1228 | 1296 | | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
1229 | 1301 | | |
1230 | 1302 | | |
1231 | 1303 | | |
1232 | 1304 | | |
1233 | 1305 | | |
| 1306 | + | |
1234 | 1307 | | |
1235 | 1308 | | |
1236 | 1309 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
0 commit comments