[Xiaomi Redmi 4X ROMs, Kernels, Recoveries, & Other] fincs:
I have been trying to do some more debugging of the battery drain issue, without success. I upgraded to Oreo 20180413, which didn't fix it (in fact it made it worse!). dpmd/msm_irqbalance are *still* corrupted and had to be manually patched. Now there are two more issues, which have already been reported by other users prior to this post (i.e. the buildstamp mismatch warning and the screen rounded corners, which seem to have been intended as a feature but it's annoying if you don't have the option to turn it off or on).

I decided to install several diagnostics applications, namely BetterBatteryStats and WakeLockDetector. With the latter I found out that the "sensor_ind" kernel wakelock was going haywire. Thankfully with Clarity's boeffla wakelock blocker (and Kernel Adiutor's support for custom settings) I was able to block this nasty wakelock; however this still didn't fix the battery drain. Speaking of Clarity, it looks like a new version (v3.1) just came out. I have flashed it, however that still didn't solve the battery drain. It looks like there are no more wakelocks preventing deep sleep, however it turns out that system_server (aka Android System) is always using nearly 100% CPU usage of a single core, even during sleep! In fact, in the processes tab in BetterBatteryStats you can see how it is the #1 CPU user, by a wide margin. What seems very weird to me is that nearly all CPU time in this process is spent in kernel mode (not in user mode!), which is very strange.

I decided to delve deeper in debugging this issue. I tried using debugging tools from the Android SDK. After a small detour with Magisk's resetprop (ro.debuggable needs to be set to 1 *and* the system server must be restarted), I used Dalvik Debug Monitor Server on system_server, and even did some profiling, which was pretty inconclusive. The function calling stats don't really show anything clear. If all, it seems like either Wifi-related sensors, or PocketService-related sensors might be going haywire somewhere. I have tried Airplane mode - didn't work. The Alarms page in BBS led me into suspecting that sensors might still be the culprit of battery drain, however I have every single sensor related thing turned off, including pocket detection, location, ambient display; and I tried turning off adaptive brightness - also didn't work. I got to the point where I tried to use GDB to debug native code, and after some messing around with gdbserver I got it to actually attach to the system_service process, and I could see that the thread that was hogging down the CPU was... the main thread. The one whose only purpose is to pump and dispatch messages... also inconclusive. In fact it was sitting at the epoll_wait Linux syscall. Other threads were likewise sitting at apparently innocuous syscalls like binder_thread_read. Speaking of binders, sometimes a binder thread also gets to burn the CPU, although I haven't been able to find a way to translate the likes of "Binder:5385_E" to an actual readable Android binder interface name. Also let me point out that this ROM ships with the 32-bit (AArch32) version of gdbserver and I had to copy over the 64-bit (AArch64) version of it in order for debugging to work (otherwise it would crash the system server process!).

At this point I am getting pretty desperate. I have tried doing many different things, including disabling Google Play Services, clearing out Settings, Dalvik cache, clearing out network settings, clearing out Google Services data, nothing has worked at all and I'm still stuck with system_server consuming 100% CPU. I dread ending up having to wipe my data and starting over. I would really want to avoid this. If anybody has any idea of what else to try (and what else to debug), please let me know.

Currently my suspicion is that somehow the sensor driver blobs in the kernel are acting up, however I have no way to confirm or debug this. May I add that my baseband version is V032_PA. In the LuisROM download page there seems to be a V030, a V033 and a V035 for download, however there seems to be (?) all sorts of confusion related to baseband versions and bigger numbers may actually not be newer?? It's confusing. The "FIRMWARES" topic here on xda is even more confusing, with firmware versions going into the 50s! Oh, and my Redmi 4X is the Global Version (3GB/32GB); i.e. the one that has band 20 for Europe. Apparently an user earlier in this thread claimed that similar system_server related battery drain issues were fixed after flashing baseband, however I have no way to tell if flashing e.g. V035 is safe or even compatible with my particular model of Santoni.

DonSanches' post has made me realize that the official RR Oreo build for Santoni has a bunch of new commits in android_device_xiaomi_santoni that haven't been merged into the LuisROM branch, including one commit which seems to rename ft5x06_ts.kl back to ft5x06_720p.kl in order to apparently fix the Recents app button issue (and others?). There also seem to be many power management related commits in the official branch, including something related to Doze. Could this be it?! It would be great anyway if this stuff could be merged into the Luis branch.

It's all very sad, because prior to the battery drain bug I could easily get around 4 days of runtime without a charge, and now I barely make it to a day an a half.