Skip to content

Commit c4371ea

Browse files
committed
Future proof threading / scheduled task flows
This adds a guard to ensure that we only attempt a further scan when we the scan cycler is started. This helps ensure we've terminated scanning for the case where all regions have been removed but the service is still bound. In this case only `stop` will be called (instead of both `stop` and `destroy`). When this happens there are two potential scheduled tasks still queued: - `scanLeDevice(true)` from `deferScanIfNeeded` - `scheduleScanCycleStop` Which potential task is queued is based on if we were in an active scan period or a between scan period when `stop` was called. In the case of a between scan period the `deferScanIfNeeded` _will_ cause scanning to start up again when it ends. It will run for one more scan cycle before it terminates in `finishScanCycle`. Similarly, if we are in an active scan period the scheduled job for finishing the scan cycle will continue for the duration of the scan period.
1 parent 831057f commit c4371ea

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Bug Fixes:
1010

1111
- Fix failure to stop scanning when unbinding from service or when the between scan period
1212
is nonzero. (#507, David G. Young)
13+
- Fix failure to stop scanning when there are no active ranged or monitored
14+
regions. (#513, Aaron Kromer)
1315

1416
### 2.10 / 2017-04-21
1517

src/main/java/org/altbeacon/beacon/service/scanner/CycledLeScanner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ protected void scanLeDevice(final Boolean enable) {
230230
if (getBluetoothAdapter() == null) {
231231
LogManager.e(TAG, "No Bluetooth adapter. beaconService cannot scan.");
232232
}
233-
if (enable) {
233+
if (enable && mScanningEnabled) {
234234
if (deferScanIfNeeded()) {
235235
return;
236236
}
@@ -294,7 +294,7 @@ protected void scanLeDevice(final Boolean enable) {
294294
protected void scheduleScanCycleStop() {
295295
// Stops scanning after a pre-defined scan period.
296296
long millisecondsUntilStop = mScanCycleStopTime - SystemClock.elapsedRealtime();
297-
if (millisecondsUntilStop > 0) {
297+
if (mScanningEnabled && millisecondsUntilStop > 0) {
298298
LogManager.d(TAG, "Waiting to stop scan cycle for another %s milliseconds",
299299
millisecondsUntilStop);
300300
if (mBackgroundFlag) {

0 commit comments

Comments
 (0)