Skip to content

Reconnect after the phone's Bluetooth restarts - #19

Merged
sayed0am merged 2 commits into
mainfrom
bt-restart
Oct 29, 2026
Merged

sayed0am merged 2 commits into
mainfrom
bt-restart

Conversation

@sayed0am

@sayed0am sayed0am commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

A user's strap card was stuck on "Connected. Not synced" with Sync stopped. android.os.DeadObjectException. The phone's Bluetooth stack had restarted. No disconnect callback came, so OpenStrap kept the dead GATT handle, still showed Connected, and every automatic sync retried on it and failed.

Changes

  • GattClient: a GATT call that throws DeadObjectException now marks the link lost, so the usual reconnect runs with a fresh handle.
  • StrapManager: listens for Bluetooth turning off and on. Off ends the link at once and no reconnect is tried while it's off (Zepp's jv3.L() also waits). On reconnects at once, without the backoff.
  • HistorySync: a link lost mid-sync stops the sync instead of failing each remaining type and ending as Done, and the card says "The link to the strap dropped." instead of a wrapped exception's class name or whatever the dead link threw.
  • Syncing after the reconnect: a reconnect syncs at once when the last sync failed, skipping the 15 minute gap. A sync cut off by the old link can end only after the reconnect has skipped its own sync (it still showed as running), so when it ends failed on a replaced session, a full sync runs on the new one.

Zepp has no equivalent: nothing on its strap side reacts to Bluetooth coming back on, and a failed write on a dead link doesn't end its connection (codemap 02 §8.4 in the analysis repo).

Testing

  • Unit tests pass.
  • On the Fold, while connected: adb shell cmd bluetooth_manager disable then enable, and adb shell am crash com.android.bluetooth. Both were back connected in 3 to 8 s, with no reconnect attempts while Bluetooth was off.
  • Bluetooth off mid-sync and a stack crash mid-sync: the interrupted sync failed, a new one ran on the new link, and the card showed "Connected. Synced just now".
  • Not covered on hardware: the DeadObjectException path itself (the Fold broadcasts Bluetooth off when its stack crashes, so the receiver gets there first).

🤖 Generated with Claude Code

sayed0am and others added 2 commits October 30, 2026 02:20
A user's card was stuck on "Connected. Not synced" with
android.os.DeadObjectException. The phone's Bluetooth stack had restarted,
no disconnect callback came, and every sync retried on the dead GATT handle.

- A GATT call that throws DeadObjectException now counts as a lost link.
- Bluetooth turning off ends the link at once. While it's off no reconnect
  is tried, and turning back on reconnects without the backoff.
- A link lost mid-sync stops the sync instead of ending as Done.
- The card no longer shows a wrapped exception's class name.

Tested on the Fold with Bluetooth off/on and am crash com.android.bluetooth:
back in 3 to 8 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After a Bluetooth restart the strap reconnected but didn't sync: the
15 minute gap since the last auto sync still applied, so a sync the restart
cut off waited up to an hour, with the card on "Sync stopped".

- A reconnect syncs at once when the last sync failed.
- A sync cut off by the old link can end only after the reconnect has
  skipped its own sync (it still showed as running). When it ends failed on
  a session that's been replaced, a full sync runs on the new one.
- A sync that lost its link says "The link to the strap dropped." instead of
  whatever the dead link threw (a missing characteristic).

Tested on the Fold with Bluetooth off mid-sync and a stack crash mid-sync:
the sync ran again on the new link and the card showed Synced just now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sayed0am
sayed0am merged commit 09b070b into main Oct 29, 2026
1 check passed
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.

1 participant