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

Update/refresh is unreliable on Marshmallow and newer due to App Doze #26

Open
fobroth opened this issue Dec 16, 2016 · 24 comments
Open
Labels
Milestone

Comments

@fobroth
Copy link

fobroth commented Dec 16, 2016

I have to open the app to get current info. Would it also be possible to dismiss expired alerts on the widget?

@justdave
Copy link
Owner

The widget should automatically update any time the available alerts change. What version of Android are you on?

@fobroth
Copy link
Author

fobroth commented Dec 16, 2016 via email

@justdave
Copy link
Owner

justdave commented Jan 2, 2017

Are you using a custom home screen app (like Apex or similar)? What model phone is it?

The only thing I can think of that might cause this is if something is causing the background service to get killed. The OS in theory should be restarting it after 30 minutes if it does get killed though (although in my experience it usually restarts it almost immediately).

@justdave
Copy link
Owner

justdave commented Jan 2, 2017

The other thing I should ask: how long are you waiting to see if it updates? Right now it polls the NWS server every 5 minutes. If an alert expires or a new one shows up right after it checks, it wouldn't get picked up until it checks again 5 minutes later. Polling more frequently than that runs a risk of getting your IP address blacklisted by the NWS. They supposedly have push notifications available now, but I've been having trouble finding documentation for it.

One thing I can do, in the case of expired alerts, is to automatically remove them when their expiration time passes, whether we've polled again yet or not. I don't do that yet, but it's on the to-do list.

@fobroth
Copy link
Author

fobroth commented Jan 3, 2017

It's a samsung edge with no 3rd party app launchers. (Just samsung's stock goofy version)
I noticed the problem when the nws was issuing alerts for the last big winter weather last month. I live in midwest. I would see from another source that nws would add/modify alerts but the widget had stale info until I actuall opened the app, then the info got updated.
There's only been one (that I know of) alert since and that was from the widget.
Let me know if there's something I can do here to help because I do like having weather info available.

@fobroth
Copy link
Author

fobroth commented Jan 3, 2017

And it was hours for old vs new data.

@fobroth
Copy link
Author

fobroth commented Jan 3, 2017

Sorry to bombard you but for giggles I just opened the app and there's a fog advisory issued almost 8 hours ago that wasn't displayed in the widget.

@justdave
Copy link
Owner

justdave commented Jan 3, 2017

Do you have access to USB Debugging by any chance? If so, getting some logs might be useful.

@fobroth
Copy link
Author

fobroth commented Jan 3, 2017

Got prepared to do that but thanks to the wife's %#$* cat, I don't have a suitable usb cable. I don't have root on the phone, so, unless you can point me in another direction (I'm no developer or coder), I'm stuck until I find a cable. So sorry if this is a hassle for you. I can update you as my situation changes.

@fobroth
Copy link
Author

fobroth commented Jan 4, 2017

I hope this helps- widget.txt is nws and widget1 is NWS. grepped from logcat
widget1.txt
widget.txt

@justdave
Copy link
Owner

justdave commented Jan 4, 2017

The only important thing I see in there is:
01-03 18:24:03.195 16350 16362 I NWSBackgroundService: Timer task fetching https://alerts.weather.gov/cap/wwaatmget.php?x=IAC045&y=0
01-03 18:24:03.595 16350 16362 I NWSBackgroundService: Newly downloaded data hasn't changed since last time we grabbed it, ignoring.
Which basically tells me it's not updating because it thinks nothing new has been posted on the NWS site.

This is the right log to get the debug data out of to track this down, we're just going to have to catch it in the act to find out what's going on (i.e. keep it recording to a file and then go look at what shows up in the file if you catch it not updating.

I would probably grep -v LauncherAppWidgetHostView on your logcat though, since that's not really relevant and using a lot of space :)

@fobroth
Copy link
Author

fobroth commented Jan 4, 2017

I was hoping you would say that it was the timer task not logging every 5 minutes.
I get the feeling you suspect network problems. Is there something else to look for that would tattle on network problems? Is polling a standard 'system' function or does everyone do it differently? Can I snoop on other things to see if polling fails when the phone is idle?
As I mentioned before, I'm not any kind of developer or coder, so I included everthing in the log snips, just in case. I can see that the words are in english, that's about all I get out of it :/
I'll prune that crap out for next time.
So, will it help to grab the log just anytime or during possible nws alerts? Thanks for being patient.

@justdave
Copy link
Owner

justdave commented Jan 4, 2017

Oh, shame on me for not noticing the timestamps. Indeed, there are 4 ocurrences of the timer task running in the log, the last 3 are 5 minutes apart from each other like they should be, but the first 2 have 45 minutes between them. So there is certainly something happening that's keeping the timer task from firing. Was the phone stationary at the time? (laying on a desk, etc) If so, see https://developer.android.com/training/monitoring-device-state/doze-standby.html

Since the app doesn't do notifications yet, I haven't seen the need to work around that, since in theory as soon as you pick up the phone, Doze would release and it would update.

@fobroth
Copy link
Author

fobroth commented Jan 4, 2017

Well, that sounds like nothing but trouble. But I guess I see the point, if only it worked more gracefully. I can monkey around with adb again tomorrow using the instructions your link gave to force doze and see what happens in the log if you want. Google ought to allow devs to make doze whitelisting a user option for apps like yours. I hope we're onto something.
And, yes, my phone does alot of laying around, therefore, dozing.

@fobroth
Copy link
Author

fobroth commented Jan 4, 2017

FWIW- I found a 'hidden' (because I find the 'more' button less than intuitive) bunch of power saving options that toggles 'battery optimization' for apps. Last night, I turned this off for some apps that are supposed to do polling and this morn, I opened my phone to see that everything was current. This doze culprit makes sense because previously, it seemed that alot would happen when I woke my phone and it would take a while for it to catch-up. This leads me (the dumb user) to believe that apps aren't dealing well with doze. For now, I'm happy with the workaround.
I'd dismissed a bunch of (probably great) weather widgets as bull$#!^ because they didn't stay current and I was unaware that I could toggle their problem. This is the only alert widget I'd come across and am relieved to think that it's going to work, now. Thank-you!

@justdave
Copy link
Owner

Yeah, once I get notifications working, this'll need to get dealt with anyway, since notifications will need to fire when they happen, not wait until you pick up your phone.

@fobroth
Copy link
Author

fobroth commented Jan 20, 2017

I know I've already made you miserable opening this can of worms but I hope you'll consider allowing a user to choose what gets notified- for me, getting notifications on warnings would be important while hearing a ding on watches and advisories would be crying wolf. While this app will likely be on all my androids, warning notification would make it indispensable.

@justdave
Copy link
Owner

Oh, definitely, I'd have the same issue. I couldn't care less about the flood warnings because I don't live near the river, etc. :-) My plan was actually to let you set distinct tones for different alerts, even. There's a lot of potential alerts though, so it'd probably need a few "default sets" to start from.

@fobroth
Copy link
Author

fobroth commented Jan 20, 2017

Wow! That sounds... (i can't believe i'm saying this) awesome! I'm thinking of my wife here, in that, if there were a particular tone for different events, it would be less tempting for her to pick up her phone while driving to see what the warning is.
If it would help to have an outside someone for testing (or ?) don't hesitate to ask.

@justdave
Copy link
Owner

If only there were more hours in the day. I don't actually get time to work on this all that often. If you know anyone that can code I'm happy to take the help :)

@fobroth
Copy link
Author

fobroth commented Jan 23, 2017

Nope :( I guess i'll just be patient and look forward to the next version. Thanks, Dave.

@justdave justdave changed the title Update/refresh Update/refresh is unreliable on Marshmallow and newer due to Doze Aug 23, 2017
@justdave justdave added the bug label Aug 23, 2017
@justdave justdave changed the title Update/refresh is unreliable on Marshmallow and newer due to Doze Update/refresh is unreliable on Marshmallow and newer due to App Doze Aug 23, 2017
@justdave
Copy link
Owner

I think I have a patch to fix this finally, unfortunately it's crashing on me when I install it :( Continuing to poke at it.

@fobroth
Copy link
Author

fobroth commented Feb 15, 2018

Hi, Dave. I hope you weren’t counting on my helping but it’s not that I wouldn’t be happy to. My wife had to get us iphones. You can delete this when you read it since it’s off topic. Just didn’t want you to think I flaked on you. Good luck.

@justdave
Copy link
Owner

justdave commented Jan 6, 2020

I have working code on the antidoze branch that prompts the user for exemption for battery optimization on first run, however, the compiler is throwing this warning when it builds:

Use of 'REQUEST_IGNORE_BATTERY_OPTIMIZATIONS' violates the Play Store Content Policy regarding acceptable use cases, as described in http://developer.android.com/training/monitoring-device-state/doze-standby.html

And I also hear many places that Google will ban apps from the Play Store for using it.... meh.

@justdave justdave added this to the Version 2.0 milestone Mar 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants