The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Lockwood | b8d9033 | 2010-10-18 17:59:48 -0400 | [diff] [blame] | 19 | #define LOG_NDEBUG 0 |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 20 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | #include "JNIHelp.h" |
| 22 | #include "jni.h" |
Mike Lockwood | b7ff457 | 2010-04-05 15:24:34 -0400 | [diff] [blame] | 23 | #include "hardware/hardware.h" |
| 24 | #include "hardware/gps.h" |
Mike Lockwood | 8f5a800 | 2010-04-07 09:05:26 -0400 | [diff] [blame] | 25 | #include "hardware_legacy/power.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | #include "utils/Log.h" |
| 27 | #include "utils/misc.h" |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 28 | #include "android_runtime/AndroidRuntime.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | |
| 30 | #include <string.h> |
| 31 | #include <pthread.h> |
| 32 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 33 | static jobject mCallbacksObj = NULL; |
| 34 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | static jmethodID method_reportLocation; |
| 36 | static jmethodID method_reportStatus; |
| 37 | static jmethodID method_reportSvStatus; |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 38 | static jmethodID method_reportAGpsStatus; |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 39 | static jmethodID method_reportNmea; |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 40 | static jmethodID method_setEngineCapabilities; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | static jmethodID method_xtraDownloadRequest; |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 42 | static jmethodID method_reportNiNotification; |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 43 | static jmethodID method_requestRefLocation; |
| 44 | static jmethodID method_requestSetID; |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 45 | static jmethodID method_requestUtcTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | |
| 47 | static const GpsInterface* sGpsInterface = NULL; |
| 48 | static const GpsXtraInterface* sGpsXtraInterface = NULL; |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 49 | static const AGpsInterface* sAGpsInterface = NULL; |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 50 | static const GpsNiInterface* sGpsNiInterface = NULL; |
Fred Fettinger | 3c8fbdf | 2010-01-04 15:38:13 -0600 | [diff] [blame] | 51 | static const GpsDebugInterface* sGpsDebugInterface = NULL; |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 52 | static const AGpsRilInterface* sAGpsRilInterface = NULL; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 54 | // temporary storage for GPS callbacks |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | static GpsSvStatus sGpsSvStatus; |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 56 | static const char* sNmeaString; |
| 57 | static int sNmeaStringLength; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | |
Mike Lockwood | 8f5a800 | 2010-04-07 09:05:26 -0400 | [diff] [blame] | 59 | #define WAKE_LOCK_NAME "GPS" |
| 60 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | namespace android { |
| 62 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 63 | static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) { |
| 64 | if (env->ExceptionCheck()) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 65 | ALOGE("An exception was thrown by callback '%s'.", methodName); |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 66 | LOGE_EX(env); |
| 67 | env->ExceptionClear(); |
| 68 | } |
| 69 | } |
| 70 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | static void location_callback(GpsLocation* location) |
| 72 | { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 73 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 74 | env->CallVoidMethod(mCallbacksObj, method_reportLocation, location->flags, |
| 75 | (jdouble)location->latitude, (jdouble)location->longitude, |
| 76 | (jdouble)location->altitude, |
| 77 | (jfloat)location->speed, (jfloat)location->bearing, |
| 78 | (jfloat)location->accuracy, (jlong)location->timestamp); |
| 79 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | static void status_callback(GpsStatus* status) |
| 83 | { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 84 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 85 | env->CallVoidMethod(mCallbacksObj, method_reportStatus, status->status); |
| 86 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | static void sv_status_callback(GpsSvStatus* sv_status) |
| 90 | { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 91 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 92 | memcpy(&sGpsSvStatus, sv_status, sizeof(sGpsSvStatus)); |
| 93 | env->CallVoidMethod(mCallbacksObj, method_reportSvStatus); |
| 94 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | } |
| 96 | |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 97 | static void nmea_callback(GpsUtcTime timestamp, const char* nmea, int length) |
| 98 | { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 99 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 100 | // The Java code will call back to read these values |
| 101 | // We do this to avoid creating unnecessary String objects |
| 102 | sNmeaString = nmea; |
| 103 | sNmeaStringLength = length; |
| 104 | env->CallVoidMethod(mCallbacksObj, method_reportNmea, timestamp); |
| 105 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 106 | } |
| 107 | |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 108 | static void set_capabilities_callback(uint32_t capabilities) |
| 109 | { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 110 | ALOGD("set_capabilities_callback: %ld\n", capabilities); |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 111 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 112 | env->CallVoidMethod(mCallbacksObj, method_setEngineCapabilities, capabilities); |
| 113 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 114 | } |
| 115 | |
Mike Lockwood | 8f5a800 | 2010-04-07 09:05:26 -0400 | [diff] [blame] | 116 | static void acquire_wakelock_callback() |
| 117 | { |
| 118 | acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_NAME); |
| 119 | } |
| 120 | |
| 121 | static void release_wakelock_callback() |
| 122 | { |
| 123 | release_wake_lock(WAKE_LOCK_NAME); |
| 124 | } |
| 125 | |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 126 | static void request_utc_time_callback() |
| 127 | { |
| 128 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 129 | env->CallVoidMethod(mCallbacksObj, method_requestUtcTime); |
| 130 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 131 | } |
| 132 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 133 | static pthread_t create_thread_callback(const char* name, void (*start)(void *), void* arg) |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 134 | { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 135 | return (pthread_t)AndroidRuntime::createJavaThread(name, start, arg); |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 136 | } |
| 137 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | GpsCallbacks sGpsCallbacks = { |
Mike Lockwood | 8f5a800 | 2010-04-07 09:05:26 -0400 | [diff] [blame] | 139 | sizeof(GpsCallbacks), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | location_callback, |
| 141 | status_callback, |
| 142 | sv_status_callback, |
Mike Lockwood | 8f5a800 | 2010-04-07 09:05:26 -0400 | [diff] [blame] | 143 | nmea_callback, |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 144 | set_capabilities_callback, |
Mike Lockwood | 8f5a800 | 2010-04-07 09:05:26 -0400 | [diff] [blame] | 145 | acquire_wakelock_callback, |
| 146 | release_wakelock_callback, |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 147 | create_thread_callback, |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 148 | request_utc_time_callback, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | }; |
| 150 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 151 | static void xtra_download_request_callback() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 153 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 154 | env->CallVoidMethod(mCallbacksObj, method_xtraDownloadRequest); |
| 155 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 156 | } |
| 157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | GpsXtraCallbacks sGpsXtraCallbacks = { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 159 | xtra_download_request_callback, |
| 160 | create_thread_callback, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | }; |
| 162 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 163 | static void agps_status_callback(AGpsStatus* agps_status) |
| 164 | { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 165 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
Stephen Li | 8efd74d | 2011-03-01 20:56:00 -0800 | [diff] [blame] | 166 | |
| 167 | uint32_t ipaddr; |
| 168 | // ipaddr field was not included in original AGpsStatus |
| 169 | if (agps_status->size >= sizeof(AGpsStatus)) |
| 170 | ipaddr = agps_status->ipaddr; |
| 171 | else |
| 172 | ipaddr = 0xFFFFFFFF; |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 173 | env->CallVoidMethod(mCallbacksObj, method_reportAGpsStatus, |
Stephen Li | 8efd74d | 2011-03-01 20:56:00 -0800 | [diff] [blame] | 174 | agps_status->type, agps_status->status, ipaddr); |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 175 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 176 | } |
| 177 | |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 178 | AGpsCallbacks sAGpsCallbacks = { |
| 179 | agps_status_callback, |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 180 | create_thread_callback, |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 181 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 183 | static void gps_ni_notify_callback(GpsNiNotification *notification) |
| 184 | { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 185 | ALOGD("gps_ni_notify_callback\n"); |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 186 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 187 | jstring requestor_id = env->NewStringUTF(notification->requestor_id); |
| 188 | jstring text = env->NewStringUTF(notification->text); |
| 189 | jstring extras = env->NewStringUTF(notification->extras); |
| 190 | |
| 191 | if (requestor_id && text && extras) { |
| 192 | env->CallVoidMethod(mCallbacksObj, method_reportNiNotification, |
| 193 | notification->notification_id, notification->ni_type, |
| 194 | notification->notify_flags, notification->timeout, |
| 195 | notification->default_response, requestor_id, text, |
| 196 | notification->requestor_id_encoding, |
| 197 | notification->text_encoding, extras); |
| 198 | } else { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 199 | ALOGE("out of memory in gps_ni_notify_callback\n"); |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | if (requestor_id) |
| 203 | env->DeleteLocalRef(requestor_id); |
| 204 | if (text) |
| 205 | env->DeleteLocalRef(text); |
| 206 | if (extras) |
| 207 | env->DeleteLocalRef(extras); |
| 208 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 209 | } |
| 210 | |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 211 | GpsNiCallbacks sGpsNiCallbacks = { |
| 212 | gps_ni_notify_callback, |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 213 | create_thread_callback, |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 214 | }; |
| 215 | |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 216 | static void agps_request_set_id(uint32_t flags) |
| 217 | { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 218 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 219 | env->CallVoidMethod(mCallbacksObj, method_requestSetID, flags); |
| 220 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 221 | } |
| 222 | |
| 223 | static void agps_request_ref_location(uint32_t flags) |
| 224 | { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 225 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 226 | env->CallVoidMethod(mCallbacksObj, method_requestRefLocation, flags); |
| 227 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 228 | } |
| 229 | |
| 230 | AGpsRilCallbacks sAGpsRilCallbacks = { |
| 231 | agps_request_set_id, |
| 232 | agps_request_ref_location, |
| 233 | create_thread_callback, |
| 234 | }; |
| 235 | |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 236 | static void android_location_GpsLocationProvider_class_init_native(JNIEnv* env, jclass clazz) { |
Mike Lockwood | b7ff457 | 2010-04-05 15:24:34 -0400 | [diff] [blame] | 237 | int err; |
| 238 | hw_module_t* module; |
Mike Lockwood | b7ff457 | 2010-04-05 15:24:34 -0400 | [diff] [blame] | 239 | |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 240 | method_reportLocation = env->GetMethodID(clazz, "reportLocation", "(IDDDFFFJ)V"); |
| 241 | method_reportStatus = env->GetMethodID(clazz, "reportStatus", "(I)V"); |
| 242 | method_reportSvStatus = env->GetMethodID(clazz, "reportSvStatus", "()V"); |
Stephen Li | 8efd74d | 2011-03-01 20:56:00 -0800 | [diff] [blame] | 243 | method_reportAGpsStatus = env->GetMethodID(clazz, "reportAGpsStatus", "(III)V"); |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 244 | method_reportNmea = env->GetMethodID(clazz, "reportNmea", "(J)V"); |
| 245 | method_setEngineCapabilities = env->GetMethodID(clazz, "setEngineCapabilities", "(I)V"); |
| 246 | method_xtraDownloadRequest = env->GetMethodID(clazz, "xtraDownloadRequest", "()V"); |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 247 | method_reportNiNotification = env->GetMethodID(clazz, "reportNiNotification", |
| 248 | "(IIIIILjava/lang/String;Ljava/lang/String;IILjava/lang/String;)V"); |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 249 | method_requestRefLocation = env->GetMethodID(clazz,"requestRefLocation","(I)V"); |
| 250 | method_requestSetID = env->GetMethodID(clazz,"requestSetID","(I)V"); |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 251 | method_requestUtcTime = env->GetMethodID(clazz,"requestUtcTime","()V"); |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 252 | |
| 253 | err = hw_get_module(GPS_HARDWARE_MODULE_ID, (hw_module_t const**)&module); |
| 254 | if (err == 0) { |
| 255 | hw_device_t* device; |
| 256 | err = module->methods->open(module, GPS_HARDWARE_MODULE_ID, &device); |
| 257 | if (err == 0) { |
| 258 | gps_device_t* gps_device = (gps_device_t *)device; |
| 259 | sGpsInterface = gps_device->get_gps_interface(gps_device); |
| 260 | } |
| 261 | } |
| 262 | if (sGpsInterface) { |
| 263 | sGpsXtraInterface = |
| 264 | (const GpsXtraInterface*)sGpsInterface->get_extension(GPS_XTRA_INTERFACE); |
| 265 | sAGpsInterface = |
| 266 | (const AGpsInterface*)sGpsInterface->get_extension(AGPS_INTERFACE); |
| 267 | sGpsNiInterface = |
| 268 | (const GpsNiInterface*)sGpsInterface->get_extension(GPS_NI_INTERFACE); |
| 269 | sGpsDebugInterface = |
| 270 | (const GpsDebugInterface*)sGpsInterface->get_extension(GPS_DEBUG_INTERFACE); |
| 271 | sAGpsRilInterface = |
| 272 | (const AGpsRilInterface*)sGpsInterface->get_extension(AGPS_RIL_INTERFACE); |
| 273 | } |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 274 | } |
| 275 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | static jboolean android_location_GpsLocationProvider_is_supported(JNIEnv* env, jclass clazz) { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 277 | return (sGpsInterface != NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | static jboolean android_location_GpsLocationProvider_init(JNIEnv* env, jobject obj) |
| 281 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 282 | // this must be set before calling into the HAL library |
| 283 | if (!mCallbacksObj) |
| 284 | mCallbacksObj = env->NewGlobalRef(obj); |
| 285 | |
| 286 | // fail if the main interface fails to initialize |
| 287 | if (!sGpsInterface || sGpsInterface->init(&sGpsCallbacks) != 0) |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 288 | return false; |
| 289 | |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 290 | // if XTRA initialization fails we will disable it by sGpsXtraInterface to null, |
| 291 | // but continue to allow the rest of the GPS interface to work. |
| 292 | if (sGpsXtraInterface && sGpsXtraInterface->init(&sGpsXtraCallbacks) != 0) |
| 293 | sGpsXtraInterface = NULL; |
| 294 | if (sAGpsInterface) |
| 295 | sAGpsInterface->init(&sAGpsCallbacks); |
| 296 | if (sGpsNiInterface) |
| 297 | sGpsNiInterface->init(&sGpsNiCallbacks); |
| 298 | if (sAGpsRilInterface) |
| 299 | sAGpsRilInterface->init(&sAGpsRilCallbacks); |
Fred Fettinger | 3c8fbdf | 2010-01-04 15:38:13 -0600 | [diff] [blame] | 300 | |
Mike Lockwood | c21a08f | 2009-04-30 15:16:39 -0400 | [diff] [blame] | 301 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 302 | } |
| 303 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | static void android_location_GpsLocationProvider_cleanup(JNIEnv* env, jobject obj) |
| 305 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 306 | if (sGpsInterface) |
| 307 | sGpsInterface->cleanup(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | } |
| 309 | |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 310 | static jboolean android_location_GpsLocationProvider_set_position_mode(JNIEnv* env, jobject obj, |
| 311 | jint mode, jint recurrence, jint min_interval, jint preferred_accuracy, jint preferred_time) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 313 | if (sGpsInterface) |
| 314 | return (sGpsInterface->set_position_mode(mode, recurrence, min_interval, preferred_accuracy, |
Mike Lockwood | 4270237 | 2010-10-10 16:04:18 -0400 | [diff] [blame] | 315 | preferred_time) == 0); |
| 316 | else |
| 317 | return false; |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 318 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 320 | static jboolean android_location_GpsLocationProvider_start(JNIEnv* env, jobject obj) |
| 321 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 322 | if (sGpsInterface) |
| 323 | return (sGpsInterface->start() == 0); |
Mike Lockwood | 4270237 | 2010-10-10 16:04:18 -0400 | [diff] [blame] | 324 | else |
| 325 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | static jboolean android_location_GpsLocationProvider_stop(JNIEnv* env, jobject obj) |
| 329 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 330 | if (sGpsInterface) |
| 331 | return (sGpsInterface->stop() == 0); |
Mike Lockwood | 4270237 | 2010-10-10 16:04:18 -0400 | [diff] [blame] | 332 | else |
| 333 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | } |
| 335 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | static void android_location_GpsLocationProvider_delete_aiding_data(JNIEnv* env, jobject obj, jint flags) |
| 337 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 338 | if (sGpsInterface) |
| 339 | sGpsInterface->delete_aiding_data(flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 340 | } |
| 341 | |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 342 | static jint android_location_GpsLocationProvider_read_sv_status(JNIEnv* env, jobject obj, |
| 343 | jintArray prnArray, jfloatArray snrArray, jfloatArray elevArray, jfloatArray azumArray, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 344 | jintArray maskArray) |
| 345 | { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 346 | // this should only be called from within a call to reportSvStatus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | |
| 348 | jint* prns = env->GetIntArrayElements(prnArray, 0); |
| 349 | jfloat* snrs = env->GetFloatArrayElements(snrArray, 0); |
| 350 | jfloat* elev = env->GetFloatArrayElements(elevArray, 0); |
| 351 | jfloat* azim = env->GetFloatArrayElements(azumArray, 0); |
| 352 | jint* mask = env->GetIntArrayElements(maskArray, 0); |
| 353 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 354 | int num_svs = sGpsSvStatus.num_svs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | for (int i = 0; i < num_svs; i++) { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 356 | prns[i] = sGpsSvStatus.sv_list[i].prn; |
| 357 | snrs[i] = sGpsSvStatus.sv_list[i].snr; |
| 358 | elev[i] = sGpsSvStatus.sv_list[i].elevation; |
| 359 | azim[i] = sGpsSvStatus.sv_list[i].azimuth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 360 | } |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 361 | mask[0] = sGpsSvStatus.ephemeris_mask; |
| 362 | mask[1] = sGpsSvStatus.almanac_mask; |
| 363 | mask[2] = sGpsSvStatus.used_in_fix_mask; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | |
| 365 | env->ReleaseIntArrayElements(prnArray, prns, 0); |
| 366 | env->ReleaseFloatArrayElements(snrArray, snrs, 0); |
| 367 | env->ReleaseFloatArrayElements(elevArray, elev, 0); |
| 368 | env->ReleaseFloatArrayElements(azumArray, azim, 0); |
| 369 | env->ReleaseIntArrayElements(maskArray, mask, 0); |
| 370 | return num_svs; |
| 371 | } |
| 372 | |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 373 | static void android_location_GpsLocationProvider_agps_set_reference_location_cellid(JNIEnv* env, |
| 374 | jobject obj, jint type, jint mcc, jint mnc, jint lac, jint cid) |
| 375 | { |
| 376 | AGpsRefLocation location; |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 377 | |
| 378 | if (!sAGpsRilInterface) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 379 | ALOGE("no AGPS RIL interface in agps_set_reference_location_cellid"); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 380 | return; |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 381 | } |
| 382 | |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 383 | switch(type) { |
| 384 | case AGPS_REF_LOCATION_TYPE_GSM_CELLID: |
| 385 | case AGPS_REF_LOCATION_TYPE_UMTS_CELLID: |
| 386 | location.type = type; |
| 387 | location.u.cellID.mcc = mcc; |
| 388 | location.u.cellID.mnc = mnc; |
| 389 | location.u.cellID.lac = lac; |
| 390 | location.u.cellID.cid = cid; |
| 391 | break; |
| 392 | default: |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 393 | ALOGE("Neither a GSM nor a UMTS cellid (%s:%d).",__FUNCTION__,__LINE__); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 394 | return; |
| 395 | break; |
| 396 | } |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 397 | sAGpsRilInterface->set_ref_location(&location, sizeof(location)); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | static void android_location_GpsLocationProvider_agps_send_ni_message(JNIEnv* env, |
| 401 | jobject obj, jbyteArray ni_msg, jint size) |
| 402 | { |
| 403 | size_t sz; |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 404 | |
| 405 | if (!sAGpsRilInterface) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 406 | ALOGE("no AGPS RIL interface in send_ni_message"); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 407 | return; |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 408 | } |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 409 | if (size < 0) |
| 410 | return; |
| 411 | sz = (size_t)size; |
| 412 | jbyte* b = env->GetByteArrayElements(ni_msg, 0); |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 413 | sAGpsRilInterface->ni_message((uint8_t *)b,sz); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 414 | env->ReleaseByteArrayElements(ni_msg,b,0); |
| 415 | } |
| 416 | |
| 417 | static void android_location_GpsLocationProvider_agps_set_id(JNIEnv *env, |
| 418 | jobject obj, jint type, jstring setid_string) |
| 419 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 420 | if (!sAGpsRilInterface) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 421 | ALOGE("no AGPS RIL interface in agps_set_id"); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 422 | return; |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 423 | } |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 424 | |
| 425 | const char *setid = env->GetStringUTFChars(setid_string, NULL); |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 426 | sAGpsRilInterface->set_set_id(type, setid); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 427 | env->ReleaseStringUTFChars(setid_string, setid); |
| 428 | } |
| 429 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 430 | static jint android_location_GpsLocationProvider_read_nmea(JNIEnv* env, jobject obj, |
| 431 | jbyteArray nmeaArray, jint buffer_size) |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 432 | { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 433 | // this should only be called from within a call to reportNmea |
| 434 | jbyte* nmea = (jbyte *)env->GetPrimitiveArrayCritical(nmeaArray, 0); |
| 435 | int length = sNmeaStringLength; |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 436 | if (length > buffer_size) |
| 437 | length = buffer_size; |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 438 | memcpy(nmea, sNmeaString, length); |
| 439 | env->ReleasePrimitiveArrayCritical(nmeaArray, nmea, JNI_ABORT); |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 440 | return length; |
| 441 | } |
| 442 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 443 | static void android_location_GpsLocationProvider_inject_time(JNIEnv* env, jobject obj, |
| 444 | jlong time, jlong timeReference, jint uncertainty) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 445 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 446 | if (sGpsInterface) |
| 447 | sGpsInterface->inject_time(time, timeReference, uncertainty); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | } |
| 449 | |
Mike Lockwood | d26ce0d | 2009-06-11 12:25:46 -0400 | [diff] [blame] | 450 | static void android_location_GpsLocationProvider_inject_location(JNIEnv* env, jobject obj, |
| 451 | jdouble latitude, jdouble longitude, jfloat accuracy) |
| 452 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 453 | if (sGpsInterface) |
| 454 | sGpsInterface->inject_location(latitude, longitude, accuracy); |
Mike Lockwood | d26ce0d | 2009-06-11 12:25:46 -0400 | [diff] [blame] | 455 | } |
| 456 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 457 | static jboolean android_location_GpsLocationProvider_supports_xtra(JNIEnv* env, jobject obj) |
| 458 | { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | return (sGpsXtraInterface != NULL); |
| 460 | } |
| 461 | |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 462 | static void android_location_GpsLocationProvider_inject_xtra_data(JNIEnv* env, jobject obj, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | jbyteArray data, jint length) |
| 464 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 465 | if (!sGpsXtraInterface) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 466 | ALOGE("no XTRA interface in inject_xtra_data"); |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 467 | return; |
| 468 | } |
| 469 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 470 | jbyte* bytes = (jbyte *)env->GetPrimitiveArrayCritical(data, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | sGpsXtraInterface->inject_xtra_data((char *)bytes, length); |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 472 | env->ReleasePrimitiveArrayCritical(data, bytes, JNI_ABORT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 473 | } |
| 474 | |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 475 | static void android_location_GpsLocationProvider_agps_data_conn_open(JNIEnv* env, jobject obj, jstring apn) |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 476 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 477 | if (!sAGpsInterface) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 478 | ALOGE("no AGPS interface in agps_data_conn_open"); |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 479 | return; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 480 | } |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 481 | if (apn == NULL) { |
| 482 | jniThrowException(env, "java/lang/IllegalArgumentException", NULL); |
| 483 | return; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 484 | } |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 485 | const char *apnStr = env->GetStringUTFChars(apn, NULL); |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 486 | sAGpsInterface->data_conn_open(apnStr); |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 487 | env->ReleaseStringUTFChars(apn, apnStr); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 490 | static void android_location_GpsLocationProvider_agps_data_conn_closed(JNIEnv* env, jobject obj) |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 491 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 492 | if (!sAGpsInterface) { |
Magnus Eriksson | 160c1ca | 2012-12-21 21:07:28 +0100 | [diff] [blame] | 493 | ALOGE("no AGPS interface in agps_data_conn_closed"); |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 494 | return; |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 495 | } |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 496 | sAGpsInterface->data_conn_closed(); |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 497 | } |
| 498 | |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 499 | static void android_location_GpsLocationProvider_agps_data_conn_failed(JNIEnv* env, jobject obj) |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 500 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 501 | if (!sAGpsInterface) { |
Magnus Eriksson | 160c1ca | 2012-12-21 21:07:28 +0100 | [diff] [blame] | 502 | ALOGE("no AGPS interface in agps_data_conn_failed"); |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 503 | return; |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 504 | } |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 505 | sAGpsInterface->data_conn_failed(); |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 506 | } |
| 507 | |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 508 | static void android_location_GpsLocationProvider_set_agps_server(JNIEnv* env, jobject obj, |
Mike Lockwood | a9e5461 | 2009-06-19 14:54:42 -0400 | [diff] [blame] | 509 | jint type, jstring hostname, jint port) |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 510 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 511 | if (!sAGpsInterface) { |
Magnus Eriksson | 160c1ca | 2012-12-21 21:07:28 +0100 | [diff] [blame] | 512 | ALOGE("no AGPS interface in set_agps_server"); |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 513 | return; |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 514 | } |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 515 | const char *c_hostname = env->GetStringUTFChars(hostname, NULL); |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 516 | sAGpsInterface->set_server(type, c_hostname, port); |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 517 | env->ReleaseStringUTFChars(hostname, c_hostname); |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 518 | } |
| 519 | |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 520 | static void android_location_GpsLocationProvider_send_ni_response(JNIEnv* env, jobject obj, |
| 521 | jint notifId, jint response) |
| 522 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 523 | if (!sGpsNiInterface) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 524 | ALOGE("no NI interface in send_ni_response"); |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 525 | return; |
Fred Fettinger | 3c8fbdf | 2010-01-04 15:38:13 -0600 | [diff] [blame] | 526 | } |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 527 | |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 528 | sGpsNiInterface->respond(notifId, response); |
Fred Fettinger | 3c8fbdf | 2010-01-04 15:38:13 -0600 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | static jstring android_location_GpsLocationProvider_get_internal_state(JNIEnv* env, jobject obj) |
| 532 | { |
| 533 | jstring result = NULL; |
| 534 | if (sGpsDebugInterface) { |
| 535 | const size_t maxLength = 2047; |
| 536 | char buffer[maxLength+1]; |
| 537 | size_t length = sGpsDebugInterface->get_internal_state(buffer, maxLength); |
| 538 | if (length > maxLength) length = maxLength; |
| 539 | buffer[length] = 0; |
| 540 | result = env->NewStringUTF(buffer); |
| 541 | } |
| 542 | return result; |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 543 | } |
| 544 | |
Mike Lockwood | 50130bb | 2010-10-11 06:22:50 -0400 | [diff] [blame] | 545 | static void android_location_GpsLocationProvider_update_network_state(JNIEnv* env, jobject obj, |
Kevin Tang | a5fe6b2 | 2011-06-05 14:25:16 -0700 | [diff] [blame] | 546 | jboolean connected, int type, jboolean roaming, jboolean available, jstring extraInfo, jstring apn) |
Mike Lockwood | 50130bb | 2010-10-11 06:22:50 -0400 | [diff] [blame] | 547 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 548 | |
| 549 | if (sAGpsRilInterface && sAGpsRilInterface->update_network_state) { |
Mike Lockwood | 50130bb | 2010-10-11 06:22:50 -0400 | [diff] [blame] | 550 | if (extraInfo) { |
| 551 | const char *extraInfoStr = env->GetStringUTFChars(extraInfo, NULL); |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 552 | sAGpsRilInterface->update_network_state(connected, type, roaming, extraInfoStr); |
Mike Lockwood | 50130bb | 2010-10-11 06:22:50 -0400 | [diff] [blame] | 553 | env->ReleaseStringUTFChars(extraInfo, extraInfoStr); |
| 554 | } else { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 555 | sAGpsRilInterface->update_network_state(connected, type, roaming, NULL); |
Mike Lockwood | 50130bb | 2010-10-11 06:22:50 -0400 | [diff] [blame] | 556 | } |
Kevin Tang | a5fe6b2 | 2011-06-05 14:25:16 -0700 | [diff] [blame] | 557 | |
| 558 | // update_network_availability callback was not included in original AGpsRilInterface |
| 559 | if (sAGpsRilInterface->size >= sizeof(AGpsRilInterface) |
| 560 | && sAGpsRilInterface->update_network_availability) { |
| 561 | const char *c_apn = env->GetStringUTFChars(apn, NULL); |
| 562 | sAGpsRilInterface->update_network_availability(available, c_apn); |
| 563 | env->ReleaseStringUTFChars(apn, c_apn); |
| 564 | } |
Mike Lockwood | 50130bb | 2010-10-11 06:22:50 -0400 | [diff] [blame] | 565 | } |
| 566 | } |
| 567 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 568 | static JNINativeMethod sMethods[] = { |
| 569 | /* name, signature, funcPtr */ |
| 570 | {"class_init_native", "()V", (void *)android_location_GpsLocationProvider_class_init_native}, |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 571 | {"native_is_supported", "()Z", (void*)android_location_GpsLocationProvider_is_supported}, |
| 572 | {"native_init", "()Z", (void*)android_location_GpsLocationProvider_init}, |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 573 | {"native_cleanup", "()V", (void*)android_location_GpsLocationProvider_cleanup}, |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 574 | {"native_set_position_mode", "(IIIII)Z", (void*)android_location_GpsLocationProvider_set_position_mode}, |
| 575 | {"native_start", "()Z", (void*)android_location_GpsLocationProvider_start}, |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 576 | {"native_stop", "()Z", (void*)android_location_GpsLocationProvider_stop}, |
| 577 | {"native_delete_aiding_data", "(I)V", (void*)android_location_GpsLocationProvider_delete_aiding_data}, |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 578 | {"native_read_sv_status", "([I[F[F[F[I)I", (void*)android_location_GpsLocationProvider_read_sv_status}, |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 579 | {"native_read_nmea", "([BI)I", (void*)android_location_GpsLocationProvider_read_nmea}, |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 580 | {"native_inject_time", "(JJI)V", (void*)android_location_GpsLocationProvider_inject_time}, |
Mike Lockwood | d26ce0d | 2009-06-11 12:25:46 -0400 | [diff] [blame] | 581 | {"native_inject_location", "(DDF)V", (void*)android_location_GpsLocationProvider_inject_location}, |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 582 | {"native_supports_xtra", "()Z", (void*)android_location_GpsLocationProvider_supports_xtra}, |
| 583 | {"native_inject_xtra_data", "([BI)V", (void*)android_location_GpsLocationProvider_inject_xtra_data}, |
| 584 | {"native_agps_data_conn_open", "(Ljava/lang/String;)V", (void*)android_location_GpsLocationProvider_agps_data_conn_open}, |
| 585 | {"native_agps_data_conn_closed", "()V", (void*)android_location_GpsLocationProvider_agps_data_conn_closed}, |
| 586 | {"native_agps_data_conn_failed", "()V", (void*)android_location_GpsLocationProvider_agps_data_conn_failed}, |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 587 | {"native_agps_set_id","(ILjava/lang/String;)V",(void*)android_location_GpsLocationProvider_agps_set_id}, |
| 588 | {"native_agps_set_ref_location_cellid","(IIIII)V",(void*)android_location_GpsLocationProvider_agps_set_reference_location_cellid}, |
Mike Lockwood | a9e5461 | 2009-06-19 14:54:42 -0400 | [diff] [blame] | 589 | {"native_set_agps_server", "(ILjava/lang/String;I)V", (void*)android_location_GpsLocationProvider_set_agps_server}, |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 590 | {"native_send_ni_response", "(II)V", (void*)android_location_GpsLocationProvider_send_ni_response}, |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 591 | {"native_agps_ni_message", "([BI)V", (void *)android_location_GpsLocationProvider_agps_send_ni_message}, |
Fred Fettinger | 3c8fbdf | 2010-01-04 15:38:13 -0600 | [diff] [blame] | 592 | {"native_get_internal_state", "()Ljava/lang/String;", (void*)android_location_GpsLocationProvider_get_internal_state}, |
Kevin Tang | a5fe6b2 | 2011-06-05 14:25:16 -0700 | [diff] [blame] | 593 | {"native_update_network_state", "(ZIZZLjava/lang/String;Ljava/lang/String;)V", (void*)android_location_GpsLocationProvider_update_network_state }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | }; |
| 595 | |
Mike Lockwood | 00b7427 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 596 | int register_android_server_location_GpsLocationProvider(JNIEnv* env) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 597 | { |
Mike Lockwood | 00b7427 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 598 | return jniRegisterNativeMethods(env, "com/android/server/location/GpsLocationProvider", sMethods, NELEM(sMethods)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | } /* namespace android */ |