Android: CyanogenMod Recovery Partition Gets Overwritten During Next Boot

February 6th, 2013 Bookmark and Share

I have been using the CyanogenMod Recovery partition to install custom ROMs, but with my stock Android 2.3.6 ROM, I was having an issue where the Recovery partition is getting restored with stock one with very next boot. This issue is also mentioned in notes for CM Recovery installation (http://wiki.cyanogenmod.org/w/Install_CM_for_passion):

Note: Some ROMs overwrite recovery at boot time so if you do not plan to immediately boot into recovery to install CyanogenMod, please be aware that this may overwrite your custom recovery with the stock one.

Though it was not a show-stopper as it gets fixed once I install the custom ROM, but what if you plan to use this recovery, but keep using the stock ROM. Fortunately, the solution for this is simple too. As mentioned above in the warning note, the Stock 2.3.6 ROM tries to restore the Recovery during the boot. The recovery backup is stored at the following path in System:
/system/recovery-from-boot.p

So, all you have to do to get rid of this automatic recovery overwrite is to delete this recovery backup file, and Android system will no longer overwrite. your custom recovery image. You can delete this file easily using ES File Explorer. If you have never used ES File Explorer, here is quick tutorial to do this:

1. Open ES File Explorer File Manager.
2. Select the menu button on your device and click on Settings.
3. Check the Up to Root option, then also check the Root Explorer option. When the prompt appears for root privileges, press the 4. Allow/Grant button.
5. Check the Mount File System option as well.
6. Go to the Root folder of your Android file-system i.e. “/” path.
7. Go to the “system” folder and long-tap on the recovery-from-boot.p file, and then delete it.

I hope you find this of help.

Android: Installing System Images using flashboot

February 1st, 2013 Bookmark and Share

In my previous article, Installing Jelly Bean on Nexus One, I discussed how I was able to install Jelly Bean on my NexusOne using couple of tools and helper applications.

However, after a couple of days of exploring it, I decided to try to downgrade it back to Gingerbread (mainly because of the Camera issues). This step was even more simple than installing the Jelly Bean on my nexus one. The good thing was that I took the full backup of my Gingerbread before upgrading to the Jelly Bean (using ROM Manager). This backup folder had flash-able images of the system, boot and recovery partitions. So all I had to do to revert back the original version was to run couple of commands in the bootloader mode.

Here are the exact commands (for your info, and my future reference):

1. First you need to boot into bootloader mode. You can do this from key combination of your phone (for Nexus-One, it’s Power+Trackball down), or you can reboot into bootloader mode using the following adb command:

1
adb reboot-bootloader

2. Wait for your cell to reboot in bootloader mode, and once you see it, test it by running following command:

1
fastboot devices

If the above command lists your device, then you are good to go forward. Otherwise wait for few more second and/or check USB cable connection.

3. Once the fastboot mode is detecting the device, you can flash your Image and System flashable images using following commands:

1
2
fastboot flash boot boot.img
fastboot flash system system.img

4. The next step is to simply clear your cache and user-data to avoid any problem with previous ROM data.

1
2
fastboot erase userdata
fastboot erase cache

5. And at last, simply reboot your phone:

1
fastboot reboot

If everything went well, you should be able to see your previous version without any problems.

Installing Jelly Bean on Nexus One

January 27th, 2013 Bookmark and Share

I have my Nexus One for more than a year. Although its stock OS (Gingerbread) is quite outdated, I still overall love it. But I must admit that it’s quite outdated OS now. So, I decided to upgrade this to Android Jelly Bean with hope to learn a lot during this process.

First of all, please note that this is not a guide to how to install Jelly Bean on Nexus One. If you are looking for one, search on the web, and you will find dozens (if not hundreds). FYI, I read many, but referenced the following two mostly:
http://marian.schedenig.name/2012/07/22/installing-android-4-ics-on-the-google-nexus-one/
http://c2med.blogspot.com/2012/07/how-to-install-ics-nexus-one.html

Here are the mains steps I used:

1. Unlocking your Phone
It’s basically unlocking your phone bootloader. this is required because if your bootloader is locked, you can’t replace your recovery image, you can’t flash a custom ROM, and you can’t edit your system files. So we have to do this before the fun start. Here is a quick guide on how to do this (just follow the “Unlocking the device” section):
http://wiki.cyanogenmod.org/w/Install_CM_for_passion

Note: Unlocking the bootloader on a Nexus device will automatically wipe all device data.

2. Rooting your Phone
Once you have unlocked the Phone, the next step is Root it. Rooting is the process of allowing you to run your device with root-level permissions i.e. allow Superuser permissions. This gives you as a user to perform all the permissions including deleting the files required to run the system. While you normally wouldn’t do this, you can still do this. The main reason for Rooting is to give you additional control while in the Android to setup the Custom ROMs.

For the rooting, you can use either install the CyanogenMod custom ROM for your device (as in the above link), or you can try some application which exploits the Android OS vulnerability to root it. I tried the OneClickSuper application, and it worked for me. So you can try it as a simple alternative too. This application interface is quite straightforward, but if you have any confusion, there are plenty of tutorials available.

3. Install Custom Recovery
Recovery refers to the dedicated, bootable partition that has the recovery console installed. This is used to detect and load the Android OS from the main partition. Plus this also has supports some basic commands/options to restore your system in case of any problem. The stock recovery is pretty basic, and don’t have much options. Specially the stock recovery doesn’t allow you to do the installation of the custom ROMs and do backup/restore.

For installing custom recovery, there are two possible ways. If you like Geeky style, then you can do this manually by following this tutorial (follow the “Installing recovery using fastboot” section):
http://wiki.cyanogenmod.org/w/Install_CM_for_passion

There is also a simple way, that I followed, and that’s to install the CyanogenMod Recovery using ROM Manager. Here is very simple tutorial on this:
http://tech2.in.com/how-to/smartphones/how-to-root-and-install-custom-recovery-on-any-android-phone/280442

4. Partition you SD Card
The next step is to reparation your SD Card so that the applications can be installed on your SD Card. This way you can leave more RAM for the system applications. I think this is required (but not very sure) to install large size ROMs like Jelly Bean. Anyway, as this was simple process, I decided to do this anyway.

For this, again there are two ways. First is geeky way and it’s to use the 4EXTRecovery to install custom recovery and use it to partition the SD-Card. Here is a good tutorial on this:
http://www.roms-au.com/howtos/ext3/

Another, simple one is to create this partition using ROM Manager. Again, as I have the ROM Manager installed, so I use this option. Here is a tutorial for this:
http://theultralinx.com/2011/10/how-to-partition-your-sd-card-with-rom-manager.html

Warning: After doing the above step, I got the famous Android boot failure (Android with Exclamation sign). To fix this, I booted in to Recovery mode, and Cleared the User-Data. This fixed my problem.

5. Partition your Internal Memory (HBoot)
To Install the Jelly Beans or ICS, you need to first resize the internal memory (called HBoot). This is because the new ROM size for the JB or ICS is so big that it will not fit on the default partition created for the Gingerbread on Nexus One. Different ROMs require the different HBoot size. I was planning to use CM10.1 VJ Jelly Bean 4.2.1 and this requires 250 HBoot. So next step is to re-size the partition. This can be done by BlackRose.

Warning: In case after the above step you can’t load into recovery. You can fix this by flashing your recovery image again from the fastboot mode.

6. Install your Custom ROM
Once all the above is done, you are ready to install your custom ROM. For this download it, and place it on your SD-Card. If you forgot to do this (like I did) before formatting and erasing your system. You can mount the SD Card from the Recovery too (if you are using CyanogenMod recovery. Once you are in the recovery mode, do “wipe data/factory reset” and also wipe all paritions except the sd-card. Then select update from SD-Card, select the new ROM ZIP file. This should start the installer. Cross your fingers while it finish the installation and do the booting.

7. Results
If everything went well, then you will see your new Android OS. I’m using Jelly Bean and it’s really great. There are still few (but minor) display issues, but overall it’s fully functional. The best thing is that as soon as I signed in with Google Account, all my contacts and applications were restored. So, the system is back in running state in an hour or so.

8. Bonus
I like the new Jelly Beans OS and overall functions. However, I didn’t find the booting animation that cute (sorry CyanogenMod designer). Fortunately, there is simple way to change that too. Here is the one I tried:
http://forum.xda-developers.com/showpost.php?p=28025789&postcount=1

The setup is simple. Just download the flashable version of the animation. Place it on SD-Card. Boot to Recovery mode, and simply flash the new animation. Enjoy the new elegant animation.

Conclusion
If you try this, please do a very thorough reading of all the above articles (and any other articles you can find on web) before trying any of this. The key is to make sure you know what you are doing. If you are not sure, read more or post questions to experts (I’m not expert). Good luck!

Windows Desktop ListView Handle

January 19th, 2013 Bookmark and Share

I have been using a utility function in my TaskbarExt application for years to get the current Desktop ListView window handle (SysListView32 to be exact) to show/hide the icons depending on user preferences.

This has worked well for years, but recently I enabled the Windows Desktop wallpaper rotation, and I noticed that this function randomly stops working. On debugging the issue, I found that when the wallpaper rotation is enabled, instead of loading the “SHELLDLL_DefView” window in the “Progman”, Windows was loading under the “WorkerW” window. BTW, the Spy++ Tool was great help in debugging all this.

Once I know what’s going on, the fix was quite easy. In case your are running into similar issues, here is the sample code which works for me:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
HWND GetDesktopListViewHWND()
{
  HWND hDesktopListView = NULL;
  HWND hWorkerW = NULL;
 
  HWND hProgman = FindWindow(_T("Progman"), 0);
  HWND hDesktopWnd = GetDesktopWindow();
 
  // If the main Program Manager window is found
  if (hProgman)
  {
	// Get and load the main List view window containing the icons (found using Spy++). 
    HWND hShellViewWin = FindWindowEx(hProgman, 0, _T("SHELLDLL_DefView"), 0);
    if (hShellViewWin)
      hDesktopListView = FindWindowEx(hShellViewWin, 0, _T("SysListView32"), 0);
	else
		// When this fails (happens in Windows-7 when picture rotation is turned ON), then look for the WorkerW windows list to get the 
		// correct desktop list handle.
		// As there can be multiple WorkerW windows, so iterate through all to get the correct one
		do
		{
			hWorkerW = FindWindowEx( hDesktopWnd, hWorkerW, _T("WorkerW"), NULL );
			hShellViewWin = FindWindowEx(hWorkerW, 0, _T("SHELLDLL_DefView"), 0);
		} while (hShellViewWin == NULL && hWorkerW != NULL);
 
		// Get the ListView control
		hDesktopListView = FindWindowEx(hShellViewWin, 0, _T("SysListView32"), 0);
  }
 
  return hDesktopListView;
}

Hopefully the comments should explain what’s going on very well. But if you still have any questions or suggestions, please do share with me.

On a side note, any wallpaper with icons turned off looks so beautiful. So I would recommend give this a try. So, if you are a programmer, which you most probably are if are reading so far, then better go ahead and implement this yourself. It will be a nice little utility. If however, busy with some other stuff, you can try my TaskbarExt application and get this in action quickly.

ASP.Net SecurityProtocol (for SSL Version Control)

January 3rd, 2013 Bookmark and Share

Recently, when working on an integration API written in ASP.Net which communicates with a web-services developed using PHP, the tech support requested to force all the secure communication (over HTTPS) to use only the SSL v3 version.

This can be controlled in PHP CURL via single line of code as shown blow:

1
curl_setopt($curl, CURLOPT_SSLVERSION,3);

For more details on this, please check curl-setopt. Doing this in the ASP.Net was a single line of code as well, but finding it was not that easy. Here is the code which did the trick for me:

1
2
3
4
5
6
7
8
9
10
11
12
13
try
{
	// Take back-up of current protocl and force use of only SSL3
	SecurityProtocolType activeProtocol = ServicePointManager.SecurityProtocol;
	ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
 
	// The ASP.Net communciation (using HttpWebRequest) goes here
}
catch {}
finally {
	// Restore the orignal protocol
	ServicePointManager.SecurityProtocol = activeProtocol;
}

I hope this helps.