I own an Xiaomi Mi A1 with LineageOS 15.1 (unofficial) and microG installed. There are three problems:
- OTA wasn’t working when I installed the ROM, so no easy updates.
- Encryption had issues when I installed the ROM and there still seem to be some now. Encrypting on stock ROM is recommended.
- There’s a problem with Whatsapp and microG, when first running it.
My aim is to install the official LineageOS 15.1 and get everything working again, so backups are kind of important. The Whatsapp backup has to be of a working state, which can only be achieved with Google services. So I end up with this plan:
- backup everything
- install stock ROM
- install Whatsapp
- backup Whatsapp
- install official LineageOS
- restore all user apps
Before starting it should be mentioned that adb and fastboot are required. In NixOS the following does the trick:
programs.adb.enable = true;
And on the phone repeatedly touching the build number in
Settings/About phone will enable developer settings from where ADB can be enabled.
ADB’s backups seem nice, but are a bit cumbersome. Restoring what’s backed up works just fine, but restoring any less gets tricky. A full system backup doesn’t hurt either way:
adb backup -all -apk -shared
With this you get a prompt on your phone to confirm the backup and after a few minutes in my case an .ab file of around 1 GiB. I’m not so sure this includes everything and really hope I won’t need it later … So for a limited backup I use Titanium Backup to batch backup all user apps and pull them off the phone via
adb pull sdcard/TitaniumBackup .
And just to be safe you can reboot into recovery and just
adb pull /dev/block/mmcblk0 mmcblk0.img
resulting in a disk image. I expect the Titanium backup to be enough - the rest is just insurance.
installing stock ROM
To flash the stock ROM the device needs to be booted into fastboot mode.
wget https://bigota.d.miui.com/V22.214.171.124.ODHMIFE/tissot_images_V126.96.36.199.ODHMIFE_20180712.0000.00_8.0_735823083f.tgz tar xzf tissot_images_V188.8.131.52.ODHMIFE_20180712.0000.00_8.0_735823083f.tgz sh tissot_images_V184.108.40.206.ODHMIFE_8.0/flash_all.sh
Installing Whatsapp from the Play Store isn’t much different than from F-Droid or Yalp. Now it would be nice to just use Titanium to back it up and be done with it. Sadly this requires root privileges which I don’t want to bother with here. As mentioned ADB backups are a thing and good enough when restoring exactly what was backed up:
adb backup -f whatsapp.ab com.whatsapp
That’s what I thought, but as it turns out apps can decide to not be backed up and Whatsapp is such an app … Well, rooting it is then. Again the device needs to enter fastboot mode.
fastboot boot recovery.img adb push Magisk-v17.1.zip sdcard/
Then just chose the zip to be installed and reboot. After that Titanium can be installed and used to back up only Whatsapp.
adb pull sdcard/TitaniumBackup ./TitaniumBackupStock
LineageOS 15.1 official
It’s finally time to install the offical ROM! The LineageOS wiki explains the necessary steps well, but I’ll deviate a bit.
adb push lineage-15.1-20180904-nightly-tissot-signed.zip /sdcard/ adb reboot bootloader fastboot boot recovery.img
Both the TWRP recovery.img and LineageOS are linked from the port thread at XDA. You could also install TWRP, but it would be wiped anyway with the next OTA update. With TWRP just do a factory reset (instead of formatting, which would clear the encryption) and install the zip. After that a reboot is required (not exactly sure why, something about switching between A and B partitions) for installing Magisk the same way, which should still be on the SD card.
adb reboot bootloader fastboot boot recovery.img
At this point the device requires some setup and is then ready to use! Except that some apps won’t work without Google services / the alternative implementation microG. Signature spoofing is required for microG to act as Google services, but because of security concerns not supported in LineageOS. There are builds from microG with this feature enabled, but I found it easier to use the Magisk module of NanoDroid. It’s as easy as downloading the zips (for me microG and F-Droid), registering them in Magisk Manager and rebooting. After that you can install Yalp Store via F-Droid and Titanium Backup via Yalp Store. To restore the backup it has to be uploaded again (I merged the Whatsapp backup in):
adb push TitaniumBackup /sdcard/
And then just run “Restore all apps with data” in Titanium Backup. Done. Whatsapp is working as well as on the stock ROM and even open tabs in Firefox are still there.