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>
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.

1 participant