signalapp / Signal-Android

A private messenger for Android.
https://signal.org
GNU Affero General Public License v3.0
25.59k stars 6.14k forks source link

Signal draining battery in background #6898

Closed ghost closed 7 years ago

ghost commented 7 years ago

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

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 commented 7 years ago

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 commented 7 years ago

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

ghost commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

Android 8 doesn't kill it because Signal doesn't target API 26.

I'm astonished you guys are still on API level 22.

On Aug 27, 2017 10:49 PM, "Moxie Marlinspike" notifications@github.com wrote:

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.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/WhisperSystems/Signal-Android/issues/6898#issuecomment-325265497, or mute the thread https://github.com/notifications/unsubscribe-auth/AA0cJ0ljLJew79Di5ahCIfCIIw6AYn1Nks5sclTOgaJpZM4PDtvG .

moxie0 commented 7 years ago

@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 commented 7 years ago

Let me know what you need

On Aug 28, 2017 9:39 AM, "Moxie Marlinspike" notifications@github.com wrote:

@bkerensa https://github.com/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.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/WhisperSystems/Signal-Android/issues/6898#issuecomment-325406065, or mute the thread https://github.com/notifications/unsubscribe-auth/AA0cJ2k7Kn6hcjVtTGnirFxWBjkNFtAhks5scu04gaJpZM4PDtvG .

moxie0 commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

Is there specific tools or methods you'd like me to check for this with? This is not a rooted device so relying on the system it does show one of those processes running 100% of the time using memory and draining battery specifically the MessageRetrieval process seems to be the culprit.

On Aug 29, 2017 9:06 AM, "Moxie Marlinspike" notifications@github.com wrote:

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

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/WhisperSystems/Signal-Android/issues/6898#issuecomment-325712839, or mute the thread https://github.com/notifications/unsubscribe-auth/AA0cJ7K2CBCi1Vl8mBfX1IZCrw4Fe9_Jks5sdDcHgaJpZM4PDtvG .

moxie0 commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

@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 commented 7 years ago

@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 commented 7 years ago

@nrizzio That is not correct see comment above https://github.com/WhisperSystems/Signal-Android/issues/6898#issuecomment-325788891 where in response to Moxie I used the profiler and pasted the instructions that are running constantly according to the profiler

Tatoniss commented 7 years ago

@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 commented 7 years ago

@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 commented 7 years ago

@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 commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

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.

RiseT commented 7 years ago

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

Doesn't change anything.

RiseT commented 7 years ago

Seems like this fixed the issue 👍

ghost commented 7 years ago

I have 4.10.11 and still seeing excessive drain Signal is top battery use and yet as an example today I haven't opened it and not received a message.

On Sep 12, 2017 9:11 AM, "RiseT" notifications@github.com wrote:

Seems like this fixed the issue 👍

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/WhisperSystems/Signal-Android/issues/6898#issuecomment-328900341, or mute the thread https://github.com/notifications/unsubscribe-auth/AA0cJ7lm4hcySX6SKRrp43UatK34oUh4ks5shqwvgaJpZM4PDtvG .

Tatoniss commented 7 years ago

I came here to comment that at first this completely fixed the excessive battery drain. Two days ago it started draining battery again. I wish I had recorded what version of signal I had but I got an update 4 days ago and since then I think the draining is back. I'm currently using the beta and just got an update to 4.10.11 today. I will watch it tomorrow to see if its still an issue. But I am sure that when @moxie0 closed this issue and pushed the update it did fix the drain. So perhaps one of the updates since then has reintroduced the issue.

ghost commented 7 years ago

@Tatoniss

But I am sure that when @moxie0 closed this issue and pushed the update it did fix the drain

meanwhile has been released a new update for android (September release). It's possible that google changed/fixed something :thinking: Do you have install it?

pgerber commented 7 years ago

There is an issue called Huge battery drain when on cellular data with no Play Services for Signal-Desktop (but concerning Android). Could it be that it only happens when you use cellular data?

Tatoniss commented 7 years ago

@pgerber yesterday I was on WiFi basically all day. I also have play services. Running unmodified Android 8 on the Google pixel XL.

Tatoniss commented 7 years ago

Ok I can definitely tell it's back. Yesterday I watched an hour worth of YouTube, I also used my Reddit app relay for almost two hours worth of on screen time. But signal used far more battery then those apps did. It was the top battery drainer by far.

Tatoniss commented 7 years ago

I hope this info helps @moxie0, I went ahead and left the signal beta and installed the stable version. This happened to be 4.9.9. The background battery drain is basically gone. With my normal usage after around 7 hours signal is 3% of my app usage. If I was still on 4.10.11 the app usage would be 30% +. After some more testing I'll update to the stable version that includes profiles that dropped today to see if the battery drain comes back. Maybe we should reopen the issue?

riyapenn commented 7 years ago

Device: Google Pixel XL Android version: 8.0.0 Signal version: 4.10.12 Log: https://gist.github.com/1104694ef6cfe90ab63ef5141059d1f6

tcables commented 7 years ago

This issue needs to be reopened. Since installing Signal my phone batteru drains twice as fast. Its due to having no google play services and the "Background connection enabled". Either we need an option to turn off that mode or to figure out what the drain is. I keep my data off most the day, and check messages in the evenings.

Lineage OS 14 Motorola X Pure (2015) Signal v4.10.12

johnmela commented 7 years ago

I second this, Signal is by far the largest battery draining app on my device.
https://gist.github.com/anonymous/b3889b498b6a3e42945c55fdb56897af

I am seeing NonSuccessfulResponseCodeException and EOFException being thrown. Hopefully this is useful

Android 8.0.0 Google Pixel XL Signal 4.10.13

moxie0 commented 7 years ago

@tcables You're probably looking for #6732 if you don't have play services. This ticket was for a different issue.

moxie0 commented 7 years ago

@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 commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

Out of curiosity as the developer why are you not investing time in doing QA to resolve issues like this? This bug has been open for weeks and you have not tried to reproduce it? Do you not have a single device running Android O?

On Thu, Oct 19, 2017 at 5:01 PM, Moxie Marlinspike <notifications@github.com

wrote:

@johnmela https://github.com/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.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/WhisperSystems/Signal-Android/issues/6898#issuecomment-338070260, or mute the thread https://github.com/notifications/unsubscribe-auth/AA0cJx-jLZ_1wUVKuOEE1rd9-4wJhe6fks5st-LtgaJpZM4PDtvG .

-- Benjamin Kerensa

moxie0 commented 7 years ago

@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.