Skip to content

Emit device ids in lower-case on every platform (breaking, next major) - #270

Open
postmaxin wants to merge 1 commit into
Navideck:mainfrom
postmaxin:lowercase-device-ids
Open

Emit device ids in lower-case on every platform (breaking, next major)#270
postmaxin wants to merge 1 commit into
Navideck:mainfrom
postmaxin:lowercase-device-ids

Conversation

@postmaxin

Copy link
Copy Markdown
Contributor

Follow-up to #269 (merged in 2.1.1): make the emitted device-id case consistent too — the fully-universal, breaking version discussed there for the next major.

What changes

Device ids are now canonicalised to lower-case throughout the Dart layer and emitted lower-case on every platform (scan results + connection / value / pairing / connection-parameter callbacks and streams). Previously each platform reported its native case — Android upper-cased MACs, Windows/WinRT lower-cased them — so a caller holding the id in the "wrong" case could split state or (before #269) miss events.

How — Dart-only, no Kotlin / Swift / C++ changes

  • The update* handlers lower-case on ingestion, so every event, callback and per-device map key is lower-case. This also lets Match device ids case-insensitively across event streams #269's dual-case stream matching collapse to a single lower-case compare.
  • Native BLE calls still need the platform's case (Android's getRemoteDevice requires upper-case and throws otherwise; Apple's peripheral cache is keyed by the upper-case uuidString, Windows parses the address either way, Linux's BlueZ address is upper-case), so the platform implementations convert back at their boundary: a single _nativeId() helper at the pigeon-channel native-op sites, and one line in the Linux instance's device lookup (the single point every Linux op funnels through).

Note the native side receives the same upper-case id it always has — it's just reconstructed at the Dart boundary now instead of being supplied by the caller — so native behaviour is unchanged.

Breaking

Callers that stored or compared an emitted id by exact case (e.g. an Android upper-case MAC) must now lower-case it, or compare case-insensitively. CHANGELOG updated under "next major".

Testing

  • 97 Dart tests pass (flutter test) and flutter analyze is clean — including 5 new tests asserting lower-case emission from every update* handler, with the existing Match device ids case-insensitively across event streams #269 case-insensitive-matching / dedup / cache tests still green.
  • Verified on a real Android device. I pointed a consumer app (a BLE pet-tracker gateway that round-trips scanned ids straight back into connect()) at this branch and confirmed the whole path: scan → connect() → auth → characteristic streaming → and the reconnect/self-heal path. That's exactly the round-trip this change relies on — Android's getRemoteDevice throws on a lower-case MAC, so a successful connect proves the boundary conversion is doing its job.

Developed with AI assistance (noted via the commit's Co-Authored-By trailer).

Follow-up to the case-insensitive matching in Navideck#269 (2.1.1): make the emitted
case consistent too. Device ids are now canonicalised to lower-case throughout
the Dart layer — every scan result, callback and stream carries the lower-case
form regardless of the case the platform reports (Android upper-cased MACs,
Windows/WinRT lower-cased them).

Native BLE calls still need the platform's case (Android's getRemoteDevice
REQUIRES upper-case; Apple's peripheral cache, Windows' address parse and
Linux's BlueZ address are upper-case too), so the platform implementations
convert back at their boundary — a single `_nativeId` helper in the pigeon
channel, and one line in the Linux instance's device lookup. No Kotlin / Swift
/ C++ changes.

This also lets the Navideck#269 stream matching collapse from a dual-case compare to a
single lower-case one.

BREAKING: callers that stored/compared an emitted id by exact case must now
lower-case it (or compare case-insensitively). For the next major release.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 standardizes BLE device IDs to a single canonical form in the Dart layer by lower-casing them on ingestion and ensuring all emitted IDs from streams/callbacks are lower-case, while converting back to the native-required case at platform boundaries (Pigeon channel + Linux BlueZ lookup). This is a breaking change intended for the next major release and is documented in the changelog.

Changes:

  • Canonicalize device IDs to lower-case in UniversalBlePlatform update handlers and simplify stream matching to a single lower-case compare.
  • Upper-case device IDs at the Dart→native boundary for Pigeon platform operations, and normalize Linux device lookup to BlueZ’s expected case.
  • Add tests asserting lower-case emission from update handlers; update changelog and example lockfile.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/device_id_case_insensitivity_test.dart Adds tests asserting lower-case emission from update* handlers.
lib/src/universal_ble_pigeon/universal_ble_pigeon_channel.dart Introduces _nativeId() and applies it to Pigeon native calls; keeps emitted IDs lower-case.
lib/src/universal_ble_linux/universal_ble_linux.dart Normalizes Linux device lookup by upper-casing IDs before BlueZ resolution.
lib/src/interfaces/universal_ble_platform_interface.dart Canonicalizes IDs to lower-case on ingestion and simplifies stream filters accordingly.
example/pubspec.lock Bumps the path-dependency version recorded for the example app.
CHANGELOG.md Documents the breaking change for “next major”.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

// Device ids are lower-case throughout the Dart layer (see UniversalBlePlatform), but the native side wants
// the upper-case form — Android's BluetoothAdapter.getRemoteDevice REQUIRES upper case, and Apple's peripheral
// cache / Windows' address parse / Linux's BlueZ address are upper-case too. Convert here, at the boundary.
String _nativeId(String deviceId) => deviceId.toUpperCase();
Comment on lines +6 to +8
// Device ids are lower-case throughout the Dart layer (see UniversalBlePlatform), but the native side wants
// the upper-case form — Android's BluetoothAdapter.getRemoteDevice REQUIRES upper case, and Apple's peripheral
// cache / Windows' address parse / Linux's BlueZ address are upper-case too. Convert here, at the boundary.
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