microg / microg/GmsCore

MicroG is always getting disconnected when phone is in Doze (Idle) mode

Open
#1,011 17 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
14.6k
Forks
3.2k
Avg merge
12d 11h
Merged PRs (30d)
4

Description

MicroG is always getting disconnected when phone is in Doze (Idle) mode.

MicroG - last version (of November 2019), excluded from battery optimization, self-checks are OK.
In non-idle phone mode, it works fine - all my apps get push messages timely.
Andoid - Oreo 8.1, LOS-based ROM.

How to reproduce:

Open MicroG, open Google Cloud Messaging screen, in the upper-right corner click three-dot menu and click Advanced, set all ping intervals = 60 seconds (in order not to wait too long on the next steps below), return to Google Cloud Messaging screen, observe line "Current State: Connected Since ... "

Your phone must be rooted, or use adb.
Open terminal emulator, type "su", then artificially enter the phone into deep Doze (Idle) mode:
(the commands are taken from https://developer.android.com/training/monitoring-device-state/doze-standby.html#testing_doze ):
dumpsys deviceidle force-idle (just run the command - no need to unplug the phone from charger, no need to wait for the screen to turn off. This command allows to quickly emulate the state of the phone it normally enters into within 1-2 hours after having been left unplugged, with screen turned-off, and motionless (deep Doze mode)).
Check if it really entered into deep doze mode:
dumpsys deviceidle (in the end of the output there should be mState=IDLE mLightState=OVERRIDE for deep and light idle modes)
Now immediately switch to MicroG, open Google Cloud Messaging screen, observe line "Current State: Connected Since ... ". As this line is not auto-updated when this screen is static, you need to frequently switch from Google Cloud Messaging screen to Main screen of Microg, and then back to Google Cloud Messaging screen, and so on - forth and back - to get updated info in the line "Current State: Connected Since ... ". After 2-3 minutes (since entered into deep doze mode) of the switching between the microg screens forth and back, you'll finally observe "Current State: Disconnected" - and from now on it will stay disconnected forever, - until you explicitly exit doze/idle mode. It's obvious, that while microg is in disconnected state, you won't receive any GCM push messages for your messengers. The same disconnects in microg are observed after phone entered deep doze mode normally, on its own (within 1-2 hours after having been left unplugged, with screen turned-off, and motionless ).

To exit the artificial doze/idle mode, run:
dumpsys deviceidle unforce ; dumpsys battery reset
Check if it really exited doze mode and returned back to normal mode:
dumpsys deviceidle (in the end of the output there should be mState=ACTIVE mLightState=ACTIVE for deep and light idle modes)

What does it all mean? Probably there is some bug in microg code responsible for handling wakelocks. As I mentioned above, microg is excluded from battery optimization, so it seems that the only cause of this behavior is incorrect wakelocks handling in microg code.

How I workarounded the problem (I hope, temporary, - until the bug is fixed):
I used command:
dumpsys deviceidle disable
-this command disables Doze mode totally, but only until next reboot. To make it persistent over reboots, add it into startup shell script - for example into /data/local/userinit.sh or (for those who have magisk): into /data/adb/service.d/any_name.sh (but never put this script into /data/adb/post-fs-data.d/ !!!). Don't forget to add "execute" permissions for this script file, and set its owners to root/root (0/0).
Code of the script:
#!/system/bin/sh
export PATH=/system/bin
#list of running services before delay:
cmd -l > /data/local/cmd-l__log__before_delay.log 2>&1
#delay in seconds - to wait until service "deviceidle" is up and running:
sleep 60
#list of running services after the delay:
cmd -l > /data/local/cmd-l__log__after_delay.log 2>&1
dumpsys deviceidle disable > /data/local/disable_doze_mode.log 2>&1

Reboot, and check log /data/local/disable_doze_mode.log
Note, that without "sleep 60" before "dumpsys deviceidle disable" the script won't work correctly, because service "deviceidle" needs time to be launched by system.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the disconnect using the reported Android Oreo Doze commands and the MicroG Google Cloud Messaging screen. Start by tracing the GCM connection and wakelock handling involved during deep Doze; done means the connection remains available and push messages continue while Doze is active.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.