Skip to content

Fixes Xiaomi Phones not Displaying Sensors#141

Open
ilteen wants to merge 1 commit into
mainfrom
fix-xiaomi-ble
Open

Fixes Xiaomi Phones not Displaying Sensors#141
ilteen wants to merge 1 commit into
mainfrom
fix-xiaomi-ble

Conversation

@ilteen

@ilteen ilteen commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@CLAassistant

CLAassistant commented Jul 7, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit 9b7bd26):

https://open-earable-lib-web-example--pr141-fix-xiaomi-ble-s9czsav8.web.app

(expires Tue, 04 Aug 2026 12:22:33 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 7f6db4d9d00b851ad49af109fa949061904b3151

@TobiasRoeddiger

Copy link
Copy Markdown
Member

is it confirmed that this does not interfere with the other platforms now?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses sensor scheme retrieval reliability on Android (notably Xiaomi devices) by ensuring BLE notification subscriptions are set up before issuing request/response writes, and by adding fallback and retry logic when notifications fail.

Changes:

  • Add an explicit prepareSubscription() step before subscribing/requesting sensor schemes to reduce first-packet drops.
  • Fall back to a direct characteristic read when a notification-based scheme response times out.
  • Improve multi-sensor scheme collection with retry passes and early-stop when no progress is made; add tests for these behaviors.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
test/v2_sensor_scheme_reader_test.dart Adds tests covering subscription ordering, notification timeout fallback, sensor-id handling, and retry behavior.
lib/src/utils/sensor_scheme_parser/v2_sensor_scheme_reader.dart Ensures subscription setup before listening, adds direct-read fallback on timeout, and introduces retry passes for scheme collection.
lib/src/managers/ble_manager.dart Adds awaitable subscription setup tracking and exposes prepareSubscription() to allow callers to wait for notification enablement.
lib/src/managers/ble_gatt_manager.dart Introduces prepareSubscription() API in the GATT manager interface for subscription preconditioning.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 88 to 92
final value = await responseFuture;
logger.d(
"Received notification for sensor scheme of sensor $sensorId: $value",
);

Comment on lines +33 to +44
/// Ensures notifications are enabled before request/response flows depend on them.
Future<void> prepareSubscription({
required String deviceId,
required String serviceId,
required String characteristicId,
}) async {
subscribe(
deviceId: deviceId,
serviceId: serviceId,
characteristicId: characteristicId,
);
}
Comment on lines 136 to 139
try {
SensorScheme scheme = await getSchemeForSensor(sensorId);
final scheme = await getSchemeForSensor(sensorId);
_sensorSchemes[scheme.sensorId] = scheme;
} catch (e) {
Comment on lines 70 to 72
final Stream<List<int>> stream = _bleManager.subscribe(
deviceId: _deviceId,
serviceId: parseInfoServiceUuid,
@ilteen

ilteen commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator Author

is it confirmed that this does not interfere with the other platforms now?

Confirmed to work on a Google Pixel and iPhone

@TobiasRoeddiger TobiasRoeddiger self-requested a review July 14, 2026 05:14
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.

4 participants