You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DEV-1250: Verisense BLE radio no longer blocks the main thread on the MTU; fail on notify/connect errors - #130
the shimmerspeedtest example, through its subclasses Shimmer3BleAndroidRadioByteCommunication and Shimmer3RAndroidRadioByteCommunication
Problem
Every connect froze the UI for ~3 s.onConnectSuccess runs on FastBle's main-thread handler and waited 3 s for an MTU result that FastBle 2.4.0 delivers on that same thread, so the wait always timed out.
eventConnected() came too early. It fired before the RX notification was even requested, and connect() returned about 200 ms later. VerisenseDevice.connect() then sends readStatus() whether or not notifications are on.
Notify failures were silent.onNotifyFailure was empty: a failed subscription left the device "connected", with every read timing out.
Change
Only VerisenseBleAndroidRadioByteCommunication.java changes, using the same structure as DEV-1247.
On the MTU result (success or failure), onMtuSet() requests connection priority, then the RX notification, then the PHY.
onNotifySuccess → onNotifyEnabled() calls eventConnected() and lets connect() return.
A connect failure, a notify failure, or a missing RX characteristic or services list calls connectionFailed(reason). That logs the reason, disconnects, calls eventDisconnected(), and connect() returns at once.
connect()'s signature is unchanged.
Bench results
The HIL doesn't drive this class, so I used a throwaway instrumentation probe (not in this PR). It called Shimmer3RAndroidRadioByteCommunication.connect(), wrote GET_SHIMMER_VERSION (0x3F), waited for the reply and disconnected, 5 times on each build. Phone: Redmi M2101K6G, Android 11. Device: Shimmer3R.
master
this PR
connect() returns
4.42–4.72 s
1.48–1.63 s
eventConnected()
4.20–4.50 s
1.28–1.43 s
reply to the first command
5/5 (FF 25 0A)
5/5 (FF 25 0A, 37–49 ms)
PerfMonitor longMsg … BleBluetooth$MainHandler
5, one per connect
0
Not verified
No Verisense on the bench. The VerisenseDevice path (readStatus, production and operational config) did not run on hardware. Only the shared radio code did, through the Shimmer3R subclass.
Failure paths, partly. The connect-failure path did run on the bench. Two real GATT 133s during the probe went through this class's connectionFailed: eventDisconnected fired ~330 ms after connect() started, and connect() returned at once, where it used to wait 5 s. The notify-failure and missing-RX paths were not forced.
… fail on notify/connect errors
The same defect DEV-1247 fixed in Shimmer3BLEAndroid. onConnectSuccess
runs on FastBle's main-thread handler and waited 3 s for an MTU result that
FastBle delivers on that same thread, so every connect froze the UI for
~3 s. It then reported eventConnected before the RX notification was even
requested. Setup now continues from the MTU callback (success or failure),
and eventConnected and connect()'s return wait for the notification to be
enabled.
A failed notify subscription, a missing RX characteristic or a connect
failure now logs the reason, disconnects and calls eventDisconnected, and
connect() returns at once. Shimmer3BleAndroidRadioByteCommunication and
Shimmer3RAndroidRadioByteCommunication inherit this.
Bench probe through Shimmer3RAndroidRadioByteCommunication on a Shimmer3R:
connect() 1.5 s (was 4.4-4.7 s), first command answered 5/5, no PerfMonitor
longMsg from BleBluetooth$MainHandler (one per connect before).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r-attempt MTU task
The same two fixes as DEV-1247's review, for the identical code here:
- connectionFailed() disconnects the BleDevice the failing callback was
given, not mBleDevice, which is unset or stale on the onConnectFail path.
- The MTU callback completes a task local to its attempt, so a late MTU
result after a timeout can't complete a later attempt's task.
Probe through Shimmer3RAndroidRadioByteCommunication on a Shimmer3R: 5/5
connects at ~1.5 s, first command answered every time.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A late onConnectSuccess can still reach this block after onConnectFail has completed mTaskConnect and requested disconnect (FastBle can deliver a result after its timeout). This starts MTU/service/notify setup on a connection that was already reported failed; onNotifyEnabled() only suppresses the later event and does not tear down that late link. Capture the completion source for this connect attempt and gate this callback, disconnecting and returning when that attempt is already complete.
Preserve distinct errors for missing services and RX characteristic
When getBluetoothGattServices() returns null, this branch reports RX characteristic not found, which hides the service-discovery failure from the new connection log. Keep the two failure reasons distinct so callers can diagnose a missing services list versus a missing RX characteristic.
… late success after a failure
The same changes as DEV-1247's second review round, for the identical code here:
- onDisConnected before setup finished now calls connectionFailed(), so
eventDisconnected fires and connect() returns at once instead of after an
MTU/notify timeout or connect()'s 5 s wait.
- connect() keeps this attempt's own task, so a late callback from an
earlier attempt can't complete or fail a newer one.
- A late onConnectSuccess for an attempt that has already failed is
disconnected instead of set up.
- A missing services list is reported as such, not as a missing RX
characteristic.
- Comments on the per-attempt tasks spelled out.
Probe through Shimmer3RAndroidRadioByteCommunication on a Shimmer3R: 5/5
connects at ~1.5 s, first command answered every time.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This late-callback check only tests whether this callback's task is completed; it does not verify that the task is still the current connection attempt. If connect() is called again while an earlier FastBle callback is pending (or after its timeout), the old success can pass this check, overwrite mBleDevice/mTaskMTU, and set up the newer attempt's state. Also compare taskConnect with mTaskConnect before proceeding.
Connection timeout leaves task incomplete and GATT link attached
When the five-second wait times out, this only prints Connect fail; it leaves taskConnect incomplete and does not disconnect the GATT link. A late MTU/notify callback can then report eventConnected() after connect() has already returned, while a missing callback leaves the link attached without a failure notification. Treat the timeout as a failed attempt and clean it up using the same attempt-owned state as the callbacks.
Callbacks use mutable task and can complete the wrong attempt
This helper uses the mutable mTaskConnect instead of the per-callback task captured by the BLE attempt; connectionFailed() below has the same problem. A late notify or failure callback from an older attempt can therefore complete/fail the current attempt and emit the wrong listener event, defeating the per-attempt isolation added in connect(). Pass the captured task through the nested callbacks and gate it against the current attempt.
…etup step
The same as DEV-1247's: onMtuSet, startServiceS, newConnectedBLEDevice and
their callbacks now carry the task of the connect attempt they belong to.
onNotifyEnabled and connectionFailed ignore an attempt that is no longer
current. The public startServiceS and newConnectedBLEDevice keep their
signatures and use the current attempt.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
onConnectSuccess returns at once if a newer connect() has replaced this
attempt's task, so it can't overwrite the newer attempt's device or MTU
task. It doesn't disconnect: the newer attempt owns the same device.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
taskConnect is only checked for completion here, not for being the current attempt. Since the five-second wait can return false while leaving the task incomplete, a late success from an older timed-out attempt can pass this branch after a new connect() has replaced mTaskConnect, overwrite mBleDevice, and start setup for the stale link. Check the task identity as well before accepting the callback.
Delayed MTU callback proceeds after connection failure
A disconnect can complete taskConnect before the MTU callback arrives, but this method has no current/completed-task guard. The delayed callback can consequently request priority and start service discovery/notification on a link that has already failed (and can race a subsequent connection). Ignore the callback unless its task is still the current, incomplete attempt.
The per-attempt task is only checked when notification succeeds, so a late MTU callback from an attempt that already failed (or from an older attempt after a new connect() replaced mTaskConnect) still requests priority and starts notification on the stale GATT here. That can re-enable notifications on a failed/old link and leak callbacks even though onNotifyEnabled() later ignores the result. Guard onMtuSet before touching gatt with the same current-and-incomplete check used by onNotifyEnabled/connectionFailed.
…attempt
onMtuSet returns at once if its attempt has failed or been replaced while
the MTU was pending, so it doesn't request priority or notifications on a
dead or stale link.
Probe through Shimmer3RAndroidRadioByteCommunication on a Shimmer3R: 5/5.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
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.
The same defect as DEV-1247 (
Shimmer3BLEAndroid, #129), fixed in the other Android BLE radio,VerisenseBleAndroidRadioByteCommunication.That class is used by:
ShimmerBluetoothManagerAndroid.connectVerisenseDevice→VerisenseDeviceshimmerspeedtestexample, through its subclassesShimmer3BleAndroidRadioByteCommunicationandShimmer3RAndroidRadioByteCommunicationProblem
onConnectSuccessruns on FastBle's main-thread handler and waited 3 s for an MTU result that FastBle 2.4.0 delivers on that same thread, so the wait always timed out.eventConnected()came too early. It fired before the RX notification was even requested, andconnect()returned about 200 ms later.VerisenseDevice.connect()then sendsreadStatus()whether or not notifications are on.onNotifyFailurewas empty: a failed subscription left the device "connected", with every read timing out.Change
Only
VerisenseBleAndroidRadioByteCommunication.javachanges, using the same structure as DEV-1247.onMtuSet()requests connection priority, then the RX notification, then the PHY.onNotifySuccess→onNotifyEnabled()callseventConnected()and letsconnect()return.connectionFailed(reason). That logs the reason, disconnects, callseventDisconnected(), andconnect()returns at once.connect()'s signature is unchanged.Bench results
The HIL doesn't drive this class, so I used a throwaway instrumentation probe (not in this PR). It called
Shimmer3RAndroidRadioByteCommunication.connect(), wroteGET_SHIMMER_VERSION(0x3F), waited for the reply and disconnected, 5 times on each build. Phone: Redmi M2101K6G, Android 11. Device: Shimmer3R.connect()returnseventConnected()FF 25 0A)FF 25 0A, 37–49 ms)PerfMonitor longMsg … BleBluetooth$MainHandlerNot verified
VerisenseDevicepath (readStatus, production and operational config) did not run on hardware. Only the shared radio code did, through the Shimmer3R subclass.connectionFailed:eventDisconnectedfired ~330 ms afterconnect()started, andconnect()returned at once, where it used to wait 5 s. The notify-failure and missing-RX paths were not forced.onDisConnectedhere only prints, so a link that drops after connect is still not reported to the listener.Jira: DEV-1250
🤖 Generated with Claude Code