fix: Import cloud-backed PKPASS files off the main thread - #3282
fix: Import cloud-backed PKPASS files off the main thread#3282mvanhorn wants to merge 4 commits into
Conversation
|
I guess this makes some sense but I have some notes:
|
…failure toasts - Route image/PDF/pkpass/espass imports through one background importFile - Restore errorReadingFile / errorReadingImage / noBarcodeFound toasts via a main-looper-marshalling showToast helper - Replace fixed-timeout awaits in the activity tests with a waitFor predicate
…read launch(Dispatchers.IO) starts the coroutine on a background thread immediately, so a paused Robolectric main looper never drives it and the activity tests time out. Launch on the lifecycle scope's default (main) dispatcher and wrap only the blocking read in withContext(Dispatchers.IO).
Two separate bugs, both in the tests I added: - new Intent(ACTION_VIEW, uri).setType(...) clears the data URI (setType and setData clear each other), so the activity received a null Uri and the read never started. Use setDataAndType. - The intermediate-state assertions (no started activity / RESULT_CANCELED) are not observable: waiting on the main looper drains it, and Robolectric drains it again during .visible(), so the import has already run to completion by the time the test regains control. Assert the off-main-thread read directly instead, which is the property these tests exist to prove.
|
All three notes addressed, CI is green.
Unrelated: LoyaltyCardViewActivityTest.startWithLoyaltyCardNoExpirySetExpiry fails locally at a date rollover (expects "August 26" and gets "August 25"). It fails the same way on the base branch without my changes, so it is not from this PR, but you may want to pin a clock in that test. |
Keep
PkpassParser,PkpassesParser, and the existing synchronous parsing utilities as the parsing boundary, but invoke PKPASS and PKPASSES work from lifecycle-scoped coroutines onDispatchers.IOin both production entry points. PKPASS imports opened through a cloud-backed Android document provider can require network access whileContentResolver.openInputStreamis resolving the URI.Opening a valid
.pkpassthroughMainActivitywith a content stream that records its caller reads the provider stream off the main looper, then processes the parsed result on the main thread; Returning a valid.pkpassfromScanActivity's picker reads and parses off the main looper, then delivers the selected result while UI/scanner state changes remain on the main thread.Fixes #2464