Sunday, April 07, 2013

Rooting & Unrooting Micromax Funbook Pro

Well, here is another rooting guide from me. This time it's on Funbook Pro P500, a 10 inch tablet from the Indian manufacturer Micromax. I am not going to talk much about the tablet here, there are several reviews on it across the internet and a good Google search could land several results on this. All I can say about it is that I have been using it over the past 6-7 months and it has been an awesome tablet at its price point.

Before I started writing this blogpost I noticed that there are several articles on the internet emphasizing on rooting Funbook Pro, but most of them focus of either using an application or a tool to get this done. However in this post, I am going to use only the Android Debug Bridge (ADB) keeping you in control of the process.

In one of my previous posts (Rooting & Unrooting HCL Me X1), I have already mentioned the advantages and risks of Rooting, please do go through it before proceeding further. Let me reiterate one point from that post - Trying to root your device might brick the device. I am not responsible if you brick your device, so proceed at your own risk.

Rooting the Device

You don't really require any exploit or any application to root the Funbook Pro, it is possible to root the device using the adb shell so make sure you have the Android Debug Bridge (ADB) on your system.

Connect the device through the USB and open the shell using adb shell at the command prompt. You would be seeing a $ here indicating that the shell does not have root access. Exit from the adb shell and restart the adb on the device using adb root, a message stating that restarting adbd as root would appear. Go back to adb shell, you would see a # now indicating that the shell has root access.

Inspecting the ro.secure property either using getprop ro.secure or from /default.prop would return a value of 1. This indicates that the adb will not login as root by default and hence we have to use the adb root command when we want root access using the adb shell.

Though the adb shell has root access, the su command which is used in Linux doesn't work in Android since there is no su binary in Android. So our next step is to setup the su command on the device. Download the su binary and the Superuser application from here.

There are two steps for rooting the device -

  1. Copying the su binary to the /system/bin directory

Unlike most other devices, the /system file system in Micromax Funbook Pro isn't read-only making things simpler for us. Use adb push and copy the su binary to the device with the command adb push su /system/bin. Don't forget to set the permissions of the binary using chmod 4777 su.

  1. Install the Superuser.apk from the system/app directory of the zip

Install the application using adb install or transfer the file to the sdcard and install it from there. The Superuser application intercepts the calls made to the su binary and informs the user about the usage so that unauthorized applications cannot attain root access.

Unrooting the Device

To unroot the device, uninstall the Superuser.apk and delete the su binary from the /system/bin directory.

Sunday, March 31, 2013

jQuery getScript, FireBug And Caching

Recently in one of my projects I had a requirement of loading JavaScript files dynamically. It was then I took a look at the jQuery getScript method. At first it looked perfect for my requirement, however as I started using it for my project I realized there were two drawbacks with its default implementation.

  1. There isn't any caching for the scripts loaded by getScript
  2. Debugging these scripts in FireBug is quite difficult since FireBug cannot map the script code to the script filename

In this post, I am going emphasize on my experiences with getScript and how I got both it to work with both these requirements. I am sure people who are spending time to get these features working will find this useful.

To help me with this, I put up an example Visual Studio project available here. I used Visual Studio for comfort but any text editor will work since it is all about HTML and JavaScript.

Basic Example

Well, getScript is pretty easy to use. In its simplest form, all we have to do is provide it with the script name. Here's an example on how it looks.

But the interesting point is the way it works. Here's a screenshot in FireBug which show three calls being made to the server since getScript appends a random number to the server call causing the browser cache to fail. And the script debugger is also unable to recognize the script name.

Enabling Caching

Solving the caching issue was simple. Following the recommendation on the jQuery getScript documentation page, I setup AJAX caching using ajaxSetup as show below.

This worked well but the only problem that I noticed was that ajaxSetup was a global option and setting it there would make all AJAX calls cached which could mean trouble for the regular data calls we make. Fortunately the documentation page also had a solution for this. I wrote a new jQuery method using that solution as shown below.

Making getScript FireBug Compatible

At first I had had no clue on why this was happening. But thanks to the guys at TechMonks who wrote an absolutely brilliant article on this problem, I could get this fixed. In short the problem was because of how jQuery implements getScript wherein it uses AJAX to the script content and makes it inline. Do read the entire article here for more details.

Here is a code snippet which make getScript compatible with FireBug. The reason why this works is because it loads the JavaScripts files as external resources instead of making it inline and FireBug shows them in the debugging panel.

Internal Caching

The new firebugGetScript from TechMonks works great with FireBug and also facilitates browser caching. However I had one more issue with it. My web application was completely dynamic and had to load a lot of scripts on the fly. Because of this there were scenarios where I was calling the same script through firebugGetScript. However the method wasn't smart enough to recognize this and added the script element multiple times.

I added the ability to recognize this and changed the code to the following.

And things looked perfect with this. I have been using this for quite some time in two different web applications and it's working as expected.

That's it for this post, hope the next time isn't as far away as this ;)