File tree Expand file tree Collapse file tree
src/main/java/org/altbeacon/beacon/service/scanner Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,7 +8,8 @@ Enhancements:
88
99Bug Fixes:
1010
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)
1213
1314### 2.10 / 2017-04-21
1415
Original file line number Diff line number Diff line change @@ -171,7 +171,20 @@ public void setDistinctPacketsDetectedPerScan(boolean detected) {
171171 }
172172
173173 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+ });
175188 }
176189
177190 protected abstract void stopScan ();
@@ -285,7 +298,7 @@ private void finishScanCycle() {
285298 // so it is best avoided. If we know the device has detected to distinct
286299 // packets in the same cycle, we will not restart scanning and just keep it
287300 // going.
288- if (!getDistinctPacketsDetectedPerScan ()) {
301+ if (!getDistinctPacketsDetectedPerScan () || mBetweenScanPeriod != 0 ) {
289302 long now = SystemClock .elapsedRealtime ();
290303 if (android .os .Build .VERSION .SDK_INT >= Build .VERSION_CODES .N &&
291304 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() {
223223 @ Override
224224 public void run () {
225225 try {
226+ LogManager .d (TAG , "Stopping LE scan on scan handler" );
226227 scanner .stopScan (scanCallback );
227228 } catch (IllegalStateException e ) {
228229 LogManager .w (TAG , "Cannot stop scan. Bluetooth may be turned off." );
You can’t perform that action at this time.
0 commit comments