I have been working for quite some time on Android Lollipop 5.0 (specifically, CyanogenMod 12.0) for the Fairphone 1 and, finally, I am unveiling what I have done.
But do not get too excited yet; this is not a fully functional Android Lollipop 5.0 at all. Hardware accelerated 3D graphics, sensors, basic GPS or Wi-Fi do work, but audio, telephony, Bluetooth, FM radio or camera do not (for a more detailed description see below).
That is a letdown, I know. Another letdown for some of you will be finding out that this Android Lollipop 5.0 version is compatible ONLY with the Fairphone 1 with the original storage layout. Do NOT use it on a Fairphone 1 with the unified storage layout, no matter if it is a Fairphone 1 or a Fairphone 1 (U).
But the worst part is that a fully functional Android Lollipop 5.0 for the Fairphone 1 is not achievable without the source code for the proprietary binary blobs which, obviously, I do not have access to. Therefore, I have no plans to work further on Android 5.0 for the Fairphone 1.
StatusThis Android 5.0 version does not add any feature that requires special hardware support and that was not already present in the official Android 4.2 version for the Fairphone 1. Moreover, as I said above, it does not even support all the features supported in that version.
Software-based features are mostly supported. As the Android base is free (as in freedom, not as in free beer) and open-source software (from now on, FOSS) its source code is available for everyone and it can be modified if needed to support a new version of Android on an old device.
However, most features that require special hardware support depend on proprietary binary blobs. That is, precompiled pieces of software for which no source code is available. As there is no source code they have to be used as is; it is not possible to modify them to add new features, fix bugs, adapt to newer Android versions… nothing.
Feature summary(Please excuse the technical jargon used in some of the feature explanations; although I tried to keep them accessible some of them also include developer-oriented information)
- Graphics: working. With proprietary binary blobs, graphics are hardware accelerated by the GPU and support OpenGL ES 2.0. Otherwise, graphics are rendered by the CPU with support only for OpenGL ES 1.0 (which shows certain problems in the system GUI).
- Sensors: working. Requires proprietary binary blobs, but it could be reimplemented in a fully FOSS way (like done in Replicant for other devices).
- GPS: working. Only basic GPS works; more advanced features like A-GPS or those introduced after Android 4.2 (like geofencing) do not work. Requires proprietary binary blobs.
- Wi-Fi: working. The software part is fully FOSS, but dependent on proprietary firmware.
- Wi-Fi Direct: I am not really sure about its status :P I could test it only against another device and it did not work (before Android 5.0 it worked depending on which device provided certain parameters), but I do not really know whether it is a problem in the Android 5.0 version for the Fairphone 1 or in the other device (although, having seen the change that I needed to do in the kernel for the Wi-Fi to work, I suspect that the faulty one is my Android 5.0 version).
- Power saving: partially working. None of the new power saving features introduced after Android 4.2 that require explicit hardware support work (for example, batching sensor reads or Wi-Fi scans). However, those features that require explicit hardware support and were available already in Android 4.2 still work (for example, disabling CPU cores when the system is not loaded), and newer features that do not require explicit hardware support also work (for example, disabling animations when the battery saver is enabled).
- Audio: not working. Well, as a matter of fact, I made it partially work just using the proprietary binary blobs. However, as I have said it only worked partially; recording at low bitrates did not work and playing high priority short sounds (like a tap/click sound) did not work (unless there was another sound already playing). Due to this I did not include support for audio in the repository. Another reason was that, in this case, rewriting the audio support in a fully FOSS way seems feasible and not very complex (it would require porting the current audio kernel driver to the ALSA SoC platform and then pairing it in user space with one of the already existing audio HALs for ALSA SoC).
- Bluetooth: not working. It may be possible to make it work without proprietary binary blobs for the software part thanks to Bluedroid or Bluez, although probably some glue code between those projects and the kernel would have to be written (but I have not checked it). However, just like the software part for the Wi-Fi is fully FOSS but dependant anyway on proprietary firmware, the software part for the Bluetooth, be it FOSS or proprietary, will depend too on proprietary firmware.
- Telephony: not working. I have not checked if the source code for the proprietary binary blobs is needed to make it work or if it can be made with just the proprietary binary blobs. However, I assume that the proprietary binary blobs are not compatible with a standard system, as they provide support for dual SIM even if in Android 4.2 only a single SIM card was supported, so their source code will be needed to make them work in a standard system.
- Camera: not working. It seems impossible to make it work without the source code for the proprietary binary blobs.
- FM radio: not working. It seems impossible to make it work without the source code for the proprietary binary blobs.
- Hardware accelerated codecs: not working (so most videos do not work with the default Gallery; you may want to use the mighty (and GPL licensed! :) ) VLC instead). It seems impossible to make them work without the source code for the proprietary binary blobs.
- Hardware composer: not working. It seems impossible to make it work without the source code for the proprietary binary blobs.
- SELinux: not working. It can be made to work without proprietary source code. It requires some kernel patches that can be got from the official Android kernel and then just configuring it appropriately.
- Tethering: not working. Support for tethering over USB could probably be added using only FOSS components (at least, the tethering itself; the connection to be shared may require proprietary components anyway, like the Wi-Fi firmware). Support for tethering over Wi-Fi would require at least the use of the proprietary firmware; it should not require proprietary binary blobs for the software, but I have not checked it. And tethering over Bluetooth... well, it would depend on how Bluetooth was implemented, but it looks like at least the proprietary firmware for the chip would be required.
- Alarm with device powered off: not working. As audio is not available I did not bother making the alarm work. However, it should be possible to make it work without proprietary source code or binary blobs; it should be just a matter of checking in the kernel what happens when an alarm is set in the original Fairphone 1 operating system and replicating it in the Android 5.0 version.
- Battery stats: not working (how much does each application consume; the current battery level is shown as expected). It requires just a configuration file with the current consumption of several components of the device, but I do not have the equipment to perform the measurements (and I can not extract them from the original Fairphone 1 operating system, as I do not know which license is that data under).
- Auto-brightness: not working. It requires just a configuration file that associates values provided by the light sensor with values of brightness for the screen.
- Unique device ID: not working. It requires just patching init (the command that initializes the system) to get the value from a specific file provided by the kernel.
- Encryption: not tested.
- GAPPS (Google Applications): not tested. However, F-Droid (the Free and Open Source Android App Repository) works ;)
- When proprietary binary blobs are not used, the graphics system will be slow due to being rendered by the CPU instead of the GPU. However, when the proprietary binary blobs are used, the graphics are not as smooth as they should in Android 5.0, because the proprietary binary blobs used are those from Android 4.2. You may have noticed in Android 4.2 that graphics "stutter" slightly (it is specially noticeable in objects moving at a slow and constant speed across the screen). This is caused by a lack of synchronization between the GPU and the display. In Android 4.4 a new synchronization system was introduced to solve this, but as the proprietary binary blobs come from Android 4.2 they do not provide that new feature.
- PhotoPhase (a dynamic wallpaper from CyanogenMod) crashes. It may be a problem in PhotoPhase itself, in the proprietary binary blobs or both. Just use a different wallpaper :P
- As mentioned above, Wi-Fi Direct may not work properly.
- The only serious bug that I have found was a total freeze of the user interface apparently caused by the proprietary binary blobs of the graphics system. However, the real culprit here could be the way that I run the Android 5.0 version (installed on a disk image on the external SD card through MultiROM) and not the proprietary binary blobs, as sometimes I have suffered read failures from the disk image that caused the operating system to malfunction (and the only way I found to fix them was to just delete the disk image and install the operating system again in a different one; it seems that kind of use was too much for my humble external SD Card). However, I do not know if there were also read failures involved when that freeze happened or not.
Build and install instructionsIf, despite all this, you still want to try this Android Lollipop 5.0 version in your Fairphone 1, keep reading to know how to build and install it.
In any case, please note that I am publishing these instructions and the Android Lollipop 5.0 version in the hope that it will be useful, but WITHOUT ANY WARRANTY. I have reviewed the instructions several times, and I think that I have not missed anything, but I could be wrong. In the same way, I have built the Android Lollipop 5.0 version and used it myself without problems, but if there is any bug or forbidden use that I am not aware of (or I have forgotten to mention) that damages your phone, the data in your phone or whatever… I am really sorry! But I am not buying you a new Fairphone
How to buildThese instructions are a quick reference of the needed steps in a GNU/Linux system. Please refer to the official Android documentation or any of the guides available on the Internet about building Android for further information.
First of all, create a directory to download all the source code and build it. For example, /home/$USER/CyanogenMod/. Now open a terminal in that directory. Except where otherwise noted, all the following commands are expected to be executed in the CyanogenMod directory.
Get repo, which is the command used in Android to manage the repositories with the source code:
curl https://storage.googleapis.com/git-repo-downloads/repo > repo
And make it executable:
chmod a+x repo
Now initialize the CyanogenMod 12.0 repositories.
./repo init -u git://github.com/CyanogenMod/android.git -b cm-12.0
If you have never used git before, that command will fail. You can ignore the failure and continue with the next step (at least, if you want to download the repositories just to build the operating system and you do not intend to develop anything), or you can configure your name and email address. Do not worry, unless you send any change to a public server it will not be used anywhere out of your computer. Set your name and email address as explained in the failure message (that is, executing git config --global user.email "firstname.lastname@example.org" and git config --global user.name “Your Name”) and then run again the same ./repo init command as before.
Create the file /home/$USER/CyanogenMod/.repo/local_manifests/fairphone_fp1.xml and add to it the following contents so repo knows where to get the sources for the Fairphone 1:
<?xml version="1.0" encoding="UTF-8"?> <manifest> <remote name="fairphone" fetch="https://gitlab.com/danxuliu/" /> <project name="android_device_fairphone_fp1.git" path="device/fairphone/fp1" remote="fairphone" revision="android-5.0" /> <project name="android_kernel_fairphone_fp1.git" path="kernel/fairphone/fp1" remote="fairphone" revision="mediatek-mt6589-3.4" /> <!-- This repository provides the support for the proprietary features. If you do not want them just remove the following line. --> <project name="android_vendor_fairphone_fp1.git" path="vendor/fairphone/fp1" remote="fairphone" revision="android-5.0" /> </manifest>
And now tell repo to download all the needed repositories. This will take time and you will need around 50 GBs of space in your hard disk:
./repo sync --current-branch
If you want to use the proprietary features you also have to provide the needed proprietary binary blobs to the build system. The helper script extract-files.sh can extract them either from your device through ADB (please refer to the TWRP installation instructions for further information about ADB) or from an uncompressed Fairphone 1 update file. To use it, open a terminal in /home/$USER/CyanogenMod/vendor/fairphone/fp1 and execute ./extract-files.sh to extract them from your device or ./extract-files.sh to extract them from an uncompressed update file.
In any case, the proprietary binary blobs must come from a Fairphone 1 Android 4.2 release. The proprietary binary blobs from the Android 4.4 release have not been tested, so they may work or not.
Now that you have the code (and, optionally, the binary blobs) you can start the build process itself.
First, prepare the build environment.
Then, state that you want to build CyanogenMod for the Fairphone 1, user debug variant (the engineer variant, eng, works too; the plain user variant does not work due to its enforcing of SELinux):
Finally, build the OTA package (a zip file that contains the operating system and is installable through the recovery). This will take several minutes or even hours, depending on your computer. It will also require around 25 GBs of additional space in your hard disk. The -j4 parameter tells make how many files to build in parallel; it should be set to the number of cores of your CPU (in this example, a quad-core CPU). However, building certain files is very memory intensive, so, depending on your hardware, your computer may run out of RAM memory if building several of them in parallel; in that case the build will fail, so you will have to use a lower number (or remove the -jX option):
make -j4 otapackage
Well, in the case of the Fairphone 1, you will have to run it again a second time. The first time it will exit shortly after being started with the message The build system was patched. Launch again the build. The Android 5.0 version for the Fairphone 1 needs some changes in the main source code from CyanogenMod, so I developed a system to patch the source code repositories as needed before building (and when that happens, the build must be launched again). It is an ugly hack, but a necessary one
How to installPlease note that I have not tested myself replacing the operating system in the Fairphone 1 by this Android 5.0 version (as I always use the MultiROM way; more on that later). It should work without problems but, I repeat, I have not tested it yet.
Remember that this Android Lollipop 5.0 version is ONLY for the Fairphone 1 with the original storage layout. Do NOT install it on a Fairphone 1 with the unified storage layout, no matter if it is a Fairphone 1 or a Fairphone 1 (U).
Have you checked it and your Fairphone 1 uses the original storage layout? Ok. Then just install the zip file generated in /out/target/product/fp1 (the name would be something like cm_fp1-ota-<random letters and numbers>.zip) with the TWRP recovery for the Fairphone 1. Do NOT use the official Fairphone 1 recovery (I have not tested it, so it may work flawlessly or it may brick your phone; I have no idea, but you have been warned ).
Obviously, installing the zip WILL REMOVE the current operating system installed in your phone, so ensure that you have made all the needed backups. Moreover, after installing the zip you should also wipe your data partition; otherwise, the new operating system could use an incompatible configuration from the current operating system. Again, ensure that you have a backup of your data partition before wiping it or you will not be able to restore the partition when going back to the previous operating system. And, when going back to the previous operating system, as explained in the TWRP article, remember to NEVER install an official Fairphone 1 update through TWRP.
Also note that, although the contents of the system partition are exclusive of each operating system, and the contents of the data partition should be exclusive of each operating system (depending on whether you wiped it or not), the rest of partitions will be shared between the old operating system and the new operating system. That is, if you (or an app) modify something in a system partition like /protect_f and then restore the old operating system that modification will still be there in the restored operating system (which may cause problems in the restored operating system, like losing the IMEI).
However, that should not happen if you do not tinker with the system or use strange (shady?) apps. A more typical scenario would be an app adding some files to the internal SD card partition or you deleting a photo stored there; unless you have a backup of the internal SD card partition its contents will not be magically restored when you restore the previous operating system. Be careful with that!
It is also possible to install a different operating system through MultiROM without overwriting the original operating system (although the issue of shared partitions still applies). Please refer to the article about MultiROM for the Fairphone 1 for further information (but be aware that installing the operating system through MultiROM, although more convenient, is still a delicate matter).
In any case, the first boot into Android 5.0 will take longer than normal, as it has to perform a lot of initializations. Do not worry if your device spends around two minutes in the boot animation (although if it spends five minutes or more, yes, you can start worrying ).
Also, you do not have to worry about Android 5.0 replacing your current recovery with its own recovery, as it has none.
And finally, I have not checked whether the Format SD card option in Settings->Backup & reset->Factory data reset resets the data partition, the internal SD card partition, the external SD card or what. If you appreciate your data, do not touch that
This article is licensed under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license. For the TWRP license please check the source files themselves; those written by me are typically licensed under the GNU General Public License version 3 or later, but in some cases I had to use a different license (for example, in the case of kernel patches they have to be licensed under the GNU General Public License version 2).