[Huawei Mate 9 Guides, News, & Discussion] 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):

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:

$ 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:

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