StephenBlackWasAlreadyTaken / NightWatch

A native android Nightscout client with alerts and google wear integration
GNU General Public License v3.0
92 stars 164 forks source link

Issue with M's doze feature #65

Closed msinkovich closed 8 years ago

msinkovich commented 9 years ago

Its not an bug but with M the doze feature will stop the watchface from updating. I am going to try to look to see if there is workaround. Ive removed both xDrip and Nightwatch from Battery Optimization but that hasnt worked.

Any suggestions would be helpful

AdrianLxM commented 8 years ago

Hi @msinkovich, do you use NightWatch with xDrip locally or pull the data from NightScout or Share?

I'don't have an M device but I could try to replicate what @mgranberry does for xDrip to work around Doze in M.

msinkovich commented 8 years ago

Im using NightwWatch locally with xDrip. Ive set what I thought would work to be not optimized my Doze but it still will go into a suspend mode...I had a Wear screen shot to show you as well but in my infinite wisdom didnt save it so I will have to wait unitl it does it again and I will update the thread.

Thanks. 2015-11-13 07 43 24

AdrianLxM commented 8 years ago

Ok, so the broadcast from xDrip works, but the rest (background task) sending it to the watch doesn't?

When not optimized, the app should be able to hold a partial wakelock. We had an issue with wakelocks solved in current master (merged a few days ago). May you try this? If you don't know how to self-compile it, I contact me and I can send you an apk.

We'll have to look into M later on anyway, as loading the data via the network won't work in doze mode like it is now. But local broadcasts from xDrip should work.

vawlk commented 8 years ago

First, awesome app. I can't thank you enough!

I am also having an issue with android M on the tablet that I keep near my bed to alert me about my son's BG. I don't get alerts late at night when I have the tablet set for priority notifications. I have heard that doze changed how notifications work.

Here is a bit about optimizing apps for doze.
http://developer.android.com/training/monitoring-device-state/doze-standby.html

Interesting tidbits about devices in doze mode: The system ignores wake locks Network access is suspended. Doze is particularly likely to affect activities that AlarmManager alarms and timers manage, because alarms in Android 5.1 (API level 22) or lower do not fire when the system is in Doze.

Hope this helps!

msinkovich commented 8 years ago

Sorry...I meant to reply earlier. I dont yet know how to compile a new apk so if you could compile it I would be happy to test it out. On another note this is a screenshot of the watch when Doze causes NightWatch to stop uploading live data. screen

as soon as I wake up the phone and start working with it the data is refreshed.

mgranberry commented 8 years ago

It isn't immediately obvious to me how to fix doze support for NightWatch, but you can avoid doze entirely by plugging in the device that is dozing. The best that I know how to do without breaking doze completely is to have NightWatch wake every 15 minutes to refresh data while dozing.

AdrianLxM commented 8 years ago

@mgranberry: waking just every 15 minutes does not sound promising. Then the value on the watch may be 17 minutes old before you get a new one (including some lag via the server). I'd rather break Doze and not have the advantages of lower battery consumption and risk not getting accepted to the play store - but still can query the server every 5 minutes.

@msinkovich I have no experience with dose, but that really sounds like it still could be the simple wakelock issue in the current .apk. Please send me an email to adrian.m@inbox.com and I will pack you an apk of current master.

AdrianLxM commented 8 years ago

Hi @msinkovich, you didn't report back after I sent you the link. Did it work? We now also have a Marshmallow branch where the basics of Marshmallow (at least in theory) are covered.

msinkovich commented 8 years ago

Hey... Been meaning to get back to you on this.... Been overwhelmed with the holiday and entertaining my family... I'll get back to you soon with my impressions on Monday.

Thanks again for all your help. On Nov 27, 2015 2:52 PM, "AdrianLxM" notifications@github.com wrote:

Hi @msinkovich https://github.com/msinkovich, you didn't report back after I sent you the link. Did it work? We now also have a Marshmallow branch where the basics of Marshmallow (at least in theory) are covered.

— Reply to this email directly or view it on GitHub https://github.com/StephenBlackWasAlreadyTaken/NightWatch/issues/65#issuecomment-160202177 .

whoiswes commented 8 years ago

I have multiple Marshmallow devices (as well as a Wear device and a Pebble) that I could test with. I will try to figure out how to compile APKs, but if anyone has a recent master build available and can post it somewhere I'd be happy to test and report back.

AdrianLxM commented 8 years ago

@whoiswes, if you want I can build you one. Email me at adrian.m@inbox.com

msinkovich commented 8 years ago

Ive been running the last linked version for a week or so and can say that the idle issue with doze looks to be solved. wouldn't hurt for a secondary tester to validate.

whoiswes commented 8 years ago

Adrian was kind enough to send over a build from master, and after just overnight I can already say it's resolved a number of issues.

First, on Android 6.0.1 / Wear 1.3, my watchfaces are remaining up to date - I no longer have to wake up the phone to get updates.

Second, because Nightwatch is staying up to date, I'm not getting any missed reading alerts (was averaging 2-3x a night where I'd have to wake up my phone and clear the alarm.

Also really loving having raw values available, as well as the uploader battery. I haven't had any other issues although I'm guessing I'll see a slight battery hit on my phone and/or watch - I will report back in a few days once any patterns have emerged.

Thanks everybody!

whoiswes commented 8 years ago

Just another quick followup, have had zero issues on the build Adrian sent, battery seems to be about the same on both the phone and watch, and I have had zero issues with the watchface being out of date.

AdrianLxM commented 8 years ago

Thanks for the feedback @whoiswes. Jason published the link to the apk on fb today to have a broader test group.

msinkovich commented 8 years ago

AdrianLxM ...what is the FB page?

AdrianLxM commented 8 years ago

@msinkovich The fb-group is "CGM in the cloud". The link to the apk: edit: it is now in the lateste Beta 2.0.4: https://github.com/StephenBlackWasAlreadyTaken/NightWatch/blob/master/Download.md

AdrianLxM commented 8 years ago

The MM updates are now in the latest beta version: https://github.com/StephenBlackWasAlreadyTaken/NightWatch/blob/master/Download.md

fivepointfiveish commented 8 years ago

Hi @AdrianLxM, sorry to bring back the topic. Could you point me to the code parts you changed in order to fix it? I'm having the same issue with the android uploader app for the standard Nightscout and I would like to give it a go. Thanks!

AdrianLxM commented 8 years ago

@MOVIgroup You could take a look at this Pull-Request: https://github.com/StephenBlackWasAlreadyTaken/NightWatch/pull/71/files

Take a look at the manifest for the permissions: <uses-permission-sdk-23 android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />

How to set the timers wou can find in the diff for this file e.g.: mobile/src/main/java/com/dexdrip/stephenblack/nightwatch/DataCollectionService.java

And how to ask to disable battery optimization you will find in the diff from this file: mobile/src/main/java/com/dexdrip/stephenblack/nightwatch/activities/Home.java

Hope that helps. It is basically copied from Matthias Granberry's M adadaption of xDrip. I'm glad to hear that someone starts working again on the wired uploader :)

fivepointfiveish commented 8 years ago

I'll do my best thanks! May I bother you again if in need? I'm not that skilled unfortunately...:)

AdrianLxM commented 8 years ago

@MOVIgroup Asking questions doesn't cost a thing ;) But I also just read the documentation and ported the code from Matthias.

You can also ask in this gitter channel: https://gitter.im/nightscout/dexdrip

cgmnellanuvola commented 8 years ago

@AdrianLxM jeez only now I'm having some time to look at it. I'm not even an half decent programmer so I appreciate your help. The code in practice create a fake alarm and then moves it again so that the system is never dozing? Can you also point me to Matthias Granberry's M adaptation of xDrip? I'm not entirely sure where is the best place to add the alarms management in the uploader code so I hope I can get a hint from that. Or maybe you could suggest me something?

cgmnellanuvola commented 8 years ago

@AdrianLxM never mind it seems I made it work. I'll share the code and send a pull request

vawlk commented 8 years ago

I know this is closed but Android N is coming soon and there have been some more changes to Doze mode. I found this website that goes in to detail about how to correctly incorporate real time notifications while a device is in doze instead of disabling battery optimizations.

https://www.bignerdranch.com/blog/diving-into-doze-mode-for-developers/

shaikrohman commented 6 years ago

as of last week or week prior, the app keeps crashing and fails to open. We use the app a lot and the wallpaper widget on all our phones. How do we resolve this please