blob: 87626d05ea073582c06dd8efa3be553b691bc2b3 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "GpsLocationProvider"
18
Mike Lockwoodb8d90332010-10-18 17:59:48 -040019#define LOG_NDEBUG 0
Danke Xie22d1f9f2009-08-18 18:28:45 -040020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021#include "JNIHelp.h"
22#include "jni.h"
Mike Lockwoodb7ff4572010-04-05 15:24:34 -040023#include "hardware/hardware.h"
24#include "hardware/gps.h"
Mike Lockwood8f5a8002010-04-07 09:05:26 -040025#include "hardware_legacy/power.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026#include "utils/Log.h"
27#include "utils/misc.h"
Mike Lockwoodf602d362010-06-20 14:28:16 -070028#include "android_runtime/AndroidRuntime.h"
Ruben Brunk87eac992013-09-09 17:44:59 -070029#include "android_runtime/Log.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030
31#include <string.h>
32#include <pthread.h>
destradaa96a14702014-06-05 11:36:30 -070033#include <linux/in.h>
34#include <linux/in6.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035
Mike Lockwoodf602d362010-06-20 14:28:16 -070036static jobject mCallbacksObj = NULL;
37
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038static jmethodID method_reportLocation;
39static jmethodID method_reportStatus;
40static jmethodID method_reportSvStatus;
Mike Lockwoode3635c92009-05-11 08:38:02 -040041static jmethodID method_reportAGpsStatus;
Mike Lockwoodb16e7802009-08-06 09:26:02 -040042static jmethodID method_reportNmea;
Mike Lockwood04598b62010-04-14 17:17:24 -040043static jmethodID method_setEngineCapabilities;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044static jmethodID method_xtraDownloadRequest;
Danke Xie22d1f9f2009-08-18 18:28:45 -040045static jmethodID method_reportNiNotification;
Miguel Torroja1e84da82010-07-27 07:02:24 +020046static jmethodID method_requestRefLocation;
47static jmethodID method_requestSetID;
Mike Lockwood9b9fb5c2011-06-29 15:09:40 -040048static jmethodID method_requestUtcTime;
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -070049static jmethodID method_reportGeofenceTransition;
50static jmethodID method_reportGeofenceStatus;
51static jmethodID method_reportGeofenceAddStatus;
52static jmethodID method_reportGeofenceRemoveStatus;
53static jmethodID method_reportGeofencePauseStatus;
54static jmethodID method_reportGeofenceResumeStatus;
destradaaea8a8a62014-06-23 18:19:03 -070055static jmethodID method_reportMeasurementData;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056
57static const GpsInterface* sGpsInterface = NULL;
58static const GpsXtraInterface* sGpsXtraInterface = NULL;
Mike Lockwoode3635c92009-05-11 08:38:02 -040059static const AGpsInterface* sAGpsInterface = NULL;
Danke Xie22d1f9f2009-08-18 18:28:45 -040060static const GpsNiInterface* sGpsNiInterface = NULL;
Fred Fettinger3c8fbdf2010-01-04 15:38:13 -060061static const GpsDebugInterface* sGpsDebugInterface = NULL;
Miguel Torroja1e84da82010-07-27 07:02:24 +020062static const AGpsRilInterface* sAGpsRilInterface = NULL;
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -070063static const GpsGeofencingInterface* sGpsGeofencingInterface = NULL;
destradaaea8a8a62014-06-23 18:19:03 -070064static const GpsMeasurementInterface* sGpsMeasurementInterface = NULL;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065
Mike Lockwoodf602d362010-06-20 14:28:16 -070066// temporary storage for GPS callbacks
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067static GpsSvStatus sGpsSvStatus;
Mike Lockwoodf602d362010-06-20 14:28:16 -070068static const char* sNmeaString;
69static int sNmeaStringLength;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070
Mike Lockwood8f5a8002010-04-07 09:05:26 -040071#define WAKE_LOCK_NAME "GPS"
72
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073namespace android {
74
Mike Lockwoodf602d362010-06-20 14:28:16 -070075static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
76 if (env->ExceptionCheck()) {
Steve Block3762c312012-01-06 19:20:56 +000077 ALOGE("An exception was thrown by callback '%s'.", methodName);
Mike Lockwoodf602d362010-06-20 14:28:16 -070078 LOGE_EX(env);
79 env->ExceptionClear();
80 }
81}
82
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083static void location_callback(GpsLocation* location)
84{
Mike Lockwoodf602d362010-06-20 14:28:16 -070085 JNIEnv* env = AndroidRuntime::getJNIEnv();
86 env->CallVoidMethod(mCallbacksObj, method_reportLocation, location->flags,
87 (jdouble)location->latitude, (jdouble)location->longitude,
88 (jdouble)location->altitude,
89 (jfloat)location->speed, (jfloat)location->bearing,
90 (jfloat)location->accuracy, (jlong)location->timestamp);
91 checkAndClearExceptionFromCallback(env, __FUNCTION__);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092}
93
94static void status_callback(GpsStatus* status)
95{
Mike Lockwoodf602d362010-06-20 14:28:16 -070096 JNIEnv* env = AndroidRuntime::getJNIEnv();
Mike Lockwoodf602d362010-06-20 14:28:16 -070097 env->CallVoidMethod(mCallbacksObj, method_reportStatus, status->status);
98 checkAndClearExceptionFromCallback(env, __FUNCTION__);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099}
100
101static void sv_status_callback(GpsSvStatus* sv_status)
102{
Mike Lockwoodf602d362010-06-20 14:28:16 -0700103 JNIEnv* env = AndroidRuntime::getJNIEnv();
104 memcpy(&sGpsSvStatus, sv_status, sizeof(sGpsSvStatus));
105 env->CallVoidMethod(mCallbacksObj, method_reportSvStatus);
106 checkAndClearExceptionFromCallback(env, __FUNCTION__);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107}
108
Mike Lockwoodb16e7802009-08-06 09:26:02 -0400109static void nmea_callback(GpsUtcTime timestamp, const char* nmea, int length)
110{
Mike Lockwoodf602d362010-06-20 14:28:16 -0700111 JNIEnv* env = AndroidRuntime::getJNIEnv();
112 // The Java code will call back to read these values
113 // We do this to avoid creating unnecessary String objects
114 sNmeaString = nmea;
115 sNmeaStringLength = length;
116 env->CallVoidMethod(mCallbacksObj, method_reportNmea, timestamp);
117 checkAndClearExceptionFromCallback(env, __FUNCTION__);
Mike Lockwoodb16e7802009-08-06 09:26:02 -0400118}
119
Mike Lockwood04598b62010-04-14 17:17:24 -0400120static void set_capabilities_callback(uint32_t capabilities)
121{
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -0700122 ALOGD("set_capabilities_callback: %du\n", capabilities);
Mike Lockwoodf602d362010-06-20 14:28:16 -0700123 JNIEnv* env = AndroidRuntime::getJNIEnv();
124 env->CallVoidMethod(mCallbacksObj, method_setEngineCapabilities, capabilities);
125 checkAndClearExceptionFromCallback(env, __FUNCTION__);
Mike Lockwood04598b62010-04-14 17:17:24 -0400126}
127
Mike Lockwood8f5a8002010-04-07 09:05:26 -0400128static void acquire_wakelock_callback()
129{
130 acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_NAME);
131}
132
133static void release_wakelock_callback()
134{
135 release_wake_lock(WAKE_LOCK_NAME);
136}
137
Mike Lockwood9b9fb5c2011-06-29 15:09:40 -0400138static void request_utc_time_callback()
139{
140 JNIEnv* env = AndroidRuntime::getJNIEnv();
141 env->CallVoidMethod(mCallbacksObj, method_requestUtcTime);
142 checkAndClearExceptionFromCallback(env, __FUNCTION__);
143}
144
Mike Lockwoodf602d362010-06-20 14:28:16 -0700145static pthread_t create_thread_callback(const char* name, void (*start)(void *), void* arg)
Mike Lockwood58bda982009-04-14 16:25:07 -0400146{
Mike Lockwoodf602d362010-06-20 14:28:16 -0700147 return (pthread_t)AndroidRuntime::createJavaThread(name, start, arg);
Mike Lockwood58bda982009-04-14 16:25:07 -0400148}
149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150GpsCallbacks sGpsCallbacks = {
Mike Lockwood8f5a8002010-04-07 09:05:26 -0400151 sizeof(GpsCallbacks),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 location_callback,
153 status_callback,
154 sv_status_callback,
Mike Lockwood8f5a8002010-04-07 09:05:26 -0400155 nmea_callback,
Mike Lockwood04598b62010-04-14 17:17:24 -0400156 set_capabilities_callback,
Mike Lockwood8f5a8002010-04-07 09:05:26 -0400157 acquire_wakelock_callback,
158 release_wakelock_callback,
Mike Lockwoodf602d362010-06-20 14:28:16 -0700159 create_thread_callback,
Mike Lockwood9b9fb5c2011-06-29 15:09:40 -0400160 request_utc_time_callback,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161};
162
Mike Lockwoodf602d362010-06-20 14:28:16 -0700163static void xtra_download_request_callback()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164{
Mike Lockwoodf602d362010-06-20 14:28:16 -0700165 JNIEnv* env = AndroidRuntime::getJNIEnv();
166 env->CallVoidMethod(mCallbacksObj, method_xtraDownloadRequest);
167 checkAndClearExceptionFromCallback(env, __FUNCTION__);
Danke Xie22d1f9f2009-08-18 18:28:45 -0400168}
169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170GpsXtraCallbacks sGpsXtraCallbacks = {
Mike Lockwoodf602d362010-06-20 14:28:16 -0700171 xtra_download_request_callback,
172 create_thread_callback,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173};
174
destradaa96a14702014-06-05 11:36:30 -0700175static jbyteArray convert_to_ipv4(uint32_t ip, bool net_order)
176{
177 if (INADDR_NONE == ip) {
178 return NULL;
179 }
180
181 JNIEnv* env = AndroidRuntime::getJNIEnv();
182 jbyteArray byteArray = env->NewByteArray(4);
183 if (byteArray == NULL) {
184 ALOGE("Unable to allocate byte array for IPv4 address");
185 return NULL;
186 }
187
188 jbyte ipv4[4];
189 if (net_order) {
190 memcpy(ipv4, &ip, sizeof(ipv4));
191 } else {
192 //endianess transparent conversion from int to char[]
193 ipv4[0] = (jbyte) (ip & 0xFF);
194 ipv4[1] = (jbyte)((ip>>8) & 0xFF);
195 ipv4[2] = (jbyte)((ip>>16) & 0xFF);
196 ipv4[3] = (jbyte) (ip>>24);
197 }
198
199 env->SetByteArrayRegion(byteArray, 0, 4, (const jbyte*) ipv4);
200 return byteArray;
201}
202
Mike Lockwoodf602d362010-06-20 14:28:16 -0700203static void agps_status_callback(AGpsStatus* agps_status)
204{
Mike Lockwoodf602d362010-06-20 14:28:16 -0700205 JNIEnv* env = AndroidRuntime::getJNIEnv();
destradaa96a14702014-06-05 11:36:30 -0700206 jbyteArray byteArray = NULL;
207 bool isSupported = false;
Stephen Li8efd74d2011-03-01 20:56:00 -0800208
destradaa96a14702014-06-05 11:36:30 -0700209 size_t status_size = agps_status->size;
210 if (status_size == sizeof(AGpsStatus_v3)) {
211 switch (agps_status->addr.ss_family)
212 {
213 case AF_INET:
214 {
215 struct sockaddr_in *in = (struct sockaddr_in*)&(agps_status->addr);
216 uint32_t *pAddr = (uint32_t*)&(in->sin_addr);
217 byteArray = convert_to_ipv4(*pAddr, true /* net_order */);
218 if (byteArray != NULL) {
219 isSupported = true;
220 }
221 }
222 break;
223 case AF_INET6:
224 {
225 struct sockaddr_in6 *in6 = (struct sockaddr_in6*)&(agps_status->addr);
226 byteArray = env->NewByteArray(16);
227 if (byteArray != NULL) {
228 env->SetByteArrayRegion(byteArray, 0, 16, (const jbyte *)&(in6->sin6_addr));
229 isSupported = true;
230 } else {
231 ALOGE("Unable to allocate byte array for IPv6 address.");
232 }
233 }
234 break;
235 default:
236 ALOGE("Invalid ss_family found: %d", agps_status->addr.ss_family);
237 break;
238 }
239 } else if (status_size >= sizeof(AGpsStatus_v2)) {
240 // for back-compatibility reasons we check in v2 that the data structure size is greater or
241 // equal to the declared size in gps.h
242 uint32_t ipaddr = agps_status->ipaddr;
243 byteArray = convert_to_ipv4(ipaddr, false /* net_order */);
244 if (ipaddr == INADDR_NONE || byteArray != NULL) {
245 isSupported = true;
246 }
247 } else if (status_size >= sizeof(AGpsStatus_v1)) {
248 // because we have to check for >= with regards to v2, we also need to relax the check here
249 // and only make sure that the size is at least what we expect
250 isSupported = true;
251 } else {
252 ALOGE("Invalid size of AGpsStatus found: %d.", status_size);
253 }
254
255 if (isSupported) {
256 env->CallVoidMethod(mCallbacksObj, method_reportAGpsStatus, agps_status->type,
257 agps_status->status, byteArray);
258
259 checkAndClearExceptionFromCallback(env, __FUNCTION__);
260 } else {
261 ALOGD("Skipping calling method_reportAGpsStatus.");
262 }
263
264 if (byteArray) {
265 env->DeleteLocalRef(byteArray);
266 }
Mike Lockwoodf602d362010-06-20 14:28:16 -0700267}
268
Mike Lockwoode3635c92009-05-11 08:38:02 -0400269AGpsCallbacks sAGpsCallbacks = {
270 agps_status_callback,
Mike Lockwoodf602d362010-06-20 14:28:16 -0700271 create_thread_callback,
Mike Lockwood58bda982009-04-14 16:25:07 -0400272};
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273
Mike Lockwoodf602d362010-06-20 14:28:16 -0700274static void gps_ni_notify_callback(GpsNiNotification *notification)
275{
Steve Block5baa3a62011-12-20 16:23:08 +0000276 ALOGD("gps_ni_notify_callback\n");
Mike Lockwoodf602d362010-06-20 14:28:16 -0700277 JNIEnv* env = AndroidRuntime::getJNIEnv();
278 jstring requestor_id = env->NewStringUTF(notification->requestor_id);
279 jstring text = env->NewStringUTF(notification->text);
280 jstring extras = env->NewStringUTF(notification->extras);
281
282 if (requestor_id && text && extras) {
283 env->CallVoidMethod(mCallbacksObj, method_reportNiNotification,
284 notification->notification_id, notification->ni_type,
285 notification->notify_flags, notification->timeout,
286 notification->default_response, requestor_id, text,
287 notification->requestor_id_encoding,
288 notification->text_encoding, extras);
289 } else {
Steve Block3762c312012-01-06 19:20:56 +0000290 ALOGE("out of memory in gps_ni_notify_callback\n");
Mike Lockwoodf602d362010-06-20 14:28:16 -0700291 }
292
293 if (requestor_id)
294 env->DeleteLocalRef(requestor_id);
295 if (text)
296 env->DeleteLocalRef(text);
297 if (extras)
298 env->DeleteLocalRef(extras);
299 checkAndClearExceptionFromCallback(env, __FUNCTION__);
300}
301
Danke Xie22d1f9f2009-08-18 18:28:45 -0400302GpsNiCallbacks sGpsNiCallbacks = {
303 gps_ni_notify_callback,
Mike Lockwoodf602d362010-06-20 14:28:16 -0700304 create_thread_callback,
Danke Xie22d1f9f2009-08-18 18:28:45 -0400305};
306
Miguel Torroja1e84da82010-07-27 07:02:24 +0200307static void agps_request_set_id(uint32_t flags)
308{
Miguel Torroja1e84da82010-07-27 07:02:24 +0200309 JNIEnv* env = AndroidRuntime::getJNIEnv();
310 env->CallVoidMethod(mCallbacksObj, method_requestSetID, flags);
311 checkAndClearExceptionFromCallback(env, __FUNCTION__);
312}
313
314static void agps_request_ref_location(uint32_t flags)
315{
Miguel Torroja1e84da82010-07-27 07:02:24 +0200316 JNIEnv* env = AndroidRuntime::getJNIEnv();
317 env->CallVoidMethod(mCallbacksObj, method_requestRefLocation, flags);
318 checkAndClearExceptionFromCallback(env, __FUNCTION__);
319}
320
321AGpsRilCallbacks sAGpsRilCallbacks = {
322 agps_request_set_id,
323 agps_request_ref_location,
324 create_thread_callback,
325};
326
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -0700327static void gps_geofence_transition_callback(int32_t geofence_id, GpsLocation* location,
328 int32_t transition, GpsUtcTime timestamp)
329{
330 JNIEnv* env = AndroidRuntime::getJNIEnv();
331
332 env->CallVoidMethod(mCallbacksObj, method_reportGeofenceTransition, geofence_id,
333 location->flags, (jdouble)location->latitude, (jdouble)location->longitude,
334 (jdouble)location->altitude,
335 (jfloat)location->speed, (jfloat)location->bearing,
336 (jfloat)location->accuracy, (jlong)location->timestamp,
337 transition, timestamp);
338 checkAndClearExceptionFromCallback(env, __FUNCTION__);
339};
340
341static void gps_geofence_status_callback(int32_t status, GpsLocation* location)
342{
343 JNIEnv* env = AndroidRuntime::getJNIEnv();
344 jint flags = 0;
345 jdouble latitude = 0;
346 jdouble longitude = 0;
347 jdouble altitude = 0;
348 jfloat speed = 0;
349 jfloat bearing = 0;
350 jfloat accuracy = 0;
351 jlong timestamp = 0;
352 if (location != NULL) {
353 flags = location->flags;
354 latitude = location->latitude;
355 longitude = location->longitude;
356 altitude = location->altitude;
357 speed = location->speed;
358 bearing = location->bearing;
359 accuracy = location->accuracy;
360 timestamp = location->timestamp;
361 }
362
363 env->CallVoidMethod(mCallbacksObj, method_reportGeofenceStatus, status,
364 flags, latitude, longitude, altitude, speed, bearing, accuracy, timestamp);
365 checkAndClearExceptionFromCallback(env, __FUNCTION__);
366};
367
368static void gps_geofence_add_callback(int32_t geofence_id, int32_t status)
369{
370 JNIEnv* env = AndroidRuntime::getJNIEnv();
371 if (status != GPS_GEOFENCE_OPERATION_SUCCESS) {
372 ALOGE("Error in geofence_add_callback: %d\n", status);
373 }
374 env->CallVoidMethod(mCallbacksObj, method_reportGeofenceAddStatus, geofence_id, status);
375 checkAndClearExceptionFromCallback(env, __FUNCTION__);
376};
377
378static void gps_geofence_remove_callback(int32_t geofence_id, int32_t status)
379{
380 JNIEnv* env = AndroidRuntime::getJNIEnv();
381 if (status != GPS_GEOFENCE_OPERATION_SUCCESS) {
382 ALOGE("Error in geofence_remove_callback: %d\n", status);
383 }
384 env->CallVoidMethod(mCallbacksObj, method_reportGeofenceRemoveStatus, geofence_id, status);
385 checkAndClearExceptionFromCallback(env, __FUNCTION__);
386};
387
388static void gps_geofence_resume_callback(int32_t geofence_id, int32_t status)
389{
390 JNIEnv* env = AndroidRuntime::getJNIEnv();
391 if (status != GPS_GEOFENCE_OPERATION_SUCCESS) {
392 ALOGE("Error in geofence_resume_callback: %d\n", status);
393 }
394 env->CallVoidMethod(mCallbacksObj, method_reportGeofenceResumeStatus, geofence_id, status);
395 checkAndClearExceptionFromCallback(env, __FUNCTION__);
396};
397
398static void gps_geofence_pause_callback(int32_t geofence_id, int32_t status)
399{
400 JNIEnv* env = AndroidRuntime::getJNIEnv();
401 if (status != GPS_GEOFENCE_OPERATION_SUCCESS) {
402 ALOGE("Error in geofence_pause_callback: %d\n", status);
403 }
404 env->CallVoidMethod(mCallbacksObj, method_reportGeofencePauseStatus, geofence_id, status);
405 checkAndClearExceptionFromCallback(env, __FUNCTION__);
406};
407
408GpsGeofenceCallbacks sGpsGeofenceCallbacks = {
409 gps_geofence_transition_callback,
410 gps_geofence_status_callback,
411 gps_geofence_add_callback,
412 gps_geofence_remove_callback,
413 gps_geofence_pause_callback,
414 gps_geofence_resume_callback,
415 create_thread_callback,
416};
417
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800418static void android_location_GpsLocationProvider_class_init_native(JNIEnv* env, jclass clazz) {
Mike Lockwoodb7ff4572010-04-05 15:24:34 -0400419 int err;
420 hw_module_t* module;
Mike Lockwoodb7ff4572010-04-05 15:24:34 -0400421
Mike Lockwoodbea31182010-10-05 14:29:53 -0400422 method_reportLocation = env->GetMethodID(clazz, "reportLocation", "(IDDDFFFJ)V");
423 method_reportStatus = env->GetMethodID(clazz, "reportStatus", "(I)V");
424 method_reportSvStatus = env->GetMethodID(clazz, "reportSvStatus", "()V");
destradaa96a14702014-06-05 11:36:30 -0700425 method_reportAGpsStatus = env->GetMethodID(clazz, "reportAGpsStatus", "(II[B)V");
Mike Lockwoodbea31182010-10-05 14:29:53 -0400426 method_reportNmea = env->GetMethodID(clazz, "reportNmea", "(J)V");
427 method_setEngineCapabilities = env->GetMethodID(clazz, "setEngineCapabilities", "(I)V");
428 method_xtraDownloadRequest = env->GetMethodID(clazz, "xtraDownloadRequest", "()V");
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800429 method_reportNiNotification = env->GetMethodID(clazz, "reportNiNotification",
430 "(IIIIILjava/lang/String;Ljava/lang/String;IILjava/lang/String;)V");
Mike Lockwoodbea31182010-10-05 14:29:53 -0400431 method_requestRefLocation = env->GetMethodID(clazz,"requestRefLocation","(I)V");
432 method_requestSetID = env->GetMethodID(clazz,"requestSetID","(I)V");
Mike Lockwood9b9fb5c2011-06-29 15:09:40 -0400433 method_requestUtcTime = env->GetMethodID(clazz,"requestUtcTime","()V");
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -0700434 method_reportGeofenceTransition = env->GetMethodID(clazz,"reportGeofenceTransition",
435 "(IIDDDFFFJIJ)V");
436 method_reportGeofenceStatus = env->GetMethodID(clazz,"reportGeofenceStatus",
437 "(IIDDDFFFJ)V");
438 method_reportGeofenceAddStatus = env->GetMethodID(clazz,"reportGeofenceAddStatus",
439 "(II)V");
440 method_reportGeofenceRemoveStatus = env->GetMethodID(clazz,"reportGeofenceRemoveStatus",
441 "(II)V");
442 method_reportGeofenceResumeStatus = env->GetMethodID(clazz,"reportGeofenceResumeStatus",
443 "(II)V");
444 method_reportGeofencePauseStatus = env->GetMethodID(clazz,"reportGeofencePauseStatus",
445 "(II)V");
destradaaea8a8a62014-06-23 18:19:03 -0700446 method_reportMeasurementData = env->GetMethodID(
447 clazz,
448 "reportMeasurementData",
449 "(Landroid/location/GpsMeasurementsEvent;)V");
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800450
451 err = hw_get_module(GPS_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
452 if (err == 0) {
453 hw_device_t* device;
454 err = module->methods->open(module, GPS_HARDWARE_MODULE_ID, &device);
455 if (err == 0) {
456 gps_device_t* gps_device = (gps_device_t *)device;
457 sGpsInterface = gps_device->get_gps_interface(gps_device);
458 }
459 }
460 if (sGpsInterface) {
461 sGpsXtraInterface =
462 (const GpsXtraInterface*)sGpsInterface->get_extension(GPS_XTRA_INTERFACE);
463 sAGpsInterface =
464 (const AGpsInterface*)sGpsInterface->get_extension(AGPS_INTERFACE);
465 sGpsNiInterface =
466 (const GpsNiInterface*)sGpsInterface->get_extension(GPS_NI_INTERFACE);
467 sGpsDebugInterface =
468 (const GpsDebugInterface*)sGpsInterface->get_extension(GPS_DEBUG_INTERFACE);
469 sAGpsRilInterface =
470 (const AGpsRilInterface*)sGpsInterface->get_extension(AGPS_RIL_INTERFACE);
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -0700471 sGpsGeofencingInterface =
472 (const GpsGeofencingInterface*)sGpsInterface->get_extension(GPS_GEOFENCING_INTERFACE);
destradaaea8a8a62014-06-23 18:19:03 -0700473 sGpsMeasurementInterface =
474 (const GpsMeasurementInterface*)sGpsInterface->get_extension(GPS_MEASUREMENT_INTERFACE);
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800475 }
Mike Lockwoodbea31182010-10-05 14:29:53 -0400476}
477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478static jboolean android_location_GpsLocationProvider_is_supported(JNIEnv* env, jclass clazz) {
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000479 if (sGpsInterface != NULL) {
480 return JNI_TRUE;
481 } else {
482 return JNI_FALSE;
483 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484}
485
486static jboolean android_location_GpsLocationProvider_init(JNIEnv* env, jobject obj)
487{
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800488 // this must be set before calling into the HAL library
489 if (!mCallbacksObj)
490 mCallbacksObj = env->NewGlobalRef(obj);
491
492 // fail if the main interface fails to initialize
493 if (!sGpsInterface || sGpsInterface->init(&sGpsCallbacks) != 0)
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000494 return JNI_FALSE;
Mike Lockwood58bda982009-04-14 16:25:07 -0400495
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -0700496 // if XTRA initialization fails we will disable it by sGpsXtraInterface to NULL,
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800497 // but continue to allow the rest of the GPS interface to work.
498 if (sGpsXtraInterface && sGpsXtraInterface->init(&sGpsXtraCallbacks) != 0)
499 sGpsXtraInterface = NULL;
500 if (sAGpsInterface)
501 sAGpsInterface->init(&sAGpsCallbacks);
502 if (sGpsNiInterface)
503 sGpsNiInterface->init(&sGpsNiCallbacks);
504 if (sAGpsRilInterface)
505 sAGpsRilInterface->init(&sAGpsRilCallbacks);
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -0700506 if (sGpsGeofencingInterface)
507 sGpsGeofencingInterface->init(&sGpsGeofenceCallbacks);
Fred Fettinger3c8fbdf2010-01-04 15:38:13 -0600508
Narayan Kamath87d6cd42014-01-08 12:26:28 +0000509 return JNI_TRUE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510}
511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512static void android_location_GpsLocationProvider_cleanup(JNIEnv* env, jobject obj)
513{
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800514 if (sGpsInterface)
515 sGpsInterface->cleanup();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516}
517
Mike Lockwood04598b62010-04-14 17:17:24 -0400518static jboolean android_location_GpsLocationProvider_set_position_mode(JNIEnv* env, jobject obj,
519 jint mode, jint recurrence, jint min_interval, jint preferred_accuracy, jint preferred_time)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520{
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000521 if (sGpsInterface) {
522 if (sGpsInterface->set_position_mode(mode, recurrence, min_interval, preferred_accuracy,
523 preferred_time) == 0) {
524 return JNI_TRUE;
525 } else {
526 return JNI_FALSE;
527 }
528 }
Mike Lockwood42702372010-10-10 16:04:18 -0400529 else
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000530 return JNI_FALSE;
Mike Lockwood04598b62010-04-14 17:17:24 -0400531}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532
Mike Lockwood04598b62010-04-14 17:17:24 -0400533static jboolean android_location_GpsLocationProvider_start(JNIEnv* env, jobject obj)
534{
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000535 if (sGpsInterface) {
536 if (sGpsInterface->start() == 0) {
537 return JNI_TRUE;
538 } else {
539 return JNI_FALSE;
540 }
541 }
Mike Lockwood42702372010-10-10 16:04:18 -0400542 else
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000543 return JNI_FALSE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544}
545
546static jboolean android_location_GpsLocationProvider_stop(JNIEnv* env, jobject obj)
547{
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000548 if (sGpsInterface) {
549 if (sGpsInterface->stop() == 0) {
550 return JNI_TRUE;
551 } else {
552 return JNI_FALSE;
553 }
554 }
Mike Lockwood42702372010-10-10 16:04:18 -0400555 else
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000556 return JNI_FALSE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557}
558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559static void android_location_GpsLocationProvider_delete_aiding_data(JNIEnv* env, jobject obj, jint flags)
560{
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800561 if (sGpsInterface)
562 sGpsInterface->delete_aiding_data(flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563}
564
Danke Xie22d1f9f2009-08-18 18:28:45 -0400565static jint android_location_GpsLocationProvider_read_sv_status(JNIEnv* env, jobject obj,
566 jintArray prnArray, jfloatArray snrArray, jfloatArray elevArray, jfloatArray azumArray,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 jintArray maskArray)
568{
Mike Lockwoodf602d362010-06-20 14:28:16 -0700569 // this should only be called from within a call to reportSvStatus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570
571 jint* prns = env->GetIntArrayElements(prnArray, 0);
572 jfloat* snrs = env->GetFloatArrayElements(snrArray, 0);
573 jfloat* elev = env->GetFloatArrayElements(elevArray, 0);
574 jfloat* azim = env->GetFloatArrayElements(azumArray, 0);
575 jint* mask = env->GetIntArrayElements(maskArray, 0);
576
Mike Lockwoodf602d362010-06-20 14:28:16 -0700577 int num_svs = sGpsSvStatus.num_svs;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 for (int i = 0; i < num_svs; i++) {
Mike Lockwoodf602d362010-06-20 14:28:16 -0700579 prns[i] = sGpsSvStatus.sv_list[i].prn;
580 snrs[i] = sGpsSvStatus.sv_list[i].snr;
581 elev[i] = sGpsSvStatus.sv_list[i].elevation;
582 azim[i] = sGpsSvStatus.sv_list[i].azimuth;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 }
Mike Lockwoodf602d362010-06-20 14:28:16 -0700584 mask[0] = sGpsSvStatus.ephemeris_mask;
585 mask[1] = sGpsSvStatus.almanac_mask;
586 mask[2] = sGpsSvStatus.used_in_fix_mask;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587
588 env->ReleaseIntArrayElements(prnArray, prns, 0);
589 env->ReleaseFloatArrayElements(snrArray, snrs, 0);
590 env->ReleaseFloatArrayElements(elevArray, elev, 0);
591 env->ReleaseFloatArrayElements(azumArray, azim, 0);
592 env->ReleaseIntArrayElements(maskArray, mask, 0);
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000593 return (jint) num_svs;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594}
595
Miguel Torroja1e84da82010-07-27 07:02:24 +0200596static void android_location_GpsLocationProvider_agps_set_reference_location_cellid(JNIEnv* env,
597 jobject obj, jint type, jint mcc, jint mnc, jint lac, jint cid)
598{
599 AGpsRefLocation location;
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800600
601 if (!sAGpsRilInterface) {
Steve Block3762c312012-01-06 19:20:56 +0000602 ALOGE("no AGPS RIL interface in agps_set_reference_location_cellid");
Miguel Torroja1e84da82010-07-27 07:02:24 +0200603 return;
Mike Lockwoodbea31182010-10-05 14:29:53 -0400604 }
605
Miguel Torroja1e84da82010-07-27 07:02:24 +0200606 switch(type) {
607 case AGPS_REF_LOCATION_TYPE_GSM_CELLID:
608 case AGPS_REF_LOCATION_TYPE_UMTS_CELLID:
609 location.type = type;
610 location.u.cellID.mcc = mcc;
611 location.u.cellID.mnc = mnc;
612 location.u.cellID.lac = lac;
613 location.u.cellID.cid = cid;
614 break;
615 default:
Steve Block3762c312012-01-06 19:20:56 +0000616 ALOGE("Neither a GSM nor a UMTS cellid (%s:%d).",__FUNCTION__,__LINE__);
Miguel Torroja1e84da82010-07-27 07:02:24 +0200617 return;
618 break;
619 }
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800620 sAGpsRilInterface->set_ref_location(&location, sizeof(location));
Miguel Torroja1e84da82010-07-27 07:02:24 +0200621}
622
623static void android_location_GpsLocationProvider_agps_send_ni_message(JNIEnv* env,
624 jobject obj, jbyteArray ni_msg, jint size)
625{
626 size_t sz;
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800627
628 if (!sAGpsRilInterface) {
Steve Block3762c312012-01-06 19:20:56 +0000629 ALOGE("no AGPS RIL interface in send_ni_message");
Miguel Torroja1e84da82010-07-27 07:02:24 +0200630 return;
Mike Lockwoodbea31182010-10-05 14:29:53 -0400631 }
Miguel Torroja1e84da82010-07-27 07:02:24 +0200632 if (size < 0)
633 return;
634 sz = (size_t)size;
635 jbyte* b = env->GetByteArrayElements(ni_msg, 0);
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800636 sAGpsRilInterface->ni_message((uint8_t *)b,sz);
Miguel Torroja1e84da82010-07-27 07:02:24 +0200637 env->ReleaseByteArrayElements(ni_msg,b,0);
638}
639
640static void android_location_GpsLocationProvider_agps_set_id(JNIEnv *env,
641 jobject obj, jint type, jstring setid_string)
642{
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800643 if (!sAGpsRilInterface) {
Steve Block3762c312012-01-06 19:20:56 +0000644 ALOGE("no AGPS RIL interface in agps_set_id");
Miguel Torroja1e84da82010-07-27 07:02:24 +0200645 return;
Mike Lockwoodbea31182010-10-05 14:29:53 -0400646 }
Miguel Torroja1e84da82010-07-27 07:02:24 +0200647
648 const char *setid = env->GetStringUTFChars(setid_string, NULL);
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800649 sAGpsRilInterface->set_set_id(type, setid);
Miguel Torroja1e84da82010-07-27 07:02:24 +0200650 env->ReleaseStringUTFChars(setid_string, setid);
651}
652
Mike Lockwoodf602d362010-06-20 14:28:16 -0700653static jint android_location_GpsLocationProvider_read_nmea(JNIEnv* env, jobject obj,
654 jbyteArray nmeaArray, jint buffer_size)
Mike Lockwoodb16e7802009-08-06 09:26:02 -0400655{
Mike Lockwoodf602d362010-06-20 14:28:16 -0700656 // this should only be called from within a call to reportNmea
657 jbyte* nmea = (jbyte *)env->GetPrimitiveArrayCritical(nmeaArray, 0);
658 int length = sNmeaStringLength;
Mike Lockwoodb16e7802009-08-06 09:26:02 -0400659 if (length > buffer_size)
660 length = buffer_size;
Mike Lockwoodf602d362010-06-20 14:28:16 -0700661 memcpy(nmea, sNmeaString, length);
662 env->ReleasePrimitiveArrayCritical(nmeaArray, nmea, JNI_ABORT);
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000663 return (jint) length;
Mike Lockwoodb16e7802009-08-06 09:26:02 -0400664}
665
Mike Lockwoodf602d362010-06-20 14:28:16 -0700666static void android_location_GpsLocationProvider_inject_time(JNIEnv* env, jobject obj,
667 jlong time, jlong timeReference, jint uncertainty)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800668{
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800669 if (sGpsInterface)
670 sGpsInterface->inject_time(time, timeReference, uncertainty);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800671}
672
Mike Lockwoodd26ce0d2009-06-11 12:25:46 -0400673static void android_location_GpsLocationProvider_inject_location(JNIEnv* env, jobject obj,
674 jdouble latitude, jdouble longitude, jfloat accuracy)
675{
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800676 if (sGpsInterface)
677 sGpsInterface->inject_location(latitude, longitude, accuracy);
Mike Lockwoodd26ce0d2009-06-11 12:25:46 -0400678}
679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800680static jboolean android_location_GpsLocationProvider_supports_xtra(JNIEnv* env, jobject obj)
681{
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000682 if (sGpsXtraInterface != NULL) {
683 return JNI_TRUE;
684 } else {
685 return JNI_FALSE;
686 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687}
688
Danke Xie22d1f9f2009-08-18 18:28:45 -0400689static void android_location_GpsLocationProvider_inject_xtra_data(JNIEnv* env, jobject obj,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800690 jbyteArray data, jint length)
691{
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800692 if (!sGpsXtraInterface) {
Steve Block3762c312012-01-06 19:20:56 +0000693 ALOGE("no XTRA interface in inject_xtra_data");
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800694 return;
695 }
696
Mike Lockwoodf602d362010-06-20 14:28:16 -0700697 jbyte* bytes = (jbyte *)env->GetPrimitiveArrayCritical(data, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 sGpsXtraInterface->inject_xtra_data((char *)bytes, length);
Mike Lockwoodf602d362010-06-20 14:28:16 -0700699 env->ReleasePrimitiveArrayCritical(data, bytes, JNI_ABORT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800700}
701
destradaa96a14702014-06-05 11:36:30 -0700702static void android_location_GpsLocationProvider_agps_data_conn_open(
703 JNIEnv* env, jobject obj, jstring apn, jint apnIpType)
The Android Open Source Project10592532009-03-18 17:39:46 -0700704{
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800705 if (!sAGpsInterface) {
Steve Block3762c312012-01-06 19:20:56 +0000706 ALOGE("no AGPS interface in agps_data_conn_open");
Mike Lockwoodbea31182010-10-05 14:29:53 -0400707 return;
The Android Open Source Project10592532009-03-18 17:39:46 -0700708 }
Mike Lockwoodbea31182010-10-05 14:29:53 -0400709 if (apn == NULL) {
710 jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
711 return;
The Android Open Source Project10592532009-03-18 17:39:46 -0700712 }
destradaa96a14702014-06-05 11:36:30 -0700713
Mike Lockwoodbea31182010-10-05 14:29:53 -0400714 const char *apnStr = env->GetStringUTFChars(apn, NULL);
destradaa96a14702014-06-05 11:36:30 -0700715
716 size_t interface_size = sAGpsInterface->size;
717 if (interface_size == sizeof(AGpsInterface_v2)) {
718 sAGpsInterface->data_conn_open_with_apn_ip_type(apnStr, apnIpType);
719 } else if (interface_size == sizeof(AGpsInterface_v1)) {
720 sAGpsInterface->data_conn_open(apnStr);
721 } else {
722 ALOGE("Invalid size of AGpsInterface found: %d.", interface_size);
723 }
724
Mike Lockwoodbea31182010-10-05 14:29:53 -0400725 env->ReleaseStringUTFChars(apn, apnStr);
The Android Open Source Project10592532009-03-18 17:39:46 -0700726}
727
Mike Lockwoode3635c92009-05-11 08:38:02 -0400728static void android_location_GpsLocationProvider_agps_data_conn_closed(JNIEnv* env, jobject obj)
Mike Lockwood58bda982009-04-14 16:25:07 -0400729{
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800730 if (!sAGpsInterface) {
Magnus Eriksson160c1ca2012-12-21 21:07:28 +0100731 ALOGE("no AGPS interface in agps_data_conn_closed");
Mike Lockwoodbea31182010-10-05 14:29:53 -0400732 return;
Mike Lockwood58bda982009-04-14 16:25:07 -0400733 }
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800734 sAGpsInterface->data_conn_closed();
Mike Lockwood58bda982009-04-14 16:25:07 -0400735}
736
Mike Lockwoode3635c92009-05-11 08:38:02 -0400737static void android_location_GpsLocationProvider_agps_data_conn_failed(JNIEnv* env, jobject obj)
Mike Lockwood58bda982009-04-14 16:25:07 -0400738{
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800739 if (!sAGpsInterface) {
Magnus Eriksson160c1ca2012-12-21 21:07:28 +0100740 ALOGE("no AGPS interface in agps_data_conn_failed");
Mike Lockwoodbea31182010-10-05 14:29:53 -0400741 return;
Mike Lockwood58bda982009-04-14 16:25:07 -0400742 }
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800743 sAGpsInterface->data_conn_failed();
Mike Lockwood58bda982009-04-14 16:25:07 -0400744}
745
Mike Lockwoode3635c92009-05-11 08:38:02 -0400746static void android_location_GpsLocationProvider_set_agps_server(JNIEnv* env, jobject obj,
Mike Lockwooda9e54612009-06-19 14:54:42 -0400747 jint type, jstring hostname, jint port)
Mike Lockwood58bda982009-04-14 16:25:07 -0400748{
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800749 if (!sAGpsInterface) {
Magnus Eriksson160c1ca2012-12-21 21:07:28 +0100750 ALOGE("no AGPS interface in set_agps_server");
Mike Lockwoodbea31182010-10-05 14:29:53 -0400751 return;
Mike Lockwood58bda982009-04-14 16:25:07 -0400752 }
Mike Lockwoodbea31182010-10-05 14:29:53 -0400753 const char *c_hostname = env->GetStringUTFChars(hostname, NULL);
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800754 sAGpsInterface->set_server(type, c_hostname, port);
Mike Lockwoodbea31182010-10-05 14:29:53 -0400755 env->ReleaseStringUTFChars(hostname, c_hostname);
Mike Lockwood58bda982009-04-14 16:25:07 -0400756}
757
Danke Xie22d1f9f2009-08-18 18:28:45 -0400758static void android_location_GpsLocationProvider_send_ni_response(JNIEnv* env, jobject obj,
759 jint notifId, jint response)
760{
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800761 if (!sGpsNiInterface) {
Steve Block3762c312012-01-06 19:20:56 +0000762 ALOGE("no NI interface in send_ni_response");
Mike Lockwoodbea31182010-10-05 14:29:53 -0400763 return;
Fred Fettinger3c8fbdf2010-01-04 15:38:13 -0600764 }
Mike Lockwoodbea31182010-10-05 14:29:53 -0400765
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800766 sGpsNiInterface->respond(notifId, response);
Fred Fettinger3c8fbdf2010-01-04 15:38:13 -0600767}
768
769static jstring android_location_GpsLocationProvider_get_internal_state(JNIEnv* env, jobject obj)
770{
771 jstring result = NULL;
772 if (sGpsDebugInterface) {
773 const size_t maxLength = 2047;
774 char buffer[maxLength+1];
775 size_t length = sGpsDebugInterface->get_internal_state(buffer, maxLength);
776 if (length > maxLength) length = maxLength;
777 buffer[length] = 0;
778 result = env->NewStringUTF(buffer);
779 }
780 return result;
Danke Xie22d1f9f2009-08-18 18:28:45 -0400781}
782
Mike Lockwood50130bb2010-10-11 06:22:50 -0400783static void android_location_GpsLocationProvider_update_network_state(JNIEnv* env, jobject obj,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000784 jboolean connected, jint type, jboolean roaming, jboolean available, jstring extraInfo, jstring apn)
Mike Lockwood50130bb2010-10-11 06:22:50 -0400785{
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800786
787 if (sAGpsRilInterface && sAGpsRilInterface->update_network_state) {
Mike Lockwood50130bb2010-10-11 06:22:50 -0400788 if (extraInfo) {
789 const char *extraInfoStr = env->GetStringUTFChars(extraInfo, NULL);
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800790 sAGpsRilInterface->update_network_state(connected, type, roaming, extraInfoStr);
Mike Lockwood50130bb2010-10-11 06:22:50 -0400791 env->ReleaseStringUTFChars(extraInfo, extraInfoStr);
792 } else {
Mike Lockwood58ec34c2011-02-23 08:21:00 -0800793 sAGpsRilInterface->update_network_state(connected, type, roaming, NULL);
Mike Lockwood50130bb2010-10-11 06:22:50 -0400794 }
Kevin Tanga5fe6b22011-06-05 14:25:16 -0700795
796 // update_network_availability callback was not included in original AGpsRilInterface
797 if (sAGpsRilInterface->size >= sizeof(AGpsRilInterface)
798 && sAGpsRilInterface->update_network_availability) {
799 const char *c_apn = env->GetStringUTFChars(apn, NULL);
800 sAGpsRilInterface->update_network_availability(available, c_apn);
801 env->ReleaseStringUTFChars(apn, c_apn);
802 }
Mike Lockwood50130bb2010-10-11 06:22:50 -0400803 }
804}
805
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -0700806static jboolean android_location_GpsLocationProvider_is_geofence_supported(JNIEnv* env,
807 jobject obj) {
808 if (sGpsGeofencingInterface != NULL) {
809 return JNI_TRUE;
810 }
811 return JNI_FALSE;
812}
813
814static jboolean android_location_GpsLocationProvider_add_geofence(JNIEnv* env, jobject obj,
815 jint geofence_id, jdouble latitude, jdouble longitude, jdouble radius,
816 jint last_transition, jint monitor_transition, jint notification_responsiveness,
817 jint unknown_timer) {
818 if (sGpsGeofencingInterface != NULL) {
819 sGpsGeofencingInterface->add_geofence_area(geofence_id, latitude, longitude,
820 radius, last_transition, monitor_transition, notification_responsiveness,
821 unknown_timer);
822 return JNI_TRUE;
823 } else {
824 ALOGE("Geofence interface not available");
825 }
826 return JNI_FALSE;
827}
828
829static jboolean android_location_GpsLocationProvider_remove_geofence(JNIEnv* env, jobject obj,
830 jint geofence_id) {
831 if (sGpsGeofencingInterface != NULL) {
832 sGpsGeofencingInterface->remove_geofence_area(geofence_id);
833 return JNI_TRUE;
834 } else {
835 ALOGE("Geofence interface not available");
836 }
837 return JNI_FALSE;
838}
839
840static jboolean android_location_GpsLocationProvider_pause_geofence(JNIEnv* env, jobject obj,
841 jint geofence_id) {
842 if (sGpsGeofencingInterface != NULL) {
843 sGpsGeofencingInterface->pause_geofence(geofence_id);
844 return JNI_TRUE;
845 } else {
846 ALOGE("Geofence interface not available");
847 }
848 return JNI_FALSE;
849}
850
851static jboolean android_location_GpsLocationProvider_resume_geofence(JNIEnv* env, jobject obj,
852 jint geofence_id, jint monitor_transition) {
853 if (sGpsGeofencingInterface != NULL) {
854 sGpsGeofencingInterface->resume_geofence(geofence_id, monitor_transition);
855 return JNI_TRUE;
856 } else {
857 ALOGE("Geofence interface not available");
858 }
859 return JNI_FALSE;
860}
861
destradaaea8a8a62014-06-23 18:19:03 -0700862static jobject translate_gps_clock(JNIEnv* env, GpsClock* clock) {
863 const char* doubleSignature = "(D)V";
864
865 jclass gpsClockClass = env->FindClass("android/location/GpsClock");
866 jmethodID gpsClockCtor = env->GetMethodID(gpsClockClass, "<init>", "()V");
867
868 jobject gpsClockObject = env->NewObject(gpsClockClass, gpsClockCtor);
869 GpsClockFlags flags = clock->flags;
870
871 if (flags & GPS_CLOCK_HAS_LEAP_SECOND) {
872 jmethodID setterMethod = env->GetMethodID(gpsClockClass, "setLeapSecond", "(S)V");
873 env->CallObjectMethod(gpsClockObject, setterMethod, clock->leap_second);
874 }
875
876 jmethodID setterMethod = env->GetMethodID(gpsClockClass, "setTimeInNs", "(J)V");
877 env->CallObjectMethod(gpsClockObject, setterMethod, clock->time_ns);
878
879 if (flags & GPS_CLOCK_HAS_TIME_UNCERTAINTY) {
880 jmethodID setterMethod = env->GetMethodID(
881 gpsClockClass,
882 "setTimeUncertaintyInNs",
883 doubleSignature);
884 env->CallObjectMethod(gpsClockObject, setterMethod, clock->time_uncertainty_ns);
885 }
886
887 if (flags & GPS_CLOCK_HAS_BIAS) {
888 jmethodID setterMethod = env->GetMethodID(gpsClockClass, "setBiasInNs", doubleSignature);
889 env->CallObjectMethod(gpsClockObject, setterMethod, clock->bias_ns);
890 }
891
892 if (flags & GPS_CLOCK_HAS_BIAS_UNCERTAINTY) {
893 jmethodID setterMethod = env->GetMethodID(
894 gpsClockClass,
895 "setBiasUncertaintyInNs",
896 doubleSignature);
897 env->CallObjectMethod(gpsClockObject, setterMethod, clock->bias_uncertainty_ns);
898 }
899
900 if (flags & GPS_CLOCK_HAS_DRIFT) {
901 jmethodID setterMethod = env->GetMethodID(
902 gpsClockClass,
903 "setDriftInNsPerSec",
904 doubleSignature);
905 env->CallObjectMethod(gpsClockObject, setterMethod, clock->drift_nsps);
906 }
907
908 if (flags & GPS_CLOCK_HAS_DRIFT_UNCERTAINTY) {
909 jmethodID setterMethod = env->GetMethodID(
910 gpsClockClass,
911 "setDriftUncertaintyInNsPerSec",
912 doubleSignature);
913 env->CallObjectMethod(gpsClockObject, setterMethod, clock->drift_uncertainty_nsps);
914 }
915
916 return gpsClockObject;
917}
918
919static jobject translate_gps_measurement(
920 JNIEnv* env,
921 GpsMeasurement* measurement,
922 uint32_t time_ns) {
923 const char* shortSignature = "(S)V";
924 const char* longSignature = "(J)V";
925 const char* floatSignature = "(F)V";
926 const char* doubleSignature = "(D)V";
927
928 jclass gpsMeasurementClass = env->FindClass("android/location/GpsMeasurement");
929 jmethodID gpsMeasurementCtor = env->GetMethodID(gpsMeasurementClass, "<init>", "()V");
930
931 jobject gpsMeasurementObject = env->NewObject(gpsMeasurementClass, gpsMeasurementCtor);
932 GpsMeasurementFlags flags = measurement->flags;
933
934
935 jmethodID prnSetterMethod = env->GetMethodID(gpsMeasurementClass, "setPrn", "(B)V");
936 env->CallObjectMethod(gpsMeasurementObject, prnSetterMethod, measurement->prn);
937
938 jmethodID localTimeSetterMethod =
939 env->GetMethodID(gpsMeasurementClass, "setLocalTimeInNs", longSignature);
940 env->CallObjectMethod(
941 gpsMeasurementObject,
942 localTimeSetterMethod,
943 time_ns + measurement->time_offset_ns);
944
945 jmethodID receivedGpsTowSetterMethod =
946 env->GetMethodID(gpsMeasurementClass, "setReceivedGpsTowInNs", longSignature);
947 env->CallObjectMethod(
948 gpsMeasurementObject,
949 receivedGpsTowSetterMethod,
950 measurement->received_gps_tow_ns);
951
952 jmethodID cn0SetterMethod = env->GetMethodID(
953 gpsMeasurementClass,
954 "setCn0InDbHz",
955 doubleSignature);
956 env->CallObjectMethod(gpsMeasurementObject, cn0SetterMethod, measurement->c_n0_dbhz);
957
958 jmethodID pseudorangeRateSetterMethod = env->GetMethodID(
959 gpsMeasurementClass,
960 "setPseudorangeRateInMetersPerSec",
961 doubleSignature);
962 env->CallObjectMethod(
963 gpsMeasurementObject,
964 pseudorangeRateSetterMethod,
965 measurement->pseudorange_rate_mpersec);
966
967 jmethodID pseudorangeRateUncertaintySetterMethod = env->GetMethodID(
968 gpsMeasurementClass,
969 "setPseudorangeRateUncertaintyInMetersPerSec",
970 doubleSignature);
971 env->CallObjectMethod(
972 gpsMeasurementObject,
973 pseudorangeRateUncertaintySetterMethod,
974 measurement->pseudorange_rate_uncertainty_mpersec);
975
976 jmethodID accumulatedDeltaRangeSetterMethod = env->GetMethodID(
977 gpsMeasurementClass,
978 "setAccumulatedDeltaRangeInMeters",
979 doubleSignature);
980 env->CallVoidMethod(
981 gpsMeasurementObject,
982 accumulatedDeltaRangeSetterMethod,
983 measurement->accumulated_delta_range_m);
984
985 jmethodID accumulatedDeltaRangeUncertaintySetterMethod = env->GetMethodID(
986 gpsMeasurementClass,
987 "setAccumulatedDeltaRangeUncertaintyInMeters",
988 doubleSignature);
989 env->CallVoidMethod(
990 gpsMeasurementObject,
991 accumulatedDeltaRangeUncertaintySetterMethod,
992 measurement->accumulated_delta_range_uncertainty_m);
993
994
995 if (flags & GPS_MEASUREMENT_HAS_PSEUDORANGE) {
996 jmethodID setterMethod = env->GetMethodID(
997 gpsMeasurementClass,
998 "setPseudorangeInMeters",
999 doubleSignature);
1000 env->CallObjectMethod(gpsMeasurementObject, setterMethod, measurement->pseudorange_m);
1001 }
1002
1003 if (flags & GPS_MEASUREMENT_HAS_PSEUDORANGE_UNCERTAINTY) {
1004 jmethodID setterMethod = env->GetMethodID(
1005 gpsMeasurementClass,
1006 "setPseudorangeUncertaintyInMeters",
1007 doubleSignature);
1008 env->CallObjectMethod(
1009 gpsMeasurementObject,
1010 setterMethod,
1011 measurement->pseudorange_uncertainty_m);
1012 }
1013
1014 if (flags & GPS_MEASUREMENT_HAS_CODE_PHASE) {
1015 jmethodID setterMethod = env->GetMethodID(
1016 gpsMeasurementClass,
1017 "setCodePhaseInChips",
1018 doubleSignature);
1019 env->CallObjectMethod(gpsMeasurementObject, setterMethod, measurement->code_phase_chips);
1020 }
1021
1022 if (flags & GPS_MEASUREMENT_HAS_CODE_PHASE_UNCERTAINTY) {
1023 jmethodID setterMethod = env->GetMethodID(
1024 gpsMeasurementClass,
1025 "setCodePhaseUncertaintyInChips",
1026 doubleSignature);
1027 env->CallObjectMethod(
1028 gpsMeasurementObject,
1029 setterMethod,
1030 measurement->code_phase_uncertainty_chips);
1031 }
1032
1033 if (flags & GPS_MEASUREMENT_HAS_CARRIER_FREQUENCY) {
1034 jmethodID setterMethod = env->GetMethodID(
1035 gpsMeasurementClass,
1036 "setCarrierFrequencyInHz",
1037 floatSignature);
1038 env->CallObjectMethod(
1039 gpsMeasurementObject,
1040 setterMethod,
1041 measurement->carrier_frequency_hz);
1042 }
1043
1044 if (flags & GPS_MEASUREMENT_HAS_CARRIER_CYCLES) {
1045 jmethodID setterMethod =
1046 env->GetMethodID(gpsMeasurementClass, "setCarrierCycles", longSignature);
1047 env->CallObjectMethod(gpsMeasurementObject, setterMethod, measurement->carrier_cycles);
1048 }
1049
1050 if (flags & GPS_MEASUREMENT_HAS_CARRIER_PHASE) {
1051 jmethodID setterMethod =
1052 env->GetMethodID(gpsMeasurementClass, "setCarrierPhase", doubleSignature);
1053 env->CallObjectMethod(gpsMeasurementObject, setterMethod, measurement->carrier_phase);
1054 }
1055
1056 if (flags & GPS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY) {
1057 jmethodID setterMethod = env->GetMethodID(
1058 gpsMeasurementClass,
1059 "setCarrierPhaseUncertainty",
1060 doubleSignature);
1061 env->CallObjectMethod(
1062 gpsMeasurementObject,
1063 setterMethod,
1064 measurement->carrier_phase_uncertainty);
1065 }
1066
1067 jmethodID lossOfLockSetterMethod =
1068 env->GetMethodID(gpsMeasurementClass, "setLossOfLock", shortSignature);
1069 env->CallObjectMethod(gpsMeasurementObject, lossOfLockSetterMethod, measurement->loss_of_lock);
1070
1071 if (flags & GPS_MEASUREMENT_HAS_BIT_NUMBER) {
1072 jmethodID setterMethod = env->GetMethodID(
1073 gpsMeasurementClass,
1074 "setBitNumber",
1075 shortSignature);
1076 env->CallObjectMethod(gpsMeasurementObject, setterMethod, measurement->bit_number);
1077 }
1078
1079 if (flags & GPS_MEASUREMENT_HAS_TIME_FROM_LAST_BIT) {
1080 jmethodID setterMethod = env->GetMethodID(
1081 gpsMeasurementClass,
1082 "setTimeFromLastBitInNs",
1083 longSignature);
1084 env->CallObjectMethod(
1085 gpsMeasurementObject,
1086 setterMethod,
1087 measurement->time_from_last_bit_ns);
1088 }
1089
1090 if (flags & GPS_MEASUREMENT_HAS_DOPPLER_SHIFT) {
1091 jmethodID setterMethod = env->GetMethodID(
1092 gpsMeasurementClass,
1093 "setDopplerShiftInHz",
1094 doubleSignature);
1095 env->CallObjectMethod(gpsMeasurementObject, setterMethod, measurement->doppler_shift_hz);
1096 }
1097
1098 if (flags & GPS_MEASUREMENT_HAS_DOPPLER_SHIFT_UNCERTAINTY) {
1099 jmethodID setterMethod = env->GetMethodID(
1100 gpsMeasurementClass,
1101 "setDopplerShiftUncertaintyInHz",
1102 doubleSignature);
1103 env->CallObjectMethod(
1104 gpsMeasurementObject,
1105 setterMethod,
1106 measurement->doppler_shift_uncertainty_hz);
1107 }
1108
1109 jmethodID multipathIndicatorSetterMethod = env->GetMethodID(
1110 gpsMeasurementClass,
1111 "setMultipathIndicator",
1112 shortSignature);
1113 env->CallObjectMethod(
1114 gpsMeasurementObject,
1115 multipathIndicatorSetterMethod,
1116 measurement->multipath_indicator);
1117
1118 if (flags & GPS_MEASUREMENT_HAS_SNR) {
1119 jmethodID setterMethod =
1120 env->GetMethodID(gpsMeasurementClass, "setSnrInDb", doubleSignature);
1121 env->CallObjectMethod(gpsMeasurementObject, setterMethod, measurement->snr_db);
1122 }
1123
1124 if (flags & GPS_MEASUREMENT_HAS_ELEVATION) {
1125 jmethodID setterMethod = env->GetMethodID(
1126 gpsMeasurementClass,
1127 "setElevationInDeg",
1128 doubleSignature);
1129 env->CallObjectMethod(gpsMeasurementObject, setterMethod, measurement->elevation_deg);
1130 }
1131
1132 if (flags & GPS_MEASUREMENT_HAS_ELEVATION_UNCERTAINTY) {
1133 jmethodID setterMethod = env->GetMethodID(
1134 gpsMeasurementClass,
1135 "setElevationUncertaintyInDeg",
1136 doubleSignature);
1137 env->CallObjectMethod(
1138 gpsMeasurementObject,
1139 setterMethod,
1140 measurement->elevation_uncertainty_deg);
1141 }
1142
1143 if (flags & GPS_MEASUREMENT_HAS_AZIMUTH) {
1144 jmethodID setterMethod =
1145 env->GetMethodID(gpsMeasurementClass, "setAzimuthInDeg", doubleSignature);
1146 env->CallObjectMethod(gpsMeasurementObject, setterMethod, measurement->azimuth_deg);
1147 }
1148
1149 if (flags & GPS_MEASUREMENT_HAS_AZIMUTH_UNCERTAINTY) {
1150 jmethodID setterMethod = env->GetMethodID(
1151 gpsMeasurementClass,
1152 "setAzimuthUncertaintyInDeg",
1153 doubleSignature);
1154 env->CallObjectMethod(
1155 gpsMeasurementObject,
1156 setterMethod,
1157 measurement->azimuth_uncertainty_deg);
1158 }
1159
1160 jmethodID usedInFixSetterMethod = env->GetMethodID(gpsMeasurementClass, "setUsedInFix", "(Z)V");
1161 env->CallObjectMethod(
1162 gpsMeasurementObject,
1163 usedInFixSetterMethod,
1164 (flags & GPS_MEASUREMENT_HAS_USED_IN_FIX) && measurement->used_in_fix);
1165
1166 return gpsMeasurementObject;
1167}
1168
1169static jobjectArray translate_gps_measurements(JNIEnv* env, GpsData* data) {
1170 size_t measurementCount = data->measurement_count;
1171 if (measurementCount == 0) {
1172 return NULL;
1173 }
1174
1175 jclass gpsMeasurementClass = env->FindClass("android/location/GpsMeasurement");
1176 jobjectArray gpsMeasurementArray = env->NewObjectArray(
1177 measurementCount,
1178 gpsMeasurementClass,
1179 NULL /* initialElement */);
1180
1181 GpsMeasurement* gpsMeasurements = data->measurements;
1182 for (uint16_t i = 0; i < measurementCount; ++i) {
1183 jobject gpsMeasurement = translate_gps_measurement(
1184 env,
1185 &gpsMeasurements[i],
1186 data->clock.time_ns);
1187 env->SetObjectArrayElement(gpsMeasurementArray, i, gpsMeasurement);
1188 env->DeleteLocalRef(gpsMeasurement);
1189 }
1190
1191 env->DeleteLocalRef(gpsMeasurementClass);
1192 return gpsMeasurementArray;
1193}
1194
1195static void measurement_callback(GpsData* data) {
1196 JNIEnv* env = AndroidRuntime::getJNIEnv();
1197 if (data == NULL) {
1198 ALOGE("Invalid data provided to gps_measurement_callback");
1199 return;
1200 }
1201
1202 if (data->size == sizeof(GpsData)) {
1203 jobject gpsClock = translate_gps_clock(env, &data->clock);
1204 jobjectArray measurementArray = translate_gps_measurements(env, data);
1205
1206 jclass gpsMeasurementsEventClass = env->FindClass("android/location/GpsMeasurementsEvent");
1207 jmethodID gpsMeasurementsEventCtor = env->GetMethodID(
1208 gpsMeasurementsEventClass,
1209 "<init>",
1210 "(Landroid/location/GpsClock;[Landroid/location/GpsMeasurement;)V");
1211
1212 jobject gpsMeasurementsEvent = env->NewObject(
1213 gpsMeasurementsEventClass,
1214 gpsMeasurementsEventCtor,
1215 gpsClock,
1216 measurementArray);
1217
1218 env->CallVoidMethod(mCallbacksObj, method_reportMeasurementData, gpsMeasurementsEvent);
1219 checkAndClearExceptionFromCallback(env, __FUNCTION__);
1220 } else {
1221 ALOGE("Invalid GpsData size found in gps_measurement_callback, size=%d", data->size);
1222 return;
1223 }
1224}
1225
1226GpsMeasurementCallbacks sGpsMeasurementCallbacks = {
1227 sizeof(GpsMeasurementCallbacks),
1228 measurement_callback,
1229};
1230
1231static jboolean android_location_GpsLocationProvider_is_measurement_supported(
1232 JNIEnv* env,
1233 jobject obj) {
1234 if (sGpsMeasurementInterface != NULL) {
1235 return JNI_TRUE;
1236 }
1237 return JNI_FALSE;
1238}
1239
1240static jboolean android_location_GpsLocationProvider_start_measurement_collection(
1241 JNIEnv* env,
1242 jobject obj) {
1243 if (sGpsMeasurementInterface == NULL) {
1244 ALOGE("Measurement interface is not available.");
1245 return JNI_FALSE;
1246 }
1247
1248 int result = sGpsMeasurementInterface->init(&sGpsMeasurementCallbacks);
1249 if (result != GPS_GEOFENCE_OPERATION_SUCCESS) {
1250 ALOGE("An error has been found on GpsMeasurementInterface::init, status=%d", result);
1251 return JNI_FALSE;
1252 }
1253
1254 return JNI_TRUE;
1255}
1256
1257static jboolean android_location_GpsLocationProvider_stop_measurement_collection(
1258 JNIEnv* env,
1259 jobject obj) {
1260 if (sGpsMeasurementInterface == NULL) {
1261 ALOGE("Measurement interface not available");
1262 return JNI_FALSE;
1263 }
1264
1265 sGpsMeasurementInterface->close();
1266 return JNI_TRUE;
1267}
1268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001269static JNINativeMethod sMethods[] = {
1270 /* name, signature, funcPtr */
1271 {"class_init_native", "()V", (void *)android_location_GpsLocationProvider_class_init_native},
Mike Lockwoode3635c92009-05-11 08:38:02 -04001272 {"native_is_supported", "()Z", (void*)android_location_GpsLocationProvider_is_supported},
1273 {"native_init", "()Z", (void*)android_location_GpsLocationProvider_init},
Mike Lockwoode3635c92009-05-11 08:38:02 -04001274 {"native_cleanup", "()V", (void*)android_location_GpsLocationProvider_cleanup},
destradaaea8a8a62014-06-23 18:19:03 -07001275 {"native_set_position_mode",
1276 "(IIIII)Z",
1277 (void*)android_location_GpsLocationProvider_set_position_mode},
Mike Lockwood04598b62010-04-14 17:17:24 -04001278 {"native_start", "()Z", (void*)android_location_GpsLocationProvider_start},
Mike Lockwoode3635c92009-05-11 08:38:02 -04001279 {"native_stop", "()Z", (void*)android_location_GpsLocationProvider_stop},
destradaaea8a8a62014-06-23 18:19:03 -07001280 {"native_delete_aiding_data",
1281 "(I)V",
1282 (void*)android_location_GpsLocationProvider_delete_aiding_data},
1283 {"native_read_sv_status",
1284 "([I[F[F[F[I)I",
1285 (void*)android_location_GpsLocationProvider_read_sv_status},
Mike Lockwoodf602d362010-06-20 14:28:16 -07001286 {"native_read_nmea", "([BI)I", (void*)android_location_GpsLocationProvider_read_nmea},
Mike Lockwoode3635c92009-05-11 08:38:02 -04001287 {"native_inject_time", "(JJI)V", (void*)android_location_GpsLocationProvider_inject_time},
destradaaea8a8a62014-06-23 18:19:03 -07001288 {"native_inject_location",
1289 "(DDF)V",
1290 (void*)android_location_GpsLocationProvider_inject_location},
Mike Lockwoode3635c92009-05-11 08:38:02 -04001291 {"native_supports_xtra", "()Z", (void*)android_location_GpsLocationProvider_supports_xtra},
destradaaea8a8a62014-06-23 18:19:03 -07001292 {"native_inject_xtra_data",
1293 "([BI)V",
1294 (void*)android_location_GpsLocationProvider_inject_xtra_data},
1295 {"native_agps_data_conn_open",
1296 "(Ljava/lang/String;I)V",
1297 (void*)android_location_GpsLocationProvider_agps_data_conn_open},
1298 {"native_agps_data_conn_closed",
1299 "()V",
1300 (void*)android_location_GpsLocationProvider_agps_data_conn_closed},
1301 {"native_agps_data_conn_failed",
1302 "()V",
1303 (void*)android_location_GpsLocationProvider_agps_data_conn_failed},
1304 {"native_agps_set_id",
1305 "(ILjava/lang/String;)V",
1306 (void*)android_location_GpsLocationProvider_agps_set_id},
1307 {"native_agps_set_ref_location_cellid",
1308 "(IIIII)V",
1309 (void*)android_location_GpsLocationProvider_agps_set_reference_location_cellid},
1310 {"native_set_agps_server",
1311 "(ILjava/lang/String;I)V",
1312 (void*)android_location_GpsLocationProvider_set_agps_server},
1313 {"native_send_ni_response",
1314 "(II)V",
1315 (void*)android_location_GpsLocationProvider_send_ni_response},
1316 {"native_agps_ni_message",
1317 "([BI)V",
1318 (void *)android_location_GpsLocationProvider_agps_send_ni_message},
1319 {"native_get_internal_state",
1320 "()Ljava/lang/String;",
1321 (void*)android_location_GpsLocationProvider_get_internal_state},
1322 {"native_update_network_state",
1323 "(ZIZZLjava/lang/String;Ljava/lang/String;)V",
1324 (void*)android_location_GpsLocationProvider_update_network_state },
1325 {"native_is_geofence_supported",
1326 "()Z",
1327 (void*) android_location_GpsLocationProvider_is_geofence_supported},
1328 {"native_add_geofence",
1329 "(IDDDIIII)Z",
1330 (void *)android_location_GpsLocationProvider_add_geofence},
1331 {"native_remove_geofence",
1332 "(I)Z",
1333 (void *)android_location_GpsLocationProvider_remove_geofence},
Jaikumar Ganesh8ce470d2013-04-03 12:22:18 -07001334 {"native_pause_geofence", "(I)Z", (void *)android_location_GpsLocationProvider_pause_geofence},
destradaaea8a8a62014-06-23 18:19:03 -07001335 {"native_resume_geofence",
1336 "(II)Z",
1337 (void *)android_location_GpsLocationProvider_resume_geofence},
1338 {"native_is_measurement_supported",
1339 "()Z",
1340 (void*) android_location_GpsLocationProvider_is_measurement_supported},
1341 {"native_start_measurement_collection",
1342 "()Z",
1343 (void*) android_location_GpsLocationProvider_start_measurement_collection},
1344 {"native_stop_measurement_collection",
1345 "()Z",
1346 (void*) android_location_GpsLocationProvider_stop_measurement_collection}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001347};
1348
Mike Lockwood00b74272010-03-26 10:41:48 -04001349int register_android_server_location_GpsLocationProvider(JNIEnv* env)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001350{
destradaaea8a8a62014-06-23 18:19:03 -07001351 return jniRegisterNativeMethods(
1352 env,
1353 "com/android/server/location/GpsLocationProvider",
1354 sMethods,
1355 NELEM(sMethods));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001356}
1357
1358} /* namespace android */