Skip to content

[codex] Add iOS BLE central background restore shim - #4770

Open
cagnulein wants to merge 13 commits into
masterfrom
codex/ios-background-central-homeform
Open

[codex] Add iOS BLE central background restore shim#4770
cagnulein wants to merge 13 commits into
masterfrom
codex/ios-background-central-homeform

Conversation

@cagnulein

Copy link
Copy Markdown
Owner

Summary

  • add an iOS-only CoreBluetooth shim that gives Qt-created CBCentralManager instances a restore identifier
  • include the shim in the iOS qmake sources without touching qt-patches
  • make homeform session gap filling preserve long timer delays instead of resetting jitter or deleting SessionLine records

Impact

This is a first central-side step for keeping physical BLE device connections recoverable when iOS suspends or restores the app. It intentionally leaves the peripheral/virtual BLE side untouched.

Validation

  • git diff --check
  • Not run: iOS build/device test

@stale

stale Bot commented Jul 24, 2026

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the wontfix This will not be worked on label Jul 24, 2026
@cagnulein
cagnulein marked this pull request as ready for review July 31, 2026 07:41
@stale stale Bot removed the wontfix This will not be worked on label Jul 31, 2026
cagnulein and others added 4 commits July 31, 2026 09:42
The bluetooth-central background mode alone does not keep the app
running: iOS suspends the process a few seconds after the screen goes
off and only resumes it for very short windows when a BLE notification
arrives. While suspended every QTimer stops, so homeform::update() and
the per-device refresh timers freeze and the session stalls.

Add an iOS keep alive built on an active AVAudioSession playing an
inaudible looping buffer (the same trick the Flutter background
execution plugins use). The session uses MixWithOthers so the music or
podcast the user is listening to is never interrupted, and it is
started only while a workout is running (Start) and stopped on Stop.
A watchdog plus the interruption / media-services-reset observers
restart the loop if iOS stops it behind our back.

Also complete the CoreBluetooth restore shim: CoreBluetooth expects the
delegate to implement centralManager:willRestoreState: when a restore
identifier is used, so install a logging-only implementation on Qt's
central manager at runtime, and log the relaunch-by-CoreBluetooth
launch option.

New setting: ios_background_keepalive (default on).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The Xcode project is checked in and is not regenerated by the CI, so
ios_background_keepalive.mm was never compiled (undefined symbols at
link time) and ios_bluetooth_background.mm, added by the previous
commit of this branch, was silently not built at all.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ActivityKit gives an app a limited budget of Live Activity updates
while it is not in foreground. QZ pushes one update per second, which
burns the budget in a few minutes: iOS then silently stops applying the
new content, the Live Activity freezes and (past the stale date) it is
rendered as outdated.

Slow the updates down to one every 5 seconds while the app is not
active, leaving the 1 Hz rate in foreground and leaving the HealthKit
metrics at full rate. The inactivity timeout that auto-closes the Live
Activity goes from 10 to 30 seconds, otherwise a single late BLE
notification would close it while in background.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@stale

stale Bot commented Aug 16, 2026

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the wontfix This will not be worked on label Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wontfix This will not be worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant