-
Notifications
You must be signed in to change notification settings - Fork 837
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add thread annotations for
CycledLeScanCallback
Through testing it's been confirmed that the bluetooth scan callbacks are always run on the main thread. This chases that through the scanners and our callbacks so that this is properly documented / annotated. During this process the unused `AsyncTask` methods were removed as we don not use them. Additionally, the `mDistinctPacketsDetectedPerScan` flag has been declared `volatile` to ensure reads always see the most recently written value without having to rely on a heavy weight `synchronized` block. As this is a flag we only perform simple reads / writes. While we do perform a multi-step operation around reading/writing this value the work performed is too heavy weight and long to wrap it in a `synchronized` block. Using `volatile` gives multipel concurrent background threads a better chance of aborting this logic if another has changed the value. However, the downside of not having complete synchronization is that a background thread will try to check a few more packets and then re-set the flag to `true`.
- Loading branch information
1 parent
0ab8bee
commit 0f5e823
Showing
5 changed files
with
54 additions
and
18 deletions.
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
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
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