Repository navigation
Request and remove a bond on Android, and expose the GATT status on failures - #42
Merged
Merged
Conversation
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
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.
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 intodevelopment. Sodevelopmenthas #34 only, andfeature/bond-requestholds both reviewed changes. This PR takes them todevelopment. The branch merges cleanly intodevelopment, so it was not rebased.Commits
Request and remove a bond on Android(from Request and remove a bond on Android #40)Expose the GATT status on characteristic and descriptor failures(from Expose the GATT status on characteristic and descriptor failures #41)feature/bond-requestThe full descriptions, design notes and per-platform behaviour are on #40 and #41. Nothing has changed since they were reviewed.
Verification