Files
Android/app
Matt Van HornandMatt Van Horn f3424b716d fix: Import cloud-backed PKPASS files off the main thread (#3282)
* fix: Import cloud-backed PKPASS files off the main thread

Fixes #2464

* Address review: move all import parsing off the main thread, restore 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

* Start the import coroutine on the main dispatcher, hop to IO for the 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).

* Fix the two failing import tests

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.

* fix: make showToast reusable with a caller-supplied duration

Take the toast length as a parameter instead of hardcoding LENGTH_LONG, so
the helper can serve short toasts too, and document why it exists: it shows
the toast directly when already on the main looper and otherwise posts it
there, which is what the off-main-thread import path needs.

Reorders the modifiers to the file's `static private` convention.

All existing call sites pass LENGTH_LONG, so behavior is unchanged.

---------

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
2026-09-05 12:31:04 +02:00
..
2026-08-12 18:56:26 +02:00
2025-10-04 14:11:42 +02:00