-
-
Notifications
You must be signed in to change notification settings - Fork 325
Unified Bonding API supports Pairing on Windows. #906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
does this mean windows projects now need to be built targeting .net 9 or something? |
No, this is due to .NET 7 going out of support. We need to remove the net7.0 targets to fix it (I'll take care of that). Note that this is not related to your changes (also happens on master). |
b26ea94
to
1c0e55e
Compare
I fixed the problem via #908 and rebased this branch/PR on top of the updated master branch (which should heal the CI failures). |
To be honest, I have a hard time reviewing this PR, mostly because it is huge and contains lots of formatting and coding-style changes that do not relate to the proposed API changes at all. First of all, you're changing whitespace and indentation in almost every file you touch. Luckily that's easy to ignore in GitHub and other diff viewers, but even then the diff has around 3000 lines. It includes lots of changes of variable names and other coding-style related changes, which are not really "necessary". That is not to say that all of these small changes are necessarily useless: Some may improve code quality, some may make things worse, and for some it may just be a matter of taste. And I'm not really inclined to spend my limited time going through thousands of lines, just to wonder: What the hell has been changed here? And why the hell? So I'd tend to simply reject the PR in this form (even if it may include useful extensions of functionality, which is hard to tell, because they are drowning in tons of small unrelated changes). I hope that reaction is understandable. Maybe I can give a bit of advice on how to increase your chances of getting contributions accepted in this repository (or anywhere else on GitHub, for that matter):
|
LoL, i was trying hard not to change more. Well I don't blame you, my OCD, autism, or both, compelled me to clean up, but frankly every change was an improvement in both form and function. |
Verified to work with |
Unified Bonding API supports Pairing on Windows
3e4ecc2
to
e4c849b
Compare
It has come to my attention, that anyone looking to try this PR should be warned an explicit call to the 'new' BondAsync overload needs to be made in order to get full pairing support in windows: This was initiated as a PR Draft with the intention of allowing access to both the old and new and get user feedback before removing the old and submitting. Though as i no longer believe I'll be doing any further work with this PR, it was submitted as is. User note, you really need to know what kind of security your peripheral supports in order to pair with your peripheral correctly. |
Proposed support for Pairing on
Windows
, while adapting a common signature to the currentAndroid
implementation.Surely the signature for this API should have had an associated return value and have the possibility for cancellation, even if both are left unused:
public Task<BondResult> BondAsync(IDevice device, BondingOptions bondingOptions = null, CancellationToken cts = CancellationToken.None);
Adding an optional parameter
BondingOptions
which can include any properties that the method may require, in this case Pairing parameters.And return value
BondResult
as a unified object that represents the result of a Bond across any platforms rather than an arbitrarily, or no result from platform to platform.(Arguably all API calls should have parameters and return values that inherent from a
BaseOption
andBaseResult
to make adding functionality less brittle. BaseOptions having cancellation property, Baseresults having success property.)The other key addition is adding a mechanism to support the Pairing Response , which allows interaction during the pairing process:
public class PairRespondedEventArgs(PairModes selectedMode, Action<IPairResponse> approvePairingResponse, string pin = null) : System.EventArgs
As the initial signature wasn't well thought out, and support on each platform varies, implementation includes 2 interfaces,
IBondable
andIPairProcess
intended to be implemented on any platform which supports the feature.IBondable
indicates that a platform supports the programmatic request for Bonding and storing of keys. WhileIPairProcess
indicates the the platform supports a programmatic implementation of the pairing process.An interface arguably also provides a more agnostic way to implement non consistent features across multiple platforms, rather than relying on programmatic platform checking with loosely coupled and incomplete documentation.
On Windows:
Where Android the pairing process is handled by the OS
As implementation by application:
Example included in the Console Demo.
Regarding the
Android
implementation a few issues were addressed.Firstly, throwing exceptions on non exceptional scenarios seems unhelpful. User cancels the Bond process? throw... Clicks outside a dialog? throw... Times out without input? throw... Bonding already in process? throw... These hardly seem like exceptional events, but ironically if bonding does actually fail or become unresponsive, it either swallows any indication of why it failed, or doesn't throw at all. And not only was there no current mechanism to cancel, but an unresponsive call to bond would hold a reference to the last request, no matter how long ago it was made, and then would throws on the next subsequent bond request, no matter when in the future it would again be made.
This all seems odd to me, but since the Bonding process in the Android OS appears solid, these bonding failures rarely manifest.
Feedback is requested as there are no project design or coding guide lines to follow. Not to mention i knew nothing about Bluetooth bonding before a few weeks ago