Prevent scanning being left on after unbind #569
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This resolves a case of scans being left on (forever) after unbind is called on the BeaconManager as reported in #567.
The problem was that scanning may not be stopped at the end of a scan cycle (for the case of avoiding too many scans per minute on Android 7+, or for keeping scans going because multiple packet detections are available.) This addresses that by setting a flag if scanning is left on for one of these cases and then explicitly stopping it at the end of the cycle.
A test run that shows this in operation is shown in the log sequence below. The fix is triggered on the line that says "Stopping scanning previously left on".
This test run used the reference app with this modification in the application class: