Skip to content

fix(android): show BitBox pairing code simultaneously (unblock serial MethodChannel queue)#26

Merged
TaprootFreak merged 9 commits into
DFXswiss:developfrom
Blume1977:fix/android-pairing-code-concurrent-init
Jun 9, 2026
Merged

fix(android): show BitBox pairing code simultaneously (unblock serial MethodChannel queue)#26
TaprootFreak merged 9 commits into
DFXswiss:developfrom
Blume1977:fix/android-pairing-code-concurrent-init

Conversation

@Blume1977

Copy link
Copy Markdown

Problem

On Android, during BitBox pairing the channel-hash (pairing code) appeared in the
app only after the user confirmed on the device — not simultaneously. iOS was
unaffected and showed the code on app and device at the same time.

Root cause

The bitbox_usb MethodChannel is bound to a serial background task queue
(makeBackgroundTaskQueue() in BitboxFlutterPlugin.kt). InitBitBoxOperation
called Api.initDevice() synchronously on that queue. Init() runs the Noise XX
handshake and then blocks until the on-device pairing confirmation
(bitbox02-api-go pairing.go: the channel hash is stored before this blocking
rawQuery, then the call waits). Because the queue is serial, the concurrent
getChannelHash poll from the app could not be serviced until initBitBox returned —
i.e. only after the user confirmed on the device. Hence the code showed device-first.

iOS does not hit this because it dispatches initBitBox to a background queue while
keeping getChannelHash lightweight, so the host reads the hash during the wait.

Fix

Run the blocking Api.initDevice() on its own thread so the serial MethodChannel
queue stays free and getChannelHash is serviced while init is in flight. The pairing
code now appears on app and device simultaneously. All other device operations remain
on the serial queue, preserving the single noise-cipher nonce ordering. This mirrors
the existing async-reply pattern already used by RequestPermissionOperation.

initBitBox now also propagates the real Api.initDevice() result instead of always
returning true (consistent with the iOS implementation).

Android-only change; no Go/native rebuild required.

Testing

  • flutter analyze + flutter pub get green (consumed via path override from
    realunit-app).
  • Manual: pair a BitBox02 over USB on Android — the pairing code must appear in the
    app at the same time as on the device, before any on-device confirmation. Rejecting
    on the device must fall back cleanly.

TaprootFreak and others added 9 commits May 8, 2026 15:27
…ueue

Run the blocking Api.initDevice() (Noise pairing handshake) on its own thread
so the serial bitbox_usb MethodChannel task queue stays free. Previously init
occupied the single queue for the whole on-device confirmation wait, so the
concurrent getChannelHash poll could not run until after the user confirmed on
the BitBox — making the pairing code appear in the app only after device
confirmation. iOS already dispatches init to a background queue and was
unaffected. Other device operations remain serial, preserving noise nonce order.
Also propagate the real initDevice() result instead of always returning true.
@TaprootFreak TaprootFreak marked this pull request as ready for review June 9, 2026 13:02
@TaprootFreak TaprootFreak merged commit 6d70a85 into DFXswiss:develop Jun 9, 2026
3 checks passed
TaprootFreak added a commit to RealUnitCH/app that referenced this pull request Jun 9, 2026
## Summary
Bumps the `bitbox_flutter` dependency from `v0.0.7` to `v0.0.8`.

`v0.0.8` contains the Android pairing-code fix
(DFXswiss/bitbox_flutter#26): `initBitBox` now runs off the serial
MethodChannel task queue, so the BitBox pairing code (channel hash)
appears in the app and on the device **simultaneously**, instead of only
after confirming on the device. iOS was already unaffected.

## Test plan
- [ ] `flutter pub get` resolves `bitbox_flutter v0.0.8`
- [ ] Android BitBox pairing: pairing code shows in-app at the same time
as on the device (before on-device confirmation)
- [ ] Existing BitBox flows (connect / sign) unaffected
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