Sunday, October 18, 2009

Android Phone Home

Getting Started

As some of you know, I've been playing with a new toy.

Android is a new operating system from Google. It's designed for cell phones and other small computers. I've been learning to program it.

For the first couple of months I was mostly working with the Android Software Development Kit (SDK) and the Android emulator. With the emulator you can write and test Android applications (Aps) from the comfort of your computer. As learning Android is like drinking from a fire hose, I wasn't going to invest any money on hardware until I knew I could get something done with it.

I'm at the stage now where I can generate simple programs and I have some definite ideas where to go, so I decided to bite the bullet and buy an Android developer phone.

I ordered my phone and a very few days it showed up. Good job Google!

I fired it up. It munches away for a few seconds, then it tells me "No SIM" and just sits there. Wha?

I know what a SIM is. It's a Subscriber Identity Module, which is a little piece of plastic that modern cell phones use to keep track of who you are. Take a SIM out of one phone and put it into another, and the new phone now has the old phone's number. Neat huh?

I'm using this as a development platform. I don't want to use it to make calls, so I don't need a SIM for it, right? I'm sure that Google has provided an easy work around for this. I'll just check the Internet tubes and find it. Oy! 2 days later I had real access to my phone.

The rest of this blog is designed to save the next poor swine the aggravation I went through in registering my phone.

After checking around I found out that Google not only wants you to have a SIM card, but you also need a data plan on that SIM card! I don't want a data plan, I don't need a data plan, And, at the rate the phone company rapes at, I can't afford a data plan!

Then it just gets silly. You only need the data plan for about 5 minutes, just long enough to connect to Google and register your phone. After that you can chuck it out the window. Oh, did I mention that the phone has WiFi?

You need a data plan to register a phone to get to the WiFi, which you could use, if you could get to it, to register your phone! You're killing me Google. Your just killing me.

Fortunately, if you have a regular SIM card (say from your current phone) and you're already running the Android SDK then it's not too hard to fire up WiFi on your phone and bypass the data plan requirement.

Away We Go!

First we'll get your Linux box to see the phone via the USB cable. I'm running CentOS 5, which is like Red Hat 5. There are other guides out there for Windows and Ubuntu. This guide is for CentOS.

First install the Android SDK on your system. Look around on the Internet for instructions. You don't need everything under the sun, but you do need the "adb" (Android Debug Bridge) command.

Plug your USB cable into your computer and your phone.

Open a root shell on your computer.

After a couple of seconds type "lsusb". You should see a list of the devices attached via USB to your computer. Somewhere in the list should be an entry for "High Tech Computer Corp." "High Tech Computer" is HTC. HTC makes your phone. If you see it then you know that USB is up and running and can see your phone.

The next question is does it see it as a phone or just a very expensive jump drive?

Type "adb devices". If you see an entry that begins with "HT" followed by a bunch of characters and the word "device", then skip to the next section. If adb can't see your phone, then we need to tweak the USB daemon so that it does.

This part took me a long time to get working. Apparently CentOS is using an older version of udevd, which is the program that scans the computer looking for new USB toys being plugged in.

Go in to /etc/udev/rules.d and look for a file named something like "90-android.rules". The leading number varies. It probably isn't there. No problem. You need to create/edit it until it looks like this. Make sure it has the same permissions as the other files in the directory.

# This file lets Linux recognise my Android Developer Phone in
# a way that the adb command can handle.
# Uncomment one of the lines below and run:
# udevcontrol reload_rules
# adb devices
# If it lists your phone, you're done. If not comment out the
# current line, uncomment the next line and run udevcontrol again.
# The 3rd line (usb_device) was the charm for me.
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666"
# SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"
# SUBSYSTEM=="usb_device", SYSFS{idVendor}=="0bb4", MODE="0666"

Follow the instructions in "90-android.rules" and you should end up with a visible Android phone.

Connecting to the Phone

From the command line type: adb shell

After a moment or two you should get a "$" prompt. This means that you're in the phone talking as a regular user.

Type "su".

If the prompt changes from "$" to "#", then you're in as root.

Type "exit" to return to a regular user.

Bypassing the SIM check

There are two ways to do this:

The first, and easiest, is to plug in a SIM card. It doesn't matter that it doesn't have a data plan. This is just to get past the check.

The second, and I haven't tried this myself, is to fool the phone into thinking it passed the check. Check out for instructions.

Note, for the second technique, if you have a developer phone then you don't need to root break it. Just type "su" at the adb shell prompt and you're root.

Registering with out the Data Plan

At this point your phone should be at the registration screen.

From adb, as a regular user, type:

am start -a android.intent.action.MAIN -n

In a couple of seconds the "settings" screen should pop up on your phone.

Set up your WiFi and hit the back arrow. You're back at the registration, which you can now do via WiFi.

If for some reason the settings screen doesn't pop up, try

setprop persist.service.adb.enable 1

and then try the settings command again.

Once you're registered you may want to go to the Android market place and pull down an ap called "APNdroid". It screws with the data plan APN so that your phone can't connect no matter how hard it tries. Bite me AT&T.

Using your Phone as a Jump Drive

One last thing, did you notice that your computer can see your phone as a jump drive but can't access it? That's easy to fix.

When you plug in your phone via USB, you'll notice a little USB forky type icon shows up in the upper left hand of the phone screen. This is the notification area. Pull it down with your finger. Click on the USB notification and then click on "mount". You're good to go!