Skip to content

fix(android): size the manufacturer data to the bytes written - #96

Merged
framinosona merged 1 commit into
mainfrom
framinosona/android-manufacturer-data-exact-size
Nov 9, 2026
Merged

framinosona merged 1 commit into
mainfrom
framinosona/android-manufacturer-data-exact-size

Conversation

@framinosona

Copy link
Copy Markdown
Member

Summary

  • AndroidBluetoothAdvertisement.ManufacturerData no longer has trailing zero bytes when a company id appears in more than one section.
  • The sizing and writing moved to a small internal class, AndroidManufacturerDataBuilder, in the same shape as WindowsManufacturerDataBuilder (fix(windows): read manufacturer data from every advertisement type #88). It touches no Android type, so it can be tested anywhere.
  • A manufacturer section too short to hold a company id is skipped. It used to throw ArgumentOutOfRangeException out 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 + 2 over 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

  • Feature
  • Bug fix
  • Refactor (refa)
  • Docs only
  • CI/build/tooling

Affected Areas

  • Abstractions
  • Core
  • Platform: Android
  • Platform: iOS/macOS
  • Platform: Windows
  • Platform: DotNetCore fallback
  • Facade (Bluetooth.Maui)
  • Documentation

Behavior And Compatibility

  • Public API changed
  • Exception behavior changed
  • DI registration behavior changed
  • Capability matrix impact
  • No externally visible behavior change

On Android, ManufacturerData of 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

  • Unit tests added/updated
  • Integration/smoke tests added/updated
  • Manual platform validation performed
  • Not applicable (explain)

Validation notes: the repository has no test projects, so I ran the real ScanRecordPart and the new builder in a throwaway console on a Mac, next to a verbatim copy of the old method, on raw scan records:

Case Old New
one section 5 bytes the same 5 bytes
advertisement + scan response, same id 9 bytes, 2 trailing zeros 7 bytes
id A, id B, id A 10 bytes, 2 trailing zeros 8 bytes
four sections, same id 12 bytes, 6 trailing zeros 6 bytes
a manufacturer section too short for an id, next to a valid one throws ArgumentOutOfRangeException the valid section only
no manufacturer section, empty record empty empty

Bluetooth.Maui.Platforms.Droid builds in Release for net10.0-android with 0 warnings and 0 errors. It was not run on an Android device, because that needs an advertiser that repeats a company id.

Documentation

  • Docs updated in same PR
  • Capability claims verified against implementation
  • Links validated
  • Not applicable (explain)

No document describes this layout in a way that changes.

Logging / Diagnostics

  • New logs added
  • EventId range validated
  • No logging changes

Risks And Follow-ups

Risk level:

  • Low
  • Medium
  • High

Known limitations or deferred follow-ups:

  • A consumer that compared the whole array with a fixed length would see a shorter value for a repeated company id, which is the point of the fix.

Checklist

  • I reviewed Docs/Best-Practices/Contribution-DoD.md
  • Commit header follows type (scope): short imperative and is <= 72 chars
  • Commit type is one of: feat, fix, refa, perf, docs, ci, chore, test, build
  • Commit body is 1-2 factual sentences (what/why), no emojis, refs, or co-authors
  • If architectural behavior changed, an ADR was added or updated under Docs/Architecture/ADR

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.
Copilot AI balanced review requested due to automatic review settings November 9, 2026 13:24

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.

🟢 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
framinosona merged commit 1089182 into main Nov 9, 2026
10 checks passed
@framinosona
framinosona deleted the framinosona/android-manufacturer-data-exact-size branch November 9, 2026 13:50
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.

[BUG] [Android] ExtractManufacturerData returns trailing zero bytes when a company id repeats

2 participants