Repository navigation
Release 4.1: bonding and the GATT status on failures - #44
Merged
Merged
Conversation
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.
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.
Release 4.1: bonding and the GATT status on failures.
This merges
developmentintomainso the release workflow publishes 4.1.What 4.1 adds
Device.BondState, withDeviceBondState.Unknownfor platforms that do not expose bonding (iOS, macOS), andAdapter.DeviceBondStateChangedon Android (the bond-state broadcast receiver is now registered).Device.CreateBondAsyncand a best-effortDevice.RemoveBondAsync; both return false where the platform does not support them.AssemblyVersionstays 4.0.0.0 for strong-name binding on net481.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.