Monday, August 12, 2013

AOSP on Sony xperia Z

Disclaimer: I dont take any responsibility for the damage of your equipment. If you point your ire at me, I will have the last laugh. USE THE INFO AT YOUR OWN RISK.

Sony android phone team has taken the android philosophy very seriously. This is one team within sony which is passionate w.r.t idea, philosophy and legality of FLOSS. If we compare the android and the GNU/Linux eco-system, I would sum up the relation between them by using Android/Linux for android and GNU/Linux for the desktop OS which we are familiar with. While GNU used the Linux kernel for coming up with a complete Desktop OS, Google built the UI shell and other mobile telephony stack over the Linux kernel. But, the similarity ends there.

The two components of GNU/Linux are licensed with "free as in freedom" philosophy with the GPL.(Though the linux kernel is licensed with GPL V2 and the GNU utils are mostly licensed with the latest GPL version). The source code of the original program and all its improvements are always and should be made available in source form for public consumption.

If we come to Android/Linux, the first part is licensed under the Apache license. This is a permissive licensing philosophy, wherein, the original source and its improvements "may" be provided in source form if the author wishes, or else the source can be withheld and only the binaries "may" be provided for public consumption. So, the author, google, and other mobile manufacturers who licence android from google are not compelled to share the original source code(scripted by google) or any variations of it for use by various mobile manufacturers with the general public. The result is, if google wants to put out the source for its newest shiny android version it will, if it is not in a mood to do it, then also, google is honoring the apache license. The second part, the linux kernel, is licensed under GPL v2, google and all the mobile manufacturers have to honor the license and give out the kernel with all their additions and alterations for public consumption.

This post is about sony, let us continue. Sony is the only phone manufacturer which honors the GPL for the linux kernel meticulously, it is almost like clockwork. Even if the sony mobile team has released a beta kernel for a specific device, the source is out within a week. But, But, with Xperia S, sony took their commitment to the FLOSS philosophy a step ahead. They went ahead and release the "android" portion of the OS also for public consumption, again, of course under the apache license. There your are. You have the entire gamot of source code of "Android/Linux" in your hands, now, Go Play.

Once the sony smartphone team released the source for xperia Z, their flagship phone for 2013(while other manufacturers closely guard their flagship phones for nearly a year by not releasing the kernel source which they are supposed to do with the release of the device), I had decided that will be my next phone. It does not match with my primary requirement of hardware keyboard, but, the hardware specs was awesome and the purple color was beautiful on this phone.

The XDA forums is full of various spins of upmarket roms with "n" number of customizations. You will be spoilt for choice. Only one rom of mention still struggling is the MIUI. But devs are on it and I definitely believe they will succeed in running it on the Z.

Oh, let us get back to our topic, FLOSS. Google releases the source code after baking the lates version of the android OS in-house. It is released under the label "AOSP" ie, the Android Open Source Project. This will be the most generic tree of the source. Normally, it would be difficult to compile this vanilla version as it is and run it on a phone. It would be missing the device specific code required to get it running on a specific phone. The other missing thing, vital, would be the binaries which are required to use the all the hardware(SoC) properly.

Now, we have a completely new word here, binary, yes all FLOSS enthusiasts hate it. Every manufacturer makes use of an Arm SoC or an Intel SoC. The manufacturer provides the drivers for these hardware components. But, the hardware manufacturers dont play well with the FLOSS philosophy. They guard their hardware, its implementation and usage with hawk eyes. The driver are always release in the form of blobs(Binary large objects). They have to be linked in during the compile stage of the rom to result in a fully working rom to be installed on your device.

We now have one non-freedom component on our otherwise "free as i freedom" system. But, we are somewhat ok with it.(Apologies to RMS). Anybody can compile an AOSP rom for the xperia z. The sources are at github with clear instructions for building it. You just have to have good bandwidth, patience, building on GNU/Linux (64 bit)(building on windows,..... forget it) and a lot of googling to use the experience of developers over the XDA forums.

If you dont want to compile it, An XDA developer going by the username pabx, has done it for us. Before I proceed, if you are an XDA member go and thank him. If you have a paypal account donate to him. This rom compiled/developed by him is awesome. It is one of the minimal rom I have seen and used. When I backed it up with CWM, with all my usual apps installed, the backup size was, believe it (or not), 560MB. How awesome is that. Compare it with the stock rom whic is approx 1.7GB. Now, that is light. But do remember that it is minus all the bells and whistles. It may not be visually appealing compared to the stock rom. Few quirks might be lurking here and there. My major quirks were two. One, the volume is awfully low(Stock rom with purexaudio is awesome. Hear it to believe it). Two, Plugging an earpiece without mic will result in phone calls not being audible both for the caller and the receptor. The number two problem does not exist for earpiece with mic(for eg, the sony supplied one). One more issue is the video playback. On the stock rom it is great even when the processor is underclocked to 800MHz with the hardware decoder. On the AOSP rom you have to use the software decoder for better performance.

How do we install this awesome effort on our phone?

Before you unlock your bootloader, try this tool. This is to backup the TA partition which is required for the Bravia Engine to work(Just remember that the Bravia engine comes into play when you watch a video or photographs. Otherwise the BE does not do anything during the general use of the device.) I have not tried this. But please go through the thread. It is quite big and intimidating. I did backup the TA partition but not tried to restore it back. But there are numerous examples on the thread where people have restored the TA partition and got back the BE. Please do remember that for restoring the TA, you should be back on "pure" stock(kernel and the rom).

If possible make an .ftf of your current stock rom or download one(Just in case)
Install flashtool
Install fastboot drivers from within the flashtool installation(The installer is in C:/flashtool/drivers). Double click the .exe in that folder. If you are using windows 7 or windows 8 go here)

1. Unlock your bootloader go here
2. Root the device go here
3. Install CWM recovery go here
4. Backup the stock rom with CWM recovery brief intro
5. Enter CWM and clear data, cache and dalvik cache
6. shutdown the phone
7. Connect one end of the USB cable to the computer and plug in the phone end of the cable to the phone while simultaneously pressing and holding the volume up button
8. Download pabx's effort from here
9. Extract the archive (unzip pabx_aosp_yuga*.zip) to c:\flashtool\x10_flasher_lib\
10. Open the cmd window on windows and change directory to x10_flasher_lib

run the command below
fastboot devices

 -- It should list the device name (not exactly the name of the device) If you get an output, then continue, otherwise you have problems regarding fastboot drivers. If you get an output, run these commands(wait for completion of the command befor entering another)

fastboot flash boot boot.img
fastboot flash system system.img

If this is an initial installation,
also run:

fastboot flash userdata userdata.img

# NOTE: The above command will wipe all your data and the internal SD card - only do this on first-install of this rom.

Now run
fastboot reboot  ---Or just disconnnect and reboot

Now, we have to root this rom. Download superuser and copy it to the external sd card of your device. reboot the device, press the volume up button continously as the phone reboots, you will enter CWM(the swiss army knife). Choose Install zip/Install from external sd card and choose the file.


Now you are rooted with an AOSP rom.

Now, we should boot into pure vanilla experience. Of course, you need google apps like the play store, gmail, maps etc... Download this, copy to external sd card and repeat the procedure for installing it via cwm.


You now have the play store. Go ahead and install your favorite apps.


To get more realestate from your phone, edit the build.prop in /system with root explorer and change the lcd density to 320.

Operating the phone using the softkeys at the bottom of this huge phone is tricky. Install LMT launcher. start the app, start the service, click the option of start this app at boot. Then edit the build.prop in /system and add the following line at the bottom



If the media players are not able to save the album details and they show empty libraries, then Edit file /system/etc/permissions/platform.xml

    Find text

        group gid="sdcard_rw"

    And replace it with
permission name="android.permission.WRITE_EXTERNAL_STORAGE"         group gid="sdcard_rw"
        group gid="media_rw"   ---> Only this line is to be added in the format exactly as in the file with the arrows and the backslashes


    Make it with caution. XMLs are very syntax sensitive. Any mistake may make your phone inoperable.

Thanks to all the users and fantastic devs at XDA for bringing in excitement into the phone arena. The info has been culled from various resources. If any user/dev requires a mention please comment. It will be immediately updated.

UPDATE: 12.11.2013:   Owing to un-ethical kang of pabx's rom, his builds and discussion will now happen
He has succesfully compiled kitkat for our device. The most important of all we now have double tap to wake for our xperia z thanx to championswimmer, dev at the xda. It is now available for this AOSP rom also. For further instructions please visit the above link and also visit his thread on xda. 

No comments:

Post a Comment

Nobody can deter me away from "free as in freedom" concept seeded by Sri RMS. See to it that u dont make fun of my belief. If u think otherwise, no need to comment.