Saturday, August 30, 2014

Nexus S - Rooting [recover from Jelly Bean slowness]

Its been a while since I received the official Jelly Bean upgrade on my Nexus S. And, the sad part was that I did upgrade. And now, the phone is unusable since then. I'd have to wait for 5-10 secs after each touch event. And, needless to say, the phone used to freeze every now and then.

I started Android development on the official Android G1/G2 [ADP] phones since 2009. When I decided to purchase one for me, I opted for Nexus S for 2 reasons. One, it looks pretty cool in a sleek-curve frame with the right specs. Second, I hoped to receive all the recent updates from Google directly as it was an unlocked phone. And, thats where I made a mistake. I forgot that Google can also treat my device as scapegoat to test its latest release without thoroughly testing the latest android releases for the specific device[specs].

Now, neither could I use the phone for personal use, nor could I use it as a dev phone. I didn't sell it as I never felt for the same. After a few months, I couldn't take it anymore. I really loved my Nexus S and I couldn't let google change it.

Though, previously, I tried looking for options to improve the phone on Jelly Bean, I did't get time to do it because of the other stuffs. Gladly, I found out some time a couple of days back and I decided: IT WAS TIME.

DISCLAIMER: The process of flashing the device can brick your device. The author doesn't take any responsibility if anything goes wrong. Make sure that you read the complete blog and know what you're doing.

There were a few options how to go about it:

1. Clear the phone memory. Uninstall unimportant apps. Move the less relevant apps to the sdcard [which do not run any service in the background].
I also removed the custom Home launcher app, sdcard locker etc..

It improved the performance by 10%.

2. I tried finding the ways to downgrade it back to gingerbread [2.3.3, API level 10] it came originally with but couldn't find a good way out.




I was left with the only option of flashing the OS which could clear the system cache. And, there were 2 ways:
1. Using google's official factory image
2. Using a custom image which could also root the phone giving you the "su" access.

I tried Pros and Cons for which one to choose.

1. Google's official factory image:
Pros:
(i) Its official so no need to worry about getting your phone data compromised.
(ii) You could get the updates on the firmware from Google. [Ahhh, I'd rather move this to Cons.]

Cons:
(i) It doesn't give me root access so that I could use "su" enabled apps.

2. 3rd Party custom image [ROMs]
Pros:
(i) I could get the root access on my phone so that I could use "su" enabled apps.
    (a) I could also use Android's Hierarchy Viewer without having to use the ViewServer.
    (b) Debugging any apps: Looking at their database/files stored at /data/data/. Wow.
    (c) Change the system settings: cpu overclocking, setting systems props [using setprops] etc..
    (d) You can use the "procrank" tool to profile the memory.

Cons:
(i) I'd have to worry about getting my data compromised if I pick any malicious Android image.
(ii) It could brick the device.

As a developer, getting the root access on the phone was one and the only option to go for. So, I decided to root the phone. But, what if it bricks my device. So, I decided to go for Google's factory image.




Flashing requires the following:
1. Unlock the bootloader so that you can write to the restricted partitions.
2. Change the recovery options. You can do that by flashing a recovery image. Android's default recovery option won't work for you.
3. Flash the system image [ROM]
4. Install Google apps separately which includes PlayStore etc. [flash this as a separate image]. Its required when you install the custom ROM which doesn't include these by default.

BEFORE FLASHING: Backup all your phone data:
1. Media: photos, videos and music files
2. Documents etc.
3. SMS/MMSs [you can try some 3rd party apps]
4. Apps, Contacts, Calendar, Email - I tried the Google sync.

Pre-requisites
1. I'd recommend a Linux based OS though Windows should work fine as long as you've the right android drivers and you can see the "adb" device. Try "adb devices" at the command prompt.
I used Ubuntu to perform the following steps.
2. Download and install the Android SDK which gives you the tools: adb, fastboot.
3. Nexus S should be 90% or more charged.


(I) Nexus S - Flash with Google's offical factory image

Here're where you can find the official page which has all the instructions and the links to download the image.
https://developers.google.com/android/nexus/images#instructions


Here're the steps I followed:

0. Download the factory image for your device from the url above. I chose the following for my device.
Factory Images "soju" for Nexus S (worldwide version, i9020t and i9023)
Android 4.1.2 (JZO54K)

You need to find your phone's exact model number to find the right image. Go to "About Phone" option. Mine was I9023**.

1. Boot into the fastboot mode. Try Volume Up/Down with Power key at the same time. Or, execute the following:
$ adb reboot bootloader

2. Unlock the bootloader so that you can write to the restricted partitions. You can see a prompt on the device. Use the Volume Up/Down keys to scroll through the options and the Power key to select. Note: This will erase all the data on the device.
$ fastboot oem unlock

3. Extract the factory image archive and run the following script. It'll flash the bootloader, firmware baseband, OS etc..
$ flash-all

4. Lock the bootloader.
$ fastboot oem lock

5. Use Volume up/down key to choose "reboot" and use the Power key to select to reboot the phone.


RESULT:
The phone is as smooth as new. I'm glad. The flashing was flawless. But, I didn't still have the root access on the phone.
You can stop here if you don't develop apps on Android or don't know what Su access means.



(II) Nexus S - Flash the Custom image which has root access [Cyanogen Mod]

There're many options to choose from. But, you've to be careful as to where you're picking the ROM because it could be bundled with malicious software which could compromise your data.

Usually, if you search "<device name> android root" or "flashing <device name>", you'll get so many options which'll confuse you as to which one to choose from. I can mention 2 credible sites here which are not known to bundle any malware with the ROMs: Cyanogen and XDA-developers.

http://wiki.cyanogenmod.org/w/Main_Page

http://www.xda-developers.com/

These are the awesome developers who made the most out of the Open-source Android OS. They might not necessarily be working for the big brands but they've shared their research and given back to the developer community, thus keeping the concept of open-source ideology alive which was started by the FSF and GNU.

Hats off to you guys!!

Now, back to flashing. I chose Cyanogen as their wiki was straight forward and didn't have too many options to deviate to/from. It comes bundled with the Superuser app.

Here's the wiki I followed for Nexus S:
http://wiki.cyanogenmod.org/w/Install_CM_for_crespo

1. Make sure that the phone is 90% or more charged and that you've Android SDK's "adb" and "fastboot" commands in your PATH.

2.  Execute the following to reboot the device in fastboot mode.
$ adb reboot bootloader

3. After the device reboots, You can try running the following command to see that the device is visible as a fastboot device.
$ fastboot devices

2. Unlock the bootloader so that you can write to the restricted partitions. You can see a prompt on the device. Use the Volume Up/Down keys to scroll through the options and the Power key to select. Note: This will erase all the data on the device.
$ fastboot oem unlock

3. If you see the "unlocked" text on the screen, then it was successful. You can also try by rebooting the device. If you reboot the device, you'd need to go to the phone home screen and re-enable "adb" from Settings.

4.  Download the recovery image for your device. I'd prefer the non-touch image.
http://clockworkmod.com/rommanager

Note: Whenever you download a large file, make sure to verify the MD5/SHA1 checksum as applicable. These tools come free and pre-installed on most of the Linux distros.

5. Run the following too boot into the fastboot mode.
$ adb reboot bootloader

6. Vefiy that you can see the device connected.
$ fastboot devices

7. Extract the recovery image archive from step-4 and use the following to flash the recovery image.
$ fastboot flash recovery your_recovery_image.img

8. Select the "recovery" option on the screen and select.
Note: Some ROMs overwrite the recovery image at boot time, so if you reboot and then try to go into the recovery mode, your recovery might already have been flashed by the stock one. So, DO NOT REBOOT.

9. Download the Cyanogen package from the following. [Includes the SuperUser app to manage permissions]
http://download.cyanogenmod.org/?device=crespo

10. Also, download the Google apps as that don't come bundled with the custom ROM. Make sure that the CM-# matches.
http://wiki.cyanogenmod.org/w/Google_Apps

11. From the ClockworkMod recovery menu options, choose "backup and restore" to create a backup of the current ROM.

12. Choose wipe data/factory reset.

13. There're 2 options to install the custom ROM and Google apps: Sideload and Push/Install. I chose the latter.

14. Under "Mounts and Storage" menu, choose to mount /sdcard//sdcard0 or /data/data/ whichever works for you.

15. Now, push the 2 archive files to that partition.
$ adb push cm-#.zip /storage/sdcard0/
$ adb push gapps-*.zip /storage/sdcard0/

16. Go back to the Main menu and choose "Install zip" and choose the cm-#.zip to install the ROM first.

17. Now, install the gapps-*.zip using the same method.

18. You can now unmount the partition from the Main menu.

19. Choose "reboot" from the Main manu.

20. Welcome to Cyanogen Mod - custom Android OS with root access.

21. From the developer options, you can choose to give Su access to adb, apps or both. You can also find various cool settings, like SuperUser app, cpu overclocking, I/O scheduler, memory management, ADB over network etc..

22. Execute the following:
$ adb root
$ adb shell
# whoami

You should now see the # prompt which is Super user[root].



Get the Su access without flashing using a hack [which doesn't work always]

If its the root access that you want and you'd like to avoid flashing, you can try this trick but it doesn't work on all the platforms.

The following is expected to work on ICS and JellyBean prior to JRO03U.
http://forum.xda-developers.com/galaxy-nexus/general/how-to-how-to-root-unlocking-bootloader-t1894717

It exploits the timing difference in the "adb restore" command.

Monday, August 25, 2014

My Android Apps


 HotSpin - Spin The Music



                                        
Homepage
Homescreen
Now playing
Now playing



Playlist-loading
Playlist-loading
Playlist
Playlist







Wednesday, February 9, 2011

Installing Packages in Linux

Here's one of my oldest articles. I'm glad I found a few of them. This one was written on 12th Jan'05, when I was pursuing my engg degree.
:-)

Linux Mandrake – Installation Guide

Here's one of my oldest articles. I'm glad I found a few of them. This one was written on 12th Dec'04, when I was pursuing my engg degree.
:-)

Monday, January 31, 2011

GMail and associated networks hacked all over the world

The world is watching and Google and its associated networks are being hacked in bulk all over the world. GMail, Orkut, GMail authenticated social networks, i.e. Facebook etc.
Google has proved to be the worst in providing security to the end-users compromising the precious user-data at the hands of a few miscreants.
Google developers are helpless as they face attack in a bulk. They have no idea about whats happening around.

It hires brightest minds just to pay. Now, when it comes to show the hi-quality work, its designed system seemed so fragile!! Now, more and more people are moving to other e-mail providers.

People speak, ""Anything but GMail!!"

I'd love to go for an e-mail provider thats paid and gives me security so that even if my account is hacked, I can activate it by calling the customer care and get all my deleted data back.

Majid

Thursday, January 20, 2011

Android ANR Debug tools


From API level 9, Android provides a tool, i.e.StrictMode class to look for UI blocking issues commonly known to dev as ANR(Application Not Responding). It happens when the main EDT(Event Dispatch Thread) doesn't return in the specified time. For BroadcastReceiver, its 10 secs, 5 secs for touch events etc. Android works on Single Thread mechanism for interrupt handling and paint routines.
 
Using the Strict mode class, you can specify the types of blocking issues, you want to catch, i.e. disk I/O, network, logs etc.
 
I'm surprised even accessing the shared preferences on a UI thread is treated as a violation. The reason presented by Android is that the Shared Preferences is actually a xml file saved onto the disk. So, accessing it in the main thread is also a violation. I wonder if if there's a workaround on this. Nobody wants another thread to deal with SharedPrefs.
 
Otherwise, a good tool(in fact, a class) to use. Only can be tested on 2.3 platform onwards. So, its time to make good use of the emulator.
 
if (DEVELOPER_MODE) {
         StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                 .detectDiskReads()
                 .detectDiskWrites()
                 .detectNetwork()   // or .detectAll() for all detectable problems
                 .penaltyLog()
                 .build());
         StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                 .detectLeakedSqlLiteObjects()
                 .penaltyLog()
                 .penaltyDeath()
                 .build());
     }
 
 
For more info, have a look at,
 
 
 

Software Versioning - The Magic Numbers


Its always benefecial to have the version number of a project clearly defining its current, past and future state. Some of the techniques are discussed below.
 
X.Y.Z. versioning
The common versioning sceme is X.Y.Z.
Z -> pure bug fix releases (can only change function implementation)
Y -> can introduce new functions, new symbolic and enumerated constants, and deprecate existing functions
X  -> Any kind of change can be made during a major version release (New features etc.)
 
The main difference between these three version numbers are Forward and Backward compatibility.
 
For more info, please have a look at the Apache page,
or
 
 
Alpha-numeric versioning
Another approach is using an alpha-numeric string, i.e.
1.0b1, 1.0b2 (with some fixes), 1.0rc1 (stable enough)
 
1. Pre-alpha - prior to testing (different milestones)
2. Alpha - first phase to begin software testing (usually ends with a feature freeze)
3. Beta - feature complete, for usability testing. often useful for demonstrations and previews within an organisation and to prospective customers (preview, prototype, technical preview (TP), or early access)
4. Open and closed Beta - closed beta versions are released to a select group of individuals for a user test, while open betas are to a larger community group, sometimes to anybody interested
5. Release candidate - code complete when the development team agrees that no entirely new source code will be added to this release
6. Release - RTM - Release to manufacturing or Release to marketing - delivered or provided to the customer
                 - GA - General Availability - commercialization activities completed. software has been made available to the general market either via the web or physical media
 
 
 
Android versioning
On Android, we've 2 options for versioning, one for public release, the other for internal debug releases, called,
versionCode, i.e."2" and versionName, i.e."0.0.0.25" respectively.
 
The company should follow the standard that suits its needs.