HACKER Q&A
📣 drekipus

How to add some custom Android kernel code to my phone?


I currently use a Google Pixel 4a and I've got a few photos, videos, apps, contacts, etc; that I want to keep on it.

I've made a few little apps and things as various little experiments, and one of my latest ideas that I want to try out, actually involve some changes to the AOSP core; (specifically, the surface flinger)

My experiment is that I want to allow for a "desaturated but not fully grayscale" experience on my phone -- looking around in the settings, I can find grayscale, colourblind settings, or "Extra dim" - but not what I want. (and programatically toggling grayscale on-and-off causes hiccups in the display)

I think I've found where the code would go, and what sort of changes I would make, but how can i add those changes to the core/kernel and run it on my phone? would replacing the kernel mean I lose all my current app / settings (as this is my only phone and I want to continue using it with my settings)?

Any help or assistance on the above?


  👤 fensgrim Accepted Answer ✓
Unless your phone has fastboot already unlocked, yes it will result in you losing all the stuff at least once (there's an unavoidable wipe on bootloader unlock/relock). In that case, if your changes are restricted to surfaceflinger rather than kernel code, you can try doing an emulator-based test (basically, just do 'm' and 'emulator' commands your from AOSP build environment).

Also, when building kernels for your specific target (4a), pure AOSP is actually least friendly option regarding build scripts/instructions; consider either building the kernel as a part of either LineageOS build (which will pull MSM 4.14 kernel) or CalyxOS/Graphene (which has its own kernel build scripts/sandbox).


👤 drekipus
I should add that I'm also fine with some workarounds.

I tried to make a service that would capture the screen, desaturate it, and then show that desaturated version on the screen (like a sort of, full screen video, with a tap-through to the underlying android system) but that doesn't work.