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

Signal draining battery in background #6898

Closed
ghost opened this issue Aug 27, 2017 · 70 comments
Closed

Signal draining battery in background #6898

ghost opened this issue Aug 27, 2017 · 70 comments

Comments

@ghost
Copy link

ghost commented Aug 27, 2017

I have:


Bug description

Signal constantly running in background and using 21% of battery in Android 8.0 and ignoring Android 8.0 background limits

Steps to reproduce

  • using hyphens as bullet points
  • list the steps
  • that reproduce the bug

Actual result: Describe here what happens after you run the steps above (i.e. the buggy behaviour)
Expected result: Describe here what should happen after you run the steps above (i.e. what would be the correct behaviour)

Screenshots

Device info

Device: Manufacturer Model XVI
Android version: 0.0.0
Signal version: 0.0.0

Link to debug log

@dkarkar92
Copy link

Same issue.

On Nexus 6P running Android 8 Oreo.

I haven't opened Signal all day, yet it's the second highest usage (only 4%)

Battery Stats Page - https://i.imgur.com/4lgWYqP.png
Signal Battery Stats Page - https://i.imgur.com/ZqvR980.png

I also noticed 12% usage on Tuesday after a 10-15 minute text based chat with 1 person.

@nrizzio
Copy link
Contributor

nrizzio commented Aug 27, 2017

Can both of you send debug logs and paste the link here please?

@ghost
Copy link
Author

ghost commented Aug 27, 2017

I will post another at the end of the day it might be more useful than this short log but basically, I am seeing 21-30% drain on Android 8.0 Google Pixel so rather high-end hardware and a stable Android release. With Android 8.0 the OS has background limits so clearly Signal is ignoring those right now somehow.
https://gist.github.com/anonymous/256018562fdb25147442924e98c4205b

@moxie0
Copy link
Contributor

moxie0 commented Aug 28, 2017

Doesn't look like Signal is doing anything. Are you running an official production update of Android 8 that you got through the device's update channel, or something that you flashed yourself?

@ghost
Copy link
Author

ghost commented Aug 28, 2017

@moxie0 I am using an official OTA of Android 8.0 nothing custom here

Signal is top user again today so far 8% of battery used for 3 minutes total in signal but shows 5 hours of background activity by signal
https://i.imgur.com/yudaYMO.png

New debug log:
https://gist.github.com/anonymous/6d91e4a646c709553a74e7347c730c81

I am pretty sure signal will get to 20% by end of night like it has the last few nights

@moxie0
Copy link
Contributor

moxie0 commented Aug 28, 2017

Strange, must be a problem with Android 8. Nothing has changed in Signal, there should be no reason why it uses more battery in Android 8 than Android 7. There are no background tasks, that debug log only shows foreground activity.

@jeremymasters
Copy link

jeremymasters commented Aug 28, 2017

In android 8,it looks like apps that run in the background would have a notification about it.
Sounds like it must not be a background thing here. http://www.androidpolice.com/2017/08/27/tasker-can-hide-android-oreos-app-running-background-notifications-root-not-required/

@moxie0
Copy link
Contributor

moxie0 commented Aug 28, 2017

I wonder what it considers "running in the background." If Android 8 isn't killing them, Signal does have services that are "persistent," like the KeyCachingService, but that service doesn't run any instructions, it just caches a key in memory.

@ghost
Copy link
Author

ghost commented Aug 28, 2017 via email

@moxie0
Copy link
Contributor

moxie0 commented Aug 28, 2017

@bkerensa This really doesn't have anything to do with target API levels. The changes made in Oreo are additive; to my knowledge nothing about Android Oreo should mean that applications which performed no background work in Android 7 now suddenly perform hours of no-op background work in Android 8 unless they're targeting API 26.

There are many possibilities, including bugs in Android 8 that misreport battery consumption. To help fix this, though, I need someone who can reliably reproduce this issue on an Android 8 device to help identify what Signal is doing in the background. If you have the time and inclination to help, I would appreciate the investigation.

@ghost
Copy link
Author

ghost commented Aug 28, 2017 via email

@moxie0
Copy link
Contributor

moxie0 commented Aug 28, 2017

@bkerensa I would need to know what Signal is doing in the background on your device. Can you take a look and see if it is actually running, and if it is actually running, how much CPU time it is using, and if it is non-idle, what work it is performing?

@ghost
Copy link
Author

ghost commented Aug 29, 2017

Confirmed process is running non-stop https://imgur.com/a/mt2wy

I tried on another device running 8.0 and was able to reproduce and can continue to confirm that Signal is the highest battery using app I have installed even more so than my social media apps which I spend a lot of time in and I spend very little time in Signal.

@moxie0
Copy link
Contributor

moxie0 commented Aug 29, 2017

@bkerensa Those are idle services, they shouldn't be executing any instructions. Could you check and see if Signal is actually doing any work?

@ghost
Copy link
Author

ghost commented Aug 29, 2017 via email

@moxie0
Copy link
Contributor

moxie0 commented Aug 29, 2017

@bkerensa You can use the thread profiler in Android Studio to see what that thread is doing. If it's in the background for more than 30 seconds, it should be completely idle waiting on this lock:

https://github.com/WhisperSystems/Signal-Android/blob/master/src/org/thoughtcrime/securesms/service/MessageRetrievalService.java#L157

@ghost
Copy link
Author

ghost commented Aug 29, 2017

Looks like these instructions are occurring spuriously throughout the day without the app being opened:
08-29 12:33:41.081 25375-25375/? W/KeyCachingService: onStartCommand, org.thoughtcrime.securesms.service.action.ACTIVITY_START_EVENT
08-29 12:33:42.720 25375-25375/? W/KeyCachingService: onStartCommand, org.thoughtcrime.securesms.service.action.ACTIVITY_STOP_EVENT

@Tatoniss
Copy link

I received the Android O update to my pixel xl last night. I can already confirm signal is using way more battery then it did on nougat. With my use patterns it would almost never show up in the battery stats. Now on Oreo my phone has been off the charger for 3 hours. Signal is already using 9% of my battery and is climbing.

@haffenloher
Copy link
Contributor

I can already confirm signal is using way more battery then it did on nougat.

Does it just show up in the stats or do you actually notice an unusually high battery drain?

@ghost
Copy link
Author

ghost commented Aug 30, 2017

@moxie0 Does that info work for you? As more and more people ramp up to Android 8.0 this is going to be a more widespread issue. I would guess you guys have thousands of users on 8.0 already suffering from this issue.

I feel like until this is fixed I am put in the precarious situation of whether I want signal draining my phone or whether I want secure messaging.

@ghost
Copy link
Author

ghost commented Aug 30, 2017

@haffenloher see above it is already confirmed in profiler in android studio and also spurious messages are in logcat about the signal process.

Seems like WhisperSystems just needs to do some QA here but ultimately this issue would not be occuring if API Level 26 was targetted because Android 8.0's background limits would kill whatever is causing KeyCachingService to constantly run instructions.

@nrizzio
Copy link
Contributor

nrizzio commented Aug 30, 2017

@bkerensa Nobody has used the thread profiler to show what battery-draining work Signal is ostensibly doing in the background. "The battery stats say Signal is using battery" doesn't answer that question, nor do the application logs.

This leaves at least two possibilities: the services are causing measurable battery drain even while being idle (seems unlikely, but maybe possible), or Android's battery stats are overzealously calculating app-specific battery usage. But there is still not enough information to make a determination between these possibilities. In order to debug this, you or someone with access to a physical Android 8.0 device will need to use TraceView (I believe this is what Moxie is referring to but if not someone please correct me) to understand what exactly Signal is doing in the background. If you can follow that guide and post the complete results here, then Moxie will be able to further understand how to solve this issue. If you cannot, unfortunately there is not much you can do other than patiently wait for someone else to do this.

Finally, OWS is a very small team. There is only one Android developer at the moment, and raising the targeted SDK level by 4 levels is a massive undertaking because of the code that needs to be written, tested, and debugged, among other things. Furthermore, it's generally unnecessary, because future Android versions try to play nicely with older apps. This issue is sadly an exception, but please realize that OWS is resource constrained, not lazy.

@ghost
Copy link
Author

ghost commented Aug 30, 2017

@nrizzio That is not correct see comment above #6898 (comment) where in response to Moxie I used the profiler and pasted the instructions that are running constantly according to the profiler

@Tatoniss
Copy link

@haffenloher I haven't had a chance yet to go home and hook it up to Android studio. The best thing I can say is it looks like my phone isn't really sleeping. Also battery stats say signal has used 331 mAh which is 14%. Granted Oero has a new battery stats screen so maybe that's it. Also I agree it probably isn't the API level. Just changing it to 26 may not help. Oreo only denies background services to apps that Target 26. If the user hasn't manually set that in the settings for the signal app it should still be able to run in the background.

@ghost
Copy link
Author

ghost commented Aug 30, 2017

@Tatoniss the default for all apps in 8.0 is optimized battery use so it will nuke constantly running processes as long as the SdkVersion is 26. Aside from Background Limitations, there are a variety of other benefits of not staying to an API level that is not even an official API level but a developer preview level not intended for production use.

@moxie0
Copy link
Contributor

moxie0 commented Aug 31, 2017

@bkerensa I'm not sure what you're referring to, that looks like logcat output rather than instructions, are you sure that you're looking at the right thing?

That intent is fired from exactly one place in the entire codebase, the onResume() method of PassphraseRequiredActionBarActivity. It is used for the KeyCachingService to track "active use" for timing out a passphrase, but it would be very strange indeed if the onResume() method of an activity were being called without the app ever being launched?

@kcschan
Copy link

kcschan commented Aug 31, 2017

@bkerensa

Android 8 doesn't kill it because Signal doesn't target API 26. I'm astonished you guys are still on API level 22.

Can you confirm that you have disabled background activity toggle of the app?
The system does not enable this for legacy apps mandatorily:

Apps -> App Info -> Signal -> Background activity
In case you don't see it(I think it is some internal bug by Android), you can also turn it on by using appops as:

adb shell
appops set [signal's package name] RUN_IN_BACKGROUND ignore

For futher investigation, you can also generate a bugreport and analysis it by yourselves with the help of battery historian V2 which is a docker container project by google:

https://github.com/google/battery-historian

@RiseT
Copy link
Contributor

RiseT commented Sep 1, 2017

Same here. Per Android's calculations, Signal has used 41% of available energy at the time I had to recharge.

Nexus 5X, Android 8.0.0

@RiseT
Copy link
Contributor

RiseT commented Sep 1, 2017

Can you confirm that you have disabled background activity toggle of the app?
The system does not enable this for legacy apps mandatorily:

Apps -> App Info -> Signal -> Background activity

Per default this is enabled for Signal. I've disabled it now and will report if something changes noticeably.

@moxie0
Copy link
Contributor

moxie0 commented Oct 16, 2017

@johnmela If you're seeing battery drain on a stock device with play services, it'd be great if you could profile the application to see what work it's doing when it should be idle. Otherwise I would need steps to be able reproduce the issue you're seeing on a device of my own. There's nothing at all abnormal in that log.

@johnmela
Copy link

johnmela commented Oct 16, 2017

@moxie0 I just uninstalled it.. which removed the state the app was in 🤕 . I'll grab the source, profile it for a bit and see if I can reproduce

@johnmela
Copy link

It has taken a while but the issue seems to have resurfaced. Hopefully this information is useful, I am not sure what specifically would cause a problem.

I removed the device off of the charger this morning. Used snapchat, messages, chrome a little but but hadn't interacted with the signal app at all. Signal appears to be using significantly more energy than any other app.

Here are a couple log cats from this morning.
https://gist.github.com/anonymous/c05785eba8dfd44662fc71f542d245db
https://gist.github.com/anonymous/035fbd2b0a8f851b60d57a370800be0e

Some device screenshots:
screenshot_20171019-095523
screenshot_20171019-095518

And a screenshot from the profiler.
screen shot 2017-10-19 at 9 54 23 am

I have noticed JIT thread pool active for 12 minutes, finalizer daemon active for 12 minutes and count and also the JVMTI Agent thread doing the same, neither concurrently running

If there is anything else I can do to assist, please let me know

@moxie0
Copy link
Contributor

moxie0 commented Oct 19, 2017

@johnmela Thanks for looking into this. The logs look normal, just looks like you did one key rotation, received an SMS or two, and that's it.

I'm afraid I can't do much with that photo of the profiler. If there's activity happening, can you look and see what it is? For instance, last time I was able to determine that some timer animations were continuing to run after the app had been backgrounded. Can you see what's happening in your case?

@johnmela
Copy link

johnmela commented Oct 19, 2017

Hey @moxie0,

I'd love to help more, unfortunately, I'm not sure where to start here. It's been a few years since i've touched any native Android projects. Where should I be looking for this.. and can I see this within the profiler?

EDIT: If you mean UI activities running while the app is in the background.. no I didn't see that but I can remain vigilant, I only noticed the running threads

@moxie0
Copy link
Contributor

moxie0 commented Oct 20, 2017

@johnmela Yeah when your app is in a state that you feel is consuming power, you can open up Android Device Monitor (Tools -> Android -> Android Device Monitor) from Android Studio. Then select the process in a connected device, and click the button in the toolbar above it with the tooltip "Start method profiling." Wait 20 seconds or so, then "Stop method profiling" (same button). There should appear on the right a sorted list of where Signal is spending its time, and you can scroll down until you start hitting some Signal (non-framework) methods.

@ghost
Copy link
Author

ghost commented Oct 20, 2017 via email

@moxie0
Copy link
Contributor

moxie0 commented Oct 20, 2017

@bkerensa This is an open source software project. I am but one person, and there more than a thousand open issues. I do have an Android 8 device (bought it just for your issue!), and I have spent time trying to reproduce this report (I even made a change that fixed things for most of the commenters here), but I have been unable to reproduce the exact problem you are seeing. There are other people who can, though, and by helping they end up improving the software for themselves and for anyone else who is in the same situation. This is the magical dream of open source software, even if the reality more often bears a closer resemblance to the highly suggestive email you just sent me and ~600 other people.

@acct412
Copy link

acct412 commented Oct 26, 2017

I'm having battery drain issues as well.

Device: Google Pixel
Android version: 8.0.0
Signal version: 4.11.5

12 minutes of signal/screen usage today and 18% battery showing up. I have very little programming experience (first time using github as well) but I'm happy to provide any info you think may be useful. I may need a bit of coaching (never used android studio either). A friend just got the same phone running the same signal version and is having the same issue. I can provide screenshots from my phone if required but they basically mirror what has already been posted. If I could get the profiler working I wouldn't know what to look for.

Thank you for your time and patience.

Edit: I might be jumping the gun a bit here but I believe the issue is somehow related to WiFi.

I turned wifi off this morning and my phone is at 85% battery with 1% of that being Signal.

I also experienced this a week ago when I was without wifi for a couple of days and was restricted to cellular data. I will continue the day without wifi and report back. I'll also turn wifi back on tomorrow and see what happens.

Again, thanks for your time.

Edit2: I don't believe wifi is connected to the issue any more. I've been getting some days with high signal usage (over 10% battery with ~9 minutes of use) and some days with low usage (3% battery with 20 minutes of use). I will keep trying to find patterns and report back.

@tcables
Copy link

tcables commented Oct 26, 2017

@moxie0, thank you for what you do!
Most people don't realize its mostly you doing all the work.

Everyone should focus on providing as much debugging/data as possible and if he has the time, he can get to it. Or others should try a pull request, I guarantee that he would appreciate the help.

@2zeroseven
Copy link

Echoing @tcables, thanks much.

Found this thread when I noticed the same issue as others. Pixel XL on stock 8.0. I have Signal's background activity limited as per app settings, and have been using the desktop app today, not the phone. Signal still shows 30 mins of background time during the 5.5 hours I've been off a charger. Worth it, but not ideal.

I haven't used Android tools in a long time, but I'll see if I can poke around and help track this thing down.

@2zeroseven
Copy link

Update: before I plugged in the tools, I R&Red the app. Didn't save messages, clean install.

It basically fixed my battery issue (so far), although I did still need to discourage background activity thru the system setting. (Before I did that, Signal was taking a lot of background time, but with much less battery drain than before the reinstall.) It's been a few days, with light Signal usage from phone and from desktop. So i'm not that helpful but it's something.

@MikkyDoubleB
Copy link

I have also massive battery drain on Android 8.0 pixel xl. Reported it here: #6732

This has been going on for ages for lots of people.

@acct412
Copy link

acct412 commented Jan 4, 2018

I'm no longer having battery drain issues after updating to android 8.1. Can anyone else on 8.1 who was having issues on 8.0 confirm?

@MikkyDoubleB
Copy link

@acct412

Great! I have been thinking about doing a clean install for the 8.1. I'll reply here the results when I have done it.

@Tatoniss
Copy link

Tatoniss commented Jan 4, 2018

The latest version of signal and Android 8.1 has fixed the battery. Signal is no longer the main battery drainer. Granted I haven't been watching it lately so I watch it over the next few days and report back.

@Le1b1
Copy link

Le1b1 commented Jan 4, 2018

@acc412 Experienced the issue with Android 8.0, is gone after update to 8.1 without any action from my side.
Device: Google Nexus 5X (stock firmware)

@jeremymasters
Copy link

Samsung S8 user here. My concern with this is that Samsung has been updating to the X.0 version of Android for awhile now and this might kick us where it counts when Oreo gets here for Samsung.

@MikkyDoubleB
Copy link

I can confirm that Signal is no more draining battery on Android 8.1.

@211217613
Copy link

I've been experiencing massive battery drain on signal. Feels like it has to do with signal calls. I thought maybe I was just imagining things but then I checked here and saw this issue.

I'm running stock android on a google pixel.

screenshot_20180516-101714

screenshot_20180516-091133

https://debuglogs.org/e89e19d93e458f0cce77f4702dcc592b7cc1577a9337328cb76ef053dad93b43

@ptc
Copy link

ptc commented Jun 11, 2018

Same here. Signal is draining battery on Oreo 8.0. why is this report closed?

@BadFi
Copy link

BadFi commented Aug 9, 2018

I am curious why this was closed as well, I am having the same problem where signal drains more battery than any other app on Oreo 8.0. This thread is closed, but according to this thread the only "fix" for the problem is getting a device that uses android 8.1 or higher.

@prg318
Copy link

prg318 commented Oct 18, 2018

Having this same problem on Android 9 - even got an Android message warning me that Signal is using a lot of my battery in the background

@z4nD4R
Copy link

z4nD4R commented Oct 2, 2019

Hello All,

looks like for me the same issue. I haven't use signal for whole day and I could see singal as 2nd app in battery usage for that day (14%). Also I have noticed signal is consuming too much data on background - the same day I haven't opened signal for whole day it consumed 53MB. Looks a quite lot for me when haven't opened the app at all.

Anyone else experiencing such a issue in Oct 2019?

Thx.

Y

@aqzxt
Copy link

aqzxt commented Nov 2, 2019

Mine's 58%!

Screenshot_20191102-123507

Device:
Xiaomi Redmi 4 Prime
Android 9 (Lineage 16)
Signal 4.48.17

Debug Log:
https://debuglogs.org/fcffc49fb4b8f77a48691de20d534aff819685aadbc67dc1a8e7d4d15e182c44

Edit:
Logs was generated just after turning off background services for Signal (w/ BackgroundRestrictor)

Another thing I noticed is that I cannot turn Battery Opmitization on again: it simply won't let me. For other apps it's ok.

For Android 7 and 8.1 with different ROMs I had, was running fine. On all of them I do not use Google Services or alternatives.

@BetterToAutomateTheWorld

Same issue here, 48 percent used! Signal never on background, always active!

Screenshot_20200213-200717_Settings

@pierre07
Copy link

Same issue with Signal 4.55.8 on my Nexus5X 1005mAh for 5h22min50s.
This issue is written "closed" do we have to open a new one on the same purpose?

@eNTi
Copy link

eNTi commented Oct 25, 2020

I'm on 4.71.5 on my de-googled (no playstore) galaxy nexus (maguro) with lineage 14.1. Signal STILL uses around 30% battery. Which IS better than before (50-75%) but still unacceptable for a chat program.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests