-
Notifications
You must be signed in to change notification settings - Fork 836
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
Android O 8.1 - Avoid 15 minute background limit #642
Comments
I had only tested while viewing logcat over USB. I can confirm that our ranging service stops around 15 minutes (monitored over wifi). See attached. |
So to confirm, Android 8.1, continuous scanning and reacting to advertisements within a couple of seconds reliably is not possible by any means? Excluding rooting / modifying the OS. |
I think there are three issues at play here, and I am unsure which one is causing the trouble:
Based on the report, I am unsure if the behavior you witness is caused by either item 2 or item 3 above. It sounds like you are saying that after 15 minutes you never see ranging results again. Is this true, or do you only see them after a delay as described in item 3? Based on default configuration, this library will react to a new beacon detection in the background beacons very quickly (within a few seconds) because it uses hardware filters and scans based on Intents that are not blocked in the background. This, however, will only work for new detections of beacons when previously no beacons had been detected. If you continually want to detect beacons in the vicinity, then you are limited to about 10 minutes of ranging every approximately 15 minutes. However, if you do not use IMPORTANT NOTE: If you are running your own service, understand that Android 8 block services running longer than about 10 minutes if the app is in the background (unless they are a foreground service that shows an icon in the top bar while they are running.) This has nothing to do with the library, but is an Android 8 restriction on your custom service. (@breon is this possibly your issue?) |
Thanks for your reply @davidgyoung . This is what I've tried, Using the test build, when the screen is off, with a filtered scan, scanning continues for a time period, previously it just stopped with the screen off. I added to my application manifest, the xml from #529, not sure if this makes much difference though. As you said, scanning does stop after a period of time. Generally it does start again, strangely not all the time. The below log was generated with
Is that message about the wake up alarm a problem, that's a lot of ms?
What I am trying to get at, is it doesn't seem possible, to reliably scan for advertisements (even ignoring battery usage) without there being a window where >= Android 8 decides not to scan. Is this correct? Thanks again |
@jonface, a few points about the log excerpt shown above:
After a ScanJob ends, a new one will be scheduled to start. If the app is in the foreground, the new one will start after the foregroundScanPeriod ends. If the app is in the background, the new one will start after the backgroundScanPeriod ends (or ~15 minutes per Android background job scheduling restrictions, whichever is longer). At this time you should start getting detections again. It is important to note that while this limit is nominally 15 minutes, Android can vary the schedule, and I have seen it take up to 25 minutes. I wrote a blog post about the detection times you can expect here You are correct that Android 8 does not let you do more than scanning for ~10 minutes every ~15 minutes when your app is in the background and beacons are present. When beacons are not present, you can scan indefinitely for them until one appears. Is my description above consistent with what you are seeing? |
OK that's great, I can only assume I got impatient at some point and scanning would have resumed, but I had assumed it was broken. So from what you are saying, it is, unfortunately, working as designed. Ideally I wanted to be able to move around and roughly know where I was, based on the visible beacons, but it seems this is not going to be reliable on Android 8 phones, unless Google change something. Thanks again for taking the time to explain this, I did read your blog post on this topic, I was just hoping I had misunderstood it. Cheers |
Closing this because it sounds like this is working as designed. @jonface please reopen if you have test results that show it does not resume after ~15 minutes in this case. |
Expected behavior
With the screen off and no external power, beacon scanning can run continuously. I am filtering for a single iBeacon UUID. After 15 minutes of no beacon activity, I start emitting the iBeacon and expect the phone to detect it.
Actual behavior
Beacon scanning stops after approx 15 minutes. Have tried running the scanning as a foreground service but this still seems to stop.
Steps to reproduce this behavior
Scan for beacons with the screen off and the phone not powered externally. Wait for approx 15 minutes with no beacon activity and then start emitting beacons. Phone application should not respond.
Mobile device model and OS version
Google Pixel 2 8.1.0
Android Beacon Library version
2.12.4-android8_1
I don't have much/any android experience, but I've read,
http://www.davidgyoungtech.com/2017/08/07/beacon-detection-with-android-8 . Now assuming battery usage doesn't matter, is there anyway around this, such that beacon detection is near instant, as it is when the screen is on? The pre-release version 2.12.4-android8_1 allowed scanning to work with the screen off which was great, I'm just wondering if anything else can be done to allow continuous scanning with the screen off, greater than 15 minutes?
Thanks
The text was updated successfully, but these errors were encountered: