mirror of
https://github.com/binwiederhier/ntfy.git
synced 2026-05-09 08:26:00 +02:00
[GH-ISSUE #76] Maximize battery life #61
Labels
No labels
ai-generated
android-app
android-app
android-app
🪲 bug
build
build
dependencies
docs
enhancement
enhancement
🔥 HOT
in-progress 🏃
ios
prio:low
prio:low
pull-request
question
🔒 security
server
server
unified-push
web-app
website
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/ntfy#61
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @karmanyaahm on GitHub (Dec 31, 2021).
Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/76
Having something like the following would be very cool, though it might be difficult to build. Basically:
@binwiederhier commented on GitHub (Dec 31, 2021):
Good Reference: https://github.com/gotify/server/issues/343
@binwiederhier commented on GitHub (Jan 1, 2022):
I'm going to use this ticket to work on battery optimization for various things. Here's a few things I've identified:
The AutoRestartWorker and the PollWorker (both every 15 minutes) should be combinedand the frequency should be reducedD/NtfyDetailActivity: Checking global and subscription-specific 'muted until' timestamp@binwiederhier commented on GitHub (Jan 2, 2022):
With the changes made in the unreleased Android version 1.5.2, my battery life has improved again. It's back to 4% for the day.
@arminus commented on GitHub (Jan 11, 2022):
I'm on 1.5.2 (play) / Android 8.0.0 with my own server.
According to GSam Battery Monitor, Ntfy used 42 mins CPU time since the last recharge 8h ago, which would mean almost 9% for those 8 hours (I didn't have it open during that time and I didn't receive any messages).
Is that to be expected? Overall it contributes to 11,2% of spent power (double the 5,1% for the Android-System and e.g. 4,4% for Outlook)
@binwiederhier commented on GitHub (Jan 11, 2022):
@arminus Thank you for providing numbers. That's very valuable.
It varies greatly, depending on your connection and phone. After attachments (#82), I'm going to look at improving battery life more, and make it more configurable. This is very very very tricky, because it's environment-dependent. What works for you may not work for others.
There are several strategies I'll try:
Should be only a week or so until I start work on this.
@binwiederhier commented on GitHub (Jan 11, 2022):
@arminus Few questions:
@arminus commented on GitHub (Jan 11, 2022):
@binwiederhier commented on GitHub (Jan 11, 2022):
Thanks for that info!!
I am pretty aggressively retrying when the connection is lost, basically every 60 seconds. But there are other horrible things I could improve.
@binwiederhier commented on GitHub (Jan 11, 2022):
Make wake lock optional: https://github.com/binwiederhier/ntfy-android/pull/10, thanks @MatMaul
@arminus commented on GitHub (Jan 12, 2022):
So today my phone is lying on my desk with connection to the LAN my server is running on.
So far 40 minutes CPU time out of 380 minutes since the last charge, or a whopping 15,8% of total battery consumption. This is even worse than yesterday with 1/ no LAN access.
@binwiederhier commented on GitHub (Jan 12, 2022):
This is horrible and totally unacceptable. If you run nginx/apache/... in front of the ntfy server, you could try to find out if there is an excessive amount of requests happening. Other than that, you could connect adb+logcat to your phone, but I'm not sure how much you're set up with Android development.
I have been running @MatMaul's change for 4 hours today and it shows 0% battery usage. I've been able to get messages through even when the phone is sleeping, so that change is very very exciting.
@arminus If you like, I can build you an .apk with the wakelock change that you can install and try for yourself.
@binwiederhier commented on GitHub (Jan 12, 2022):
0% for almost 6 hours.
@arminus commented on GitHub (Jan 12, 2022):
gladly.
I have adb and an old SDK/Android DevStudo installed, but I forgot most of what I knew about Android dev a while ago... If you tell me what to do (or point me somewhere), I'll try, though...
@binwiederhier commented on GitHub (Jan 12, 2022):
Thank you for helping out. It means a lot.
apk
Here's the .apk: https://phil.nopaste.net/kVu2T0jdwA?d=1&f=app-play-debug.apk&a=3H9iMXMzwK
This is the latest
mainbranch, which includes MatMaul's wake lock changes.Install:
adb
adb connect <yourphoneip>. It could say "connected" after you ACK it on your phoneadb logcat --pid=$(adb shell pidof -s io.heckel.ntfy)@arminus commented on GitHub (Jan 12, 2022):
Install worked, adb logcat returns this (after some init stuff) approx every 30 seconds:
Full log is attached, I guess there's nothing more to be gained by keeping logcat running any longer?
Then I'll have more detail on the power consumption tomorrow
logcat.txt
@binwiederhier commented on GitHub (Jan 12, 2022):
Yeah the log looks perfectly normal. We'd have to keep it running for a longer period of time if there are reconnects or something I think. Or get and excerpt from longer ago...
@arminus commented on GitHub (Jan 12, 2022):
I'll keep you posted on the power stats of the new version.
@arminus commented on GitHub (Jan 13, 2022):
Ok, today, ntfy doesn't event register on the battery monitor's app sucker page :-), i.e. no problem whatsoever with Persistent wakelock set to off.
So just being curious: Why would that wake lock need to be turned on? In my case (Android 8), I still get immediate notifications. Is that needed on newer Android version so as to not being killed by the OS? I might eventually have a newer phone, so just to be "future-proof" ;-)
@binwiederhier commented on GitHub (Jan 13, 2022):
That is awesome to hear, and mirrors my experience.
I get immediate notifications too, and I have a OnePlus phone which are notorious for killing apps. All of the docs say that Android can and will eventually kill apps that run in the background like this. But it doesn't. I don't know is the short answer. It seems contrary to the docs.
@binwiederhier commented on GitHub (Jan 19, 2022):
I think I'm okay with what we have with JSON stream and websockets. Closing this.
Now that wakelock is not the default anymore.
@GitHubGeek commented on GitHub (Jan 20, 2022):
A quick thank you note to people involved. The battery saving upgrading from 1.5.2 to 1.6 (wakelock disabled) is amazing. Much appreciated!
@binwiederhier commented on GitHub (Jan 20, 2022):
Much appreciated. It was all @MatMaul really, he deserves all the credit.