Skip to content

Release 4.1: bonding and the GATT status on failures - #44

Merged
newky2k merged 8 commits into
mainfrom
development
Oct 18, 2026
Merged

newky2k merged 8 commits into
mainfrom
development

Conversation

@newky2k

@newky2k newky2k commented Oct 18, 2026

Copy link
Copy Markdown
Owner

Release 4.1: bonding and the GATT status on failures.

This merges development into main so the release workflow publishes 4.1.

What 4.1 adds

Testing

Builds with no errors and no new warnings on all target frameworks, and CI passed on each PR. The repository has no test project, and none of these changes has been run on hardware yet.

Device.BondState reports the bond (pairing) state as the platform sees it:
read from the system on Android, from the pairing information on Windows,
and Unknown on Apple platforms, where CoreBluetooth does not expose bonding.
DeviceBondState gains Unknown, declared last so the existing values do not
move. It is also reported where the state cannot be read: Android 12 and
later without BLUETOOTH_CONNECT, the platform-neutral targets, stand-in
devices and disposed devices. Reading the property never throws.

The Android adapter now registers BondStatusBroadcastReceiver for its
lifetime and raises Adapter.DeviceBondStateChanged, resolving the device
to the instance it already tracks so PropertyChanged fires for BondState
on that instance too. The receiver previously could not have worked: it
built a Device with a null adapter, which throws. It keeps its public
surface, and handles its own failures because OnReceive runs on the main
looper. Registration uses RECEIVER_NOT_EXPORTED from API 33 and is
undone when the adapter is disposed.

The README gains a Bonding section describing each platform, including
how pairing works on Apple platforms.

Fixes #34
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
The release that adds bonding (#34, #35) and the GATT status on failures
(#36) adds public API, so it is a minor version. The release workflow now
stamps 4.1.yyMM.<run number + 100>, VersionPrefix moves to 4.1.0 for
local builds, the release notes name 4.1, and the README's install
example and CI description follow.

AssemblyVersion stays 4.0.0.0: it is pinned for the strong-named net481
binding, for the reason recorded in the project file.
@newky2k
newky2k merged commit 8581952 into main Oct 18, 2026
1 check passed
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