Thursday 12 May 2011

Android on HTC TyTN II

As I mentioned, one of my previous phones is a HTC TyTN II, also known as the HTC Kaiser and as the AT&T Tilt in the US.

It's a great phone with excellent hardware, and still one of the few models with a hardware keyboard, something I'm personally a fan of. Heck, the only thing that's better is the relatively new HTC Desire Z. (And I Want One Of Those.)

Of course, the TyTN II runs Windows Mobile 6.x. However, these days, with the help of the people at XDA Developers, you can fix that!

So, without further ado, here are my notes on how to install Android on a European HTC TyTN II.

A modern smart phone has two kinds of memory: regular RAM like any computer in which applications run, and NAND (aka flash) memory, which remembers its content even when the power is off, like a harddisk without moving parts. Writing something into NAND memory is called 'flashing'.

When your phone starts, it executes something called the IPL. This tiny bit of code initializes memory and then copies the SPL from NAND into RAM and executes that. The SPL finishes initialization, reads and checks the OS image as it copies it into RAM and then starts the OS. The SPL is also the bit that checks for OS updates and flashes those into NAND memory.

If you change the OS to something unsupported like Android, the SPL will complain. The solution to that is to install a new SPL that doesn't require OS images to be cryptographically signed by the hardware manufacturer. This is generally referred to as security unlocking your phone, but is different from a SIM unlock, which enables your phone to be used with any carrier's SIM.

Of course, the manufacturers try to block unsupported SPL updates too, so you need an additional step. First, you run a software SPL which you then use to flash the desired hardware SPL into NAND. Whew, and that's only the first stage.
  1. Make sure your phone has all the latest official updates, both OS and radio. The radio is sort of like the device driver for your phone hardware. For me, that meant Windows Mobile 6.1 and R 1.65.17.56 (You can see that last number briefly on the boot screen.)
  2. Make sure your phone is fully charged.
  3. Get the software SPL, JumpSPL1.56-KAIS.zip, or the version matching your radio version. Get the hardware SPL, Kaiser-HardSPL-3.56.zip.
  4. Copy JumpSPL to your phone, run it there according to the instructions in the first forum post. When you reach step 6, flashing HardSPL, run KaiserCustomRUU.exe from the second forum post on your PC. Be sure to unplug the USB cable when you're done. Congratulations, you've unlocked your phone!
Now you're ready to install a new OS. Android for the TyTN II comes in two parts: a hardware dependent part which functions as boot loader and installer, and the actual OS image. These are installed from your SD card, and I really recommend having a SD card USB plug so you can copy files onto it without needing your phone.

Get the boot loader images, KAISIMG-PANEL1-320.NBH, KAISIMG-PANEL2-320.NBH, KAISIMG-PANEL3-320.NBH. There's three different types of LCD panel that's been used on the TyTN II, and you can't tell which one you have from the outside. For me, it turned out to be panel type 3. The only way you can find out is by just trying them all, and sticking with the one that doesn't produce graphical glitches on your screen.

Pick one to start with, rename it to "KAISimg.nbh", copy it to the root of your SD card.

For your OS image, you have multiple choices. You can get a fully pimped and modded version such as polymod 2.1g. If that's too much, there's OpenEclair v1.2.1. If you merely want to use the phone for testing, a clean stock-Google ROM is a better choice. I decided to grab the latest and greatest from Android HTC, Froyo 07-04-11 06 from the link at the top of that page.

By the way, Eclair is Android 2.1, Froyo is Android 2.2. Both run fine on the TyTN II.

Rename your OS image to "androidinstall.tgz", and copy it to a subdirectory called "andboot".

Right, time to flash Android.
  1. Reboot your phone into update mode. You do this by holding down the camera button while inserting the stylus into the reset hole at the bottom. You'll get a white screen with a progress bar where it will flash KAISimg.nbh into NAND. Once it's done, wait a few seconds, then pull the battery. (This is the step you'll have to repeat with a different panel type KAISimg.nbh if you get graphical glitches once Android is running.)
  2. Reinsert battery and power on normally. Android will boot and you'll see all sorts of diagnostic messages scroll by until you see, "Hold down volume up or d-pad center to start installer". Press and hold the D-pad center button down. It might take a while but eventually you'll enter the setup menu.
  3. In the setup menu, double-check that the NAND option is marked with an asterisk for both system and data, then use the D-pad to navigate down to "install". Press the D-pad center button to start installing.
  4. Installing takes a bit. After a while, you'll see an animated colorful "X" and then eventually you'll end up in Android's initial setup. Run through the initial setup, but don't set up any accounts or other customization. Finally turn off the phone and pull the battery.
  5. Reinsert battery, start phone, and you're done! Congratulations!
With Android, the Windows key on your phone is Menu, the OK key is Back, the IE key is Home. The Mail key doesn't do anything.

For additional information, I recommend Flashing Your First Kaiser ROM and Flashing NAND Is Easy.

Thursday 3 February 2011

Android Market

Google has finally released a proper web version of the Android Market! Sure took 'em long enough.

And my apps are on there, obviously.

Notepad is my simple little notetaking app. No frills, no ads, and you can import from and export to to SD card. I believe Notepad is as done as it will ever be. I'll do bugfixes if needed, but any more features would take away from the simplicity people seem to like.

FileMan is my simple little file manager. Browse and manage the files on your SD card. I've got one more feature release planned, and if users request a feature I'll certainly consider it, but I think FileMan is also approaching the 'done' state.

TaskMan is the red-headed stepchild, I'm afraid. It was my first Android app, more a proof of concept than anything else. It doesn't do anything the stock 'Manage Applications' doesn't do, and due to the Force Stop functionality being misused, as of Android 2.1, Google decided to make it stop working.

So what else am I working on? I've got a bunch of ideas and prototypes kicking around: An app that stores your notes online so you'll never loose them (but requires an active data connection). An app to list and track your book collection. A simple but fun puzzle game. A terminal application to connect to talkers like MUDs, MUCKs and MOOs.

If you've got any feedback on my current apps, my ideas or even ideas for Android applications of your own, please post 'em here!

Monday 18 October 2010

HTC

Android devices made by HTC have a few special startup modes that aren't really documented very well, so I'll write them up here in the hope someone else might get some use out of them.

In all these cases, start with your device powered off completely. Pull the battery to make sure it's off if neccesary.

Press and hold Back, power on:
Start in Bootloader. Press Volume Down to start HBoot. Not very useful, but the boot screen tells you various version numbers.
Press and hold Home + Back, power on:
Clear Data. Doing this resets your device to factory defaults. Useful if something got messed up at OS or application level.
Press and hold Home, power on:
Recovery mode. On my Hero, this shows a danger triangle with an exclamation mark. In this mode, you can connect your device to a PC with the USB cable and then run HTC's ROM Update Utility (RUU) to (re)flash your device's ROM. Depending on your device, you might need to press Home + End Call to start the process. Useful when your device no longer boots.
Have any additions, corrections or reports on devices where these work/don't work? Let me know in the comments!

Tuesday 14 September 2010

Feedback

The Google Market has terrible search and filtering, only really works when you're browsing it on a phone using the Google Market app, and it's slow. But there's one thing it does right: It makes it really easy to leave comments and feedback on the applications you download. And for developers like me, that's a wonderful thing. Like, for example, this email I received the other day regarding my Notepad app.
This app is great. it really allows me to put all my Alchemy notes in one easy place and is just perfect for my research. thank you for making this app for us.
For me, feedback like this makes it worth all the time and effort I put into making my apps.

Even negative feedback is a wonderful thing, if it comes with an explanation of why. Like in this comment someone left in the Market:
Don't like that when you change your screens orientation it clears the screen and creates a new note (saves the text).
That one made me realize I wasn't handling orientation changes correctly, and led to the release of Notepad v1.03.

So if you find something wrong with any of my apps or have suggestions to improve them, please feel free to write me an email, or file an issue!

Friday 10 September 2010

Mobile Internet Device

Recently, I got an Eken M002 Android tablet. Or rather, I think it's a M002, since neither the device nor the manual contains any sort of brand or make markings except "MID".

It has a 7" screen, built-in webcam, microphone, speakers, tilt sensor and WiFi. There's hard buttons for power on, menu, volume + and volume -, and an iPad-like back button. On the bottom, MicroSD slot, 3.5mm headphone jack, a power jack for the included power adapter and a custom slot that fits a weird little expansion box with an ethernet port and two USB ports.

OS-wise, it runs Android 1.6, kernel version 2.6.29, build number 1.7.3. Reported memory size is 256 MB, and the model number is reported as "generic". It's got 1GB internal storage, called LocalDisk.

It has the default Android Alarm Clock, Browser, Calendar, Camera, Contacts, Email, Gallery and Maps apps. The device doesn't have any location sources, so that last one is of limited use.

Magic Album
In addition, there's a bunch of custom apps made by WonderMedia Technologies, including Magic Album, My Music, My Photo and My Video, plus a number of utilities: File Browser, PK Manager (manages packages), Picture Capture (takes screenshots) and YouTube, the latter definitely not the official YouTube app.

Magic Album is actually pretty nice. Displays the weather (defaulting to Beijing), time and date. And since it prevents the device from sleeping, it actually is useful as a calendar/clock.

Finally it has Apps Store, which is the Wonder App Store app. Looks nice, but a lot of the apps are Chinese, and I can't read Chinese.

Apps Store
Finally, it has a bunch of shortcut apps. "Gravity sensor setting" links to exactly that, "Ethernet" links to the system settings Configure ethernet page, "Settings" links directly to the overall system settings list, "Wi-Fi settings" links directly to that.

The device feels noticeably slow opening apps and the touch screen isn't of the highest quality, needing a delicate touch to prevent the first touch of a scroll swipe from being read as a press. Web browsing works acceptably. I mostly use it as a clock and weather station with Magic Album and occasionally as a digital photo frame and for that, it works very well.

And with the not too-recent version of Android and the hdpi screen, it's a very, very good platform for testing my apps on.

Wednesday 8 September 2010

Bad Sample Is Bad

If you look at Google's Note Pad sample application (and code based on it), you will find a pattern that goes something like this:

\samples\NotePad\src\com\example\android\notepad\NoteEditor.java:109

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Intent intent = getIntent();
    final String action = intent.getAction();
    if (Intent.ACTION_EDIT.equals(action)) {
        mState = STATE_EDIT;
        mUri = intent.getData();
    } else if (Intent.ACTION_INSERT.equals(action)) {
        mState = STATE_INSERT;
        mUri = getContentResolver().insert(intent.getData(), null);
    }
    ...

This is bad and wrong.

The idea is entirely logical: You have an Activity that either loads an existing item or creates a new one depending on the action that's passed to it, and then lets the user edit what it has. The UI for 'fill out new item' and 'edit existing item' is the same so it makes sense to roll the two cases into one.

The catch is actually clearly pointed out in the Activity Lifecycle documentation: Android can completely stop and destroy your activity and then create it anew when the user moves back to it.

One place this happens is during configuration changes, like anytime the user tilts his phone to the side and the screen goes from portrait to landscape. The activity gets paused, gets a chance to save state, then stopped. And then it gets created again, with the saved state passed along.

And in the code above, that saved state is completely ignored and a new, empty item is cheerfully inserted into the database, loosing whatever the user had previously entered. Tilt the phone to and fro a few times and you end up with a whole bunch of blank items and a very confused, unhappy user.

The fix is to save the uri of the item that's being working on in onSaveInstanceState() and reload that item in onCreate(). During ACTION_INSERT, insert a new item only when savedInstanceState is null.

In my own code I create a new note only when no saved state is passed along. And I actually go one step further and save the entire original note so I can offer a 'Revert Edits' command.

Tuesday 7 September 2010

Devices and SDKs

My first real smart device was a Palm V. For its time, it was an amazing device and even today, the hardware looks gorgeous. I never managed to find an SDK for it, though.

After that I got a Sony Ericsson P800, and later upgraded to the P910. There is a Symbian/UIQ SDK, but I never got it to work. A humongous download, an ancient gcc toolset, separate emulator images, everything command-line and nothing documented.

Compared to that, the HTC TyTN II running Windows Mobile 5 (and later 6) I got after that was a delight to develop for. Full-featured, well-documented SDK, first-class emulator, everything integrated with Visual Studio, and you could use any .NET language or straight C to make apps. You can say about Microsoft what you want, but their developer support is still the best there is. I stuck with the .NET Compact Framework and made a game and a couple of quite useful apps.

And then Android appeared. Java-based SDK, which isn't my favorite, but entirely free-of-charge and integrated with a proper IDE, and excellent emulator support. Extensive API for various Google services. Windows Mobile wasn't really going anywhere, so when my contract was up, I got my current device, the HTC Hero. And I've been having tons of fun with it ever since.

You can tinker around with your own Android device as little or as much as you want, but on top of that, Google makes it really, really easy for you to take what you made and offer it to others in the form of the Android Market.

And, at the urging of friends, that's what I did. Currently, I have three apps available, a note-taking app, a file manager, and a running tasks app, which you can find on the market if you search for "banderlabs" and on the web on my Google Code page.

And at 113.395 downloads and 73.980 active installs, I'm rather happy. It's great seeing something I developed getting used and making people's life better. And I plan to keep refining my current apps and adding new ones, a few of which I'm already close to finishing.

Let's see how long I can keep it up. =)