You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Finally, I'm using microG two days without any signs of #31. But unfortunately, I'm experiencing occasional battery drains (perhaps related to #47?) and I would like to report it, just in case. Perhaps someone could explain to me what am I actually seeing here (pics attached).
As you can see, during night, the properly went in deep sleep state (green lines). But today I plugged it off, and left it for few hours (red lines). The phone didn't go to deep sleep state, wifi wasn't active, so some messages I received on WhatsApp few hours ago arrived only when I picked the phone up and turned the screen on. (Yes, I reinstalled WhatsApp after installation of microG). Shouldn't the whole purpose of a push service be to wake the phone up and retrieve messages?
Also FWIW, BetterBatteryStats app reports com.google.android.gms.microG services partial wake lock was active 94,8%. Any thoughts?
For your particular period a logcat may be useful. But overall, I also noticed some battery drain: For 21hours (including 8 hours night time with internet off) I have 613 MCS Wakelocks which accounts for 36 minutes in total.
The red box area definitely is a bug. A logcat would be helpful but I guess it's not easy to reproduce. However there should be a way to fix it by ensuring every wakelock will time out, which is not the case yet. Do you remember how many wakelocks were detected by BBS (not only the time)
Changing the heartbeat interval will decrease battery usage in "normal" runtime (your green area), but will not help in case of a bug like the one described.
Changing some logic in the wakelock for heartbeat might also have more influence to the battery usage than changing the interval. And reducing the heartbeat interval will reduce wakeups which is good for battery, but without a wakeup push messages can not be delivered.
Do you remember how many wakelocks were detected by BBS (not only the time)
No, unfortunately, I wanted to capture a screenshot but forgot. I'll keep an eye on my battery usage, if something like this happens again, I'll try to capture as much information as I can.
Note that I'm using 5 minute beat interval. BetterBattery stats report allot of wasted time (1153s, 89,7%) on microG wakelocks (com.google.android.gms.microG services) but counts only 6 of them. (The phone is about two hours on battery, 15 hours of total turned on time.)
Also, one thing that I don't understand: Gms should wake my phone and check for new messages, right? When I turned screen on a moment ago, few messages arrived on Viber upon connecting to wifi. Shouldn't Gms wake the phone, turn on wifi, and retrieve those messages? Option _Keep Wi-Fi on during sleep_ is set to Only when plugged in.
Unfortunately the log does not contain any meaningful entries. I'd like to encourage you to always provide logs with timestamps, as they're crucial to find battery issues (e.g. I can't say if your log is for a timescope of 24h or just 2min). You can easily add timestamps to logcat by using the -v threadtime option (e.g. run adb logcat -v threadtime | grep GmsGcm).
Additionally, looking at the battery usage graph, it seems interesting to me, that last time the high power consumption happened when there was no wifi connection, and this time after the wifi came back... So maybe it's another issue this time?
I think one problem here is (was) that the wake lock was not released when no ack message was received after a heartbeat ping message. I had the situation that no ack messages were received anymore even though heartbeat pings were sent relatively reliably here because of relatively long intervals between heartbeats (8 minutes and above seems to trigger the problem). The SSL connection reports errors only after several further ping requests as it can also be seen in the log above.
From reading the code I think the wake lock is only released when an ack message is received. Is it really necessary to keep a wake lock for receiving the ack or couldn't the lock be released directly after sending the heart beat ping? Same question for the login request. On the other hand I wonder if microg shouldn't acquire a wake lock as soon as data is received in order to make sure that the device stays awake between the time when the data is received, dispatchMessage() is called and the message has been fully handled as I could imagine that otherwise the device goes back to sleep in between and the app receives the message only after unlocking the device as experienced by @pejakm. An interesting discussion about such issues is this Stackoverflow question.
I'm not sure about the wake locks but I've tried fixing the connectivity issues. I've done this by changing two things:
Not using inexact alarms. From my logs it seems they are delayed up to 15 minutes if no other events occur even if the interval is set to e.g. 4 minutes. In order to not to drain the battery too much an interval can be used on API level 19 and above. For API Level >= 23 probably even setExactAndAllowWhileIdle() should be used but I guess there some more testing is necessary which I can't do as don't have a device with Android 6.
Report the connection as broken much earlier when no ack-messages are received anymore. I've currently implemented this by storing the time when ack messages are received and checking if an ack message has been received at most two intervals back. A better way might be to store the stream id on the last heartbeat ping and require it to have changed between to heartbeat but this might also introduce new race conditions.
I'll test this for some more hours especially also when the phone is not connected to WiFi and the charger (where I also had these problems, there they seem to be fixed), if my tests are successful I'll open a pull request.
@michitux I'm open to test your changes and report back. I also must point out that I haven't been able to reproduce this issue since long time. The problems I'm mostly facing now are:
very often I need to open an app (Viber or WhatsApp) to receive a message (although my phone is connected to wifi)
if my device goes to sleep, after some time wifi shuts down (option Keep WiFi off during sleep is set to Only when plugged in), and I no longer receive messages until I pick it up and unlock it (so that it can establish connection to wifi again)
@pejakm I've just created #74 with my changes. This should make the connection stabler, at least for me the connection works reliably with 5 minutes interval. However I could still reproduce your problem that WhatsApp did not receive a message, see #75.
If your device does not have an internet connection, no messages will be received. Gms won't turn your WiFi on. The idea is that the app keeps an active connection to Google and wakes the phone up when data is received on that connection - which needs a persistent internet connection of course. However when WiFi goes off and you still have an internet connection (e.g. UMTS), the connection should be re-established using that connection. This should be the same behavior with the official Google Play Services.
I had few problems with wakelocks at Nov 17, 2015 commits. Could only use gmail 4.2.2 but with amplify I could limit wakelocks to max every 15 minutes. Now just upgrading to latest GMSCore and gmail to 4.9 I have gmail hold much longer locks... ie many minutes at a time. GCM isn't on... just pure sync.
An app automatically kills the connection when the screen is off and is supposed to sync gmail every 45 minutes. Once it does gmail prevents going back to deep sleep and amplify can't help since it holds the lock.
From this thread it sounds like gms isn't properly failing connections. So I'm not getting new mails and the phone can't sleep.
Hi, I experienced a battery drain this week with last version. I fixed it by checking-in. Next time I'll try to get the logcat, for this report to be more helpful.. ;)
Thanks.
J.
Just saw something that looked weird in my logcat output - I had my interval set to 60 seconds and seemed to be getting heartbeats every 30 seconds instead. Not sure if this is normal. I noticed this due to high battery drain; switched to a 300 second interval and I seem to be getting heartbeats every 5 minutes now as expected.
03-14 14:20:12.033 3222 4845 D GmsGcmMcsSvc: Scheduling heartbeat in 60 seconds...
03-14 14:20:12.034 3222 25904 D GmsGcmMcsOutput: Outgoing message: HeartbeatPing{last_stream_id_received=526}
03-14 14:20:12.773 3222 25903 D GmsGcmMcsInput: Incoming message: HeartbeatAck{last_stream_id_received=526}
03-14 14:20:42.036 3222 4845 D GmsGcmMcsSvc: Heartbeat initiated, reason: Intent { act=org.microg.gms.gcm.mcs.HEARTBEAT flg=0x4 cmp=com.google.android.gms/org.microg.gms.gcm.McsService (has extras) }
03-14 14:20:42.036 3222 4845 D GmsGcmMcsSvc: Scheduling heartbeat in 60 seconds...
03-14 14:20:42.038 3222 25904 D GmsGcmMcsOutput: Outgoing message: HeartbeatPing{last_stream_id_received=527}
03-14 14:20:42.752 3222 25903 D GmsGcmMcsInput: Incoming message: HeartbeatAck{last_stream_id_received=527}
03-14 14:21:12.038 3222 4845 D GmsGcmMcsSvc: Heartbeat initiated, reason: Intent { act=org.microg.gms.gcm.mcs.HEARTBEAT flg=0x4 cmp=com.google.android.gms/org.microg.gms.gcm.McsService (has extras) }
03-14 14:21:12.038 3222 4845 D GmsGcmMcsSvc: Scheduling heartbeat in 60 seconds...
03-14 14:21:12.040 3222 25904 D GmsGcmMcsOutput: Outgoing message: HeartbeatPing{last_stream_id_received=528}
03-14 14:21:13.401 3222 25903 D GmsGcmMcsInput: Incoming message: HeartbeatAck{last_stream_id_received=528}
03-14 14:21:42.041 3222 4845 D GmsGcmMcsSvc: Heartbeat initiated, reason: Intent { act=org.microg.gms.gcm.mcs.HEARTBEAT flg=0x4 cmp=com.google.android.gms/org.microg.gms.gcm.McsService (has extras) }
03-14 14:21:42.041 3222 4845 D GmsGcmMcsSvc: Scheduling heartbeat in 60 seconds...
03-14 14:21:42.043 3222 25904 D GmsGcmMcsOutput: Outgoing message: HeartbeatPing{last_stream_id_received=529}
03-14 14:21:43.272 3222 25903 D GmsGcmMcsInput: Incoming message: HeartbeatAck{last_stream_id_received=529}
03-14 14:22:38.870 3222 4845 D GmsGcmMcsSvc: Heartbeat initiated, reason: Intent { act=org.microg.gms.gcm.mcs.HEARTBEAT flg=0x4 cmp=com.google.android.gms/org.microg.gms.gcm.McsService (has extras) }
03-14 14:22:38.870 3222 4845 D GmsGcmMcsSvc: Scheduling heartbeat in 60 seconds...
03-14 14:22:38.872 3222 25904 D GmsGcmMcsOutput: Outgoing message: HeartbeatPing{last_stream_id_received=530}
03-14 14:22:40.223 3222 25903 D GmsGcmMcsInput: Incoming message: HeartbeatAck{last_stream_id_received=530}
03-14 14:23:08.873 3222 4845 D GmsGcmMcsSvc: Heartbeat initiated, reason: Intent { act=org.microg.gms.gcm.mcs.HEARTBEAT flg=0x4 cmp=com.google.android.gms/org.microg.gms.gcm.McsService (has extras) }
@jfrederickson This is intended behaviour. The ping will be sent within the interval [heartbeatMs/2, heartbeatMs] since KitKat. The exact time will be selected based on the device wake state. This will reduce battery consumption when the cpu has less wake-ups (as the system will merge schedules from multiple apps). However when the system is awake (like when you have it connected to your pc) it will always choose heartbeatMs/2 to ensure it's not necassary to wake up later.
We might want to change this behaviour a bit, maybe something like [hearbeatMs*3/4, heartbeatMs*5/4] is a better choice?
As you noticed, you can freely choose heartbeat interval, however values like 300 might be a little high for "push message feeling"
I'm not using microg anymore, but when I implemented this [heartbeatMs/2, heartbeatMs] interval I tested this mainly with 300s as interval and this worked perfectly fine and I would actually suggest this as default value. Note that the connection is maintained permanently and push messages will also wake up your device when no ping is sent as long as the connection hasn't been dropped in the meantime. You can see connection drops in the log as microg reconnects as soon as it detects that the connection is not alive anymore. Depending on your internet provider and your router when you are using WiFi also longer intervals might work. Every time the connection is lost the stream id is reset, so if you see small values of the stream id in the log and you have had a stable and permanent internet connection (and did not switch between WiFi and mobile data) during the last hours, your interval might be too long.
After update to 0.2.2-5-g6bf59b2 the microg would drain entire battery during the night, when wifi is off. Just to note, device checkin is off. I had to revert to stable 0.2.5. No logs for now, as I'm not in position to experiment these days. My best guess is that commit 2a394f9 is the cause of this.
Activity
bonanza123 commentedon Nov 1, 2015
For your particular period a logcat may be useful. But overall, I also noticed some battery drain: For 21hours (including 8 hours night time with internet off) I have 613 MCS Wakelocks which accounts for 36 minutes in total.
pejakm commentedon Nov 3, 2015
Well, I've compiled GmsCore with heartbeat interval of 5 minutes, and it's much better now, almost all night with minimal battery change.
mar-v-in commentedon Nov 3, 2015
The red box area definitely is a bug. A logcat would be helpful but I guess it's not easy to reproduce. However there should be a way to fix it by ensuring every wakelock will time out, which is not the case yet. Do you remember how many wakelocks were detected by BBS (not only the time)
Changing the heartbeat interval will decrease battery usage in "normal" runtime (your green area), but will not help in case of a bug like the one described.
Changing some logic in the wakelock for heartbeat might also have more influence to the battery usage than changing the interval. And reducing the heartbeat interval will reduce wakeups which is good for battery, but without a wakeup push messages can not be delivered.
pejakm commentedon Nov 3, 2015
No, unfortunately, I wanted to capture a screenshot but forgot. I'll keep an eye on my battery usage, if something like this happens again, I'll try to capture as much information as I can.
pejakm commentedon Nov 4, 2015
I haven't yet experienced that battery drain, but I captured a half an hour log just in case:
Note that I'm using 5 minute beat interval. BetterBattery stats report allot of wasted time (1153s, 89,7%) on microG wakelocks (com.google.android.gms.microG services) but counts only 6 of them. (The phone is about two hours on battery, 15 hours of total turned on time.)
pejakm commentedon Nov 4, 2015
Also, one thing that I don't understand: Gms should wake my phone and check for new messages, right? When I turned screen on a moment ago, few messages arrived on Viber upon connecting to wifi. Shouldn't Gms wake the phone, turn on wifi, and retrieve those messages? Option _Keep Wi-Fi on during sleep_ is set to Only when plugged in.
pejakm commentedon Nov 16, 2015
I think this happened once again, last night. Pictures and log attached, I hope they will be of use.
http://pastebin.com/vPTNdmDh
https://framapic.org/V0l4ssg6Atfv/wW9YNLSL
https://framapic.org/7DgZR4WmsJZV/g6XOOYdY
https://framapic.org/rfwMfmasMTON/pAsNGTUC
https://framapic.org/DC08zhd5MpUA/ygOKEQEQ
mar-v-in commentedon Nov 17, 2015
Unfortunately the log does not contain any meaningful entries. I'd like to encourage you to always provide logs with timestamps, as they're crucial to find battery issues (e.g. I can't say if your log is for a timescope of 24h or just 2min). You can easily add timestamps to logcat by using the
-v threadtimeoption (e.g. runadb logcat -v threadtime | grep GmsGcm).Additionally, looking at the battery usage graph, it seems interesting to me, that last time the high power consumption happened when there was no wifi connection, and this time after the wifi came back... So maybe it's another issue this time?
michitux commentedon Jan 10, 2016
I think one problem here is (was) that the wake lock was not released when no ack message was received after a heartbeat ping message. I had the situation that no ack messages were received anymore even though heartbeat pings were sent relatively reliably here because of relatively long intervals between heartbeats (8 minutes and above seems to trigger the problem). The SSL connection reports errors only after several further ping requests as it can also be seen in the log above.
From reading the code I think the wake lock is only released when an ack message is received. Is it really necessary to keep a wake lock for receiving the ack or couldn't the lock be released directly after sending the heart beat ping? Same question for the login request. On the other hand I wonder if microg shouldn't acquire a wake lock as soon as data is received in order to make sure that the device stays awake between the time when the data is received,
dispatchMessage()is called and the message has been fully handled as I could imagine that otherwise the device goes back to sleep in between and the app receives the message only after unlocking the device as experienced by @pejakm. An interesting discussion about such issues is this Stackoverflow question.I'm not sure about the wake locks but I've tried fixing the connectivity issues. I've done this by changing two things:
setExactAndAllowWhileIdle()should be used but I guess there some more testing is necessary which I can't do as don't have a device with Android 6.I'll test this for some more hours especially also when the phone is not connected to WiFi and the charger (where I also had these problems, there they seem to be fixed), if my tests are successful I'll open a pull request.
pejakm commentedon Jan 10, 2016
@michitux I'm open to test your changes and report back. I also must point out that I haven't been able to reproduce this issue since long time. The problems I'm mostly facing now are:
Keep WiFi off during sleepis set toOnly when plugged in), and I no longer receive messages until I pick it up and unlock it (so that it can establish connection to wifi again)michitux commentedon Jan 11, 2016
@pejakm I've just created #74 with my changes. This should make the connection stabler, at least for me the connection works reliably with 5 minutes interval. However I could still reproduce your problem that WhatsApp did not receive a message, see #75.
If your device does not have an internet connection, no messages will be received. Gms won't turn your WiFi on. The idea is that the app keeps an active connection to Google and wakes the phone up when data is received on that connection - which needs a persistent internet connection of course. However when WiFi goes off and you still have an internet connection (e.g. UMTS), the connection should be re-established using that connection. This should be the same behavior with the official Google Play Services.
forkoz commentedon Jan 11, 2016
I had few problems with wakelocks at Nov 17, 2015 commits. Could only use gmail 4.2.2 but with amplify I could limit wakelocks to max every 15 minutes. Now just upgrading to latest GMSCore and gmail to 4.9 I have gmail hold much longer locks... ie many minutes at a time. GCM isn't on... just pure sync.
An app automatically kills the connection when the screen is off and is supposed to sync gmail every 45 minutes. Once it does gmail prevents going back to deep sleep and amplify can't help since it holds the lock.
From this thread it sounds like gms isn't properly failing connections. So I'm not getting new mails and the phone can't sleep.
pejakm commentedon Jan 12, 2016
@michitux Compiled, installed, set timeout to 300 and looking forward to report back.
pejakm commentedon Jan 12, 2016
@michitux With your changes I have a feeling that I have GAPPS installed! Thanks, it really works great now!
jeekajoo commentedon Feb 27, 2016
Hi, I experienced a battery drain this week with last version. I fixed it by checking-in. Next time I'll try to get the logcat, for this report to be more helpful.. ;)
Thanks.
J.
jfrederickson commentedon Mar 14, 2016
Just saw something that looked weird in my logcat output - I had my interval set to 60 seconds and seemed to be getting heartbeats every 30 seconds instead. Not sure if this is normal. I noticed this due to high battery drain; switched to a 300 second interval and I seem to be getting heartbeats every 5 minutes now as expected.
mar-v-in commentedon Mar 14, 2016
@jfrederickson This is intended behaviour. The ping will be sent within the interval
[heartbeatMs/2, heartbeatMs]since KitKat. The exact time will be selected based on the device wake state. This will reduce battery consumption when the cpu has less wake-ups (as the system will merge schedules from multiple apps). However when the system is awake (like when you have it connected to your pc) it will always chooseheartbeatMs/2to ensure it's not necassary to wake up later.We might want to change this behaviour a bit, maybe something like
[hearbeatMs*3/4, heartbeatMs*5/4]is a better choice?As you noticed, you can freely choose heartbeat interval, however values like 300 might be a little high for "push message feeling"
michitux commentedon Mar 15, 2016
I'm not using microg anymore, but when I implemented this [heartbeatMs/2, heartbeatMs] interval I tested this mainly with 300s as interval and this worked perfectly fine and I would actually suggest this as default value. Note that the connection is maintained permanently and push messages will also wake up your device when no ping is sent as long as the connection hasn't been dropped in the meantime. You can see connection drops in the log as microg reconnects as soon as it detects that the connection is not alive anymore. Depending on your internet provider and your router when you are using WiFi also longer intervals might work. Every time the connection is lost the stream id is reset, so if you see small values of the stream id in the log and you have had a stable and permanent internet connection (and did not switch between WiFi and mobile data) during the last hours, your interval might be too long.
pejakm commentedon Apr 22, 2016
After update to 0.2.2-5-g6bf59b2 the microg would drain entire battery during the night, when wifi is off. Just to note, device checkin is off. I had to revert to stable 0.2.5. No logs for now, as I'm not in position to experiment these days. My best guess is that commit 2a394f9 is the cause of this.
pejakm commentedon Jun 4, 2016
I can confirm, with 0.2.3 I cannot reproduce this anymore.
mar-v-in commentedon Jun 8, 2016
Seems to be no problem anymore, closing.