File tree 3 files changed +18
-3
lines changed
src/main/java/org/altbeacon/beacon/service/scanner 3 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,8 @@ Enhancements:
8
8
9
9
Bug Fixes:
10
10
11
- - TODO
11
+ - Fix failure to stop scanning when unbinding from service or when the between scan period
12
+ is nonzero. (#507 , David G. Young)
12
13
13
14
### 2.10 / 2017-04-21
14
15
Original file line number Diff line number Diff line change @@ -171,7 +171,20 @@ public void setDistinctPacketsDetectedPerScan(boolean detected) {
171
171
}
172
172
173
173
public void destroy () {
174
- mScanThread .quit ();
174
+ LogManager .d (TAG , "Destroying" );
175
+ // We cannot quit the thread used by the handler until queued Runnables have been processed,
176
+ // because the handler is what stops scanning, and we do not want scanning left on.
177
+ // So we stop the thread using the handler, so we make sure it happens after all other
178
+ // waiting Runnables are finished.
179
+ mHandler .post (new Runnable () {
180
+ @ Override
181
+ public void run () {
182
+ LogManager .d (TAG , "Quitting scan thread" );
183
+ // Remove any postDelayed Runnables queued for the next scan cycle
184
+ mHandler .removeCallbacksAndMessages (null );
185
+ mScanThread .quit ();
186
+ }
187
+ });
175
188
}
176
189
177
190
protected abstract void stopScan ();
@@ -285,7 +298,7 @@ private void finishScanCycle() {
285
298
// so it is best avoided. If we know the device has detected to distinct
286
299
// packets in the same cycle, we will not restart scanning and just keep it
287
300
// going.
288
- if (!getDistinctPacketsDetectedPerScan ()) {
301
+ if (!getDistinctPacketsDetectedPerScan () || mBetweenScanPeriod != 0 ) {
289
302
long now = SystemClock .elapsedRealtime ();
290
303
if (android .os .Build .VERSION .SDK_INT >= Build .VERSION_CODES .N &&
291
304
mBetweenScanPeriod +mScanPeriod < ANDROID_N_MIN_SCAN_CYCLE_MILLIS &&
Original file line number Diff line number Diff line change @@ -223,6 +223,7 @@ private void postStopLeScan() {
223
223
@ Override
224
224
public void run () {
225
225
try {
226
+ LogManager .d (TAG , "Stopping LE scan on scan handler" );
226
227
scanner .stopScan (scanCallback );
227
228
} catch (IllegalStateException e ) {
228
229
LogManager .w (TAG , "Cannot stop scan. Bluetooth may be turned off." );
You can’t perform that action at this time.
0 commit comments