How does the phone know it has been docked How does the Android phone phone it has been docked in a car holder?

I think the HTC Desire car dock can launch Car Home, but how does the phone known it's been docked?
Typically, the phone knows whether it has been docked by the placement of a magnet on a certain area on the back of the phone.  You can therefore create your own cheap dock using a magnet and some sort of stand.  Here is an example with the Droid.