Friday, 9 January 2009

Android GPS Internals: Satellite Status Updates

Trudging through the Android source code one will find that in addition to the location updates, the location library also provides updates on the state of satellites. But this functionality is hidden from developers, unless one delves into a bit of hacking as demonstrated here.

First of all a quick recap of how the GPS functionality works. On the G1 phone there is a library libgps.so which provides the interface to the GPS hardware. The code for this is not open source and is not available. However, what we do know is that this library communicates with Android over a set of callbacks, which are defined in
hardware/libhardware/include/hardware/gps.h.

In the emulator this hardware functionality is replicated in gps_qemu.cpp and can parse two of the many GPS NMEA sentences which are then sent on to trigger location updates. This allows users to trigger updates through the geo nmea messages mentioned in the documentation. However, satellite status updates are not part of this and any such message is just eaten.

However, changing this is not that difficult: it requires adding code to parse NMEA GPGSV messages in the qemu code and triggering the status update callback. I made an inital attempt at these changes for my OpenMoko Freerunner, which I posted in the Koolu Forums.