Installing LineageOS on Xiaomi MI8

My wife's Wiko Rainbow Up could not be updated anymore with the latest security patches, so it was time to buy a new phone.

Her requirement was the best camera, my requirement was LineageOS support.

I scrolled through the official device list that .. lists 2012 devices beside the ones from 2018. Being a good citizen, I made a patch for the wiki that added the release date to the devices list. It was unrightfully rejected, so I publish my own device list now.

The list of devices released in 2018 is not that long, so I checked German phone tests for those and finally decided for the Xiaomi Mi 8. It cost 340€ here.

Xiaomi Mi8

I did not read the installation page before I ordered it. It says:

This step is mandatory and will trigger a countdown of 360 hours, the waiting period before a device can be unlocked.

I had to install some dumb Windows-based unlocking application to be able to unlock the bootloader. That application told me that I had to wait fscking 172 hours (7 days) until I could unlock it. I went psycho, but still had to wait.

Xiaomi customer support was not helpful at all and pretended not to understand my request for shortening the wait time.

(I now know that LG is even worse; at work I have to wait 14 days for unlocking the bootloader.)

After removing the old system, I tried to flash the new one and got...

ERROR: This package requires firmware from MIUI 9.2.15 developer build or newer. Please upgrade firmware and retry!

The wiki only said:

Tip: It is highly recommended to have the latest official MIUI dev package installed on the device, before proceeding with unlock.

The dev package is 1.8GiB and can be downloaded from the official Xiaomi Mi 8/Pro/Lite download page. (The LineageOS guys also rejected my patch to use clearer words)

I installed the MicroG LineageOS flavor because it brings F-Droid and enables it to install updates without showing the manual confirmation screen for every. single. update.

Camera

The stock camera on LineageOS is not really good, so I installed the Google camera "gcam" (which does not require google play services!) and makes awesome photos.

My wife is very pleased with the photo quality.

The images takes with gcam are equal to those taken with Xiaomi's own Miui Camera (Download site), which has to be installed in TWRP via adb sideload.

Firmware update

After a week, a LineageOS update arrived and I installed it. It downloaded, rebooted to TWRP, unzipped the update and rebooted. It tried to boot for 3 minutes, failed somehow and went back to recovery mode (TWRP).

When attaching it to my laptop and running adb logcat (no unlocking/enabling needed; I immediately got logs), I saw an infinite loop with the following exception:

E System  : ************ Failure starting system services
E System  : java.lang.SecurityException: Permission android.permission.WRITE_MEDIA_STORAGE is not a changeable permission type
E System  : 	at com.android.server.pm.permission.BasePermission.enforceDeclaredUsedAndRuntimeOrDevelopment(BasePermission.java:383)
E System  : 	at com.android.server.pm.permission.PermissionManagerService.grantRuntimePermission(PermissionManagerService.java:1404)
E System  : 	at com.android.server.pm.permission.PermissionManagerService.access$900(PermissionManagerService.java:89)
E System  : 	at com.android.server.pm.permission.PermissionManagerService$PermissionManagerInternalImpl.grantRuntimePermission(PermissionManagerService.java:2093)
E System  : 	at com.android.server.pm.PackageManagerService$PackageManagerInternalImpl.grantRuntimePermission(PackageManagerService.java:24256)
E System  : 	at com.android.server.pm.permission.DefaultPermissionGrantPolicy.grantRuntimePermissions(DefaultPermissionGrantPolicy.java:1253)
E System  : 	at com.android.server.pm.permission.DefaultPermissionGrantPolicy.grantRuntimePermissions(DefaultPermissionGrantPolicy.java:1148)
E System  : 	at com.android.server.pm.permission.DefaultPermissionGrantPolicy.grantDefaultPermissionExceptions(DefaultPermissionGrantPolicy.java:1337)
E System  : 	at com.android.server.pm.permission.DefaultPermissionGrantPolicy.grantDefaultPermissions(DefaultPermissionGrantPolicy.java:269)
E System  : 	at com.android.server.pm.PackageManagerService.systemReady(PackageManagerService.java:21324)
E System  : 	at com.android.server.SystemServer.startOtherServices(SystemServer.java:1761)
E System  : 	at com.android.server.SystemServer.run(SystemServer.java:457)
E System  : 	at com.android.server.SystemServer.main(SystemServer.java:302)
E System  : 	at java.lang.reflect.Method.invoke(Native Method)
E System  : 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E System  : 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:838)

Android tried to init the system again and again, but always came to the same exception.

The LineageOS IRC channel reacted to my support request so:

Jun 13 20:11:27 <LuK1337> that kinda makes no sense
Jun 13 20:11:37 <LuK1337> unless you added some trash to system

The most probable cause for the problem is my sideloaded installation of the MIUI camera. So better don't use it!

The solution was to boot into TWRP, wipe the system partition and then install the latest LineageOS zip file just like when doing a normal installation.

After that, the phone booted up fine and all data were still there.

The only problem I encountered was that TWRP 3.3.1 (the latest) told me:

Decrypt data

Pattern failed, please try again

I had to install an unofficial TWRP 3.3.1 that properly supported data decryption. I also opened a bug at the official TRWP dipper issue tracker.

No Google play

My wife's old phone had one application that we paid for: awinto. She uses it to quickly enter her work shifts into the calendar.

I installed it onto the phone with Yalp store, but that only got me the demo version which allows 3 shifts only.

In a e-mail to the author I explained my situation, and he suggested that I should try Open GApps, unlock awinto and then remove them again. "Open GApps" is actually not open, the project only packages up the official Google play services and applications into different packages:

First of all, the GApps themselves are not open source, neither will they probably ever be.

I dit not want to use Google applications at all.

So I saw down and did the things I described in Unlocking Android games until I found the setter for the isPremium configuration variable, which I modified to always assume a true, generated a modified apk and installed it.

Now my wife is able to use the premium features she bought on the Google-free phone. Just updates to awinto will be a problem.

Written by Christian Weiske.

Comments? Please send an e-mail.