[HD2 Android NAND Development] htcvidi:
So, i finished the study of implementation of xtra data.

In HyperDroid, the main code is in GpsLocationProvider.java, GpsExtraDownaloder.java and com_android_server_location_GpsLocationProvider.cpp

Xtra_Server list are retrieved in the constructor of the class GpsLocationProvider.java

Parts of code

========================

File : GpsLocationProvider.java

GpsXtraDownloader(Context context, Properties properties) {

mContext = context;

// read XTRA servers from the Properties object

int count = 0;

String server1 = properties.getProperty("XTRA_SERVER_1");

String server2 = properties.getProperty("XTRA_SERVER_2");

String server3 = properties.getProperty("XTRA_SERVER_3");

if (server1 != null) count++;

if (server2 != null) count++;

if (server3 != null) count++;

if (count == 0) {

Log.e(TAG, "No XTRA servers were specified in the GPS configuration");

return;

} else {

mXtraServers = new String[count];

count = 0;

if (server1 != null) mXtraServers[count++] = server1;

if (server2 != null) mXtraServers[count++] = server2;

if (server3 != null) mXtraServers[count++] = server3;

// randomize first server

Random random = new Random();

mNextServerIndex = random.nextInt(count);

}

}

==========================

Only 3 servers are tested. So it's useless to have more XTRA_SERVER line in gps.conf.

It's funny to see that the choice of the first server to use is random

Here is the code in GpsLocationProvider that initiate the download of data from server

==========================

File : GpsLocationProvider.java

private void handleDownloadXtraData() {

if (!mNetworkAvailable) {

// try again when network is up

mDownloadXtraDataPending = true;

return;

}

mDownloadXtraDataPending = false;

GpsXtraDownloader xtraDownloader = new GpsXtraDownloader(mContext, mProperties); <==== init object to the class

GpsXtraDownloader

byte[] data = xtraDownloader.downloadXtraData(); <=== download the file form Xtra server

if (data != null) { <==== if data is returned

if (DEBUG) {

Log.d(TAG, "calling native_inject_xtra_data");

}

native_inject_xtra_data(data, data.length); <==== inject data in gps

} else { <==== if no data retrieve, try later

// try again later

// since this is delayed and not urgent we do not hold a wake lock here

mHandler.removeMessages(DOWNLOAD_XTRA_DATA);

mHandler.sendMessageDelayed(Message.obtain(mHandler, DOWNLOAD_XTRA_DATA), RETRY_INTERVAL);

}

}

=================================

After download (xtraDownloader.downloadXtraData()), if data has been retrieved from server (we will see code after in this post), the data are injected in Gps through 'native_inject_xtra_data' method.

Like NTP_SERVER, this function is in file 'com_android_server_location_GpsLocationProvider.cpp'

=================================

File : com_android_server_location_GpsLocationProvider.cpp

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},

Here =====> {"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 },

};

======================

It points to the function 'android_location_GpsLocationProvider_inject_xtra_data'

======================

File : com_android_server_location_GpsLocationProvider.cpp

static void android_location_GpsLocationProvider_inject_xtra_data(JNIEnv* env, jobject obj,

jbyteArray data, jint length)

{

jbyte* bytes = (jbyte *)env->GetPrimitiveArrayCritical(data, 0);

sGpsXtraInterface->inject_xtra_data((char *)bytes, length); <==== injection of xtra data to Gps

env->ReleasePrimitiveArrayCritical(data, bytes, JNI_ABORT);

}

============================

We can see that sGpsXtraInterface is used here but not initialized here.

the initialisation is made in function 'android_location_GpsLocationProvider_supports_xtra'

============================

File : com_android_server_location_GpsLocationProvider.cpp

static jboolean android_location_GpsLocationProvider_supports_xtra(JNIEnv* env, jobject obj)

{

if (!sGpsXtraInterface) {

const GpsInterface* interface = GetGpsInterface(env, obj);

if (!interface)

return false;

sGpsXtraInterface = (const GpsXtraInterface*)interface->get_extension(GPS_XTRA_INTERFACE); <=== init here

if (sGpsXtraInterface) {

int result = sGpsXtraInterface->init(&sGpsXtraCallbacks);

if (result) {

sGpsXtraInterface = NULL;

}

}

}

return (sGpsXtraInterface != NULL);

}

===========================

So, where android_location_GpsLocationProvider_supports_xtra is called for the first time ?

the answer is : in GpsLocationProvider.java, function 'handleEnable'.

============================

File : GpsLocationProvider.java

private void handleEnable() {

if (DEBUG) Log.d(TAG, "handleEnable");

if (mEnabled) return;

mEnabled = native_init();

if (mEnabled) {

mSupportsXtra = native_supports_xtra(); <=== here we init the XtraInterface pointer

if (mSuplServerHost != null) {

native_set_agps_server(AGPS_TYPE_SUPL, mSuplServerHost, mSuplServerPort);

}

if (mC2KServerHost != null) {

native_set_agps_server(AGPS_TYPE_C2K, mC2KServerHost, mC2KServerPort);

}

} else {

Log.w(TAG, "Failed to enable location provider");

}

}

============================

Where is the pb ?. All seem to be here !!!

In fact, no.

The main pb is that there is no interface in gps library for xtra.

How can i know it ?

It's simple : when you run logcat at android boot, the following line appears :

'E/GpsLocationProvider( 507): no AGPS interface in agps_data_conn_open'

This line is written by the function 'android_location_GpsLocationProvider_agps_data_conn_open' called by the function handleUpdateNetworkState in GpsLocationProvider

So, Hyperdroid seems ready to manage Xtra Data but the gps module doesn't offer any implementation to store it in GPS.

That's all. You can make thousands modifications to gps.conf, while gps module will not be modified xtra will not work. I think this pb is not specific to HyperDroid.