Repository navigation
feat(bluetooth): reconnect automatically when the scale link drops - #1566
Closed
kashif-khan wants to merge 1 commit into
Closed
kashif-khan wants to merge 1 commit into
kashif-khan wants to merge 1 commit into
Conversation
A GATT scale that hangs up on its own (it went to sleep, or dropped the link after a few seconds) left openScale disconnected until the user tapped connect again. Vendor apps keep listening for the next weigh-in instead. When the existing auto-connect setting is on, BleConnector now starts a new connection to the same scale after an unexpected drop. The attempt scans until the scale advertises again, so a sleeping scale is picked up as soon as it wakes. Repeated quick drops back off from 2 s up to 30 s (ReconnectPolicy); a connection that stayed up for 20 s starts over. Disconnects that the app or a device handler asked for never trigger it: GattScaleAdapter now reports them through BluetoothEvent.Disconnected.requested, so the 39 handlers that disconnect after a finished weigh-in behave as before. SPP sessions report their normal end as requested and are not reconnected. Pressing disconnect, or turning the setting off, cancels a pending reconnect. The setting's English label now says it also covers drops.
Owner
|
Thanks for your PR, but I'd rather not add this.
Closing it for now. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
When a Bluetooth scale ends the connection by itself, openScale stays disconnected until the user taps the connect icon again. That is the usual case for scales that power off after a weigh-in: the connection is lost about 18 s after the scale's last packet (
CONNECTION_TIMEOUT), and the next weigh-in is not picked up. Vendor apps keep listening instead.Change
With the existing auto-connect setting on,
BleConnectornow starts a new connection to the same scale after an unexpected drop. The new attempt scans for the saved address until the scale advertises again (the adapter has no scan timeout), so a scale that went to sleep is picked up as soon as it wakes.ReconnectPolicy). A connection that stayed up for 20 s or more starts the sequence over.BluetoothEvent.Disconnectedgets arequestedflag.GattScaleAdaptersets it when the app or a device handler asked for the disconnect (requestDisconnect(), which 39 handlers call after a finished weigh-in). Those never trigger a reconnect, so handlers that disconnect on purpose behave as before. SPP reports its normal end of session as requested, so SPP scales are not reconnected.What was verified
On a Samsung Galaxy S24 Ultra (SM-S928W, Android 16) with a Urikar Aero I Pro (a GATT scale, using a handler that is not part of this PR). Each weigh-in ends with the scale switching itself off, then:
The scale was picked up again, without tapping connect, on every drop in my test sessions (five times in the first session, with the backoff going 2 s, 2 s, 4 s, then back to 2 s after a connection that lasted over 20 s), and each weigh-in after a reconnect was saved.
./gradlew :app:testDebugUnitTestpasses (936 tests, including 4 new forReconnectPolicy).Not verified
requestedflag keeps handler-initiated disconnects out of the reconnect path, but I did not exercise other handlers.