-
Notifications
You must be signed in to change notification settings - Fork 838
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
Scan documentation update and stop scan bug fix #513
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3acdfa0
Add some documentation for cycled scanner handlers
cupakromer 1be324b
Start documenting thread usage for service objects
cupakromer 5f98c55
Fix where scanner thread is quit.
cupakromer 0ab8bee
Future proof threading / scheduled task flows
cupakromer 0f5e823
Add thread annotations for `CycledLeScanCallback`
cupakromer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
11 changes: 9 additions & 2 deletions
11
src/main/java/org/altbeacon/beacon/service/scanner/CycledLeScanCallback.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
package org.altbeacon.beacon.service.scanner; | ||
|
||
import android.bluetooth.BluetoothDevice; | ||
import android.support.annotation.MainThread; | ||
|
||
/** | ||
* Android API agnostic Bluetooth scan callback wrapper. | ||
* <p> | ||
* Since Android bluetooth scan callbacks occur on the main thread it is expected that these | ||
* callbacks will also occur on the main thread. | ||
* | ||
* Created by dyoung on 10/6/14. | ||
*/ | ||
@MainThread | ||
public interface CycledLeScanCallback { | ||
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord); | ||
public void onCycleEnd(); | ||
void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord); | ||
void onCycleEnd(); | ||
} |
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this annotation intended to be used this way? The docs say it is supposed to indicate that the method should only be called on the main thread, and I don't see why that would be true in this case. It seems to be intended for methods that manipulate the UI. In this case, I don't think there is anything wrong from calling on a worker thread. Perhaps a comment would be a better way to indicate that it is not necessarily run on a worker thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The scanner classes are not thread safe. They are started / run from the beacon service which runs from the main thread. Additionally, in the scanner class
mHandler
is defined on the main looper. One of the deferred tasks which are queued on this handler callscanLeDevice
. As things are right now, for all intents and purposes these methods need to run on the main thread.While we could add this to the javadoc, the annotation documents this with the benefit of giving an extra hint to intellisense. Now if you write the following you'll get a lint warning/error depending on the IDE configuration: