Skip to content
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

Adapter isDiscovering() behaviour #38

Closed
srware opened this issue Jul 9, 2020 · 3 comments
Closed

Adapter isDiscovering() behaviour #38

srware opened this issue Jul 9, 2020 · 3 comments

Comments

@srware
Copy link

srware commented Jul 9, 2020

I am seeing some strange behaviour with the isDiscovering() call in BluetoothAdapter.

I am frequently getting the following error when calling stopDiscovery() despite the isDiscovering() function returning "true":

org.freedesktop.dbus.exceptions.DBusExecutionException: No discovery started

I guess this exception should also be caught in the BluetoothAdapter.stopDiscovery() function. I am also wondering whether initialising the internalDiscover variable to false would help this although I guess that assumption could lead to other problems...

@hypfvieh
Copy link
Owner

The member internalDiscover is only used when startDiscovery() / stopDiscovery() is used.
The method isDiscovering() will return true if internalDiscovery is true (when startDiscovery() was called and stopDiscovery() was not yet called), or if the DBus-Response says discovery is active.

The internal member does not need to be initialized with false, because that is the default for primitive boolean members in Java.

The exception might occur because internalDiscovery was not set correctly when startDiscovery() / stopDiscovery() was called due to exception catched in these methods. Therefore isDiscovering() still returns true/false and the start/stop method will be executed instead of being omitted.

Setting the member and calling start/stopDiscovery on DBus is not atomic, so in the current code, DBus is called first, then the member is changed. If DBus throws an exception, setting the member to true/false is never called, so the internalDiscovery flag has the wrong state.

I change the code to first set the member, then call DBus.

hypfvieh added a commit that referenced this issue Jul 10, 2020
@srware
Copy link
Author

srware commented Jul 10, 2020

Thanks for the explanation @hypfvieh

Is there a timeline for a new release incorporating some of the recent fixes?

@hypfvieh
Copy link
Owner

no there is no timeline

@srware srware closed this as completed Jul 10, 2020
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

No branches or pull requests

2 participants