Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Enhancements:

Bug Fixes:

- TODO
- Fix failure to stop scanning when unbinding from service or when the between scan period
is nonzero. (#507, David G. Young)

### 2.10 / 2017-04-21

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,20 @@ public void setDistinctPacketsDetectedPerScan(boolean detected) {
}

public void destroy() {
mScanThread.quit();
LogManager.d(TAG, "Destroying");
// We cannot quit the thread used by the handler until queued Runnables have been processed,
// because the handler is what stops scanning, and we do not want scanning left on.
// So we stop the thread using the handler, so we make sure it happens after all other
// waiting Runnables are finished.
mHandler.post(new Runnable() {
@Override
public void run() {
LogManager.d(TAG, "Quitting scan thread");
// Remove any postDelayed Runnables queued for the next scan cycle
mHandler.removeCallbacksAndMessages(null);
mScanThread.quit();
}
});
}

protected abstract void stopScan();
Expand Down Expand Up @@ -285,7 +298,7 @@ private void finishScanCycle() {
// so it is best avoided. If we know the device has detected to distinct
// packets in the same cycle, we will not restart scanning and just keep it
// going.
if (!getDistinctPacketsDetectedPerScan()) {
if (!getDistinctPacketsDetectedPerScan() || mBetweenScanPeriod != 0) {
long now = SystemClock.elapsedRealtime();
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N &&
mBetweenScanPeriod+mScanPeriod < ANDROID_N_MIN_SCAN_CYCLE_MILLIS &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ private void postStopLeScan() {
@Override
public void run() {
try {
LogManager.d(TAG, "Stopping LE scan on scan handler");
scanner.stopScan(scanCallback);
} catch (IllegalStateException e) {
LogManager.w(TAG, "Cannot stop scan. Bluetooth may be turned off.");
Expand Down