Skip to content

Improve watch reconnect handling on GrapheneOS#148

Open
and1mon wants to merge 2 commits intoizivkov:mainfrom
and1mon:feat/graphene_os_support
Open

Improve watch reconnect handling on GrapheneOS#148
and1mon wants to merge 2 commits intoizivkov:mainfrom
and1mon:feat/graphene_os_support

Conversation

@and1mon
Copy link
Copy Markdown

@and1mon and1mon commented Apr 23, 2026

Summary

This changes reconnect handling so the app no longer depends primarily on CDM/CompanionDevice presence events to reconnect to a previously paired watch.

On GrapheneOS, the initial pairing/connection worked, but later reconnect attempts after a watch-side disconnect were often not detected unless the watch was paired again. The root issue appeared to be that the app was not reliably receiving a fresh reconnect trigger from the OS.

What changed

  • Added a ReconnectManager to centralize reconnect state and policy
  • Use CDM presence as one reconnect trigger, but not the only one
  • Start BLE scan fallback for known watches when appropriate
  • Re-open a reconnect retry window after disconnect / connection failure
  • Stop duplicate connection attempts for the same device appearance
  • Preserve locally known device addresses when CDM associations are temporarily missing
  • Require BLUETOOTH_SCAN for the scan fallback path on Android 12+

Why

The reconnect itself was able to succeed once started. The failure mode was that, after a disconnect, the app often did not notice a later reconnect attempt from the watch on GrapheneOS.

This PR makes reconnect detection more app-driven and less dependent on ROM-specific CDM behavior.

@izivkov
Copy link
Copy Markdown
Owner

izivkov commented Apr 23, 2026 via email

@and1mon
Copy link
Copy Markdown
Author

and1mon commented Apr 23, 2026

Yeah I totally get that, it is a big change and I cannot reliably test it for all devices.

The retry logic is also not my preferred way of solving this, however so far it has been the only way I got it work.

There is no need to merge this as is, maybe it can help find a cleaner solution though.

@sonarqubecloud
Copy link
Copy Markdown

@and1mon
Copy link
Copy Markdown
Author

and1mon commented Apr 23, 2026

Slimmed down the PR to only include the necessary logic without a bigger refactor as before, so hopefully it's a bit better to read now for further analysis.

@izivkov
Copy link
Copy Markdown
Owner

izivkov commented Apr 23, 2026

@and1mon

So, you are right - the GrapheneOS is eating "onDeviceAppeared" events and we cannot rely on the CDM generated events alone. I have incorporated ideas from your Pull Request and other AI feedback into a branch grapheneos. Please check it out and try it. I'm pretty confident it will work on GrapheneOS. You can take a look at the release notes in this file on this branch: RELEASE_NOTES_GRAPHENEOS.md

Let me know how it goes,
Thanks

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