-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
Very high battery usage #15
Comments
Thank you for reporting this as well. I'll take a look and see what can be put in place to lower battery usage. I think there is a way this could be more optimized. |
The latest release, 2.3.2, I made some changes that should hopefully help the battery usage. This is especially true when VPN is active. I change the statistics monitoring (handshake and packets) from a 1 second to 10 second interval which should help battery usage. I made another change to how VPN auto tunneling works that could potentially have a minor improvement to battery usage as well (especially for a device that is constantly changing network connectivity). Please let me know if you notice any change in battery usage performance in this new release. I will also monitor it for myself. Thanks again! |
So even after these changes in 2.3.2 I am still seeing high battery usage. I believe I found a solution that involves switching from a foreground service to a broadcast receiver for listening to the connectivity changes. If I can get this working it would massively improve battery performance. I'll keep you posted on my progress. |
You may want to have a look at how the Automate app (a free alternative to Tasker) monitors for connection changes, using my Automate flow. Also, I needed to set "battery usage" of Automate app to "Unrestricted". But battery usage is rarely more than 0%. I use this in combination with the official Wireguard app. But it requires the Automate app, my flow, several configurations (see the flow description) and additionally, you have to remember to reboot your phone after every Automate app update. I can't wait for you to fix the battery usage, me, my wife and some others will definitely switch to WG Tunnel and get rid of tis cumbersome setup with Automate and the official app. Offtopic: |
Hi, thanks for the detailed background and information on other potential solutions. Is Automate open source? I can't find the source code to see how they are accomplishing monitoring of network changes with low battery usage. I think I might be able to give some background in the off topic bit. I know this feature seems like a pretty basic feature but Android has actually made it extremely difficult to accomplish the monitoring of the network SSID changes (especially in the background) as their APIs/Android have progressed. They have removed system wide broadcasts of network changes and have further restricted the access of reading the wifi SSID. This is likely why you see this feature implement on all of the other WireGuard apps but not on Android. This is the reason I was pushed to use a more power consuming foreground service approach for this feature. You can see the list of system level broadcasts events here: I have come up with an potential alternative solution but it has some quirks. There is a way to receive a broadcast from the system when network changes happen. From my testing, this functionality is only available to an app that is currently open or backgrounded (unlike the system level broadcasts list above). So, essentially, if you use this battery saving feature you would have to background the app and not close it for the auto tunneling to still work. I haven't full tested this idea but it should reduce the battery consumption. What are your thoughts? |
I think Automate is closed source but there is an official forum and Reddit page: Regarding your proposed solution: I think that's exactly how for example Automate but also FolderSync work, they are always active in the background. The notification is not necessary or disabled. On Android 13 it looks like this: I just rebooted my device, before that it said 175 hours for both. Battery consumption is basically 0. |
Just FYI:
The tunnel does not auto-turn on when I leave the house/wifi. The app is also not shown anymore in the notification list of "Active apps". It was present there for a while though in the past hour. Once I open the app, go back home, connect to wifi then disable wifi, it does autoconnect again. So I guess the current solution to monitor for network changes/stay active is indeed a bit unreliable on some devices/latest Android? |
The only thing I can think of is that the system killed the app. I'll investigate and see if I can reproduce. |
I have this issue conistently one one of my devices. The app somehow gets killed even if the vpn is currently connected. On another device this happens less often, about 2-3 times a week. |
That's for the additional info! Could you tell me the model and version of your device that it happens less often on? |
Yeah, thats a Pixel 5 with Android 13 latest Patch. |
In my case, it was a human error! I had set battery usage to Restricted instead of Unrestricted. |
I can confirm, with:
The app still does not stay active.. it disappeared from the list of active apps.. |
Thanks for the additional details. I'm doing more testing to see if I can replicate and remediate. I have a few different changes I'm currently testing out. In dev, I did get it working where you can now start VPN from the tile even if the app is closed and auto tunneling service is not active (this does not work on the official app). This would also relaunch the auto tunneling service if it had been killed by the OS. I still want to get to the bottom of why the OS is killing the service but we'll get there with time I am sure. I also invite you both @zilexa @mich2k to join the Discord if you're interested and have not already joined. It is a bit easier to go back and forth on ideas, improvements and discoveries there. |
@mich2k I don't think you are in the right place. You just go to your app drawer where all your apps are and long press. You need to get to "App Info". Additionally I did a test, I didn't charge my phone last night. It had enough battery to not automatically switch to an extreme battery save mode. Now I see both apps that should stay active, stayed active:
Not sure why yesterday (while not at home) wg-tunnel did stop. Not sure what triggers that. I will pay attention the next few days to see what happens :) And will join Discord! |
@zaneschepke maybe there is no issue: I don't have the updated version yet that re-enables auto-tunnel via the tile. Maybe I disabled/paused the tunnel via the tile and enabled it again via the tile, but then auto-tunnel stays disabled with the version that I have. |
In order to avoid suspension on Samsung you have to tweak two menus, the one you are saying "Unrestricted" and this other one that states "app never in suspension" (this last one allows the app to run on battery saving etc) I even managed to find the background consumption (is in the multitasking panel and the consumption is always around 1 and 3% |
Added the ability to turn on and off tunnels via intents to the shortcut activity. #44 Added a setting to enable or disable shortcut/intent control of tunnels. Added an experimental battery saver setting to auto-tunneling to fix the battery drain issue caused by wakelock. #15 Fixes a bug where sometimes the config screen could crash if there are issues parsing the tunnel config data.
I'm sorry it has taken me a long time to address this issue. In version 3.1.6, I've added an experimental feature in the settings screen to address the battery drain. With this feature enabled, the app will no longer hold a wake lock on the CPU for longer than 10 minutes. This change will prevent the battery drain. I have done some light testing with this new feature. I did not see an impact on auto-tunneling, but I only tested a few scenarios. Any feedback on this would be greatly appreciated! |
So far, I have seen positive results and positive feedback from users on the new battery saver setting. With that, I am going to mark this one as closed. Any future feedback on the battery saver/power usage can be opened as a new issue. |
The app uses about 30-40% of my battery in the background. I can see this happening on three different phones.
The app runs on the default optimized battery mode.
Is there something that can be done or is it not fixable?
The text was updated successfully, but these errors were encountered: