Simple Analysis of android Qemu GPS module
The gps module of Android is gps. default. so on the system/lib/hw/directory. Generally, the mobile phone that provides the gps function should implement the interaction between this module and the real gps hardware.
In Qemu, gps is to construct a gps. default. so, but this so does not deal with real hardware. It is just a simulated interface, and its code is in sdk/emulator/gps/gps_qemu.c.
A gps device is implemented outside the Qemu container, but this device can only interact with Android through pipelines. Therefore, the gps_qemu.c function is to deal with pipelines and provide gps functions required by Android, as shown below:
Static const GpsInterface qemuGpsInterface = {
sizeof(GpsInterface), qemu_gps_init, qemu_gps_start, qemu_gps_stop, qemu_gps_cleanup, qemu_gps_inject_time, qemu_gps_inject_location, qemu_gps_delete_aiding_data, qemu_gps_set_position_mode, qemu_gps_get_extension,};
Qemu external GPS sends data to the gps module through the QEMU_CHANNEL_NAME pipe in the NMEA format. Therefore, the gps module has several functions responsible for parse data.
The GPS module has a requirement that its callback must be used to create a thread (gps_state_thread), while the location information callback can only be in this thread (gps_state_thread ), this is because the framework requires a java thread visible to the vm, and gps_state_thread will be attach to the vm, And the java layer function will be called back from time to time.
state->thread = callbacks->create_thread_cb( "gps_state_thread", gps_state_thread, state );
Therefore, when the location information of QEMU_CHANNEL_NAME is returned, callback cannot be called directly. Instead, it must be sent to the android framework at gps_state_thread.
Therefore, gps. default. so calls the epoll function to listen to the file fd, so that location information is returned in gps_state_thread.