Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix thread leak with 0 regions and settings applied #888

Merged
merged 2 commits into from
Jul 9, 2019

Conversation

davidgyoung
Copy link
Member

This fixes an thread leak in an usual case where:

  • ScanJobs are being used (default on Android 8+) AND
  • 0 regions are being monitored and ranged, AND one of the following happens:
    • BeaconManager is used to apply a scanning settings change to the scanning service/job
    • BackgroundPowerSaver is active and the app switches foreground/background mode

The most likely way this could affect users of this library is by leaving BackgroundPowerSaver enabled on Android 8+ when the app is not ranging and monitoring any regions.

This happened because the ScanJob code failed to stop all the threads on CycledLeScanner by calling destroy() in the case where a ScanJob was abandoned because the BLE scan did not start. And the BLE scan did not start (by design) if the number of regions monitored and ranged were 0.

This change also adds code to the ScanJobScheduler that cancels all scheduled ScanJobs if there are 0 regions monitored and ranged. It is pointless and wasteful to keep the jobs going in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant