Louis-Philippe Véronneau - batteryhttps://veronneau.org/2022-06-11T00:00:00-04:00Updating a rooted Pixel 3a2022-06-11T00:00:00-04:002022-06-11T00:00:00-04:00Louis-Philippe Véronneautag:veronneau.org,2022-06-11:/updating-a-rooted-pixel-3a.html<p>A short while after <a href="https://veronneau.org/goodbye-nexus-5.html">getting a Pixel 3a</a>, 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 …</p><p>A short while after <a href="https://veronneau.org/goodbye-nexus-5.html">getting a Pixel 3a</a>, 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.</p>
<p>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. <a href="https://github.com/VR-25/acc">acc</a> 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 <a href="https://f-droid.org/en/packages/mattecarra.accapp/">AccA app</a> instead of
playing on the command line to fine tune your battery settings.</p>
<p>Sadly, having a rooted phone also means I need to re-root it each time there is
an OS update (typically each week).</p>
<p>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 :)</p>
<p>Note that these instructions might not apply to your exact phone model, proceed
with caution!</p>
<h2>Extract the boot.img file</h2>
<p>This procedure mostly comes from the <a href="https://wiki.lineageos.org/extracting_blobs_from_zips#extracting-proprietary-blobs-from-payload-based-otas">LineageOS documentation</a> on
extracting proprietary blobs from the payload.</p>
<ol>
<li>
<p>Download the <a href="https://download.lineageos.org/sargo">latest LineageOS image</a> for your phone.</p>
</li>
<li>
<p>unzip the image to get the <code>payload.bin</code> file inside it.</p>
</li>
<li>
<p>Clone the LineageOS scripts git repository:</p>
<p><code>$ git clone https://github.com/LineageOS/scripts</code></p>
</li>
<li>
<p>extract the boot image (requires <code>python3-protobuf</code>):</p>
<p><code>$ mkdir extracted-payload</code>
<code>$ python3 scripts/update-payload-extractor/extract.py payload.bin --output_dir extracted-payload</code></p>
</li>
</ol>
<p>You should now have a <code>boot.img</code> file.</p>
<h2>Patch the boot image file using Magisk</h2>
<ol>
<li>
<p>Upload the <code>boot.img</code> file you previously extracted to your device.</p>
</li>
<li>
<p>Open Magisk and patch the <code>boot.img</code> file.</p>
</li>
<li>
<p>Download the patched file back on your computer.</p>
</li>
</ol>
<h2>Flash the patched boot image</h2>
<ol>
<li>
<p>Enable ADB debug mode on your phone.</p>
</li>
<li>
<p>Reboot into fastboot mode.</p>
<p><code>$ adb reboot fastboot</code></p>
</li>
<li>
<p>Flash the patched boot image file:</p>
<p><code>$ fastboot flash boot magisk_patched-foo.img</code></p>
</li>
<li>
<p>Disable ADB debug mode on your phone.</p>
</li>
</ol>
<h2>Troubleshooting</h2>
<p>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.</p>
<p>To simplify things, you can try to flash an old patched <code>boot.img</code> file after
upgrading, instead of generating it each time.</p>
<p>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.</p>
<p>If that happens:</p>
<ol>
<li>
<p>Download the latest LineageOS version for your phone.</p>
</li>
<li>
<p>Reboot into recovery (Power + Volume Down).</p>
</li>
<li>
<p>Click on "Apply Updates"</p>
</li>
<li>
<p>Sideload the ROM:</p>
<p><code>$ adb sideload lineageos-foo.zip</code></p>
</li>
</ol>