Repository navigation
fix(app): keep a live native BLE link from showing as Disconnected #21430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Git-on-my-level
merged 4 commits into
BasedHardware:main
from
Git-on-my-level:lane/ble-late-ready
Oct 14, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e52224a
fix(app): keep a live native BLE link from showing as Disconnected
Git-on-my-level 2c27dd9
fix(app): revalidate pairing when a queued readoption is admitted
Git-on-my-level a23da45
fix(app): guard fresh reconcile adoption and replay a ready lost to a…
Git-on-my-level cf6a8aa
fix(app): carry the readoption pairing constraint through publication
Git-on-my-level File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
app/changelog/unreleased/20261014-pendant-reconnect-on-open.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "change": "Your Omi shows as connected again when you reopen the app, instead of staying stuck on Disconnected while it's actually connected" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import 'dart:async'; | ||
|
|
||
| import 'package:flutter/widgets.dart'; | ||
|
|
||
| import 'package:omi/backend/preferences.dart'; | ||
| import 'package:omi/gen/pigeon_communicator.g.dart'; | ||
| import 'package:omi/providers/device_provider.dart'; | ||
| import 'package:omi/services/devices.dart'; | ||
| import 'package:omi/services/services.dart'; | ||
| import 'package:omi/utils/logger.dart'; | ||
|
|
||
| /// Native owns the BLE link and Dart mirrors it. Any lost device-ready (a | ||
| /// launch connect that timed out, a retired transport, a dropped callback) | ||
| /// otherwise leaves the UI disconnected over a live link until the app is | ||
| /// killed. On foreground, re-adopt a link native already holds: native answers | ||
| /// manageDevice for a connected peripheral by replaying device-ready, so this | ||
| /// never touches the radio and never starts a physical connect. | ||
| class NativeLinkReconciler { | ||
| NativeLinkReconciler(this._provider, {Future<bool> Function(String deviceId)? nativeLinkProbe}) | ||
| : _nativeLinkProbe = nativeLinkProbe ?? BleHostApi().isPeripheralConnected; | ||
|
|
||
| final DeviceProvider _provider; | ||
| final Future<bool> Function(String deviceId) _nativeLinkProbe; | ||
| AppLifecycleListener? _lifecycle; | ||
| bool _disposed = false; | ||
|
|
||
| void bindAppLifecycle() { | ||
| if (_disposed) return; | ||
| _lifecycle ??= AppLifecycleListener(onResume: () => unawaited(reconcile())); | ||
| } | ||
|
|
||
| /// The paired device id while the mirror shows it disconnected, else null. | ||
| String? _disconnectedPairedDeviceId() { | ||
| if (_disposed || _provider.isConnected || _provider.isConnecting || _provider.isFirmwareUpdateInProgress) { | ||
| return null; | ||
| } | ||
| final id = SharedPreferencesUtil().btDevice.id; | ||
| return id.isEmpty ? null : id; | ||
| } | ||
|
|
||
| Future<void> reconcile() async { | ||
| final deviceId = _disconnectedPairedDeviceId(); | ||
| if (deviceId == null) return; | ||
| final bool linkUp; | ||
| try { | ||
| linkUp = await _nativeLinkProbe(deviceId); | ||
| } catch (_) { | ||
| return; | ||
| } | ||
| // Adopt only the device whose link was probed: pairing or the mirror may | ||
| // have changed while the probe was in flight. | ||
| if (!linkUp || _disconnectedPairedDeviceId() != deviceId) return; | ||
| Logger.debug('NativeLinkReconciler: native holds $deviceId while disconnected; re-adopting'); | ||
| final deviceService = ServiceManager.instance().device; | ||
| if (deviceService.connectionFor(deviceId)?.status == DeviceConnectionState.connected) { | ||
| // DeviceService holds the link but the provider never heard. Admission | ||
| // revalidates the persisted pairing when the debounced handler runs, so | ||
| // a pairing that moved on during the queue is not published. | ||
| _provider.readoptServiceLink(deviceId); | ||
| return; | ||
| } | ||
| // Otherwise native replays device-ready into a fresh transport. Its | ||
| // connected event queues an admission through the generic path, which can | ||
| // start running before this reconcile finishes (DeviceConnection.connect | ||
| // emits connected before awaiting ping/getDeviceInfo). Arm the pairing | ||
| // constraint on the provider *before* the link starts forming so every | ||
| // admission for this device — whichever event queued it — revalidates the | ||
| // probe-time pairing, and keep it armed through publication: a pairing | ||
| // persisted while the link was forming (an input picker seeding another | ||
| // microphone) is never published over. | ||
| _provider.armReadoptPairConstraint(deviceId); | ||
| final connection = await deviceService.ensureConnection(deviceId, force: true); | ||
| if (connection?.status == DeviceConnectionState.connected) { | ||
| _provider.readoptServiceLink(deviceId); | ||
| } | ||
| } | ||
|
|
||
| void dispose() { | ||
| _disposed = true; | ||
| _lifecycle?.dispose(); | ||
| _lifecycle = null; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When resume admission for A reaches this assignment and the Ray-Ban picker then seeds B while
setConnectedDevice(A)is awaiting, the new pairing guard abandons A but leaves(connection, epoch)latched. If B fails,rayban_meta_input_picker_sheet.dart:101-112restores A; subsequent resume readoptions see the same live A/epoch and are dropped by the equality check immediately above, recreating the stuck Disconnected state until a manual or physical reconnect. Fresh evidence after the prior pairing comments is that none of the newly added guard returns clears_admittedLink; only commit the latch after setup succeeds or clear it on every abandoned setup.Useful? React with 👍 / 👎.