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

Search This thread

lexelby

Senior Member
Jan 6, 2012
94
84
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.
 

ante0

Senior Member
Dec 28, 2009
3,213
1,581
Stockholm
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.
 

ante0

Senior Member
Dec 28, 2009
3,213
1,581
Stockholm
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.
 

Hielko

Senior Member
Feb 27, 2012
93
25
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).
 

lexelby

Senior Member
Jan 6, 2012
94
84
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.
 
  • Like
Reactions: Sammath

p51d007

Senior Member
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.
 

lexelby

Senior Member
Jan 6, 2012
94
84
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.
 

Dylan2232

Member
Jun 19, 2018
29
2
..................

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

.............

Typing in the above code in Terminal Emulator on my rooted Huawei Y5 (2017) MYA-L22 does nothing. I type it in, press enter, nothing.

Any help would be greatly appreciated!

Jo4GhkV.png
 
Last edited:
  • Like
Reactions: le grande magnetto

Iceman8888

New member
Mar 23, 2019
1
0
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.

Hi, may I know if you have written a post on how to send the intent using automagic? Like to avoid rotting my device.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 7
    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.
    1
    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.
    1
    ..................

    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

    .............

    Typing in the above code in Terminal Emulator on my rooted Huawei Y5 (2017) MYA-L22 does nothing. I type it in, press enter, nothing.

    Any help would be greatly appreciated!

    Jo4GhkV.png