Repository navigation
fix(android): size the manufacturer data to the bytes written - #96
Merged
framinosona merged 1 commit intoNov 9, 2026
Merged
Conversation
The array was sized for every section but written once per company id, so a company id present in both the advertisement and its scan response left trailing zero bytes. A manufacturer section too short to hold a company id is now skipped instead of throwing.
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the Android manufacturer-data sizing change.
No open issues 🎉
What changed in this PR
Fixes #94 by removing trailing zero bytes from Android manufacturer data when a company ID repeats, preserving the existing layout and matching the exact-sizing approach introduced for Windows in #88.
Changes:
- Adds an internal builder that writes each company ID once, followed by its combined payloads.
- Skips manufacturer sections too short to contain a company ID.
- Delegates Android advertisement extraction to the new builder without changing the public API.
| File | Description |
|---|---|
Bluetooth.Maui.Platforms.Droid/Scanning/AndroidManufacturerDataBuilder.cs |
Builds exactly sized manufacturer data and skips undersized sections. |
Bluetooth.Maui.Platforms.Droid/Scanning/AndroidBluetoothAdvertisement.cs |
Replaces inline extraction logic with the new builder. |
Review effort: Balanced
framinosona
deleted the
framinosona/android-manufacturer-data-exact-size
branch
November 9, 2026 13:50
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
AndroidBluetoothAdvertisement.ManufacturerDatano longer has trailing zero bytes when a company id appears in more than one section.AndroidManufacturerDataBuilder, in the same shape asWindowsManufacturerDataBuilder(fix(windows): read manufacturer data from every advertisement type #88). It touches no Android type, so it can be tested anywhere.ArgumentOutOfRangeExceptionout of the scan callback.Why
The scan record holds the advertisement and its scan response one after the other, so a device that sends manufacturer data in both has the same company id twice. The old code sized the result as the sum of
data.Length + 2over every section, wrote the 2-byte company id once per company id, and returned the array as allocated. With N sections of one company id the array was 2 x (N - 1) bytes too long, and a consumer that walks the layout (company id, then its data) could read the trailing zeros as another company with id 0x0000.Fixes #94.
Change Type
refa)Affected Areas
Bluetooth.Maui)Behavior And Compatibility
On Android,
ManufacturerDataof an advertisement whose company id repeats is now shorter: the same bytes without the trailing zeros. The layout is unchanged (for each company id in order of first appearance, the id once, then the data of every section that carries it), and an advertisement with one section is byte-for-byte the same. A consumer that read only the leading bytes sees no difference. A malformed section no longer throws.Platform Notes
Android only. Windows already builds the same layout with exact sizes (#88).
Tests
Validation notes: the repository has no test projects, so I ran the real
ScanRecordPartand the new builder in a throwaway console on a Mac, next to a verbatim copy of the old method, on raw scan records:ArgumentOutOfRangeExceptionBluetooth.Maui.Platforms.Droidbuilds in Release fornet10.0-androidwith 0 warnings and 0 errors. It was not run on an Android device, because that needs an advertiser that repeats a company id.Documentation
No document describes this layout in a way that changes.
Logging / Diagnostics
Risks And Follow-ups
Risk level:
Known limitations or deferred follow-ups:
Checklist
type (scope): short imperativeand is <= 72 chars