July 18, 2010

Prison Break

I commute and travel just enough to make easy-to-use portable entertainment a big deal for me. I've been a loyal iPod user ever since the original 5GB, Mac-only, no-wireless, less-space-than-a-Nomad, lame version. But when the iPhone came along, the attraction of gadget-convergence plus the online-anywhere functionality immediately consigned the iPods to the same dustbin of electronics past where my Discman-plus-Airhead setup still resides. Now I can listen to the same music and podcasts, and check RSS headlines, tweets, and Facebook updates on one 3.5" screen, all automatically synced through the same iTunes setup I had before. By making the iPod-to-iPhone transition so seamless, Apple's really build themselves a significant competitive advantage that other smartphone vendors can steal, but not match.

If one device is going to be my all-everything pocket master, it better be rock-solid stable and ready to go all the time. iPhone's barely-adequate battery life is well documented, but it's no problem for me to charge-and-sync every night, and keep an extra iPod cable at work for a quick top-up in case some rogue process sucks up all the juice. Plus the iPhone is sold unlocked in Taiwan out-of-the-box. That's why I've never bothered to look into jailbreaking my iPhone, despite all the supposed freedom from Apple tyranny and all that. Most folks around here jailbreak immediately, of course, mostly for the ability to pirate Apps, but also to install improved Chinese input methods or Bluetooth stacks. Far from me to judge on the legality or morality of those uses, at least for me none of those are deal-breaker functions, so I've been content with the vanilla Apple firmware. And Apple has done a relatively good job of consistently upgrading iOS across its entire line of devices, up 'til now.

Yes, the cut-and-paste function was a long time coming. The (pseudo) multi-tasking even longer, only arriving with the introduction of iOS 4, designed in parallel with iPhone 4. However, unlike the past iOS upgrades, the iOS 4 upgrade clearly segregates the iPhone generations, back-porting the multi-tasking support only one generation back. It's not entirely unreasonable, since the iPhone 3Gs carries more RAM than the previous iPhones, critical for holding all the multi-tasking Apps in memory. I could live without the wallpaper support for my not-yet-two years old iPhone 3G, but missing out on the signature feature of iOS 4 took a lot of juice out of the new-version-high.

Thankfully, the underground iPhone dev-team was hard at work even during the iOS beta stage, and they produced a jailbreak mechanism almost immediately after the formal release of iOS 4. I waited for a few more weeks for the supporting infrastructure to shake out the integration issues with the new major version. Then I went ahead and redsn0w'ed the puppy. Stayed away from the more garish themes and kept it vanilla-looking as much as possible. SBSettings is a practical addition, allowing easy toggling of many functions without digging into the Settings app. Had to install SSH, because it just ain't really hacking unless you can get a command line. But the main goal was to inject the single toggle to enable multi-tasking on the iPhone 3G.

The SBSettings display shows the amount of free memory remaining, and even on a fresh boot it was showing a precariously low number for multi-app usage. Sure enough, double-clicking the Home button to bring up the task-switcher and jumping to background apps resulted in long lags and crashes more often than not. Looks like we need more memory. Well, I wasn't about to go desoldering SMT RAM chips or anything like that. iOS's Unix foundation provides just the answer for this situation via the virtual memory system. Apple was even kind enough to leave their dynamic_pager VM manager in the default iPhone system setup, so all it takes to activate VM is to drop a property list file into the right LaunchDaemons directory and off it goes. Virtual memory storage on solid-state storage carries substantial risks, as frequent writing of the swapfile from heavy memory access will do bad things to the NAND flash chips due to their limited write-cycle lifetime. Nevertheless, it's such a simple mod that I decided to give it a try, figuring that I've already got my money's worth out of the 3G and betting that I wouldn't wear out the flash before iPhone 4's out on the local market.

The virtual memory gave the system the illusion of enough RAM breathing room to allow multi-task switching, but reading from the swapfile is still orders of magnitude slower than real-RAM access, so such switches still take an inordinate amount of time, and there's still a significant chance that the system will lose patience and just kill the task before the switch completes. As more apps get opened over time, the system keeps expanding the swapfile to fit them all in, resulting in the whole phone starting to lag over time. So I either had to reboot the phone to clean out the swapfiles, or keep opening up SBSettings to kill processes to manually free up memory, which seems to defeat the purpose of convenient multi-tasking. Kinda reminds me of the good old days, when I tried to make Switcher work on my puny 512KE Mac, shoehorning too many applications into too little memory on a system that wasn't designed to handle it.

Still, I might've put up with all that, until I had to travel for work and left the comforts of my home cell network. Having the phone flash No Service on me at the airport was no joke when I was depending on roaming coverage to keep me in touch with my customer and for my own border pickup. Checked the Carrier settings and figured that the jailbroken OS image did not contain the roaming profiles for my home carrier, so it did not know what carrier it should attach to upon landing in a strange land, and unfortunately neither did I. So I had to click through each carrier and wait for it to try to associate with the network to see if it would take. This was no trivial task in a competitive market like Hong Kong with its myriad of wireless carriers. Wasted half an hour fiddling with the settings before I finally got a dial tone, so to speak. Thank goodness I knew where the carrier settings were hidden in the menu tree, whereas a less knowledgeable user might've been seriously hosed. Couldn't get the phone to associate with HKG's free Wifi service, either, but I was in too much of a hurry to work out that problem.

By the time I got out from behind The Great Firewall, iOS 4.0.1 had been released to fix issues unrelated to my phone. Others warned that installing the minor update would undo the jailbreaking process and to hold off until the dev-team could update the JB toolchain. On the other hand, undoing the jailbreak was exactly what I was looking to do at that point, and I dutifully clicked the Install And Update button when iTunes asked me about the new update when I synced the phone at home. Soon thereafter, my iPhone was back on the straight-and-narrow, without the multi-tasking and jailbroken apps, but with a new signal scale and hopefully improved stability.

Now before y'all come to take my geek-card away, I've still got my Tomato-re-flashed router, the debian-hacked NAS, an HTPC next to the TV, which also happens to run a virtualized Linux instance for all my external server needs. So I've already got more gear than I've got time to tweak. Right now my biggest challenge is figuring out how to crack the BabyOS that's running inside the kid's head. Let's see if we can get him to do something useful besides making funny faces.

Posted by mikewang on 11:19 PM