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

HW filter background time optimization #974

Merged

Conversation

vladvladau
Copy link
Contributor

Issue

First beacon detection happens after ~25 minutes after the first run of the application in background mode.

Cause

It takes ~10 minutes to launch the application after is being killed + 15 minutes to run the first scheduled periodic scan job in order to install the HW filter.

Fix

After the application is launched in background, do an immediate scan job in order to install immediately the HW filter (which is installed after a scan job life-cycle is completed).
The monitored beacons are detected in 10 minutes (how much it takes to re-launch the application).

The fix is composed from two commits:

  1. Initiate background mode before bind in order to avoid 2nd schedule call;
  2. Add a "first time scan flag" in order to trigger the immediate scan job if we start in background;

The 2nd commit depends on the 1st one.

Roboelectric tests

The tests are passed (with fix #973).
image

Manual tests

Device: Huawei Mate 20 Pro
AndroidOS: 10
Debug without wire (over Wi-Fi)

  1. Before fix
  • BeaconManager started up on pid ...
  • This consumer is not bound.
  • Not starting beacon scanning service. Using scheduled jobs
  • Activating background region monitoring
  • Background region monitoring activated for region id1:
  • Applying settings to ScanJob //1st run
  • Applying scan job settings with background mode false
  • Scheduling immediate ScanJob to run in 50 millis
  • Scheduling ScanJob (...) to run every 300000 millis
  • updating background flag to true
  • updating scan period to 10000, 300000
  • Applying settings to ScanJob //2nd run
  • Applying scan job settings with background mode true
  • Register calls: global=2 instance=2
  • Not scheduling an immediate scan because we are in background mode. Cancelling existing immediate ScanJob.
  • Scheduling ScanJob (...) to run every 310000 millis
  • consumer count is now: 1
  • Waiting for BeaconService connection
  1. After fix
  • BeaconManager started up on pid ...
  • updating background flag to true
  • updating scan period to 10000, 300000
  • This consumer is not bound.
  • Activating background region monitoring
  • Background region monitoring activated for region id1:
  • Applying settings to ScanJob //1st and only run
  • Applying scan job settings with background mode true
  • This is the first time we schedule a job and we are in background, set immediate scan flag to true in order to trigger the HW filter install. //new logs
  • Register calls: global=1 instance=1
  • We just woke up in the background based on a new scan result or first run of the app. Start scan job immediately.
  • Scheduling immediate ScanJob to run in 0 millis
  • First immediate scan job scheduled successful, change the flag to false. //new logs
  • Scheduling periodic ScanJob (...) to run every 310000 millis
  • Notify beacon manager that the immediate scan job in background was scheduled successful. new logs
  • consumer count is now: 1
  • Waiting for BeaconService connection
  • Register calls: global=2 instance=2
  • Beacon simulator not enabled
  • Started passive beacon scan //HW filter is installed after immediate scan job

Copy link
Member

@davidgyoung davidgyoung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, @vladvladau. The only thing we need to change before merging is moving that new flag so it is not part of the public interface. Please do add an entry to CHANGELOG.md, too.

lib/src/main/java/org/altbeacon/beacon/BeaconManager.java Outdated Show resolved Hide resolved
@davidgyoung davidgyoung merged commit d7a74f2 into AltBeacon:master Jun 7, 2020
@davidgyoung
Copy link
Member

Thanks @vladvladau!

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.

2 participants