Skip to content

Request and remove a bond on Android, and expose the GATT status on failures - #42

Merged
newky2k merged 3 commits into
developmentfrom
feature/bond-request
Oct 15, 2026
Merged

newky2k merged 3 commits into
developmentfrom
feature/bond-request

Conversation

@newky2k

@newky2k newky2k commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Closes #35. Closes #36.

This PR carries two changes that were already reviewed: #40 (request and remove a bond on Android, issue #35) and #41 (GATT status on characteristic and descriptor failures, issue #36).

Why a new PR. #40 and #41 were stacked on #39. When #39 merged into development, GitHub deleted its head branch, feature/bond-state. That closed #40 unmerged, because the branch it was based on no longer existed. #41 then merged into its own base, feature/bond-request, not into development. So development has #34 only, and feature/bond-request holds both reviewed changes. This PR takes them to development. The branch merges cleanly into development, so it was not rebased.

Commits

The full descriptions, design notes and per-platform behaviour are on #40 and #41. Nothing has changed since they were reviewed.

Verification

  • Each change built with 0 errors and no new warnings for netstandard2.0, net10.0, net10.0-android, net10.0-ios, net10.0-maccatalyst, net10.0-windows10.0.19041.0 and net481 when its PR was opened. CI on this PR builds the combined result.
  • Not tested on hardware. Neither bonding nor a refused read, write or subscribe has been run against a real device on Android or iOS.
  • There is no test project in the repository, so no automated tests were added.

Device.CreateBondAsync calls BluetoothDevice.createBond and completes when
the adapter reports the device Bonded (true) or back to NotBonded (false).
A device that is already bonded returns true at once, and one that is
already bonding is waited on rather than asked again. The wait subscribes
before starting so a fast outcome is not missed, and only the success
state is re-checked afterwards, because straight after createBond Android
can still report NotBonded.

Device.RemoveBondAsync calls the hidden BluetoothDevice.removeBond by
reflection and waits for NotBonded. It is best effort: any refusal,
including the method being blocked as a non-SDK interface, is returned
as false rather than thrown, and the documentation says so.

Both return false on Apple platforms, Windows and stand-in devices, and
throw PlatformNotSupportedException on the platform-neutral targets as
other native members do. Cancellation stops the wait but not bonding the
system has already started.

Fixes #35
CharacteristicReadException, CharacteristicWriteException,
DescriptorReadException and DescriptorWriteException gain GattStatus, the
GATT status code where one was reported, and GattFailure, which
classifies it as InsufficientAuthentication (0x05), InsufficientAuthorization
(0x08), InsufficientEncryption (0x0F), Other or None. All four implement
the new IGattStatusException, so one catch can recognise a security
failure from any of them.

Android passes the GattStatus from the read, write and descriptor
callbacks. Apple platforms pass the NSError code only when its domain is
CBATTErrorDomain, because CBError codes in other domains mean something
else. Windows passes the ATT protocol error it already reported.

NativeStatus keeps its earlier meaning, including the NSError code
whatever its domain on Apple platforms, and every message is unchanged.
The new value is set through an added constructor overload, so the
existing constructors behave exactly as before.

Fixes #36
@newky2k
newky2k merged commit 9726cb1 into development Oct 15, 2026
1 check passed
@newky2k
newky2k deleted the feature/bond-request branch October 15, 2026 20:03
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