Skip to content

Conversation

@krushnarout
Copy link
Member

Android processes only one ble write at once, that’s why it was crashing

fix: added sequential queue, timeout, and busy error handling

closes #3440

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a sequential write queue with retry logic to handle BLE write limitations on Android. The implementation correctly serializes write operations and adds robustness with timeouts and exponential backoff for retries. My review includes one suggestion to improve the robustness of the error-checking logic for retries, to avoid potential false positives from a broad string match.

bool _isRetryable(Object e) {
if (e is FlutterBluePlusException && e.code == 201) return true;
final msg = e.toString().toLowerCase();
return msg.contains("busy") || msg.contains("201");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The string check msg.contains("201") is a bit fragile and could lead to incorrectly retrying on errors that are not retryable. For example, it could match parts of other numbers in an error message (e.g., a different error code like 1201, or part of a memory address). To make this more robust, consider using a more specific pattern, for example by checking for word boundaries.

Suggested change
return msg.contains("busy") || msg.contains("201");
return msg.contains("busy") || RegExp(r'\b201\b').hasMatch(msg);

@aaravgarg aaravgarg requested a review from beastoin November 21, 2025 06:13
@beastoin
Copy link
Collaborator

where are the tests sir ?

@krushnarout

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.

FlutterError - PlatformException(writeCharacteristic, device is disconnected, null, null)

3 participants