Skip to content

fix(startup): keep screens responsive while a large wallet loads - #1772

Merged
HashEngineering merged 7 commits into
fix/foreground-start-wallet-load-off-mainfrom
fix/wallet-load-screens-stay-responsive
Dec 1, 2026
Merged

HashEngineering merged 7 commits into
fix/foreground-start-wallet-load-off-mainfrom
fix/wallet-load-screens-stay-responsive

Conversation

@HashEngineering

@HashEngineering HashEngineering commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Issue being fixed or feature implemented

Stacked on #1765, which loads the wallet off the main thread on every launch. That PR's blocking review finding: each new activity still waited for the load in WalletApplication.onActivityPreCreated, on the main thread. On a large wallet the wait lasts seconds (a 12.0.2 report: a 61.6 MB wallet file), and a Back press during it starts Android's 5-second "no focused window" timer. That ends in an input-dispatch ANR, which counts toward safe mode.

What was done?

Screens marked with a new WalletLoadAware interface skip the pre-create wait. Before anything reads the wallet they check WalletApplication.isLaunchWalletLoadInProgress(), which never waits. While the load runs:

  • OnboardingActivity (the launcher) is the loading screen. It shows only the splash (its theme's window background), so Back closes it. When the load finishes, either way, it recreates itself and routes as usual.
  • LockScreenActivity (every subclass) and the shortcut screens hand over to it (redirectWhileWalletLoads).
    • A fresh start keeps its intent (a dash: payment link, App Connect, NFC, a shortcut) and opens it on top of the home screen once the wallet is loaded.
    • The intent is kept in WalletApplication memory, never in an extra, because OnboardingActivity is exported. The copy names this app's own component and carries no flags and no ClipData.
    • A screen the system restores after the process died does not hand over: its saved state (SendCoinsActivity's payment under review) is not in its intent. It waits in place, as before this PR.
    • The decision is made before super.onCreate, and a screen that hands over passes a null state. Otherwise saved fragments that read the wallet in onAttach (the address book lists, the network monitor's block list) would block during restore.
    • Back on the loading screen discards the link it was waiting for, up to the moment the recreated screen takes it.
    • When the load ends while the user is in another app, the loading screen waits until it is back in front before it routes on.
  • The transparent link and share handlers wait in place (afterLaunchWalletLoad): WalletUriHandlerActivity, InviteHandlerActivity and ImportSharedImageActivity. A calling app keeps its result, and a share keeps its content grant. After a wait they go on only with their screen in front, and the invite handler routes only in front after reading the invite. WalletUriHandlerActivity.onNewIntent re-handles its first request, as before, so a request still in flight is answered with its own data.
  • Every other screen still waits before it is created, as before. Those are rarely the first screen of a launch.

Known gaps (from the last local review round), tracked in #1777

  1. Restored screens, and screens with a calling app or a content grant, still wait on the main thread. For example, a SendCoinsActivity restored after process death, a payment another app started with BitcoinIntegration.requestForResult(), or a BIP70 content: request. Handing those over would lose the saved payment, cancel the caller's result or drop the grant, so they keep the old behaviour. Fixing it needs a non-blocking wait inside LockScreenActivity while its subclasses run, which is a larger design change.
  2. The pending link is lost if Android kills the process while the loading screen is in the background. It lives in memory only. Keeping it in the loading screen's saved state would fix it.
  3. The link is dropped when routing goes through the one-time security upgrade (AppUpgradeActivity, or SetPinActivity for an unencrypted wallet) instead of straight to MainActivity. It would need to be carried through the upgrade.
  4. A loading screen restored after process death drops its own saved state, for example an open Contact Support dialog after a degraded launch. Rare: it needs a degraded launch, the dialog open, and the process killed and restored while the wallet loads again.

Related PR's and Dependencies

Stacked on #1765; retarget to feat/kotlin-sdk-phase-1 once that merges. Same 12.0.2 report as #1766 and #1767.

Screenshots / Videos

None.

How Has This Been Tested?

  • New tests:

    • the load status and its waiters (a waiter hears the result once the load reads as finished; a removed waiter is not called);
    • the pre-create wait decision;
    • pending-link handover and cancellation;
    • lock-screen handover for fresh and restored screens;
    • no fragment restore while handing over (this test fails without the fix);
    • a screen started for a result keeps its caller;
    • the intent copy and the content-access check;
    • the wait-in-place helper.
  • WalletApplicationStartWalletLoadTest, LockScreenActivityCreateGateTest, WalletLoadAwareEntryTest, RecoveredWalletPersistenceTest, DeferredWalletLoadTest, SafeModeRetryWaitersTest and the invite tests pass on _testNet3Debug. ktlint reports nothing on the changed files.

  • Local pre-review: two rounds before the first push, and two more after thepastaclaw's first review. Fixed from those: callers and grants, fragment restore, cancelled links, restored payments, the Back race at the end of the load, URI results, and navigation while in the background. What the last round still lists is the known gaps above.

  • New tests since the first push: a restored screen waits in place and keeps its saved fragments; a fresh screen hands over and a restored one never does; a load that ends while the user is in another app goes on only once the screen is back in front (fails without the gate).

  • Not tested on a device. Not yet covered:

    • OnboardingActivity's loading path (it can't be built without Hilt in Robolectric);
    • any object injected into the first screen that reads the wallet in its constructor.

    The planned check: cold-start a large testnet wallet and send adb shell input keyevent KEYCODE_BACK during the splash; open a dash: link and an invite link during the load; restore after the process is killed.

  • QA (Mobile Team)

Checklist:

  • I have performed a self-review of my own code and added comments where necessary
  • I have added or updated relevant unit/integration/functional/e2e tests

🤖 Generated with Claude Code

HashEngineering and others added 3 commits November 30, 2026 13:03
Every launch loads the wallet off the main thread, and each new activity
waited for that load in onActivityPreCreated on the main thread. On a large
wallet the wait lasts seconds, and a Back press during it is an
input-dispatch ANR, which counts toward safe mode.

Screens marked WalletLoadAware no longer wait there. They check
isLaunchWalletLoadInProgress() before anything reads the wallet:
- OnboardingActivity shows the splash and recreates itself once the load
  has finished;
- LockScreenActivity (every subclass) and the shortcut screens hand over to
  it, and a fresh start keeps its intent (a payment or App Connect link, a
  shortcut) to open once the wallet is loaded; a restored screen comes back
  on the home screen;
- the transparent link and share handlers wait in place without blocking,
  so a caller's result and a share's grant are kept.
Any other screen still waits before it is created, as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nts restore

Pre-review of the responsive-loading change:
- a screen started for a result, or whose intent carries content access,
  no longer hands over to the loading screen: finishing it would cancel its
  caller's result or drop the grant. It waits for the load as before;
- the hand-over is decided before super.onCreate, which restored saved
  fragments that read the wallet as they attach (the address book's lists,
  the network monitor's block list); a screen that hands over restores none;
- Back on the loading screen discards the link it was waiting to open, so a
  later launch does not open it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…dles

onNewIntent handled getIntent(), which is still the first intent, so a
second link delivered while the wallet loaded was lost and the first one
handled twice.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review: 2

  • feat/kotlin-sdk-phase-.*
  • feat/kotlin-sdk-phase\d+

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@thepastaclaw

thepastaclaw commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

⛔ Final review complete — 2 blocking finding(s) (commit ca17501) · triage: normal

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final validation — Phase 1 + Phase 2

Changes requested: 6 blockers

  • A restored payment request is discarded during cold-start handover — wallet/src/de/schildbach/wallet/ui/LockScreenActivity.kt:201-205 (new)
    Impact: If Android restores SendCoinsActivity after killing the wallet process while its launch load is running, the payment request is replaced by the home screen and any caller receives cancellation instead of the request being reviewed.
  • Back can leave a cancelled entry link queued after loading completes — wallet/src/de/schildbach/wallet/ui/OnboardingActivity.kt:206-214 (new)
    Impact: If the user presses Back after the load callback clears loadingEntryIntent but before the recreated onboarding activity claims the pending intent, the cancelled payment or shortcut can open on a later unrelated launch.
  • The handed-over entry link is lost if the loading process is killed — wallet/src/de/schildbach/wallet/ui/OnboardingActivity.kt:160-168 (new)
    Impact: If Android reclaims the process while the onboarding splash is backgrounded, the recreated wallet opens normally but drops the payment, invite, or shortcut that initiated the launch.
  • External payment screens still freeze while the wallet loads — wallet/src/de/schildbach/wallet/ui/LockScreenActivity.kt:201-214 (new; not shown inline, see below)
    Impact: A payment opened through BitcoinIntegration.requestForResult() or a content-backed request can still block the main thread for the full wallet parse and trigger the startup input-dispatch ANR.
  • Deferred entry links disappear when the one-time security upgrade is required — wallet/src/de/schildbach/wallet/ui/OnboardingActivity.kt:444-449 (new; not shown inline, see below)
    Impact: A payment, App Connect, or shortcut link received during wallet loading is lost when the wallet requires the PIN/security upgrade, so the user reaches an ordinary home screen instead of the requested flow.
  • A second wallet URI can produce a result for the previous URI — wallet/src/de/schildbach/wallet/ui/WalletUriHandlerActivity.kt:63-69 (new; not shown inline, see below)
    Impact: When an existing URI handler receives another payment, master-key, or address request through onNewIntent(), the caller can receive a result containing the first URI's request data even though the second URI was handled.

This change lets selected entry activities avoid the main-thread wallet-load wait and routes fresh launches through a responsive onboarding splash, while preserving caller-sensitive handlers in place. The build and check CI jobs passed, CodeRabbit passed, and the review check is still in progress; no device verification was performed.

🔴 6 blocking

3 finding(s) not shown inline (the lines are not part of this PR's diff)

🔴 Blocking: External payment screens still freeze while the wallet loads
Impact: A payment opened through BitcoinIntegration.requestForResult() or a content-backed request can still block the main thread for the full wallet parse and trigger the startup input-dispatch ANR.
wallet/src/de/schildbach/wallet/ui/LockScreenActivity.kt:201-214

These supported payment flows still become unresponsive during a large-wallet launch. handsOverWhileWalletLoads() deliberately returns false when the activity has a calling activity or carries content access, so the original activity and its result/grant are retained; however, this path then reaches isWalletLoadDegraded and walletData.wallet, both of which synchronously wait for the deferred load, and restored fragments may read the wallet during super.onCreate() even earlier. Keep the original activity and its caller/grants, but add an asynchronous lifecycle-aware readiness path in LockScreenActivity that defers wallet-dependent setup and fragment restoration until the load completes.

source: gpt-6.2-sol (phase2-reviewer: general, security-auditor)

🔴 Blocking: Deferred entry links disappear when the one-time security upgrade is required
Impact: A payment, App Connect, or shortcut link received during wallet loading is lost when the wallet requires the PIN/security upgrade, so the user reaches an ordinary home screen instead of the requested flow.
wallet/src/de/schildbach/wallet/ui/OnboardingActivity.kt:444-449

pendingEntryIntent is consumed only by startMainActivity(). When SecurityGuard.isConfiguredQuickCheck() is false, this branch starts AppUpgradeActivity without transferring the pending entry; AppUpgradeActivity.onCorrectPin() then starts a plain MainActivity, leaving the request stranded in the onboarding instance underneath. Keep the pending entry associated with the upgrade flow and dispatch it exactly once after successful PIN setup, discarding it if the upgrade is cancelled.

source: gpt-6.2-sol (phase2-reviewer: general, security-auditor)

🔴 Blocking: A second wallet URI can produce a result for the previous URI
Impact: When an existing URI handler receives another payment, master-key, or address request through onNewIntent(), the caller can receive a result containing the first URI's request data even though the second URI was handled.
wallet/src/de/schildbach/wallet/ui/WalletUriHandlerActivity.kt:63-69

The new onNewIntent() path passes the delivered intent to handleIntent(), but it never calls setIntent() or otherwise associates the delivered request with the result callbacks. Those callbacks still read intent.data from the activity's original stored intent at lines 67, 182, and 199. Consequently, the second request can be launched while the result is constructed from the first request. Track the request data alongside the specific operation, or update and consistently use the delivered intent for the matching callback.

source: muse-spark-1.3-contributor (phase1-reviewer: general); gpt-6.2-sol (phase2-reviewer: general, security-auditor)

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); reviewer 4: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 5: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.2-sol (effort low) — This is a substantial, cross-cutting Android lifecycle and startup-routing change with concurrency, intent handoff, state restoration, and activity-result behavior, but it does not modify consensus, funds movement, cryptography, key handling, peer-facing deserialization, or storage migrations.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Second Phase-2 pass: on this first full review every Phase-2 reviewer also ran a second, independent time, and the verifier weighed both sets
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — security-auditor (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — security-auditor (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `wallet/src/de/schildbach/wallet/ui/LockScreenActivity.kt`:
- [BLOCKING] wallet/src/de/schildbach/wallet/ui/LockScreenActivity.kt:201-214: External payment screens still freeze while the wallet loads
  Impact: A payment opened through BitcoinIntegration.requestForResult() or a content-backed request can still block the main thread for the full wallet parse and trigger the startup input-dispatch ANR.
  These supported payment flows still become unresponsive during a large-wallet launch. `handsOverWhileWalletLoads()` deliberately returns false when the activity has a calling activity or carries content access, so the original activity and its result/grant are retained; however, this path then reaches `isWalletLoadDegraded` and `walletData.wallet`, both of which synchronously wait for the deferred load, and restored fragments may read the wallet during `super.onCreate()` even earlier. Keep the original activity and its caller/grants, but add an asynchronous lifecycle-aware readiness path in `LockScreenActivity` that defers wallet-dependent setup and fragment restoration until the load completes.
- [BLOCKING] wallet/src/de/schildbach/wallet/ui/LockScreenActivity.kt:201-205: A restored payment request is discarded during cold-start handover
  Impact: If Android restores SendCoinsActivity after killing the wallet process while its launch load is running, the payment request is replaced by the home screen and any caller receives cancellation instead of the request being reviewed.
  The handover branch passes `null` to `super.onCreate()` and sets `keepIntent` from `savedInstanceState == null`. A restored SendCoinsActivity therefore does not pass its saved state to the subclass, which is where `PaymentIntent` is restored, and it does not copy the original intent into the application handoff; `redirectWhileWalletLoads()` then clears the task. Preserve the restored payment state through an asynchronous wait in the original activity, or use a private saved-state-backed handoff that restores the same request without trusting exported launcher extras.

In `wallet/src/de/schildbach/wallet/ui/OnboardingActivity.kt`:
- [BLOCKING] wallet/src/de/schildbach/wallet/ui/OnboardingActivity.kt:444-449: Deferred entry links disappear when the one-time security upgrade is required
  Impact: A payment, App Connect, or shortcut link received during wallet loading is lost when the wallet requires the PIN/security upgrade, so the user reaches an ordinary home screen instead of the requested flow.
  `pendingEntryIntent` is consumed only by `startMainActivity()`. When `SecurityGuard.isConfiguredQuickCheck()` is false, this branch starts `AppUpgradeActivity` without transferring the pending entry; `AppUpgradeActivity.onCorrectPin()` then starts a plain `MainActivity`, leaving the request stranded in the onboarding instance underneath. Keep the pending entry associated with the upgrade flow and dispatch it exactly once after successful PIN setup, discarding it if the upgrade is cancelled.
- [BLOCKING] wallet/src/de/schildbach/wallet/ui/OnboardingActivity.kt:206-214: Back can leave a cancelled entry link queued after loading completes
  Impact: If the user presses Back after the load callback clears `loadingEntryIntent` but before the recreated onboarding activity claims the pending intent, the cancelled payment or shortcut can open on a later unrelated launch.
  The completion callback sets `loadingEntryIntent = null` before calling `recreate()`. If Back finishes the old splash in that window, `onDestroy()` has no identity to pass to `discardPendingEntryIntent()`, so the application-level pending intent remains queued. Retain the cancellation identity until the replacement activity actually claims the entry, and explicitly discard it when Back is handled.
- [BLOCKING] wallet/src/de/schildbach/wallet/ui/OnboardingActivity.kt:160-168: The handed-over entry link is lost if the loading process is killed
  Impact: If Android reclaims the process while the onboarding splash is backgrounded, the recreated wallet opens normally but drops the payment, invite, or shortcut that initiated the launch.
  The handed-over request exists only in `WalletApplication.pendingEntryIntent` and the activity-local `loadingEntryIntent`; neither is saved in instance state or persisted. After process death, the new application has no pending entry, and the recreated onboarding screen therefore takes null at line 221 and routes to home. Persist a sanitized app-owned representation through the loading screen's saved state and restore it into the in-process handoff before normal routing.

In `wallet/src/de/schildbach/wallet/ui/WalletUriHandlerActivity.kt`:
- [BLOCKING] wallet/src/de/schildbach/wallet/ui/WalletUriHandlerActivity.kt:63-69: A second wallet URI can produce a result for the previous URI
  Impact: When an existing URI handler receives another payment, master-key, or address request through onNewIntent(), the caller can receive a result containing the first URI's request data even though the second URI was handled.
  The new `onNewIntent()` path passes the delivered intent to `handleIntent()`, but it never calls `setIntent()` or otherwise associates the delivered request with the result callbacks. Those callbacks still read `intent.data` from the activity's original stored intent at lines 67, 182, and 199. Consequently, the second request can be launched while the result is constructed from the first request. Track the request data alongside the specific operation, or update and consistently use the delivered intent for the matching callback.

Comment on lines +201 to +205
val handOver = handsOverWhileWalletLoads(walletApplicationBeforeInjection())
super.onCreate(if (handOver) null else savedInstanceState)

if (handOver && redirectWhileWalletLoads(walletApplication, keepIntent = savedInstanceState == null)) {
finishedForNoWallet = true

@thepastaclaw thepastaclaw Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Resolved at ca175015; see the replies below.

🔴 Blocking: A restored payment request is discarded during cold-start handover
Impact: If Android restores SendCoinsActivity after killing the wallet process while its launch load is running, the payment request is replaced by the home screen and any caller receives cancellation instead of the request being reviewed.

The handover branch passes null to super.onCreate() and sets keepIntent from savedInstanceState == null. A restored SendCoinsActivity therefore does not pass its saved state to the subclass, which is where PaymentIntent is restored, and it does not copy the original intent into the application handoff; redirectWhileWalletLoads() then clears the task. Preserve the restored payment state through an asynchronous wait in the original activity, or use a private saved-state-backed handoff that restores the same request without trusting exported launcher extras.

source: gpt-6.2-sol (phase2-reviewer: general, security-auditor)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3ad9e98: a screen the system restores no longer hands over. handsOverWhileWalletLoads takes restoring = savedInstanceState != null, so a restored SendCoinsActivity keeps its saved state and its caller and waits in place, as before this PR. Test: while the launch load runs a restored screen waits in place and keeps its saved state. That restored screen still waits on the main thread; that part is known gap 1 in the description.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved (re-reviewed at ca175015): The restoring check you added keeps the original activity and passes the saved bundle through to the payment restoration code. The synchronous wait is separate from the loss of saved payment state.

Comment on lines +206 to +214
if (loading && walletApplication.isLaunchWalletLoadInProgress) {
log.info("the wallet is still loading — showing the splash until it has loaded")
loadingEntryIntent = walletApplication.peekPendingEntryIntent()
afterLaunchWalletLoad(walletApplication) {
// Created again with the wallet loaded: the link it waits for
// now belongs to the new screen.
loadingEntryIntent = null
recreate()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Blocking: Back can leave a cancelled entry link queued after loading completes
Impact: If the user presses Back after the load callback clears loadingEntryIntent but before the recreated onboarding activity claims the pending intent, the cancelled payment or shortcut can open on a later unrelated launch.

The completion callback sets loadingEntryIntent = null before calling recreate(). If Back finishes the old splash in that window, onDestroy() has no identity to pass to discardPendingEntryIntent(), so the application-level pending intent remains queued. Retain the cancellation identity until the replacement activity actually claims the entry, and explicitly discard it when Back is handled.

source: gpt-6.2-sol (phase2-reviewer: general, security-auditor)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3ad9e98: the load callback no longer clears loadingEntryIntent before recreate(). The identity stays set until the recreated screen takes the link, so a Back that finishes the splash in between still discards it in onDestroy; recreate() is not a finish, so it discards nothing. Since ca17501 the recreation also waits until the screen is in front.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still applies (re-reviewed at ca175015): Keeping the cancellation identity fixes the case where finishing wins, but the resumed check does not make Android's Back finish synchronous. The framework can post the finish behind the relaunch, so the replacement can still claim the link before the old instance sees isFinishing.

Comment on lines +160 to +168
/** The intent of a screen that handed over to this one while the wallet loaded. See [onCreate]. */
private var pendingEntryIntent: Intent? = null

/**
* On the loading screen: the pending entry intent it is waiting to open.
* Discarded when the user closes the loading screen (Back), so the link
* does not open on a later, unrelated launch.
*/
private var loadingEntryIntent: Intent? = null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Blocking: The handed-over entry link is lost if the loading process is killed
Impact: If Android reclaims the process while the onboarding splash is backgrounded, the recreated wallet opens normally but drops the payment, invite, or shortcut that initiated the launch.

The handed-over request exists only in WalletApplication.pendingEntryIntent and the activity-local loadingEntryIntent; neither is saved in instance state or persisted. After process death, the new application has no pending entry, and the recreated onboarding screen therefore takes null at line 221 and routes to home. Persist a sanitized app-owned representation through the loading screen's saved state and restore it into the in-process handoff before normal routing.

source: muse-spark-1.3-contributor (phase1-reviewer: general); gpt-6.2-sol (phase2-reviewer: general, security-auditor)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deferred to #1777 (section 2): keeping the handed-over link through process death needs a saved-state hand-off on the loading screen, a new mechanism outside this PR's scope. Listed as known gap 2 in the description.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still applies (re-reviewed at ca175015): Section 2 of #1777 describes the right saved-state follow-up, but the new task replacement is what removes Android's original entry intent, and waiting for resume extends the memory-only window. I’ve lowered this to a suggestion because the user can reopen the link and no payment was submitted.

HashEngineering and others added 3 commits November 30, 2026 16:44
…let-load-screens-stay-responsive

# Conflicts:
#	wallet/test/de/schildbach/wallet/WalletApplicationStartWalletLoadTest.kt
…d link is the one answered

- A screen the system restores (a payment under review after the process
  died) no longer hands over to the loading screen: its saved state is not
  in its intent. It waits in place, as before.
- The loading screen keeps its link's identity until the recreated screen
  takes it, so a Back in between still discards the link.
- WalletUriHandlerActivity makes a delivered request its intent when it
  handles it, so the result callbacks answer that request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lash routes only in front

- WalletUriHandlerActivity.onNewIntent handles getIntent() again, as before
  the wallet-load wait: a request still in flight is answered with its own
  data, never a later request's.
- The loading screen recreates itself only once resumed, so a load that ends
  after the user switched apps does not bring the wallet back over them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@HashEngineering

Copy link
Copy Markdown
Collaborator Author

QA run 56 — PASS, including the mid-load link

Tested on a wallet whose parse takes ~4 seconds (73,724,772 bytes), which is what makes the race reachable at all.

Screens stay usable while it loads

Cold start: the wallet is handed off 38 ms in, parsed on [wallet-load] in 3.989 s, and MAIN_UI_SHOWN lands at +4992 ms. The lock screen was already up and rendering at +7 s. No ANR, no skipped-frame warnings.

A link delivered to a waiting handler

This is the commit I wanted to see fail and couldn't. Force-stop, launch, then fire the link 1,256 ms into the 4-second parse — the window where there is no wallet yet to hand it to:

adb shell am start -a android.intent.action.VIEW \
  -d "dash:yjSvwyLB5X4dqQqVMPMu6UdrFpYZ3u9v5U?amount=0.001"

After the load finished, the Send screen carried exactly that payee and amount:

Send to  yjSvwyLB5X4dqQqVMPMu6UdrFpYZ3u9v5U
0.001    $ 0.04

Not dropped, not substituted, not a stale intent. Backed out with BACK without sending; nothing was broadcast (0 matches for any broadcast marker).

Run twice, on both the int42 and the final int43 cut — the link arrived intact at +1322 ms and +1256 ms respectively.

This PR carries #1765, so the two merged as one.


QA run 56, 2026-11-30. Build 12000305 (12.0.3-qa05), branch qa/integration-12.0.3-qa05
off feat/kotlin-sdk-phase-1 @ 19ec4858dd — twelve PRs in ten merges, no conflicts.
Pins: Kotlin SDK 5.1.0-int43-20261126.183836-1, dashj-platform 5.1.0, dashj 24.0.0 — the
same pairing the shipped 12.0.3 builds use. APK sha256
76d464966bcad134c9e5360d8524ae5fb2850b46f6d9e23f83f9d0d08d56a2c3.
Unit tests 4,841 / 330 classes, 2 failures, both reproduced on the bare base.
Devices: Android 16 emulators, testnet at Platform protocol 15.

afterLaunchWalletLoad runs its callback, after a wait, only once the screen
is resumed, and InviteHandlerActivity routes only in front after reading
the invite: a load that ends while the user is in another app no longer
brings the wallet back over it. OnboardingActivity's own gate moves into
the helper.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@HashEngineering

Copy link
Copy Markdown
Collaborator Author

Fixed in 56579b3: "A second wallet URI can produce a result for the previous URI" (WalletUriHandlerActivity.kt). onNewIntent re-handles getIntent() again, as before this PR, still after the wallet load. The result callbacks read getIntent().data, so every result is built from the request that was handled, including one still in flight (an address being generated). The earlier setIntent alternative would have answered an in-flight request with a later one's data.

Also in ca17501 (from a local review round): after a wait, the deferred handlers and the loading screen go on only with their screen in front, so a load that ends while the user is in another app no longer brings the wallet back over it.

@HashEngineering

Copy link
Copy Markdown
Collaborator Author

Deferred to #1777, as new mechanisms outside this PR's scope (known gaps 1 and 3 in the description):

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 1 + Phase 2

Changes requested: 2 blockers

  • A second wallet URI can replay or cancel the first request during a cold start — wallet/src/de/schildbach/wallet/ui/WalletUriHandlerActivity.kt:78-101 (new; not shown inline, see below)
    Impact: A user whose app redelivers a URI to a waiting wallet handler can lose the first request or see two send screens for it and pay twice if they approve both.
  • Back can leave a cancelled entry link queued after loading completes — wallet/src/de/schildbach/wallet/ui/OnboardingActivity.kt:208-225 (thread, carried)
    Impact: A user who presses Back on the loading splash as the wallet finishes loading can still see the payment or shortcut they cancelled open.

New on this head: This revision keeps restored payment screens in place, ties wallet URI results to the original request, and waits for deferred screens to resume before navigating. The build and check jobs passed on the assigned head; CodeRabbit was skipped for this base branch, and PastaClaw review was pending.

🔴 2 blocking | 🟡 2 suggestion(s)

1 finding(s) not shown inline (the lines are not part of this PR's diff)

🔴 Blocking: A second wallet URI can replay or cancel the first request during a cold start
Impact: A user whose app redelivers a URI to a waiting wallet handler can lose the first request or see two send screens for it and pay twice if they approve both.
wallet/src/de/schildbach/wallet/ui/WalletUriHandlerActivity.kt:78-101

One payment request can produce two send screens or close without being shown. The exported handler can receive another delivery on the same top instance via FLAG_ACTIVITY_SINGLE_TOP. During the load, onCreate() and onNewIntent() both register callbacks, and since 56579b30f both dispatch the original intent. If the handler is resumed at completion, both callbacks can run in the same main-thread delivery before the first child launch pauses it. Neither launch marks the request as dispatched, and each send activity has its own confirmation and send guard. Conversely, since ca1750158, if the handler is paused when the load finishes, the first callback still awaits resume. Android can deliver a new intent before resume, for example to the top activity while the device is asleep. That delivery skips the wait because the application load is done, but the activity's wallet field is still null, so it finishes with RESULT_CANCELED. Keep the original intent for result construction and use one pending/in-flight state so only the initialization callback can dispatch it, at most once.

Confirmed by an independent pass: An exported WalletUriHandlerActivity can receive a second ACTION_VIEW with FLAG_ACTIVITY_SINGLE_TOP while the first instance is waiting for the launch wallet load, registering two completion callbacks. When the load finishes while the handler is resumed, both callbacks can execute before the activity pauses and each calls handleIntent(getIntent()), launching duplicate SendCoinsActivity instances for the same request; alternatively, if completion occurs while the handler is paused, a subsequent onNewIntent sees the load as finished and calls handleIntent immediately while wallet is still null, causing RESULT_CANCELED and losing the request.

source: gpt-6.2-sol (phase2-reviewer: general, security-auditor)

Still open from earlier rounds (2)

  • 🔴 Blocking: Back can leave a cancelled entry link queued after loading completes — wallet/src/de/schildbach/wallet/ui/OnboardingActivity.kt:208-225 (thread)
  • 🟡 Suggestion: The handed-over entry link is lost if the loading process is killed — wallet/src/de/schildbach/wallet/ui/OnboardingActivity.kt:206-225 (thread)
Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.2-sol (effort low) — This is a substantial, cross-cutting Android lifecycle and startup-flow change with concurrency, state restoration, intent routing, and UI responsiveness implications, but it does not modify funds movement, cryptography, key handling, consensus, peer-facing deserialization, or storage migrations.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • New since the last final review (57d075c0): 1 new blocker(s) went to an independent confirmation pass (the final verifier's model in a fresh session, without its reasoning): 1 confirmed
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — security-auditor (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `wallet/src/de/schildbach/wallet/ui/WalletUriHandlerActivity.kt`:
- [BLOCKING] wallet/src/de/schildbach/wallet/ui/WalletUriHandlerActivity.kt:78-101: A second wallet URI can replay or cancel the first request during a cold start
  Impact: A user whose app redelivers a URI to a waiting wallet handler can lose the first request or see two send screens for it and pay twice if they approve both.
  One payment request can produce two send screens or close without being shown. The exported handler can receive another delivery on the same top instance via `FLAG_ACTIVITY_SINGLE_TOP`. During the load, `onCreate()` and `onNewIntent()` both register callbacks, and since `56579b30f` both dispatch the original intent. If the handler is resumed at completion, both callbacks can run in the same main-thread delivery before the first child launch pauses it. Neither launch marks the request as dispatched, and each send activity has its own confirmation and send guard. Conversely, since `ca1750158`, if the handler is paused when the load finishes, the first callback still awaits resume. Android can deliver a new intent before resume, for example to the top activity while the device is asleep. That delivery skips the wait because the application load is done, but the activity's `wallet` field is still null, so it finishes with `RESULT_CANCELED`. Keep the original intent for result construction and use one pending/in-flight state so only the initialization callback can dispatch it, at most once.

  _Confirmed by an independent pass: An exported WalletUriHandlerActivity can receive a second ACTION_VIEW with FLAG_ACTIVITY_SINGLE_TOP while the first instance is waiting for the launch wallet load, registering two completion callbacks. When the load finishes while the handler is resumed, both callbacks can execute before the activity pauses and each calls handleIntent(getIntent()), launching duplicate SendCoinsActivity instances for the same request; alternatively, if completion occurs while the handler is paused, a subsequent onNewIntent sees the load as finished and calls handleIntent immediately while wallet is still null, causing RESULT_CANCELED and losing the request._

In `wallet/src/de/schildbach/wallet/ui/OnboardingActivity.kt`:
- [SUGGESTION] wallet/src/de/schildbach/wallet/ui/OnboardingActivity.kt:429-469: Deferred entry links disappear when the one-time security upgrade is required
  Impact: A user who opens a payment link during a cold start on a wallet that still needs a security upgrade reaches home after setup and must reopen the link.
  Completing the required security upgrade does not reopen the request that launched the wallet. Before this PR, the direct entry activity kept the request while waiting for the wallet. The handoff now finishes that activity and leaves its request in `OnboardingActivity`, where only `startMainActivity()` replays it. Both `AppUpgradeActivity` and the unencrypted-wallet `SetPinActivity` path start a plain `MainActivity` on success. Keep the request with the handoff until setup succeeds, then replay it once; discard it if setup is cancelled.
- [BLOCKING] wallet/src/de/schildbach/wallet/ui/OnboardingActivity.kt:208-225: Back can leave a cancelled entry link queued after loading completes
  (carried; thread: https://github.com/dashpay/dash-wallet/pull/1772#discussion_r4746752668)
- [SUGGESTION] wallet/src/de/schildbach/wallet/ui/OnboardingActivity.kt:206-225: The handed-over entry link is lost if the loading process is killed
  (carried; thread: https://github.com/dashpay/dash-wallet/pull/1772#discussion_r4746752674)

Comment on lines 457 to +469
val intent = Intent(this, MainActivity::class.java).apply {
putExtras([email protected] ?: Bundle())
}
startActivity(intent)
val entry = pendingEntryIntent
pendingEntryIntent = null
when {
entry == null -> startActivity(intent)
// The home screen itself, started by a link (App Connect, a key
// import): open it with that link.
entry.component?.className in MAIN_ACTIVITY_CLASS_NAMES -> startActivity(entry)
// Another screen (a payment link, a shortcut) opens on top of the
// home screen, so Back from it lands in the wallet.
else -> startActivities(arrayOf(intent, entry))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Suggestion: Deferred entry links disappear when the one-time security upgrade is required
Impact: A user who opens a payment link during a cold start on a wallet that still needs a security upgrade reaches home after setup and must reopen the link.

Completing the required security upgrade does not reopen the request that launched the wallet. Before this PR, the direct entry activity kept the request while waiting for the wallet. The handoff now finishes that activity and leaves its request in OnboardingActivity, where only startMainActivity() replays it. Both AppUpgradeActivity and the unencrypted-wallet SetPinActivity path start a plain MainActivity on success. Keep the request with the handoff until setup succeeds, then replay it once; discard it if setup is cancelled.

source: gpt-6.2-sol (phase2-reviewer: general, security-auditor)

Comment on lines +201 to +205
val handOver = handsOverWhileWalletLoads(walletApplicationBeforeInjection())
super.onCreate(if (handOver) null else savedInstanceState)

if (handOver && redirectWhileWalletLoads(walletApplication, keepIntent = savedInstanceState == null)) {
finishedForNoWallet = true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved (re-reviewed at ca175015): The restoring check you added keeps the original activity and passes the saved bundle through to the payment restoration code. The synchronous wait is separate from the loss of saved payment state.

Comment on lines +206 to +214
if (loading && walletApplication.isLaunchWalletLoadInProgress) {
log.info("the wallet is still loading — showing the splash until it has loaded")
loadingEntryIntent = walletApplication.peekPendingEntryIntent()
afterLaunchWalletLoad(walletApplication) {
// Created again with the wallet loaded: the link it waits for
// now belongs to the new screen.
loadingEntryIntent = null
recreate()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still applies (re-reviewed at ca175015): Keeping the cancellation identity fixes the case where finishing wins, but the resumed check does not make Android's Back finish synchronous. The framework can post the finish behind the relaunch, so the replacement can still claim the link before the old instance sees isFinishing.

Comment on lines +160 to +168
/** The intent of a screen that handed over to this one while the wallet loaded. See [onCreate]. */
private var pendingEntryIntent: Intent? = null

/**
* On the loading screen: the pending entry intent it is waiting to open.
* Discarded when the user closes the loading screen (Back), so the link
* does not open on a later, unrelated launch.
*/
private var loadingEntryIntent: Intent? = null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still applies (re-reviewed at ca175015): Section 2 of #1777 describes the right saved-state follow-up, but the new task replacement is what removes Android's original entry intent, and waiting for resume extends the memory-only window. I’ve lowered this to a suggestion because the user can reopen the link and no payment was submitted.

@HashEngineering
HashEngineering merged commit ca17501 into fix/foreground-start-wallet-load-off-main Dec 1, 2026
3 of 4 checks passed
@HashEngineering

Copy link
Copy Markdown
Collaborator Author

GitHub marked this PR merged because its commits are now on its base branch: it was folded into #1765 (now at e680151). #1765 replaces this PR's hand-over with a wait in place. While the launch's wallet load runs, a screen keeps its own activity, caller, grants, intent and saved state, then recreates itself once the load has finished. The details are in #1765's description.

The open findings here, as they stand in #1765:

  • "Back can leave a cancelled entry link queued after loading completes": the pending entry link is gone, so there is nothing to leave queued.
  • "The handed-over entry link is lost if the loading process is killed": nothing is handed over. The link stays the screen's own intent, and the held saved state survives a process death during the wait.
  • "A second wallet URI can replay or cancel the first request during a cold start": WalletUriHandlerActivity.onNewIntent re-handles the request only after the waiter from onCreate has run (wallet set), so one request opens once.
  • The gaps tracked in Wallet-load hand-over: screens and links #1772 does not yet cover #1777 (result and content screens, process death, the upgrade flows, onboarding's own state) all wait in place now.

@HashEngineering HashEngineering self-assigned this Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants