A short while after getting a Pixel 3a, I decided to root it, mostly to have more control over the charging procedure. In order to preserve battery life, I like my phone to stop charging at around 75% of full battery capacity and to shut down automatically at around 12%. Some Android ROMs have extra settings to manage this, but LineageOS unfortunately does not.
Android already comes with a fairly complex mechanism to handle the charge cycle, but it is mostly controlled by the kernel and cannot be easily configured by end-users. acc is a higher-level "systemless" interface for the Android kernel battery management, but one needs root to do anything interesting with it. Once rooted, you can use the AccA app instead of playing on the command line to fine tune your battery settings.
Sadly, having a rooted phone also means I need to re-root it each time there is an OS update (typically each week).
Somehow, I keep forgetting the exact procedure to do this! Hopefully, I will be able to use this post as a reference in the future :)
Note that these instructions might not apply to your exact phone model, proceed with caution!
Extract the boot.img file
This procedure mostly comes from the LineageOS documentation on extracting proprietary blobs from the payload.
-
Download the latest LineageOS image for your phone.
-
unzip the image to get the
payload.bin
file inside it. -
Clone the LineageOS scripts git repository:
$ git clone https://github.com/LineageOS/scripts
-
extract the boot image (requires
python3-protobuf
):$ mkdir extracted-payload
$ python3 scripts/update-payload-extractor/extract.py payload.bin --output_dir extracted-payload
You should now have a boot.img
file.
Patch the boot image file using Magisk
-
Upload the
boot.img
file you previously extracted to your device. -
Open Magisk and patch the
boot.img
file. -
Download the patched file back on your computer.
Flash the patched boot image
-
Enable ADB debug mode on your phone.
-
Reboot into fastboot mode.
$ adb reboot fastboot
-
Flash the patched boot image file:
$ fastboot flash boot magisk_patched-foo.img
-
Disable ADB debug mode on your phone.
Troubleshooting
In an ideal world, you would do this entire process each time you upgrade to a new LineageOS version. Sadly, this creates friction and makes updating much more troublesome.
To simplify things, you can try to flash an old patched boot.img
file after
upgrading, instead of generating it each time.
In my experience, it usually works. When it does not, the device behaves weirdly after a reboot and things that require proprietary blobs (like WiFi) will stop working.
If that happens:
-
Download the latest LineageOS version for your phone.
-
Reboot into recovery (Power + Volume Down).
-
Click on "Apply Updates"
-
Sideload the ROM:
$ adb sideload lineageos-foo.zip