FORUMS
Remove All Ads from XDA

[GUIDE] Huawei's background task freezer and how to turn it off

94 posts
Thanks Meter: 75
 
By lexelby, Member on 31st December 2017, 09:35 PM
Post Reply Email Thread
Huawei has long had... "Ideas" about killing background tasks. In earlier versions of EMUI, their task killer was very aggressive and it was necessary to "protect" apps that you didn't want to be killed. Now, they do something different: "Phone Manager" pauses background apps , halting them in their tracks and preventing them from doing any processing. This caused problems for me, and I'll show you how I fixed it.

The best example of this behavior can be seen if I use GMD Gestures on my Mate 9 (L29). Gestures work great for 1-2 minutes, but after awhile, they just stop working. If I open GMD, suddenly it seems to "catch up" and process gestures that it missed all at once.

The GMD process hasn't been killed, but it has been frozen in place. The only way to wake it up (that I've found) is to interact with the app in some way: open it or send an intent to it. Even a completely spurious intent that the app doesn't handle is enough to wake it up, and in the case of GMD it will see gestures it missed and run their associated actions.

One way to solve this is to freeze Phone Manager using Titanium Backup or the like. This very effectively prevents the background app pausing behavior. However, it also breaks some bulit-in functionality of EMUI, such as battery usage stats and removal of notification icons from the status bar. In short, a lot of the functionality of EMUI is implemented by Phone Manager, and if you freeze it, you lose it.

What you don't sacrifice by freezing Phone Manager is battery life! I still seem to get the same great battery life with or without Phone Manager, better than any android phone I've owned previously. So if you're willing to sacrifice the functionality that Phone Manager provides, then freezing it is a simple way to regain control over your background apps.

I wanted a more targeted answer, and I've found it. If you're interested, read on.

Phone Manager is using a feature of Linux called the cgroup freezer. The cgroup freezer can pause processing in a whole group of processes -- in the case of Android, that's all the processes that make up an app. The cgroup freezer pauses processes in exactly the same way that Linux pauses all processes before going into suspend or hibernation on a laptop (and probably a phone). Absolutely all CPU activity ceases.

You can observe that a process is frozen by looking at /proc/<pid>/wchan. If this "file" contains __refrigerator then the process has been frozen. You can see a list of processes that Phone Manager has frozen using this command in a terminal window (root not required):

Code:
grep __refrigerator /proc/*/wchan
I can see what Huawei's doing here: Phone Manager looks for apps doing a lot of processing in the background and stops them until the user interacts with them. However, in my experience, this kind of draconian control isn't necessary, and it just results in apps that I want to use not working properly. There's also no way to whitelist apps to prevent this functionality.

How do we make it stop? We take away its access to the cgroup freezer system. All control of the cgroup freezer is done by writing to files exposed by the kernel. On the Mate 9 (and presumably anything running EMUI 5.0) that's under /dev/frz. Unmount this filesystem and it's game over for Phone Manager. It no longer has the ability to freeze processes, and apparently it doesn't try to remount the filesystem.

How do we do this? I'd love it if it were as simple as "umount /dev/frz", but unfortunately it's not that easy. Due to the way Nougat (and probably other versions of android) have set things up, each app sees a different view of what's mounted (this is called "separate mount namespaces"). We'll have to unmount /dev/frz in all namespaces.

I haven't packaged this up into a tidy script yet due to lack of free time, but perhaps someone reading this might throw together an APK? I just run this in Termux:

Code:
$ su
# for pid in $(ls | grep -E '[0-9]+'); do /data/data/com/termux/files/usr/bin/nsenter -m -t $pid -- umount /dev/frz; done
(there may be a spew of errors here -- just ignore them)

Note that I'm using Termux's nsenter binary. That's because busybox's nsenter is buggy and just plain doesn't work. Bah.

Great, so that prevents Phone Manager from freezing anything else. Unfortunately, it also leaves anything that's already frozen stuck, so we'll need to unfreeze it ourselves. Just killing an app (using root) and restarting it should be enough to wake it up, but we can do better:

Code:
# mkdir /sdcard/frz
# mount -t cgroup -ofreezer freezer /sdcard/frz
# for f in /sdcard/frz/*/freezer.state; do echo THAWED > $f; done
# umount /sdcard/frz
This briefly mounts our own copy of the cgroup freezer filesystem, thaws everything, and then unmounts it.

I'd love it if someone who knows more about writing android apps than me could package this up into a tidy APK. I'm pretty sure it will be applicable for any EMUI 5.0 phone, and maybe even 6.0.

All this said, I can't provide tech support on what I've shared above. I discovered this as a somewhat advanced Android user and an expert-level Linux user, and I'm documenting it so that other folks can build on it. I don't have time to follow this up and package it into a usable form, and I definitely can't teach a bunch of individual people how to run this stuff themselves. Please don't PM me about this. I'll keep an eye here and try to answer questions, but I'm probably going to concentrate most on folks that are looking to turn this into an APK or ZIP that other folks can use.
The Following 3 Users Say Thank You to lexelby For This Useful Post: [ View ] Gift lexelby Ad-Free
 
 
1st January 2018, 12:59 AM |#2  
Senior Member
Flag Stockholm
Thanks Meter: 1,056
 
Donate to Me
More
Quote:
Originally Posted by lexelby

Huawei has long had... "Ideas" about killing background tasks. In earlier versions of EMUI, their task killer was very aggressive and it was necessary to "protect" apps that you didn't want to be killed. Now, they do something different: "Phone Manager" pauses background apps , halting them in their tracks and preventing them from doing any processing. This caused problems for me, and I'll show you how I fixed it.

The best example of this behavior can be seen if I use GMD Gestures on my Mate 9 (L29). Gestures work great for 1-2 minutes, but after awhile, they just stop working. If I open GMD, suddenly it seems to "catch up" and process gestures that it missed all at once.

The GMD process hasn't been killed, but it has been frozen in place. The only way to wake it up (that I've found) is to interact with the app in some way: open it or send an intent to it. Even a completely spurious intent that the app doesn't handle is enough to wake it up, and in the case of GMD it will see gestures it missed and run their associated actions.

One way to solve this is to freeze Phone Manager using Titanium Backup or the like. This very effectively prevents the background app pausing behavior. However, it also breaks some bulit-in functionality of EMUI, such as battery usage stats and removal of notification icons from the status bar. In short, a lot of the functionality of EMUI is implemented by Phone Manager, and if you freeze it, you lose it.

What you don't sacrifice by freezing Phone Manager is battery life! I still seem to get the same great battery life with or without Phone Manager, better than any android phone I've owned previously. So if you're willing to sacrifice the functionality that Phone Manager provides, then freezing it is a simple way to regain control over your background apps.

I wanted a more targeted answer, and I've found it. If you're interested, read on.

Phone Manager is using a feature of Linux called the cgroup freezer. The cgroup freezer can pause processing in a whole group of processes -- in the case of Android, that's all the processes that make up an app. The cgroup freezer pauses processes in exactly the same way that Linux pauses all processes before going into suspend or hibernation on a laptop (and probably a phone). Absolutely all CPU activity ceases.

You can observe that a process is frozen by looking at /proc/<pid>/wchan. If this "file" contains __refrigerator then the process has been frozen. You can see a list of processes that Phone Manager has frozen using this command in a terminal window (root not required):

Code:
grep __refrigerator /proc/*/wchan
I can see what Huawei's doing here: Phone Manager looks for apps doing a lot of processing in the background and stops them until the user interacts with them. However, in my experience, this kind of draconian control isn't necessary, and it just results in apps that I want to use not working properly. There's also no way to whitelist apps to prevent this functionality.

How do we make it stop? We take away its access to the cgroup freezer system. All control of the cgroup freezer is done by writing to files exposed by the kernel. On the Mate 9 (and presumably anything running EMUI 5.0) that's under /dev/frz. Unmount this filesystem and it's game over for Phone Manager. It no longer has the ability to freeze processes, and apparently it doesn't try to remount the filesystem.

How do we do this? I'd love it if it were as simple as "umount /dev/frz", but unfortunately it's not that easy. Due to the way Nougat (and probably other versions of android) have set things up, each app sees a different view of what's mounted (this is called "separate mount namespaces"). We'll have to unmount /dev/frz in all namespaces.

I haven't packaged this up into a tidy script yet due to lack of free time, but perhaps someone reading this might throw together an APK? I just run this in Termux:

Code:
$ su
# for pid in $(ls | grep -E '[0-9]+'); do /data/data/com/termux/files/usr/bin/nsenter -m -t $pid -- umount /dev/frz; done
(there may be a spew of errors here -- just ignore them)

Note that I'm using Termux's nsenter binary. That's because busybox's nsenter is buggy and just plain doesn't work. Bah.

Great, so that prevents Phone Manager from freezing anything else. Unfortunately, it also leaves anything that's already frozen stuck, so we'll need to unfreeze it ourselves. Just killing an app (using root) and restarting it should be enough to wake it up, but we can do better:

Code:
# mkdir /sdcard/frz
# mount -t cgroup -ofreezer freezer /sdcard/frz
# for f in /sdcard/frz/*/freezer.state; do echo THAWED > $f; done
# umount /sdcard/frz
This briefly mounts our own copy of the cgroup freezer filesystem, thaws everything, and then unmounts it.

I'd love it if someone who knows more about writing android apps than me could package this up into a tidy APK. I'm pretty sure it will be applicable for any EMUI 5.0 phone, and maybe even 6.0.

All this said, I can't provide tech support on what I've shared above. I discovered this as a somewhat advanced Android user and an expert-level Linux user, and I'm documenting it so that other folks can build on it. I don't have time to follow this up and package it into a usable form, and I definitely can't teach a bunch of individual people how to run this stuff themselves. Please don't PM me about this. I'll keep an eye here and try to answer questions, but I'm probably going to concentrate most on folks that are looking to turn this into an APK or ZIP that other folks can use.

/dev/frz exists in 8.0 as well, and there are a few frozen things.
Thanks for sharing.
1st January 2018, 08:15 AM |#3  
Senior Member
Flag Łódź
Thanks Meter: 68
 
More
Did you check if setting Battery -> Lunch -> Manage Manually does the same thing? Prevents from freezing?
1st January 2018, 10:55 AM |#4  
Senior Member
Flag Stockholm
Thanks Meter: 1,056
 
Donate to Me
More
Quote:
Originally Posted by rufik

Did you check if setting Battery -> Lunch -> Manage Manually does the same thing? Prevents from freezing?

It's weird, because if I turn on Manual for Gmail, it stops synching. If I put Auto it works fine. If I use Auto on LastPass it's closed after a while, if manual it works fine. It's really weird.
1st January 2018, 01:11 PM |#5  
Member
Thanks Meter: 26
 
More
It's not really a Huawei issue, freezing background services after a short time is by design for Oreo https://developer.android.com/about/...ackground.html
1st January 2018, 01:33 PM |#6  
OP Member
Thanks Meter: 75
 
More
Quote:
Originally Posted by rufik

Did you check if setting Battery -> Lunch -> Manage Manually does the same thing? Prevents from freezing?

What? Lunch? I don't know what "manage manually" setting you're talking about...
1st January 2018, 01:34 PM |#7  
OP Member
Thanks Meter: 75
 
More
Quote:
Originally Posted by Hielko

It's not really a Huawei issue, freezing background services after a short time is by design for Oreo https://developer.android.com/about/...ackground.html

Interesting! However I'm on Nougat, so I don't think this applies?
1st January 2018, 02:29 PM |#8  
Member
Thanks Meter: 26
 
More
Which Nougat? I never had problems with background services running with Nougat (stock) on the Mate 9 (L29), but I have seen freezes of background services (of my own apps) on several devices running Oreo (stock).
1st January 2018, 02:33 PM |#9  
OP Member
Thanks Meter: 75
 
More
7.0, b190, US version. I've only really had trouble with GMD, but then again I've only had this phone for a couple weeks.
2nd January 2018, 01:35 AM |#10  
p51d007's Avatar
Senior Member
Flag Springfield, Mo
Thanks Meter: 277
 
More
I've had this glitch on Nougat & the beta (321 version) of Oreo.
For whatever reason, I stop receiving email notifications. It's like it just went to sleep until I wake it up.
Tried everything short of a full reset. Different email apps, ensuring the battery savers are all off, keep
awake the email app...sometimes I get notifications of email, most times I don't unless I open the app.
2nd January 2018, 01:01 PM |#11  
OP Member
Thanks Meter: 75
 
More
Yeah, that sounds familiar. I strongly suspect that this is not the same thing as Oreo's background service restrictions. Oreo is reasonable about it and terminates services rather than just freezing their computation.

p51d007, if you're rooted, give my technique a try and see if it fixes your problem. If you're not, you can use an automation program like Automagic to send an intent (any intent) to your app every ten seconds to keep it alive.
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes