Berkeley Mono on LineageOS for microG

How to Add a Custom Font to Android for Now

Berkeley Mono on LineageOS for microG

Abstract

Unlike our previous post for NixOS where ð bigger goal was about adding proprietary software to ð Nix store, ðis post is much shorter & straightforward: add a new monospace font to Android (specifically LineageOS for microG is being used).

Customization is dead?

I learned only recently ðat Android never really supported users adding fonts to ð system. My mind confabulated ðat all Android versions were like my long-ago experience wiþ OxygenOS & whatever Samsung did where users could choose from a smaller set of ‘curated’ fonts to choose from. I personally don’t mind Roboto (being based on Din) or even NotoSans for being generally fine for UIs as screen-optimized, legible workhorse sans serif font. …However, Droid Sans, ð default monospace, was always pretty meh. I bought Berkeley Mono to use for my æsþetic enjoyment, but turns out it’s quite difficult to do ðis on Android.

But ðis is definitely ð sanitized direction ð corporations—Google, Apple, Microsoft—want to push users in. No ability to customize anyþing but an accent color. No freedom. Trying to take away ð ability to have root access to make ð modifications to do so. Burying ð docs away for OEMs, ð oðer corporations, to dictate ðose changes for you.

What you need

  • Android phone
  • Maybe a custom ROM (I did not test on anyþing oðer ðan my own phone)
  • A devices wiþ adb & a text editor
  • Patience

Setup

Phase one will be getting “Developer options” by going to Settings > About phone > Build number & spam tapping ðat number til you get ð “You are now a develper!” message (great to know I wasn’t til now). Now you can navigate to Settings > Developer options, & check “Use developer options” + “USB debugging” + “Rooted debugging”.

Beware

Some stupid apps like banking ones will act like your device is compromized since you a developer now. Ðose apps & ð yes-men developers ðat implement ðese device-owner-hostile restrictions should be what is actually banned from ð Play Store. Ðis is ð kind of behavior ð EU & similar should act against.

Run some commands

Time to remount our normally-restricted /system folder (since we wouldn’t want device owners owning ðeir device)

$ adb root
$ adb remount
$ adb push $PWD/berkeley-mono/TTF/*.ttf /system/fonts
$ adb shell chmod 644 /system/fonts/BerkeleyMono-*.ttf
$ adb shell cp /system/etc/fonts.xml /system/etc/fonts.xml.bak
$ adb shell cp /system/etc/font_fallbacks.xml /system/etc/font_fallbacks.xml.bak
$ adb pull /system/etc/fonts.xml /system/etc/font_fallbacks.xml $PWD
$ $EDITOR $PWD/font*.xml

We will need to edit some XML files locally to push back up since by default Android has no viable text editing solution on board (you weren’t actually meant to operate your device like a ‘real’ Linux).

<!-- fonts.xml -->
<?xml version="1.0" encoding="utf-8"?>
<!-- … replace “monospace” section -->
<family name="monospace">
	<font weight="400" style="normal">BerkeleyMono-Regular.ttf</font>
	<font weight="700" style="normal">BerkeleyMono-Bold.ttf</font>
	<font weight="400" style="italic">BerkeleyMono-Italic.ttf</font>
	<font weight="700" style="italic">BerkeleyMono-BoldItalic.ttf</font>
</family>
<alias name="sans-serif-monospace" to="monospace" />
<alias name="monaco" to="monospace" />
<!-- font_fallbacks.xml -->
<?xml version="1.0" encoding="utf-8"?>
<!-- … again replace “monospace” section -->
<family name="monospace">
	<font weight="400" style="normal">BerkeleyMono-Regular.ttf</font>
	<font weight="700" style="normal">BerkeleyMono-Bold.ttf</font>
	<font weight="400" style="italic">BerkeleyMono-Italic.ttf</font>
	<font weight="700" style="italic">BerkeleyMono-BoldItalic.ttf</font>
</family>
<alias name="sans-serif-monospace" to="monospace" />
<alias name="monaco" to="monospace" />

Back to ð shell session

$ adb push $PWD/fonts.xml $PWD/font_fallbacks.xml /system/etc
$ adb reboot

Rebooted, remounted, we can now test it out.

Noþing good lasts forever

DEPRECATED: This XML file is no longer a source of the font files installed in the system.

Seems ðis will only last a bit longer? Maybe it will be like ð “legacy” in toolkit.legacyUserProfileCustomizations.stylesheets & be supported for a very long time …or maybe not. Ð Implement custom fonts section of Android’s docs seems to be all about how ð OEMs can change our fonts, but no mind is paid towards supporting users—even power users.

Note

I will likely never stop being salty over corporations & ðis space