GPS Android Runtime
LocationManagerService
* The system service
that manages LocationProvider and issues location
updates and alerts.
* Allows applications to obtain periodic updates of the device's geographical location
* Allows applications to obtain periodic updates of the device's geographical location
//location
providers implementing the Geocoder services.
- GeocoderProxy mGeocodeProvider;
//
This provider determines location based on availability of cell tower and WiFi
access points
- LocationProviderProxy mNetworkLocationProvider;
// This provider
determines location using satellites
- GpsLocationProvider mGpsLocationProvider;
GpsLocationProvider
•A
GPS implementation of LocationProvider used by LocationManagerService.
•This
provider determines location using satellites (GPS/AGPS Devices).
•Interact
with GPS HAL lib through JNI Layer .
•Get’s
location information latitude,
longitude, altitude etc..
forms Location object and pass it to LocationManagerService.
JNI
Method table
•List
of JNI method used by GPSLocationProvider to initialize gps hal lib and retrieve
location information from gps hardware.
static JNINativeMethod sMethods[] = { /* name, signature, funcPtr */ {"class_init_native", "()V", (void *)android_location_GpsLocationProvider_class_init_native}, {"native_is_supported", "()Z", (void*)android_location_GpsLocationProvider_is_supported}, {"native_init", "()Z", (void*)android_location_GpsLocationProvider_init}, {"native_cleanup", "()V", (void*)android_location_GpsLocationProvider_cleanup}, {"native_set_position_mode", "(IIIII)Z", (void*)android_location_GpsLocationProvider_set_position_mode}, {"native_start", "()Z", (void*)android_location_GpsLocationProvider_start}, {"native_stop", "()Z", (void*)android_location_GpsLocationProvider_stop}, {"native_delete_aiding_data", "(I)V", (void*)android_location_GpsLocationProvider_delete_aiding_data}, {"native_read_sv_status", "([I[F[F[F[I)I", (void*)android_location_GpsLocationProvider_read_sv_status}, {"native_read_nmea", "([BI)I", (void*)android_location_GpsLocationProvider_read_nmea}, {"native_inject_time", "(JJI)V", (void*)android_location_GpsLocationProvider_inject_time}, {"native_inject_location", "(DDF)V", (void*)android_location_GpsLocationProvider_inject_location}, {"native_supports_xtra", "()Z", (void*)android_location_GpsLocationProvider_supports_xtra}, {"native_inject_xtra_data", "([BI)V", (void*)android_location_GpsLocationProvider_inject_xtra_data}, {"native_agps_data_conn_open", "(Ljava/lang/String;)V", (void*)android_location_GpsLocationProvider_agps_data_conn_open}, {"native_agps_data_conn_closed", "()V", (void*)android_location_GpsLocationProvider_agps_data_conn_closed}, {"native_agps_data_conn_failed", "()V", (void*)android_location_GpsLocationProvider_agps_data_conn_failed}, {"native_agps_set_id","(ILjava/lang/String;)V",(void*)android_location_GpsLocationProvider_agps_set_id}, {"native_agps_set_ref_location_cellid","(IIIII)V",(void*)android_location_GpsLocationProvider_agps_set_reference_location_cellid}, {"native_set_agps_server", "(ILjava/lang/String;I)V", (void*)android_location_GpsLocationProvider_set_agps_server}, {"native_send_ni_response", "(II)V", (void*)android_location_GpsLocationProvider_send_ni_response}, {"native_agps_ni_message", "([BI)V", (void *)android_location_GpsLocationProvider_agps_send_ni_message}, {"native_get_internal_state", "()Ljava/lang/String;", (void*)android_location_GpsLocationProvider_get_internal_state}, {"native_update_network_state", "(ZIZLjava/lang/String;)V", (void*)android_location_GpsLocationProvider_update_network_state }, };
At
frameworks\base\services\jni\com_android_server_location_GpsLocationProvider.cpp
Building
a GPS Library
•Android
defines a user space C abstraction interface for GPS hardware. The interface
header is defined in include/hardware/gps.h.
•To
implement a GPS driver, create a shared library that implements the interface
defined in gps.h. You must name your shared library libgps.so.
•android
does not rely on anything in the Linux kernel for GPS. just need to implement
the interface in gps.h.
HAL
Stub
GPS-HAL Lib Initialization
•During
boot up init process launches the System Server. System Server is the first
java component to run in the system. It starts all android system services
including LocationManagerService.
•LocationManagerService initializes GpsLocationProvider and gps device hardware.
Device data structure
- gps.h includes device data
structure gps_device_t .
-
gps lib hardware should
define the device structure gps_device_t and the public
method get_gps_interface.
struct gps_device_t { /** * Every device data structure must begin with hw_device_t */ struct hw_device_t common; /** * return GpsInterface structure - to interact with gps lib hardware. */ const GpsInterface* (*get_gps_interface)(struct gps_device_t* dev); };
at
(hardware\libhardware\include\hardware\ Gps.h)
GpsInterface data structure
- gps.h includes device data
structure GpsInterface.
- Gps device hardware should return initialized GpsInterface structure on function
call get_gps_interface.
- GpsInterface structure includes
number interface methods for location related input.
/** Represents the standard GPS interface. */ typedef struct { size_t size; //opens the interface and provides the callback routines to the implmentation of this interface int (*init)( GpsCallbacks* callbacks ); int (*start)( void ); /** Starts the location tracking session. */ int (*stop)( void ); /** Stop the location tracking session. */ void (*cleanup)( void ); /** This is used by Java native function to do time injection. */ int (*inject_time)(GpsUtcTime time, int64_t timeReference, int uncertainty); //This is used by Java native function to do location aiding data injection. int (*inject_location)(double latitude, double longitude, float accuracy); void (*delete_aiding_data)(GpsAidingData flags); int (*set_position_mode)(GpsPositionMode mode, GpsPositionRecurrence recurrence, uint32_t min_interval, uint32_t preferred_accuracy, uint32_t preferred_time); const void* (*get_extension)(const char* name); /** Get a pointer to extension information. */ } GpsInterface;
at
(hardware\libhardware\include\hardware\ Gps.h)
GpsCallbacks data structure
-gps.h includes another
device data structure GpsCallbacks.
- GpsCallbacks structure includes
number interface methods for gps device hardware to send the location data to GpsLocationProvider.
- GpsLocationProvider initialize GpsCallbacks structure and pass
it to the gps device hardware
through int (*init)( GpsCallbacks* callbacks ) function call.
-After init function call
connection between GpsLocationProvider and gps device hardware been
completed established
/** GPS callback structure. */ typedef struct { /** set to sizeof(GpsCallbacks) */ size_t size; gps_location_callback location_cb; gps_status_callback status_cb; gps_sv_status_callback sv_status_cb; gps_nmea_callback nmea_cb; } GpsCallbacks; typedef void (* gps_location_callback)(GpsLocation* location); /** Callback with location information*/ typedef void (* gps_status_callback)(GpsStatus* status); /** Callback with status information */ typedef void (* gps_sv_status_callback)(GpsSvStatus* sv_info); /** Callback with SV status information */ typedef void (* gps_nmea_callback)(GpsUtcTime timestamp, const char* nmea, int length); /** Callback for reporting NMEA */
at
(hardware\libhardware\include\hardware\ Gps.h)
Reading
data from GPS harware
• add
property for GPS device like below
• ro.kernel.android.gps=ttyS1 (
in system.prop)
• After
recognizing GPS device, you can check your device in ‘/dev/ttyS1’.
• Gps library reads the gps location data from
the device file path and form structure GpsLocation provided in gps.h and pass it to the JNI layer.
Structure –
represents location
typedef struct { size_t size; /** set to sizeof(GpsLocation) */ uint16_t flags; /** Contains GpsLocationFlags bits. */ double latitude; /** Represents latitude in degrees. */ double longitude; /** Represents longitude in degrees. */ double altitude; /** Represents altitude in meters above the WGS 84 reference ellipsoid. */ float speed; /** Represents speed in meters per second. */ float bearing; /** Represents heading in degrees. */ float accuracy; /** Represents expected accuracy in meters. */ GpsUtcTime timestamp; /** Timestamp for the location fix. */ } GpsLocation;
GPS Runtime
Gps extended services
- gps.h included some more
interface to support AGPS, GPS XTRA etc..
-AGpsInterface is an extended
interface for AGPS support.
-GpsXtraInterface is an extended
interface for XTRA support.
-GpsLocationProvide gets the extended
service interface through function call const void* (*get_extension)(const char* name) in GpsInterface.
typedef struct { size_t size; //Opens the AGPS interface and provides the callback routines //to the implemenation of this interface. void (*init)( AGpsCallbacks* callbacks ); //Notifies that a data connection is available and sets //the name of the APN to be used for SUPL. int (*data_conn_open)( const char* apn ); //Notifies that the AGPS data connection has been closed. int (*data_conn_closed)(); //Notifies that a data connection is not available for AGPS. int (*data_conn_failed)(); //Sets the hostname and port for the AGPS server. int (*set_server)( AGpsType type, const char* hostname, int port ); } AGpsInterface;
-gps.h includes different
names for gps extended interface
#define GPS_XTRA_INTERFACE "gps-xtra“
#define
AGPS_INTERFACE "agps“
-Gps device hardware
implementation should return initialized extended interface on function call
const void* (*get_extension)(const char* name).
typedef struct { /** set to sizeof(GpsXtraInterface) */ size_t size; /** * Opens the XTRA interface and provides the callback routines * to the implemenation of this interface. */ int (*init)( GpsXtraCallbacks* callbacks ); /** Injects XTRA data into the GPS. */ int (*inject_xtra_data)( char* data, int length ); } GpsXtraInterface;
at
(hardware\libhardware\include\hardware\ Gps.h)
0 comments:
Post a Comment