A post on Android, AOSP, Custom ROMs, Bootloader, Recovery, etc

While not sysadmin related, this is a long post I wrote today on Google+ and figured I must put a copy of it elsewhere too.


Been meaning to write a post on Android past few days, so here goes …

Modern phones are like computers. Similar to how computers have an OS (Windows, Linux, Mac etc) phones have a firmware (also called ROM). The names firmware and ROM are misleading. They are just legacy hangups from an era when the phone OS was basic and you rarely flashed (installed) a new OS or updated it. So although we still call it firmware or ROM, it’s actually an OS. In the case of Android, an OS based on Linux.

The Android OS is built by Google. Each release is named after a pastry. So you have Jelly Bean, Ice Cream Sandwich, Gingerbread, Eclair, and so on. With each new release Google usually also releases the source code to the OS. This open source release is called the Android Open Source Project (AOSP). Enthusiasts around the world take this AOSP release and make their own modifications. Since these are custom Android OSes, they are usually simply called custom ROM. The result is AOSP based firmware such as CyanogenMod, Carbon, AOKP, Paranoid Android, and so on. Most of these contain many more features than stock Android, as well as performance hacks and such. So they are quite popular among Android geeks.

Apart from the AOSP Google also releases its OS to partners such as Samsung, Sony Ericsson, LG, HTC, etc. They take the OS, add their own customization and tweaks, drivers for their hardware, additional software that differentiates their products from others, and (in the past but not so much now) useless “bloatware” software. Once upon a time this was the only way to get Android. You buy a phone from these partners and use their modified version of Android. So Google started creating its own brand of hardware, under the name Nexus. These are devices made by a partner such as HTC, Samsung, or LG, but built according to specs from Google (I think) and more importantly they come with “pure” Android. That is, Android the way Google intended it to be – without any additions or subtractions from the hardware partners. USually you have one Nexus phone a year.

Nexus devices are thus popular with those who want a pure Android experience. They are also not so popular with the general public as most people like the extra software and features provided by the non-Nexus-but-modified-Android phones. Plus Google doesn’t market the Nexus device much (though in recent past it has) and they are usually low in specs compared to the competition (though that too has changed in the recent past). Nexus devices have an advantage over other devices in that since they run pure Android they are the first to get Google’s new Android releases. Other phones take longer as Samsung or Sony or what-have-you must take the released Android, make their changes, customize the UI, test, etc before releasing to the public. Moreover, it is not in their best interests to let you have the greatest and latest Android release on their yesteryear handsets – even though it may work perfectly well – and so they may not even release the latest Android for the phone you have. (A good example being the Samsung Galaxy S II which can easily run Android 4.2 – as seen by the fact that it runs CyanogenMod 10 – but Samsung hasn’t officially released Android 4.2 for this device).

Yet another advantage of the Nexus devices is that since they are designed to run pure Android, they will run all AOSP based firmwares without any issue. On the other hand, devices created by other manufacturers could be made to run – provided the volunteers have the time and inclination to do so, and there’s enough demand for it, etc. Thus, for instance, you do have CyanogenMod builds for Samsung Galaxy S II, but you don’t have the latest CyanogenMod builds for Sony Ericsson Xperia Arc S (even though both were released around the same time). Some custom firmware may have builds for one device, but not for another – it all depends on the interest of the volunteers and demand from their target audience.

The reason devices by other manufacturers have sketchy support is to do with drivers. Drivers are blobs of code that tell the OS how to interact with a piece of hardware. The OS talks to the hardware through drivers, and that in turns depends on the phone manufacturer (whether they provide drivers, whether people know what hardware is being used, etc).

Back to the OS. As I said above Android is the OS that runs on your phone. Now, an OS is something that’s stored on the phone’s “disk” (not exactly the correct term here, hence the double quotes, but you get the point). When the phone is off and you power it on, something has to load this OS into the phone’s memory so it run and be “self initialized”. This “something” is required in the case of computers too – when you turn on your machine, there is a piece of software that loads first and asks you whether you want to load Windows 8 or Windows XP – assuming you have both OSes installed on your machine – or just goes ahead and launches one of these OSes if you only have one installed. This software is called a bootloader and the process of loading an OS via a bootloader is known as bootstrapping. (It comes from the idea that say you are sitting on a floor and want to get up but you can’t just push your hands down and lift yourself up. (Just assume you can’t for this example sakes. That’s how a phone/ computer OS is. It is sitting in the disk and needs to get up, but can’t do it on its own). What would you do? You are wearing boots (coz that’s how you are!) and these boots have bootstraps (the little piece sticking out at the top back of the boot) so you hold these bootstraps and pull yourself up – thus getting up on your own without any external help. Thus came about the name bootstrapping. And from there came the word bootloader).

So anyways, phones have a bootloader, which is what loads the OS into phone memory when you power it on. On computers (typically) bootloaders are free to load whatever OS you tell it to – so that’s why you can multiboot Windows, Linux, multiple versions of these, etc pretty easily. But on Android phones the bootloader is typically locked. Why? Coz that’s how phone manufacturers are. They don’t want you booting other OSes on their phones and writing to protected parts of the system (and maybe they have some others reasons too based on how the contract system of phones work in the US and other parts of the world, I don’t know) – so if you have a Samsung Galaxy S II (say) you can’t just go ahead and install CyanogenMod on it as the bootloader is locked and it won’t be able to boot CyanogenMod for you! I am not very familiar how one used to unlock bootloaders in the past, but nowadays most phone manufacturers let you request for an unlock key from their website and then you can use a piece of software provided by Google to unlock the bootloader. (Another advantage of using Nexus devices is that unlocking their bootloader is a straightforward process – just type a command and you are done!)

Apart from the ROM and bootloader, another piece of software Android phones have is called recovery. Think of it like your computers’ BIOS, though it is not really like that. Or maybe a better way to think of it would be like a separate partition/ disk on your computer that contains a bare minimum OS that only lets you do basic stuff like backup/ restore your data and install/ upgrade your main OS. Most computers don’t have such a software as computers have CD-drives and USB disks and geeky chaps who want to do similar operations on computers just put in a Live-CD or USB and boot into an alternate OS to do their deeds. But phones don’t have such a luxury and so come with the recovery software installed onto it.

The recovery that usually comes with phones is pretty bare. There exist third party recovery software – notably ClockworkMod Recovery (and its touch enabled variant ClockworkMod Recovery Touch) and TeamWin Recovery Project (TWRP) (which is touch enabled by default). If you want to install a new ROM on your phone, you definitely need one of these recovery software. There are couple of ways to install a custom recovery and the process is pretty straightfoward. You don’t even need an unlocked bootloader to install a custom recovery, though if you plan on installing a custom ROM later you do need an unlocked bootloader. Some methods of installing a custom recovery require an unlocked bootloader, while others require a rooted phone.

Which brings us to the question of what is a rooted phone. You see, by default your phone OS lets you do things on it as a regular user. Again, it’s similar to how computers operate. Taking the case of Windows for instance: in the past, with Windows XP, when you logged in to the system chances are you had full rights to the OS and could do pretty much anything with it – install software, devices, and even viruses. Nowadays, though, Windows (Vista onwards) logs you in as a regular user and usually prompts you for an administrator username/ password when you are trying to do things like install apps. This is because Windows is more security conscious nowadays and doesn’t give you full rights by default. It logs you in as a user and only gives you elevated rights if you are authorized for it. Phone OSes are similar. By default they log you in as a user and you can do most tasks – including install apps – but if you want to tamper with the OS itself (such as install software that installs a custom recovery!) you need elevated rights. Problem is, Android and its variants (and also iOS etc) usually actively deny giving you elevated rights and so you need to do things to break the locks that prevent you from doing so. This process is known as rooting, and a phone that is thus “broken” is known as a rooted phone. (The term comes from Unix, where the user with full control over the system has username “root”. Since Android and iOS and based on Linux and BSD, which have Unix roots, the name stuck on. As an aside, on Windows the user with full access is known as “administrator”. And it’s as a homage to these that Harold Finch, of the TV show “Person of Interest”, worked under the username “admin” (short of “administrator”) while the girl who was trying to hack into the machine worked under the username “root”).

There is no one-size-fits-all method for rooting your Android phone. Since rooting depends on exploiting bugs in the OS to give you more rights, it depends on the version of the OS on the phone and also whether its pure Android or modifed by the phone manufacturers, etc. Nexus phones usually have it very easy – and there’s even a “Nexus Root Toolkit” software that easily roots the phone for you. For other phones a quick Google search usually turns up ways to root them. (By the way, this is what “jailbreaking” an iPhone entails. You exploit bugs in iOS to gain root access, and then you modify the OS to let you install your tweaks etc. That word is a homage to FreeBSD, a branch of BSD that the Mac OS X is based on).

Custom ROMs such as CyanogenMod etc are rooted by default. So once you install one of these there’s no separate need to root the phone. And if your aim is to replace the stock firmware with a custom one, there’s no need to root it either. Simply unlock the bootloader, install a custom recovery, and install the custom ROM. A good thing about Android is that you don’t need to root the phone or unlock the bootloader (or install a custom ROM) if all you are interested in is general customizing. You can easily theme the phone, make changes to your notification bar, install non-Play Store apps – all by default. This is unlike iOS where you can’t even change the theme or install non-App Store apps and so jail breaking is necessary even for those “basic” things. On Android you do all this only if you really like to play around with your phone (or your phone manufacturer isn’t updating it with newer firmware and so you want to switch to a custom ROM).

The rabbit hole doesn’t stop here actually. Most people go ahead and change the kernel too of their ROM. The kernel – as its name suggests (a kernel is the seed inside the nut of most plants, so it’s like the core-most thing of a plant) – is the core component of an OS. It is the actual bit of code in the OS that interfaces with the hardware (via drivers) on one side, and the OS & user applications on the other. With Android, you can change the kernel too – many people do this to get better performance out of their phone or for some feature only offered by a custom kernel. Installing a new kernel is quite straightforward – similar to how you would install a custom ROM.

And that’s it.

This post should have given you a high level overview of custom ROMS and rooting etc in terms of Android. One last thing to keep in mind is that if you are installing a custom ROM you must also install Google Apps (Gapps) separately. Once upon a time custom ROMs included the “Google for Android” software such as Gmail, Calendar, Search, Google+, Play Store, etc. Then due to licensing issues they stopped including these by default, so nowadays one must download the Gapps package separately, along with the custom ROM. They are usually found in the same place one downloads a custom ROM from, as there is (usually) a version of Gapps for each version of the custom ROM. In theory you can install a custom ROM without Gapps – leaving you unable to install any Google for Android apps or even access the Play Store – but it’s possible if you want it that way (just download the install files for packages you want and install yourself).