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 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 17 | #define LOG_TAG "GnssLocationProvider" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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" |
Lifu Tang | a8b7bb5 | 2016-01-26 01:22:10 -0800 | [diff] [blame] | 24 | #include "hardware/gps_internal.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" |
Ruben Brunk | 87eac99 | 2013-09-09 17:44:59 -0700 | [diff] [blame] | 29 | #include "android_runtime/Log.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | |
destradaa | 931a37f | 2014-08-12 16:36:59 -0700 | [diff] [blame] | 31 | #include <arpa/inet.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | #include <string.h> |
| 33 | #include <pthread.h> |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 34 | #include <linux/in.h> |
| 35 | #include <linux/in6.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 37 | static jobject mCallbacksObj = NULL; |
| 38 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | static jmethodID method_reportLocation; |
| 40 | static jmethodID method_reportStatus; |
| 41 | static jmethodID method_reportSvStatus; |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 42 | static jmethodID method_reportAGpsStatus; |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 43 | static jmethodID method_reportNmea; |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 44 | static jmethodID method_setEngineCapabilities; |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 45 | static jmethodID method_setGpsYearOfHardware; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | static jmethodID method_xtraDownloadRequest; |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 47 | static jmethodID method_reportNiNotification; |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 48 | static jmethodID method_requestRefLocation; |
| 49 | static jmethodID method_requestSetID; |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 50 | static jmethodID method_requestUtcTime; |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 51 | static jmethodID method_reportGeofenceTransition; |
| 52 | static jmethodID method_reportGeofenceStatus; |
| 53 | static jmethodID method_reportGeofenceAddStatus; |
| 54 | static jmethodID method_reportGeofenceRemoveStatus; |
| 55 | static jmethodID method_reportGeofencePauseStatus; |
| 56 | static jmethodID method_reportGeofenceResumeStatus; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 57 | static jmethodID method_reportMeasurementData; |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 58 | static jmethodID method_reportNavigationMessages; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | |
| 60 | static const GpsInterface* sGpsInterface = NULL; |
| 61 | static const GpsXtraInterface* sGpsXtraInterface = NULL; |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 62 | static const AGpsInterface* sAGpsInterface = NULL; |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 63 | static const GpsNiInterface* sGpsNiInterface = NULL; |
Fred Fettinger | 3c8fbdf | 2010-01-04 15:38:13 -0600 | [diff] [blame] | 64 | static const GpsDebugInterface* sGpsDebugInterface = NULL; |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 65 | static const AGpsRilInterface* sAGpsRilInterface = NULL; |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 66 | static const GpsGeofencingInterface* sGpsGeofencingInterface = NULL; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 67 | static const GpsMeasurementInterface* sGpsMeasurementInterface = NULL; |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 68 | static const GpsNavigationMessageInterface* sGpsNavigationMessageInterface = NULL; |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 69 | static const GnssConfigurationInterface* sGnssConfigurationInterface = NULL; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 71 | #define MAX_SATELLITE_COUNT 512 |
Lifu Tang | a8b7bb5 | 2016-01-26 01:22:10 -0800 | [diff] [blame] | 72 | #define MAX_GPS_SATELLITE_COUNT 512 |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 73 | |
| 74 | #define PRN_SHIFT_WIDTH 3 |
| 75 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 76 | // temporary storage for GPS callbacks |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 77 | static GnssSvInfo sGnssSvList[MAX_SATELLITE_COUNT]; |
| 78 | static size_t sGnssSvListSize; |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 79 | static const char* sNmeaString; |
| 80 | static int sNmeaStringLength; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | |
Mike Lockwood | 8f5a800 | 2010-04-07 09:05:26 -0400 | [diff] [blame] | 82 | #define WAKE_LOCK_NAME "GPS" |
| 83 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | namespace android { |
| 85 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 86 | static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) { |
| 87 | if (env->ExceptionCheck()) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 88 | ALOGE("An exception was thrown by callback '%s'.", methodName); |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 89 | LOGE_EX(env); |
| 90 | env->ExceptionClear(); |
| 91 | } |
| 92 | } |
| 93 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | static void location_callback(GpsLocation* location) |
| 95 | { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 96 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 97 | env->CallVoidMethod(mCallbacksObj, method_reportLocation, location->flags, |
| 98 | (jdouble)location->latitude, (jdouble)location->longitude, |
| 99 | (jdouble)location->altitude, |
| 100 | (jfloat)location->speed, (jfloat)location->bearing, |
| 101 | (jfloat)location->accuracy, (jlong)location->timestamp); |
| 102 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | static void status_callback(GpsStatus* status) |
| 106 | { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 107 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 108 | env->CallVoidMethod(mCallbacksObj, method_reportStatus, status->status); |
| 109 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | static void sv_status_callback(GpsSvStatus* sv_status) |
| 113 | { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 114 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 115 | size_t status_size = sv_status->size; |
| 116 | // Some drive doesn't set the size field correctly. Assume GpsSvStatus_v1 if |
| 117 | // it doesn't provide a valid size. |
| 118 | if (status_size == 0) { |
| 119 | status_size = sizeof(GpsSvStatus_v1); |
| 120 | } |
Lifu Tang | a8b7bb5 | 2016-01-26 01:22:10 -0800 | [diff] [blame] | 121 | if (status_size == sizeof(GpsSvStatus)) { |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 122 | sGnssSvListSize = sv_status->gnss_sv_list_size; |
| 123 | // Cramp the list size |
| 124 | if (sGnssSvListSize > MAX_SATELLITE_COUNT) { |
| 125 | sGnssSvListSize = MAX_SATELLITE_COUNT; |
| 126 | } |
| 127 | // Copy GNSS SV info into sGnssSvList, if any. |
| 128 | if (sGnssSvListSize > 0 && sv_status->gnss_sv_list) { |
| 129 | memcpy(sGnssSvList, sv_status->gnss_sv_list, sizeof(GnssSvInfo) * sGnssSvListSize); |
| 130 | } |
| 131 | } else if (status_size == sizeof(GpsSvStatus_v1)) { |
| 132 | sGnssSvListSize = sv_status->num_svs; |
Lifu Tang | a8b7bb5 | 2016-01-26 01:22:10 -0800 | [diff] [blame] | 133 | // Cramp the list size |
| 134 | if (sGnssSvListSize > MAX_GPS_SATELLITE_COUNT) { |
| 135 | sGnssSvListSize = MAX_GPS_SATELLITE_COUNT; |
| 136 | } |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 137 | uint32_t ephemeris_mask = sv_status->ephemeris_mask; |
| 138 | uint32_t almanac_mask = sv_status->almanac_mask; |
| 139 | uint32_t used_in_fix_mask = sv_status->used_in_fix_mask; |
| 140 | for (size_t i = 0; i < sGnssSvListSize; i++) { |
| 141 | GnssSvInfo& info = sGnssSvList[i]; |
| 142 | info.constellation = GNSS_CONSTELLATION_GPS; |
| 143 | info.prn = sv_status->sv_list[i].prn; |
| 144 | info.snr = sv_status->sv_list[i].snr; |
| 145 | info.elevation = sv_status->sv_list[i].elevation; |
| 146 | info.azimuth = sv_status->sv_list[i].azimuth; |
| 147 | info.flags = GNSS_SV_FLAGS_NONE; |
Lifu Tang | a8b7bb5 | 2016-01-26 01:22:10 -0800 | [diff] [blame] | 148 | if (info.prn > 0 && info.prn <= 32) { |
| 149 | int32_t this_prn_mask = (1 << (info.prn - 1)); |
| 150 | if ((ephemeris_mask & this_prn_mask) != 0) { |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 151 | info.flags |= GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA; |
Lifu Tang | a8b7bb5 | 2016-01-26 01:22:10 -0800 | [diff] [blame] | 152 | } |
| 153 | if ((almanac_mask & this_prn_mask) != 0) { |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 154 | info.flags |= GNSS_SV_FLAGS_HAS_ALMANAC_DATA; |
Lifu Tang | a8b7bb5 | 2016-01-26 01:22:10 -0800 | [diff] [blame] | 155 | } |
| 156 | if ((used_in_fix_mask & this_prn_mask) != 0) { |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 157 | info.flags |= GNSS_SV_FLAGS_USED_IN_FIX; |
Lifu Tang | a8b7bb5 | 2016-01-26 01:22:10 -0800 | [diff] [blame] | 158 | } |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | } else { |
| 162 | sGnssSvListSize = 0; |
| 163 | ALOGE("Invalid size of GpsSvStatus found: %zd.", status_size); |
| 164 | return; |
| 165 | } |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 166 | env->CallVoidMethod(mCallbacksObj, method_reportSvStatus); |
| 167 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 170 | static void nmea_callback(GpsUtcTime timestamp, const char* nmea, int length) |
| 171 | { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 172 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 173 | // The Java code will call back to read these values |
| 174 | // We do this to avoid creating unnecessary String objects |
| 175 | sNmeaString = nmea; |
| 176 | sNmeaStringLength = length; |
| 177 | env->CallVoidMethod(mCallbacksObj, method_reportNmea, timestamp); |
| 178 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 179 | } |
| 180 | |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 181 | static void set_system_info_callback(const GpsSystemInfo* info) { |
| 182 | ALOGD("set_system_info_callback: year_of_hw=%d\n", info->year_of_hw); |
| 183 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 184 | env->CallVoidMethod(mCallbacksObj, method_setGpsYearOfHardware, |
| 185 | info->year_of_hw); |
| 186 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 187 | } |
| 188 | |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 189 | static void set_capabilities_callback(uint32_t capabilities) |
| 190 | { |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 191 | ALOGD("set_capabilities_callback: %du\n", capabilities); |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 192 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 193 | env->CallVoidMethod(mCallbacksObj, method_setEngineCapabilities, capabilities); |
| 194 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 195 | } |
| 196 | |
Mike Lockwood | 8f5a800 | 2010-04-07 09:05:26 -0400 | [diff] [blame] | 197 | static void acquire_wakelock_callback() |
| 198 | { |
| 199 | acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_NAME); |
| 200 | } |
| 201 | |
| 202 | static void release_wakelock_callback() |
| 203 | { |
| 204 | release_wake_lock(WAKE_LOCK_NAME); |
| 205 | } |
| 206 | |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 207 | static void request_utc_time_callback() |
| 208 | { |
| 209 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 210 | env->CallVoidMethod(mCallbacksObj, method_requestUtcTime); |
| 211 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 212 | } |
| 213 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 214 | 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] | 215 | { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 216 | return (pthread_t)AndroidRuntime::createJavaThread(name, start, arg); |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 217 | } |
| 218 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | GpsCallbacks sGpsCallbacks = { |
Mike Lockwood | 8f5a800 | 2010-04-07 09:05:26 -0400 | [diff] [blame] | 220 | sizeof(GpsCallbacks), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | location_callback, |
| 222 | status_callback, |
| 223 | sv_status_callback, |
Mike Lockwood | 8f5a800 | 2010-04-07 09:05:26 -0400 | [diff] [blame] | 224 | nmea_callback, |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 225 | set_capabilities_callback, |
Mike Lockwood | 8f5a800 | 2010-04-07 09:05:26 -0400 | [diff] [blame] | 226 | acquire_wakelock_callback, |
| 227 | release_wakelock_callback, |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 228 | create_thread_callback, |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 229 | request_utc_time_callback, |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 230 | set_system_info_callback, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | }; |
| 232 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 233 | static void xtra_download_request_callback() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 235 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 236 | env->CallVoidMethod(mCallbacksObj, method_xtraDownloadRequest); |
| 237 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 238 | } |
| 239 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | GpsXtraCallbacks sGpsXtraCallbacks = { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 241 | xtra_download_request_callback, |
| 242 | create_thread_callback, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | }; |
| 244 | |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 245 | static jbyteArray convert_to_ipv4(uint32_t ip, bool net_order) |
| 246 | { |
| 247 | if (INADDR_NONE == ip) { |
| 248 | return NULL; |
| 249 | } |
| 250 | |
| 251 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 252 | jbyteArray byteArray = env->NewByteArray(4); |
| 253 | if (byteArray == NULL) { |
| 254 | ALOGE("Unable to allocate byte array for IPv4 address"); |
| 255 | return NULL; |
| 256 | } |
| 257 | |
| 258 | jbyte ipv4[4]; |
| 259 | if (net_order) { |
destradaa | 931a37f | 2014-08-12 16:36:59 -0700 | [diff] [blame] | 260 | ALOGV("Converting IPv4 address(net_order) %x", ip); |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 261 | memcpy(ipv4, &ip, sizeof(ipv4)); |
| 262 | } else { |
destradaa | 931a37f | 2014-08-12 16:36:59 -0700 | [diff] [blame] | 263 | ALOGV("Converting IPv4 address(host_order) %x", ip); |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 264 | //endianess transparent conversion from int to char[] |
| 265 | ipv4[0] = (jbyte) (ip & 0xFF); |
| 266 | ipv4[1] = (jbyte)((ip>>8) & 0xFF); |
| 267 | ipv4[2] = (jbyte)((ip>>16) & 0xFF); |
| 268 | ipv4[3] = (jbyte) (ip>>24); |
| 269 | } |
| 270 | |
| 271 | env->SetByteArrayRegion(byteArray, 0, 4, (const jbyte*) ipv4); |
| 272 | return byteArray; |
| 273 | } |
| 274 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 275 | static void agps_status_callback(AGpsStatus* agps_status) |
| 276 | { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 277 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 278 | jbyteArray byteArray = NULL; |
| 279 | bool isSupported = false; |
Stephen Li | 8efd74d | 2011-03-01 20:56:00 -0800 | [diff] [blame] | 280 | |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 281 | size_t status_size = agps_status->size; |
Lifu Tang | a8b7bb5 | 2016-01-26 01:22:10 -0800 | [diff] [blame] | 282 | if (status_size == sizeof(AGpsStatus)) { |
Bernhard Rosenkränzer | 46c82b4 | 2014-11-30 11:04:10 +0100 | [diff] [blame] | 283 | ALOGV("AGpsStatus is V3: %zd", status_size); |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 284 | switch (agps_status->addr.ss_family) |
| 285 | { |
| 286 | case AF_INET: |
| 287 | { |
| 288 | struct sockaddr_in *in = (struct sockaddr_in*)&(agps_status->addr); |
destradaa | ce48c1c | 2015-05-29 13:47:39 -0700 | [diff] [blame] | 289 | uint32_t ipAddr = *(uint32_t*)&(in->sin_addr); |
| 290 | byteArray = convert_to_ipv4(ipAddr, true /* net_order */); |
| 291 | if (ipAddr == INADDR_NONE || byteArray != NULL) { |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 292 | isSupported = true; |
| 293 | } |
destradaa | 931a37f | 2014-08-12 16:36:59 -0700 | [diff] [blame] | 294 | IF_ALOGD() { |
| 295 | // log the IP for reference in case there is a bogus value pushed by HAL |
| 296 | char str[INET_ADDRSTRLEN]; |
| 297 | inet_ntop(AF_INET, &(in->sin_addr), str, INET_ADDRSTRLEN); |
| 298 | ALOGD("AGPS IP is v4: %s", str); |
| 299 | } |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 300 | } |
| 301 | break; |
| 302 | case AF_INET6: |
| 303 | { |
| 304 | struct sockaddr_in6 *in6 = (struct sockaddr_in6*)&(agps_status->addr); |
| 305 | byteArray = env->NewByteArray(16); |
| 306 | if (byteArray != NULL) { |
| 307 | env->SetByteArrayRegion(byteArray, 0, 16, (const jbyte *)&(in6->sin6_addr)); |
| 308 | isSupported = true; |
| 309 | } else { |
| 310 | ALOGE("Unable to allocate byte array for IPv6 address."); |
| 311 | } |
destradaa | 931a37f | 2014-08-12 16:36:59 -0700 | [diff] [blame] | 312 | IF_ALOGD() { |
| 313 | // log the IP for reference in case there is a bogus value pushed by HAL |
| 314 | char str[INET6_ADDRSTRLEN]; |
| 315 | inet_ntop(AF_INET6, &(in6->sin6_addr), str, INET6_ADDRSTRLEN); |
| 316 | ALOGD("AGPS IP is v6: %s", str); |
| 317 | } |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 318 | } |
| 319 | break; |
| 320 | default: |
| 321 | ALOGE("Invalid ss_family found: %d", agps_status->addr.ss_family); |
| 322 | break; |
| 323 | } |
| 324 | } else if (status_size >= sizeof(AGpsStatus_v2)) { |
Bernhard Rosenkränzer | 46c82b4 | 2014-11-30 11:04:10 +0100 | [diff] [blame] | 325 | ALOGV("AGpsStatus is V2+: %zd", status_size); |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 326 | // for back-compatibility reasons we check in v2 that the data structure size is greater or |
| 327 | // equal to the declared size in gps.h |
| 328 | uint32_t ipaddr = agps_status->ipaddr; |
destradaa | 931a37f | 2014-08-12 16:36:59 -0700 | [diff] [blame] | 329 | ALOGV("AGPS IP is v4: %x", ipaddr); |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 330 | byteArray = convert_to_ipv4(ipaddr, false /* net_order */); |
| 331 | if (ipaddr == INADDR_NONE || byteArray != NULL) { |
| 332 | isSupported = true; |
| 333 | } |
| 334 | } else if (status_size >= sizeof(AGpsStatus_v1)) { |
Bernhard Rosenkränzer | 46c82b4 | 2014-11-30 11:04:10 +0100 | [diff] [blame] | 335 | ALOGV("AGpsStatus is V1+: %zd", status_size); |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 336 | // because we have to check for >= with regards to v2, we also need to relax the check here |
| 337 | // and only make sure that the size is at least what we expect |
| 338 | isSupported = true; |
| 339 | } else { |
Bernhard Rosenkränzer | 46c82b4 | 2014-11-30 11:04:10 +0100 | [diff] [blame] | 340 | ALOGE("Invalid size of AGpsStatus found: %zd.", status_size); |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | if (isSupported) { |
destradaa | 931a37f | 2014-08-12 16:36:59 -0700 | [diff] [blame] | 344 | jsize byteArrayLength = byteArray != NULL ? env->GetArrayLength(byteArray) : 0; |
| 345 | ALOGV("Passing AGPS IP addr: size %d", byteArrayLength); |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 346 | env->CallVoidMethod(mCallbacksObj, method_reportAGpsStatus, agps_status->type, |
| 347 | agps_status->status, byteArray); |
| 348 | |
| 349 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 350 | } else { |
| 351 | ALOGD("Skipping calling method_reportAGpsStatus."); |
| 352 | } |
| 353 | |
| 354 | if (byteArray) { |
| 355 | env->DeleteLocalRef(byteArray); |
| 356 | } |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 359 | AGpsCallbacks sAGpsCallbacks = { |
| 360 | agps_status_callback, |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 361 | create_thread_callback, |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 362 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 364 | static void gps_ni_notify_callback(GpsNiNotification *notification) |
| 365 | { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 366 | ALOGD("gps_ni_notify_callback\n"); |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 367 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 368 | jstring requestor_id = env->NewStringUTF(notification->requestor_id); |
| 369 | jstring text = env->NewStringUTF(notification->text); |
| 370 | jstring extras = env->NewStringUTF(notification->extras); |
| 371 | |
| 372 | if (requestor_id && text && extras) { |
| 373 | env->CallVoidMethod(mCallbacksObj, method_reportNiNotification, |
| 374 | notification->notification_id, notification->ni_type, |
| 375 | notification->notify_flags, notification->timeout, |
| 376 | notification->default_response, requestor_id, text, |
| 377 | notification->requestor_id_encoding, |
| 378 | notification->text_encoding, extras); |
| 379 | } else { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 380 | ALOGE("out of memory in gps_ni_notify_callback\n"); |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | if (requestor_id) |
| 384 | env->DeleteLocalRef(requestor_id); |
| 385 | if (text) |
| 386 | env->DeleteLocalRef(text); |
| 387 | if (extras) |
| 388 | env->DeleteLocalRef(extras); |
| 389 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 390 | } |
| 391 | |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 392 | GpsNiCallbacks sGpsNiCallbacks = { |
| 393 | gps_ni_notify_callback, |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 394 | create_thread_callback, |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 395 | }; |
| 396 | |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 397 | static void agps_request_set_id(uint32_t flags) |
| 398 | { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 399 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 400 | env->CallVoidMethod(mCallbacksObj, method_requestSetID, flags); |
| 401 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 402 | } |
| 403 | |
| 404 | static void agps_request_ref_location(uint32_t flags) |
| 405 | { |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 406 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 407 | env->CallVoidMethod(mCallbacksObj, method_requestRefLocation, flags); |
| 408 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 409 | } |
| 410 | |
| 411 | AGpsRilCallbacks sAGpsRilCallbacks = { |
| 412 | agps_request_set_id, |
| 413 | agps_request_ref_location, |
| 414 | create_thread_callback, |
| 415 | }; |
| 416 | |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 417 | static void gps_geofence_transition_callback(int32_t geofence_id, GpsLocation* location, |
| 418 | int32_t transition, GpsUtcTime timestamp) |
| 419 | { |
| 420 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 421 | |
| 422 | env->CallVoidMethod(mCallbacksObj, method_reportGeofenceTransition, geofence_id, |
| 423 | location->flags, (jdouble)location->latitude, (jdouble)location->longitude, |
| 424 | (jdouble)location->altitude, |
| 425 | (jfloat)location->speed, (jfloat)location->bearing, |
| 426 | (jfloat)location->accuracy, (jlong)location->timestamp, |
| 427 | transition, timestamp); |
| 428 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 429 | }; |
| 430 | |
| 431 | static void gps_geofence_status_callback(int32_t status, GpsLocation* location) |
| 432 | { |
| 433 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 434 | jint flags = 0; |
| 435 | jdouble latitude = 0; |
| 436 | jdouble longitude = 0; |
| 437 | jdouble altitude = 0; |
| 438 | jfloat speed = 0; |
| 439 | jfloat bearing = 0; |
| 440 | jfloat accuracy = 0; |
| 441 | jlong timestamp = 0; |
| 442 | if (location != NULL) { |
| 443 | flags = location->flags; |
| 444 | latitude = location->latitude; |
| 445 | longitude = location->longitude; |
| 446 | altitude = location->altitude; |
| 447 | speed = location->speed; |
| 448 | bearing = location->bearing; |
| 449 | accuracy = location->accuracy; |
| 450 | timestamp = location->timestamp; |
| 451 | } |
| 452 | |
| 453 | env->CallVoidMethod(mCallbacksObj, method_reportGeofenceStatus, status, |
| 454 | flags, latitude, longitude, altitude, speed, bearing, accuracy, timestamp); |
| 455 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 456 | }; |
| 457 | |
| 458 | static void gps_geofence_add_callback(int32_t geofence_id, int32_t status) |
| 459 | { |
| 460 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 461 | if (status != GPS_GEOFENCE_OPERATION_SUCCESS) { |
| 462 | ALOGE("Error in geofence_add_callback: %d\n", status); |
| 463 | } |
| 464 | env->CallVoidMethod(mCallbacksObj, method_reportGeofenceAddStatus, geofence_id, status); |
| 465 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 466 | }; |
| 467 | |
| 468 | static void gps_geofence_remove_callback(int32_t geofence_id, int32_t status) |
| 469 | { |
| 470 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 471 | if (status != GPS_GEOFENCE_OPERATION_SUCCESS) { |
| 472 | ALOGE("Error in geofence_remove_callback: %d\n", status); |
| 473 | } |
| 474 | env->CallVoidMethod(mCallbacksObj, method_reportGeofenceRemoveStatus, geofence_id, status); |
| 475 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 476 | }; |
| 477 | |
| 478 | static void gps_geofence_resume_callback(int32_t geofence_id, int32_t status) |
| 479 | { |
| 480 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 481 | if (status != GPS_GEOFENCE_OPERATION_SUCCESS) { |
| 482 | ALOGE("Error in geofence_resume_callback: %d\n", status); |
| 483 | } |
| 484 | env->CallVoidMethod(mCallbacksObj, method_reportGeofenceResumeStatus, geofence_id, status); |
| 485 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 486 | }; |
| 487 | |
| 488 | static void gps_geofence_pause_callback(int32_t geofence_id, int32_t status) |
| 489 | { |
| 490 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 491 | if (status != GPS_GEOFENCE_OPERATION_SUCCESS) { |
| 492 | ALOGE("Error in geofence_pause_callback: %d\n", status); |
| 493 | } |
| 494 | env->CallVoidMethod(mCallbacksObj, method_reportGeofencePauseStatus, geofence_id, status); |
| 495 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 496 | }; |
| 497 | |
| 498 | GpsGeofenceCallbacks sGpsGeofenceCallbacks = { |
| 499 | gps_geofence_transition_callback, |
| 500 | gps_geofence_status_callback, |
| 501 | gps_geofence_add_callback, |
| 502 | gps_geofence_remove_callback, |
| 503 | gps_geofence_pause_callback, |
| 504 | gps_geofence_resume_callback, |
| 505 | create_thread_callback, |
| 506 | }; |
| 507 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 508 | static void android_location_GnssLocationProvider_class_init_native(JNIEnv* env, jclass clazz) { |
Mike Lockwood | b7ff457 | 2010-04-05 15:24:34 -0400 | [diff] [blame] | 509 | int err; |
| 510 | hw_module_t* module; |
Mike Lockwood | b7ff457 | 2010-04-05 15:24:34 -0400 | [diff] [blame] | 511 | |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 512 | method_reportLocation = env->GetMethodID(clazz, "reportLocation", "(IDDDFFFJ)V"); |
| 513 | method_reportStatus = env->GetMethodID(clazz, "reportStatus", "(I)V"); |
| 514 | method_reportSvStatus = env->GetMethodID(clazz, "reportSvStatus", "()V"); |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 515 | method_reportAGpsStatus = env->GetMethodID(clazz, "reportAGpsStatus", "(II[B)V"); |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 516 | method_reportNmea = env->GetMethodID(clazz, "reportNmea", "(J)V"); |
| 517 | method_setEngineCapabilities = env->GetMethodID(clazz, "setEngineCapabilities", "(I)V"); |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 518 | method_setGpsYearOfHardware = env->GetMethodID(clazz, "setGpsYearOfHardware", "(I)V"); |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 519 | method_xtraDownloadRequest = env->GetMethodID(clazz, "xtraDownloadRequest", "()V"); |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 520 | method_reportNiNotification = env->GetMethodID(clazz, "reportNiNotification", |
| 521 | "(IIIIILjava/lang/String;Ljava/lang/String;IILjava/lang/String;)V"); |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 522 | method_requestRefLocation = env->GetMethodID(clazz,"requestRefLocation","(I)V"); |
| 523 | method_requestSetID = env->GetMethodID(clazz,"requestSetID","(I)V"); |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 524 | method_requestUtcTime = env->GetMethodID(clazz,"requestUtcTime","()V"); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 525 | method_reportGeofenceTransition = env->GetMethodID(clazz,"reportGeofenceTransition", |
| 526 | "(IIDDDFFFJIJ)V"); |
| 527 | method_reportGeofenceStatus = env->GetMethodID(clazz,"reportGeofenceStatus", |
| 528 | "(IIDDDFFFJ)V"); |
| 529 | method_reportGeofenceAddStatus = env->GetMethodID(clazz,"reportGeofenceAddStatus", |
| 530 | "(II)V"); |
| 531 | method_reportGeofenceRemoveStatus = env->GetMethodID(clazz,"reportGeofenceRemoveStatus", |
| 532 | "(II)V"); |
| 533 | method_reportGeofenceResumeStatus = env->GetMethodID(clazz,"reportGeofenceResumeStatus", |
| 534 | "(II)V"); |
| 535 | method_reportGeofencePauseStatus = env->GetMethodID(clazz,"reportGeofencePauseStatus", |
| 536 | "(II)V"); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 537 | method_reportMeasurementData = env->GetMethodID( |
| 538 | clazz, |
| 539 | "reportMeasurementData", |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 540 | "(Landroid/location/GnssMeasurementsEvent;)V"); |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 541 | method_reportNavigationMessages = env->GetMethodID( |
| 542 | clazz, |
| 543 | "reportNavigationMessage", |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 544 | "(Landroid/location/GnssNavigationMessageEvent;)V"); |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 545 | |
| 546 | err = hw_get_module(GPS_HARDWARE_MODULE_ID, (hw_module_t const**)&module); |
| 547 | if (err == 0) { |
| 548 | hw_device_t* device; |
| 549 | err = module->methods->open(module, GPS_HARDWARE_MODULE_ID, &device); |
| 550 | if (err == 0) { |
| 551 | gps_device_t* gps_device = (gps_device_t *)device; |
| 552 | sGpsInterface = gps_device->get_gps_interface(gps_device); |
| 553 | } |
| 554 | } |
| 555 | if (sGpsInterface) { |
| 556 | sGpsXtraInterface = |
| 557 | (const GpsXtraInterface*)sGpsInterface->get_extension(GPS_XTRA_INTERFACE); |
| 558 | sAGpsInterface = |
| 559 | (const AGpsInterface*)sGpsInterface->get_extension(AGPS_INTERFACE); |
| 560 | sGpsNiInterface = |
| 561 | (const GpsNiInterface*)sGpsInterface->get_extension(GPS_NI_INTERFACE); |
| 562 | sGpsDebugInterface = |
| 563 | (const GpsDebugInterface*)sGpsInterface->get_extension(GPS_DEBUG_INTERFACE); |
| 564 | sAGpsRilInterface = |
| 565 | (const AGpsRilInterface*)sGpsInterface->get_extension(AGPS_RIL_INTERFACE); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 566 | sGpsGeofencingInterface = |
| 567 | (const GpsGeofencingInterface*)sGpsInterface->get_extension(GPS_GEOFENCING_INTERFACE); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 568 | sGpsMeasurementInterface = |
| 569 | (const GpsMeasurementInterface*)sGpsInterface->get_extension(GPS_MEASUREMENT_INTERFACE); |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 570 | sGpsNavigationMessageInterface = |
| 571 | (const GpsNavigationMessageInterface*)sGpsInterface->get_extension( |
| 572 | GPS_NAVIGATION_MESSAGE_INTERFACE); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 573 | sGnssConfigurationInterface = |
| 574 | (const GnssConfigurationInterface*)sGpsInterface->get_extension( |
| 575 | GNSS_CONFIGURATION_INTERFACE); |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 576 | } |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 577 | } |
| 578 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 579 | static jboolean android_location_GnssLocationProvider_is_supported( |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 580 | JNIEnv* /* env */, jclass /* clazz */) |
| 581 | { |
| 582 | return (sGpsInterface != NULL) ? JNI_TRUE : JNI_FALSE; |
| 583 | } |
| 584 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 585 | static jboolean android_location_GnssLocationProvider_is_agps_ril_supported( |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 586 | JNIEnv* /* env */, jclass /* clazz */) |
| 587 | { |
| 588 | return (sAGpsRilInterface != NULL) ? JNI_TRUE : JNI_FALSE; |
| 589 | } |
| 590 | |
| 591 | static jboolean android_location_gpsLocationProvider_is_gnss_configuration_supported( |
| 592 | JNIEnv* /* env */, jclass /* jclazz */) |
| 593 | { |
| 594 | return (sGnssConfigurationInterface != NULL) ? JNI_TRUE : JNI_FALSE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 595 | } |
| 596 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 597 | static jboolean android_location_GnssLocationProvider_init(JNIEnv* env, jobject obj) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 598 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 599 | // this must be set before calling into the HAL library |
| 600 | if (!mCallbacksObj) |
| 601 | mCallbacksObj = env->NewGlobalRef(obj); |
| 602 | |
| 603 | // fail if the main interface fails to initialize |
| 604 | if (!sGpsInterface || sGpsInterface->init(&sGpsCallbacks) != 0) |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 605 | return JNI_FALSE; |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 606 | |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 607 | // if XTRA initialization fails we will disable it by sGpsXtraInterface to NULL, |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 608 | // but continue to allow the rest of the GPS interface to work. |
| 609 | if (sGpsXtraInterface && sGpsXtraInterface->init(&sGpsXtraCallbacks) != 0) |
| 610 | sGpsXtraInterface = NULL; |
| 611 | if (sAGpsInterface) |
| 612 | sAGpsInterface->init(&sAGpsCallbacks); |
| 613 | if (sGpsNiInterface) |
| 614 | sGpsNiInterface->init(&sGpsNiCallbacks); |
| 615 | if (sAGpsRilInterface) |
| 616 | sAGpsRilInterface->init(&sAGpsRilCallbacks); |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 617 | if (sGpsGeofencingInterface) |
| 618 | sGpsGeofencingInterface->init(&sGpsGeofenceCallbacks); |
Fred Fettinger | 3c8fbdf | 2010-01-04 15:38:13 -0600 | [diff] [blame] | 619 | |
Narayan Kamath | 87d6cd4 | 2014-01-08 12:26:28 +0000 | [diff] [blame] | 620 | return JNI_TRUE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | } |
| 622 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 623 | static void android_location_GnssLocationProvider_cleanup(JNIEnv* /* env */, jobject /* obj */) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 624 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 625 | if (sGpsInterface) |
| 626 | sGpsInterface->cleanup(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 627 | } |
| 628 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 629 | static jboolean android_location_GnssLocationProvider_set_position_mode(JNIEnv* /* env */, |
Andreas Gampe | 184e3ed | 2014-09-29 15:04:06 -0700 | [diff] [blame] | 630 | jobject /* obj */, jint mode, jint recurrence, jint min_interval, jint preferred_accuracy, |
| 631 | jint preferred_time) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | { |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 633 | if (sGpsInterface) { |
| 634 | if (sGpsInterface->set_position_mode(mode, recurrence, min_interval, preferred_accuracy, |
| 635 | preferred_time) == 0) { |
| 636 | return JNI_TRUE; |
| 637 | } else { |
| 638 | return JNI_FALSE; |
| 639 | } |
| 640 | } |
Mike Lockwood | 4270237 | 2010-10-10 16:04:18 -0400 | [diff] [blame] | 641 | else |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 642 | return JNI_FALSE; |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 643 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 644 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 645 | static jboolean android_location_GnssLocationProvider_start(JNIEnv* /* env */, jobject /* obj */) |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 646 | { |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 647 | if (sGpsInterface) { |
| 648 | if (sGpsInterface->start() == 0) { |
| 649 | return JNI_TRUE; |
| 650 | } else { |
| 651 | return JNI_FALSE; |
| 652 | } |
| 653 | } |
Mike Lockwood | 4270237 | 2010-10-10 16:04:18 -0400 | [diff] [blame] | 654 | else |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 655 | return JNI_FALSE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 656 | } |
| 657 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 658 | static jboolean android_location_GnssLocationProvider_stop(JNIEnv* /* env */, jobject /* obj */) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 659 | { |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 660 | if (sGpsInterface) { |
| 661 | if (sGpsInterface->stop() == 0) { |
| 662 | return JNI_TRUE; |
| 663 | } else { |
| 664 | return JNI_FALSE; |
| 665 | } |
| 666 | } |
Mike Lockwood | 4270237 | 2010-10-10 16:04:18 -0400 | [diff] [blame] | 667 | else |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 668 | return JNI_FALSE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 669 | } |
| 670 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 671 | static void android_location_GnssLocationProvider_delete_aiding_data(JNIEnv* /* env */, |
Andreas Gampe | 184e3ed | 2014-09-29 15:04:06 -0700 | [diff] [blame] | 672 | jobject /* obj */, |
| 673 | jint flags) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 675 | if (sGpsInterface) |
| 676 | sGpsInterface->delete_aiding_data(flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 677 | } |
| 678 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 679 | static jint android_location_GnssLocationProvider_read_sv_status(JNIEnv* env, jobject /* obj */, |
| 680 | jintArray prnWithFlagArray, jfloatArray snrArray, jfloatArray elevArray, |
| 681 | jfloatArray azumArray, jintArray constellationTypeArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 682 | { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 683 | // this should only be called from within a call to reportSvStatus |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 684 | jint* prnWithFlags = env->GetIntArrayElements(prnWithFlagArray, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 685 | jfloat* snrs = env->GetFloatArrayElements(snrArray, 0); |
| 686 | jfloat* elev = env->GetFloatArrayElements(elevArray, 0); |
| 687 | jfloat* azim = env->GetFloatArrayElements(azumArray, 0); |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 688 | jint* constellationTypes = env->GetIntArrayElements(constellationTypeArray, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 689 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 690 | // GNSS SV info. |
| 691 | for (size_t i = 0; i < sGnssSvListSize; ++i) { |
| 692 | const GnssSvInfo& info = sGnssSvList[i]; |
| 693 | constellationTypes[i] = info.constellation; |
| 694 | prnWithFlags[i] = (info.prn << PRN_SHIFT_WIDTH) | info.flags; |
| 695 | snrs[i] = info.snr; |
| 696 | elev[i] = info.elevation; |
| 697 | azim[i] = info.azimuth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 698 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 699 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 700 | env->ReleaseIntArrayElements(prnWithFlagArray, prnWithFlags, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 701 | env->ReleaseFloatArrayElements(snrArray, snrs, 0); |
| 702 | env->ReleaseFloatArrayElements(elevArray, elev, 0); |
| 703 | env->ReleaseFloatArrayElements(azumArray, azim, 0); |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 704 | env->ReleaseIntArrayElements(constellationTypeArray, constellationTypes, 0); |
| 705 | return (jint) sGnssSvListSize; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 706 | } |
| 707 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 708 | static void android_location_GnssLocationProvider_agps_set_reference_location_cellid( |
Andreas Gampe | 184e3ed | 2014-09-29 15:04:06 -0700 | [diff] [blame] | 709 | JNIEnv* /* env */, jobject /* obj */, jint type, jint mcc, jint mnc, jint lac, jint cid) |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 710 | { |
| 711 | AGpsRefLocation location; |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 712 | |
| 713 | if (!sAGpsRilInterface) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 714 | ALOGE("no AGPS RIL interface in agps_set_reference_location_cellid"); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 715 | return; |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 716 | } |
| 717 | |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 718 | switch(type) { |
| 719 | case AGPS_REF_LOCATION_TYPE_GSM_CELLID: |
| 720 | case AGPS_REF_LOCATION_TYPE_UMTS_CELLID: |
| 721 | location.type = type; |
| 722 | location.u.cellID.mcc = mcc; |
| 723 | location.u.cellID.mnc = mnc; |
| 724 | location.u.cellID.lac = lac; |
| 725 | location.u.cellID.cid = cid; |
| 726 | break; |
| 727 | default: |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 728 | ALOGE("Neither a GSM nor a UMTS cellid (%s:%d).",__FUNCTION__,__LINE__); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 729 | return; |
| 730 | break; |
| 731 | } |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 732 | sAGpsRilInterface->set_ref_location(&location, sizeof(location)); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 733 | } |
| 734 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 735 | static void android_location_GnssLocationProvider_agps_send_ni_message(JNIEnv* env, |
Andreas Gampe | 184e3ed | 2014-09-29 15:04:06 -0700 | [diff] [blame] | 736 | jobject /* obj */, jbyteArray ni_msg, jint size) |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 737 | { |
| 738 | size_t sz; |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 739 | |
| 740 | if (!sAGpsRilInterface) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 741 | ALOGE("no AGPS RIL interface in send_ni_message"); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 742 | return; |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 743 | } |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 744 | if (size < 0) |
| 745 | return; |
| 746 | sz = (size_t)size; |
| 747 | jbyte* b = env->GetByteArrayElements(ni_msg, 0); |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 748 | sAGpsRilInterface->ni_message((uint8_t *)b,sz); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 749 | env->ReleaseByteArrayElements(ni_msg,b,0); |
| 750 | } |
| 751 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 752 | static void android_location_GnssLocationProvider_agps_set_id(JNIEnv *env, jobject /* obj */, |
Andreas Gampe | 184e3ed | 2014-09-29 15:04:06 -0700 | [diff] [blame] | 753 | jint type, jstring setid_string) |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 754 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 755 | if (!sAGpsRilInterface) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 756 | ALOGE("no AGPS RIL interface in agps_set_id"); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 757 | return; |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 758 | } |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 759 | |
| 760 | const char *setid = env->GetStringUTFChars(setid_string, NULL); |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 761 | sAGpsRilInterface->set_set_id(type, setid); |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 762 | env->ReleaseStringUTFChars(setid_string, setid); |
| 763 | } |
| 764 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 765 | static jint android_location_GnssLocationProvider_read_nmea(JNIEnv* env, jobject /* obj */, |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 766 | jbyteArray nmeaArray, jint buffer_size) |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 767 | { |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 768 | // this should only be called from within a call to reportNmea |
| 769 | jbyte* nmea = (jbyte *)env->GetPrimitiveArrayCritical(nmeaArray, 0); |
| 770 | int length = sNmeaStringLength; |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 771 | if (length > buffer_size) |
| 772 | length = buffer_size; |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 773 | memcpy(nmea, sNmeaString, length); |
| 774 | env->ReleasePrimitiveArrayCritical(nmeaArray, nmea, JNI_ABORT); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 775 | return (jint) length; |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 776 | } |
| 777 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 778 | static void android_location_GnssLocationProvider_inject_time(JNIEnv* /* env */, jobject /* obj */, |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 779 | jlong time, jlong timeReference, jint uncertainty) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 780 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 781 | if (sGpsInterface) |
| 782 | sGpsInterface->inject_time(time, timeReference, uncertainty); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 783 | } |
| 784 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 785 | static void android_location_GnssLocationProvider_inject_location(JNIEnv* /* env */, |
Andreas Gampe | 184e3ed | 2014-09-29 15:04:06 -0700 | [diff] [blame] | 786 | jobject /* obj */, jdouble latitude, jdouble longitude, jfloat accuracy) |
Mike Lockwood | d26ce0d | 2009-06-11 12:25:46 -0400 | [diff] [blame] | 787 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 788 | if (sGpsInterface) |
| 789 | sGpsInterface->inject_location(latitude, longitude, accuracy); |
Mike Lockwood | d26ce0d | 2009-06-11 12:25:46 -0400 | [diff] [blame] | 790 | } |
| 791 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 792 | static jboolean android_location_GnssLocationProvider_supports_xtra( |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 793 | JNIEnv* /* env */, jobject /* obj */) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 794 | { |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 795 | return (sGpsXtraInterface != NULL) ? JNI_TRUE : JNI_FALSE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 796 | } |
| 797 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 798 | static void android_location_GnssLocationProvider_inject_xtra_data(JNIEnv* env, jobject /* obj */, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 799 | jbyteArray data, jint length) |
| 800 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 801 | if (!sGpsXtraInterface) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 802 | ALOGE("no XTRA interface in inject_xtra_data"); |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 803 | return; |
| 804 | } |
| 805 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 806 | jbyte* bytes = (jbyte *)env->GetPrimitiveArrayCritical(data, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 807 | sGpsXtraInterface->inject_xtra_data((char *)bytes, length); |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 808 | env->ReleasePrimitiveArrayCritical(data, bytes, JNI_ABORT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 809 | } |
| 810 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 811 | static void android_location_GnssLocationProvider_agps_data_conn_open( |
Andreas Gampe | 184e3ed | 2014-09-29 15:04:06 -0700 | [diff] [blame] | 812 | JNIEnv* env, jobject /* obj */, jstring apn, jint apnIpType) |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 813 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 814 | if (!sAGpsInterface) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 815 | ALOGE("no AGPS interface in agps_data_conn_open"); |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 816 | return; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 817 | } |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 818 | if (apn == NULL) { |
| 819 | jniThrowException(env, "java/lang/IllegalArgumentException", NULL); |
| 820 | return; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 821 | } |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 822 | |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 823 | const char *apnStr = env->GetStringUTFChars(apn, NULL); |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 824 | |
| 825 | size_t interface_size = sAGpsInterface->size; |
Lifu Tang | a8b7bb5 | 2016-01-26 01:22:10 -0800 | [diff] [blame] | 826 | if (interface_size == sizeof(AGpsInterface)) { |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 827 | sAGpsInterface->data_conn_open_with_apn_ip_type(apnStr, apnIpType); |
| 828 | } else if (interface_size == sizeof(AGpsInterface_v1)) { |
| 829 | sAGpsInterface->data_conn_open(apnStr); |
| 830 | } else { |
Bernhard Rosenkränzer | 46c82b4 | 2014-11-30 11:04:10 +0100 | [diff] [blame] | 831 | ALOGE("Invalid size of AGpsInterface found: %zd.", interface_size); |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 832 | } |
| 833 | |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 834 | env->ReleaseStringUTFChars(apn, apnStr); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 837 | static void android_location_GnssLocationProvider_agps_data_conn_closed(JNIEnv* /* env */, |
Andreas Gampe | 184e3ed | 2014-09-29 15:04:06 -0700 | [diff] [blame] | 838 | jobject /* obj */) |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 839 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 840 | if (!sAGpsInterface) { |
Magnus Eriksson | 160c1ca | 2012-12-21 21:07:28 +0100 | [diff] [blame] | 841 | ALOGE("no AGPS interface in agps_data_conn_closed"); |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 842 | return; |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 843 | } |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 844 | sAGpsInterface->data_conn_closed(); |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 845 | } |
| 846 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 847 | static void android_location_GnssLocationProvider_agps_data_conn_failed(JNIEnv* /* env */, |
Andreas Gampe | 184e3ed | 2014-09-29 15:04:06 -0700 | [diff] [blame] | 848 | jobject /* obj */) |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 849 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 850 | if (!sAGpsInterface) { |
Magnus Eriksson | 160c1ca | 2012-12-21 21:07:28 +0100 | [diff] [blame] | 851 | ALOGE("no AGPS interface in agps_data_conn_failed"); |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 852 | return; |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 853 | } |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 854 | sAGpsInterface->data_conn_failed(); |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 855 | } |
| 856 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 857 | static void android_location_GnssLocationProvider_set_agps_server(JNIEnv* env, jobject /* obj */, |
Mike Lockwood | a9e5461 | 2009-06-19 14:54:42 -0400 | [diff] [blame] | 858 | jint type, jstring hostname, jint port) |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 859 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 860 | if (!sAGpsInterface) { |
Magnus Eriksson | 160c1ca | 2012-12-21 21:07:28 +0100 | [diff] [blame] | 861 | ALOGE("no AGPS interface in set_agps_server"); |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 862 | return; |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 863 | } |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 864 | const char *c_hostname = env->GetStringUTFChars(hostname, NULL); |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 865 | sAGpsInterface->set_server(type, c_hostname, port); |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 866 | env->ReleaseStringUTFChars(hostname, c_hostname); |
Mike Lockwood | 58bda98 | 2009-04-14 16:25:07 -0400 | [diff] [blame] | 867 | } |
| 868 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 869 | static void android_location_GnssLocationProvider_send_ni_response(JNIEnv* /* env */, |
Andreas Gampe | 184e3ed | 2014-09-29 15:04:06 -0700 | [diff] [blame] | 870 | jobject /* obj */, jint notifId, jint response) |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 871 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 872 | if (!sGpsNiInterface) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 873 | ALOGE("no NI interface in send_ni_response"); |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 874 | return; |
Fred Fettinger | 3c8fbdf | 2010-01-04 15:38:13 -0600 | [diff] [blame] | 875 | } |
Mike Lockwood | bea3118 | 2010-10-05 14:29:53 -0400 | [diff] [blame] | 876 | |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 877 | sGpsNiInterface->respond(notifId, response); |
Fred Fettinger | 3c8fbdf | 2010-01-04 15:38:13 -0600 | [diff] [blame] | 878 | } |
| 879 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 880 | static jstring android_location_GnssLocationProvider_get_internal_state(JNIEnv* env, |
Andreas Gampe | 184e3ed | 2014-09-29 15:04:06 -0700 | [diff] [blame] | 881 | jobject /* obj */) { |
Fred Fettinger | 3c8fbdf | 2010-01-04 15:38:13 -0600 | [diff] [blame] | 882 | jstring result = NULL; |
| 883 | if (sGpsDebugInterface) { |
| 884 | const size_t maxLength = 2047; |
| 885 | char buffer[maxLength+1]; |
| 886 | size_t length = sGpsDebugInterface->get_internal_state(buffer, maxLength); |
| 887 | if (length > maxLength) length = maxLength; |
| 888 | buffer[length] = 0; |
| 889 | result = env->NewStringUTF(buffer); |
| 890 | } |
| 891 | return result; |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 892 | } |
| 893 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 894 | static void android_location_GnssLocationProvider_update_network_state(JNIEnv* env, jobject /* obj */, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 895 | jboolean connected, jint type, jboolean roaming, jboolean available, jstring extraInfo, jstring apn) |
Mike Lockwood | 50130bb | 2010-10-11 06:22:50 -0400 | [diff] [blame] | 896 | { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 897 | |
| 898 | if (sAGpsRilInterface && sAGpsRilInterface->update_network_state) { |
Mike Lockwood | 50130bb | 2010-10-11 06:22:50 -0400 | [diff] [blame] | 899 | if (extraInfo) { |
| 900 | const char *extraInfoStr = env->GetStringUTFChars(extraInfo, NULL); |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 901 | sAGpsRilInterface->update_network_state(connected, type, roaming, extraInfoStr); |
Mike Lockwood | 50130bb | 2010-10-11 06:22:50 -0400 | [diff] [blame] | 902 | env->ReleaseStringUTFChars(extraInfo, extraInfoStr); |
| 903 | } else { |
Mike Lockwood | 58ec34c | 2011-02-23 08:21:00 -0800 | [diff] [blame] | 904 | sAGpsRilInterface->update_network_state(connected, type, roaming, NULL); |
Mike Lockwood | 50130bb | 2010-10-11 06:22:50 -0400 | [diff] [blame] | 905 | } |
Kevin Tang | a5fe6b2 | 2011-06-05 14:25:16 -0700 | [diff] [blame] | 906 | |
| 907 | // update_network_availability callback was not included in original AGpsRilInterface |
| 908 | if (sAGpsRilInterface->size >= sizeof(AGpsRilInterface) |
| 909 | && sAGpsRilInterface->update_network_availability) { |
| 910 | const char *c_apn = env->GetStringUTFChars(apn, NULL); |
| 911 | sAGpsRilInterface->update_network_availability(available, c_apn); |
| 912 | env->ReleaseStringUTFChars(apn, c_apn); |
| 913 | } |
Mike Lockwood | 50130bb | 2010-10-11 06:22:50 -0400 | [diff] [blame] | 914 | } |
| 915 | } |
| 916 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 917 | static jboolean android_location_GnssLocationProvider_is_geofence_supported( |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 918 | JNIEnv* /* env */, jobject /* obj */) |
Andreas Gampe | 184e3ed | 2014-09-29 15:04:06 -0700 | [diff] [blame] | 919 | { |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 920 | return (sGpsGeofencingInterface != NULL) ? JNI_TRUE : JNI_FALSE; |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 921 | } |
| 922 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 923 | static jboolean android_location_GnssLocationProvider_add_geofence(JNIEnv* /* env */, |
Andreas Gampe | 184e3ed | 2014-09-29 15:04:06 -0700 | [diff] [blame] | 924 | jobject /* obj */, jint geofence_id, jdouble latitude, jdouble longitude, jdouble radius, |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 925 | jint last_transition, jint monitor_transition, jint notification_responsiveness, |
| 926 | jint unknown_timer) { |
| 927 | if (sGpsGeofencingInterface != NULL) { |
| 928 | sGpsGeofencingInterface->add_geofence_area(geofence_id, latitude, longitude, |
| 929 | radius, last_transition, monitor_transition, notification_responsiveness, |
| 930 | unknown_timer); |
| 931 | return JNI_TRUE; |
| 932 | } else { |
| 933 | ALOGE("Geofence interface not available"); |
| 934 | } |
| 935 | return JNI_FALSE; |
| 936 | } |
| 937 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 938 | static jboolean android_location_GnssLocationProvider_remove_geofence(JNIEnv* /* env */, |
Andreas Gampe | 184e3ed | 2014-09-29 15:04:06 -0700 | [diff] [blame] | 939 | jobject /* obj */, jint geofence_id) { |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 940 | if (sGpsGeofencingInterface != NULL) { |
| 941 | sGpsGeofencingInterface->remove_geofence_area(geofence_id); |
| 942 | return JNI_TRUE; |
| 943 | } else { |
| 944 | ALOGE("Geofence interface not available"); |
| 945 | } |
| 946 | return JNI_FALSE; |
| 947 | } |
| 948 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 949 | static jboolean android_location_GnssLocationProvider_pause_geofence(JNIEnv* /* env */, |
Andreas Gampe | 184e3ed | 2014-09-29 15:04:06 -0700 | [diff] [blame] | 950 | jobject /* obj */, jint geofence_id) { |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 951 | if (sGpsGeofencingInterface != NULL) { |
| 952 | sGpsGeofencingInterface->pause_geofence(geofence_id); |
| 953 | return JNI_TRUE; |
| 954 | } else { |
| 955 | ALOGE("Geofence interface not available"); |
| 956 | } |
| 957 | return JNI_FALSE; |
| 958 | } |
| 959 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 960 | static jboolean android_location_GnssLocationProvider_resume_geofence(JNIEnv* /* env */, |
Andreas Gampe | 184e3ed | 2014-09-29 15:04:06 -0700 | [diff] [blame] | 961 | jobject /* obj */, jint geofence_id, jint monitor_transition) { |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 962 | if (sGpsGeofencingInterface != NULL) { |
| 963 | sGpsGeofencingInterface->resume_geofence(geofence_id, monitor_transition); |
| 964 | return JNI_TRUE; |
| 965 | } else { |
| 966 | ALOGE("Geofence interface not available"); |
| 967 | } |
| 968 | return JNI_FALSE; |
| 969 | } |
| 970 | |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 971 | static jobject translate_gps_clock(JNIEnv* env, void* data, size_t size) { |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 972 | const char* doubleSignature = "(D)V"; |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 973 | const char* longSignature = "(J)V"; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 974 | |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 975 | GpsClock* clock = reinterpret_cast<GpsClock*>(data); |
| 976 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 977 | jclass gpsClockClass = env->FindClass("android/location/GnssClock"); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 978 | jmethodID gpsClockCtor = env->GetMethodID(gpsClockClass, "<init>", "()V"); |
| 979 | |
| 980 | jobject gpsClockObject = env->NewObject(gpsClockClass, gpsClockCtor); |
| 981 | GpsClockFlags flags = clock->flags; |
| 982 | |
| 983 | if (flags & GPS_CLOCK_HAS_LEAP_SECOND) { |
| 984 | jmethodID setterMethod = env->GetMethodID(gpsClockClass, "setLeapSecond", "(S)V"); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 985 | env->CallVoidMethod(gpsClockObject, setterMethod, clock->leap_second); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 986 | } |
| 987 | |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 988 | jmethodID typeSetterMethod = env->GetMethodID(gpsClockClass, "setType", "(B)V"); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 989 | env->CallVoidMethod(gpsClockObject, typeSetterMethod, clock->type); |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 990 | |
| 991 | jmethodID setterMethod = env->GetMethodID(gpsClockClass, "setTimeInNs", longSignature); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 992 | env->CallVoidMethod(gpsClockObject, setterMethod, clock->time_ns); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 993 | |
| 994 | if (flags & GPS_CLOCK_HAS_TIME_UNCERTAINTY) { |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 995 | jmethodID setterMethod = |
| 996 | env->GetMethodID(gpsClockClass, "setTimeUncertaintyInNs", doubleSignature); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 997 | env->CallVoidMethod(gpsClockObject, setterMethod, clock->time_uncertainty_ns); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 998 | } |
| 999 | |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 1000 | if (flags & GPS_CLOCK_HAS_FULL_BIAS) { |
| 1001 | jmethodID setterMethod = env->GetMethodID(gpsClockClass, "setFullBiasInNs", longSignature); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1002 | env->CallVoidMethod(gpsClockObject, setterMethod, clock->full_bias_ns); |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1005 | if (flags & GPS_CLOCK_HAS_BIAS) { |
| 1006 | jmethodID setterMethod = env->GetMethodID(gpsClockClass, "setBiasInNs", doubleSignature); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1007 | env->CallVoidMethod(gpsClockObject, setterMethod, clock->bias_ns); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | if (flags & GPS_CLOCK_HAS_BIAS_UNCERTAINTY) { |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 1011 | jmethodID setterMethod = |
| 1012 | env->GetMethodID(gpsClockClass, "setBiasUncertaintyInNs", doubleSignature); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1013 | env->CallVoidMethod(gpsClockObject, setterMethod, clock->bias_uncertainty_ns); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | if (flags & GPS_CLOCK_HAS_DRIFT) { |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 1017 | jmethodID setterMethod = |
| 1018 | env->GetMethodID(gpsClockClass, "setDriftInNsPerSec", doubleSignature); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1019 | env->CallVoidMethod(gpsClockObject, setterMethod, clock->drift_nsps); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | if (flags & GPS_CLOCK_HAS_DRIFT_UNCERTAINTY) { |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 1023 | jmethodID setterMethod = |
| 1024 | env->GetMethodID(gpsClockClass, "setDriftUncertaintyInNsPerSec", doubleSignature); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1025 | env->CallVoidMethod(gpsClockObject, setterMethod, clock->drift_uncertainty_nsps); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1026 | } |
| 1027 | |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 1028 | if (flags & GPS_CLOCK_TYPE_LOCAL_HW_TIME) { |
| 1029 | if (size == sizeof(GpsClock)) { |
| 1030 | jmethodID setterMethod = |
| 1031 | env->GetMethodID(gpsClockClass, |
| 1032 | "setTimeOfLastHwClockDiscontinuityInNs", |
| 1033 | longSignature); |
| 1034 | env->CallVoidMethod(gpsClockObject, |
| 1035 | setterMethod, |
| 1036 | clock->time_of_last_hw_clock_discontinuity_ns); |
| 1037 | } |
| 1038 | } |
| 1039 | |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1040 | env->DeleteLocalRef(gpsClockClass); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1041 | return gpsClockObject; |
| 1042 | } |
| 1043 | |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 1044 | static jobject translate_gps_measurement(JNIEnv* env, void* data, size_t size) { |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 1045 | const char* byteSignature = "(B)V"; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1046 | const char* shortSignature = "(S)V"; |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1047 | const char* intSignature = "(I)V"; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1048 | const char* longSignature = "(J)V"; |
| 1049 | const char* floatSignature = "(F)V"; |
| 1050 | const char* doubleSignature = "(D)V"; |
| 1051 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1052 | jclass gnssMeasurementClass = env->FindClass("android/location/GnssMeasurement"); |
| 1053 | jmethodID gnssMeasurementCtor = env->GetMethodID(gnssMeasurementClass, "<init>", "()V"); |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 1054 | GpsMeasurement* measurement = reinterpret_cast<GpsMeasurement*>(data); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1055 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1056 | jobject gnssMeasurementObject = env->NewObject(gnssMeasurementClass, gnssMeasurementCtor); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1057 | GpsMeasurementFlags flags = measurement->flags; |
| 1058 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1059 | jmethodID prnSetterMethod = env->GetMethodID(gnssMeasurementClass, "setPrn", byteSignature); |
| 1060 | env->CallVoidMethod(gnssMeasurementObject, prnSetterMethod, measurement->prn); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1061 | |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 1062 | jmethodID timeOffsetSetterMethod = |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1063 | env->GetMethodID(gnssMeasurementClass, "setTimeOffsetInNs", doubleSignature); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1064 | env->CallVoidMethod( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1065 | gnssMeasurementObject, |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 1066 | timeOffsetSetterMethod, |
| 1067 | measurement->time_offset_ns); |
| 1068 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1069 | jmethodID stateSetterMethod = env->GetMethodID(gnssMeasurementClass, "setState", shortSignature); |
| 1070 | env->CallVoidMethod(gnssMeasurementObject, stateSetterMethod, measurement->state); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1071 | |
| 1072 | jmethodID receivedGpsTowSetterMethod = |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1073 | env->GetMethodID(gnssMeasurementClass, "setReceivedGpsTowInNs", longSignature); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1074 | env->CallVoidMethod( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1075 | gnssMeasurementObject, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1076 | receivedGpsTowSetterMethod, |
| 1077 | measurement->received_gps_tow_ns); |
| 1078 | |
destradaa | 81cabb8 | 2014-07-22 09:59:43 -0700 | [diff] [blame] | 1079 | jmethodID receivedGpsTowUncertaintySetterMethod = env->GetMethodID( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1080 | gnssMeasurementClass, |
destradaa | 81cabb8 | 2014-07-22 09:59:43 -0700 | [diff] [blame] | 1081 | "setReceivedGpsTowUncertaintyInNs", |
| 1082 | longSignature); |
| 1083 | env->CallVoidMethod( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1084 | gnssMeasurementObject, |
destradaa | 81cabb8 | 2014-07-22 09:59:43 -0700 | [diff] [blame] | 1085 | receivedGpsTowUncertaintySetterMethod, |
| 1086 | measurement->received_gps_tow_uncertainty_ns); |
| 1087 | |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 1088 | jmethodID cn0SetterMethod = |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1089 | env->GetMethodID(gnssMeasurementClass, "setCn0InDbHz", doubleSignature); |
| 1090 | env->CallVoidMethod(gnssMeasurementObject, cn0SetterMethod, measurement->c_n0_dbhz); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1091 | |
| 1092 | jmethodID pseudorangeRateSetterMethod = env->GetMethodID( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1093 | gnssMeasurementClass, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1094 | "setPseudorangeRateInMetersPerSec", |
| 1095 | doubleSignature); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1096 | env->CallVoidMethod( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1097 | gnssMeasurementObject, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1098 | pseudorangeRateSetterMethod, |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 1099 | measurement->pseudorange_rate_mps); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1100 | |
| 1101 | jmethodID pseudorangeRateUncertaintySetterMethod = env->GetMethodID( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1102 | gnssMeasurementClass, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1103 | "setPseudorangeRateUncertaintyInMetersPerSec", |
| 1104 | doubleSignature); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1105 | env->CallVoidMethod( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1106 | gnssMeasurementObject, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1107 | pseudorangeRateUncertaintySetterMethod, |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 1108 | measurement->pseudorange_rate_uncertainty_mps); |
| 1109 | |
| 1110 | jmethodID accumulatedDeltaRangeStateSetterMethod = |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1111 | env->GetMethodID(gnssMeasurementClass, "setAccumulatedDeltaRangeState", shortSignature); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1112 | env->CallVoidMethod( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1113 | gnssMeasurementObject, |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 1114 | accumulatedDeltaRangeStateSetterMethod, |
| 1115 | measurement->accumulated_delta_range_state); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1116 | |
| 1117 | jmethodID accumulatedDeltaRangeSetterMethod = env->GetMethodID( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1118 | gnssMeasurementClass, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1119 | "setAccumulatedDeltaRangeInMeters", |
| 1120 | doubleSignature); |
| 1121 | env->CallVoidMethod( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1122 | gnssMeasurementObject, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1123 | accumulatedDeltaRangeSetterMethod, |
| 1124 | measurement->accumulated_delta_range_m); |
| 1125 | |
| 1126 | jmethodID accumulatedDeltaRangeUncertaintySetterMethod = env->GetMethodID( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1127 | gnssMeasurementClass, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1128 | "setAccumulatedDeltaRangeUncertaintyInMeters", |
| 1129 | doubleSignature); |
| 1130 | env->CallVoidMethod( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1131 | gnssMeasurementObject, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1132 | accumulatedDeltaRangeUncertaintySetterMethod, |
| 1133 | measurement->accumulated_delta_range_uncertainty_m); |
| 1134 | |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1135 | if (flags & GPS_MEASUREMENT_HAS_PSEUDORANGE) { |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 1136 | jmethodID setterMethod = |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1137 | env->GetMethodID(gnssMeasurementClass, "setPseudorangeInMeters", doubleSignature); |
| 1138 | env->CallVoidMethod(gnssMeasurementObject, setterMethod, measurement->pseudorange_m); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | if (flags & GPS_MEASUREMENT_HAS_PSEUDORANGE_UNCERTAINTY) { |
| 1142 | jmethodID setterMethod = env->GetMethodID( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1143 | gnssMeasurementClass, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1144 | "setPseudorangeUncertaintyInMeters", |
| 1145 | doubleSignature); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1146 | env->CallVoidMethod( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1147 | gnssMeasurementObject, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1148 | setterMethod, |
| 1149 | measurement->pseudorange_uncertainty_m); |
| 1150 | } |
| 1151 | |
| 1152 | if (flags & GPS_MEASUREMENT_HAS_CODE_PHASE) { |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 1153 | jmethodID setterMethod = |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1154 | env->GetMethodID(gnssMeasurementClass, "setCodePhaseInChips", doubleSignature); |
| 1155 | env->CallVoidMethod(gnssMeasurementObject, setterMethod, measurement->code_phase_chips); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | if (flags & GPS_MEASUREMENT_HAS_CODE_PHASE_UNCERTAINTY) { |
| 1159 | jmethodID setterMethod = env->GetMethodID( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1160 | gnssMeasurementClass, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1161 | "setCodePhaseUncertaintyInChips", |
| 1162 | doubleSignature); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1163 | env->CallVoidMethod( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1164 | gnssMeasurementObject, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1165 | setterMethod, |
| 1166 | measurement->code_phase_uncertainty_chips); |
| 1167 | } |
| 1168 | |
| 1169 | if (flags & GPS_MEASUREMENT_HAS_CARRIER_FREQUENCY) { |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 1170 | jmethodID setterMethod = |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1171 | env->GetMethodID(gnssMeasurementClass, "setCarrierFrequencyInHz", floatSignature); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1172 | env->CallVoidMethod( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1173 | gnssMeasurementObject, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1174 | setterMethod, |
| 1175 | measurement->carrier_frequency_hz); |
| 1176 | } |
| 1177 | |
| 1178 | if (flags & GPS_MEASUREMENT_HAS_CARRIER_CYCLES) { |
| 1179 | jmethodID setterMethod = |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1180 | env->GetMethodID(gnssMeasurementClass, "setCarrierCycles", longSignature); |
| 1181 | env->CallVoidMethod(gnssMeasurementObject, setterMethod, measurement->carrier_cycles); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | if (flags & GPS_MEASUREMENT_HAS_CARRIER_PHASE) { |
| 1185 | jmethodID setterMethod = |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1186 | env->GetMethodID(gnssMeasurementClass, "setCarrierPhase", doubleSignature); |
| 1187 | env->CallVoidMethod(gnssMeasurementObject, setterMethod, measurement->carrier_phase); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
| 1190 | if (flags & GPS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY) { |
| 1191 | jmethodID setterMethod = env->GetMethodID( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1192 | gnssMeasurementClass, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1193 | "setCarrierPhaseUncertainty", |
| 1194 | doubleSignature); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1195 | env->CallVoidMethod( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1196 | gnssMeasurementObject, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1197 | setterMethod, |
| 1198 | measurement->carrier_phase_uncertainty); |
| 1199 | } |
| 1200 | |
| 1201 | jmethodID lossOfLockSetterMethod = |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1202 | env->GetMethodID(gnssMeasurementClass, "setLossOfLock", byteSignature); |
| 1203 | env->CallVoidMethod(gnssMeasurementObject, lossOfLockSetterMethod, measurement->loss_of_lock); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1204 | |
| 1205 | if (flags & GPS_MEASUREMENT_HAS_BIT_NUMBER) { |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 1206 | jmethodID setterMethod = |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1207 | env->GetMethodID(gnssMeasurementClass, "setBitNumber", intSignature); |
| 1208 | env->CallVoidMethod(gnssMeasurementObject, setterMethod, measurement->bit_number); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | if (flags & GPS_MEASUREMENT_HAS_TIME_FROM_LAST_BIT) { |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 1212 | jmethodID setterMethod = |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1213 | env->GetMethodID(gnssMeasurementClass, "setTimeFromLastBitInMs", shortSignature); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1214 | env->CallVoidMethod( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1215 | gnssMeasurementObject, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1216 | setterMethod, |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 1217 | measurement->time_from_last_bit_ms); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | if (flags & GPS_MEASUREMENT_HAS_DOPPLER_SHIFT) { |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 1221 | jmethodID setterMethod = |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1222 | env->GetMethodID(gnssMeasurementClass, "setDopplerShiftInHz", doubleSignature); |
| 1223 | env->CallVoidMethod(gnssMeasurementObject, setterMethod, measurement->doppler_shift_hz); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | if (flags & GPS_MEASUREMENT_HAS_DOPPLER_SHIFT_UNCERTAINTY) { |
| 1227 | jmethodID setterMethod = env->GetMethodID( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1228 | gnssMeasurementClass, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1229 | "setDopplerShiftUncertaintyInHz", |
| 1230 | doubleSignature); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1231 | env->CallVoidMethod( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1232 | gnssMeasurementObject, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1233 | setterMethod, |
| 1234 | measurement->doppler_shift_uncertainty_hz); |
| 1235 | } |
| 1236 | |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 1237 | jmethodID multipathIndicatorSetterMethod = |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1238 | env->GetMethodID(gnssMeasurementClass, "setMultipathIndicator", byteSignature); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1239 | env->CallVoidMethod( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1240 | gnssMeasurementObject, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1241 | multipathIndicatorSetterMethod, |
| 1242 | measurement->multipath_indicator); |
| 1243 | |
| 1244 | if (flags & GPS_MEASUREMENT_HAS_SNR) { |
| 1245 | jmethodID setterMethod = |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1246 | env->GetMethodID(gnssMeasurementClass, "setSnrInDb", doubleSignature); |
| 1247 | env->CallVoidMethod(gnssMeasurementObject, setterMethod, measurement->snr_db); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | if (flags & GPS_MEASUREMENT_HAS_ELEVATION) { |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 1251 | jmethodID setterMethod = |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1252 | env->GetMethodID(gnssMeasurementClass, "setElevationInDeg", doubleSignature); |
| 1253 | env->CallVoidMethod(gnssMeasurementObject, setterMethod, measurement->elevation_deg); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | if (flags & GPS_MEASUREMENT_HAS_ELEVATION_UNCERTAINTY) { |
destradaa | 2102dd7 | 2014-07-18 17:50:24 -0700 | [diff] [blame] | 1257 | jmethodID setterMethod = |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1258 | env->GetMethodID(gnssMeasurementClass, "setElevationUncertaintyInDeg", doubleSignature); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1259 | env->CallVoidMethod( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1260 | gnssMeasurementObject, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1261 | setterMethod, |
| 1262 | measurement->elevation_uncertainty_deg); |
| 1263 | } |
| 1264 | |
| 1265 | if (flags & GPS_MEASUREMENT_HAS_AZIMUTH) { |
| 1266 | jmethodID setterMethod = |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1267 | env->GetMethodID(gnssMeasurementClass, "setAzimuthInDeg", doubleSignature); |
| 1268 | env->CallVoidMethod(gnssMeasurementObject, setterMethod, measurement->azimuth_deg); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | if (flags & GPS_MEASUREMENT_HAS_AZIMUTH_UNCERTAINTY) { |
| 1272 | jmethodID setterMethod = env->GetMethodID( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1273 | gnssMeasurementClass, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1274 | "setAzimuthUncertaintyInDeg", |
| 1275 | doubleSignature); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1276 | env->CallVoidMethod( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1277 | gnssMeasurementObject, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1278 | setterMethod, |
| 1279 | measurement->azimuth_uncertainty_deg); |
| 1280 | } |
| 1281 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1282 | jmethodID usedInFixSetterMethod = env->GetMethodID(gnssMeasurementClass, "setUsedInFix", "(Z)V"); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1283 | env->CallVoidMethod( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1284 | gnssMeasurementObject, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1285 | usedInFixSetterMethod, |
| 1286 | (flags & GPS_MEASUREMENT_HAS_USED_IN_FIX) && measurement->used_in_fix); |
| 1287 | |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 1288 | if (size == sizeof(GpsMeasurement)) { |
| 1289 | jmethodID setterMethod = |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1290 | env->GetMethodID(gnssMeasurementClass, |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 1291 | "setPseudorangeRateCarrierInMetersPerSec", |
| 1292 | doubleSignature); |
| 1293 | env->CallVoidMethod( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1294 | gnssMeasurementObject, |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 1295 | setterMethod, |
| 1296 | measurement->pseudorange_rate_carrier_mps); |
| 1297 | |
| 1298 | setterMethod = |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1299 | env->GetMethodID(gnssMeasurementClass, |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 1300 | "setPseudorangeRateCarrierUncertaintyInMetersPerSec", |
| 1301 | doubleSignature); |
| 1302 | env->CallVoidMethod( |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1303 | gnssMeasurementObject, |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 1304 | setterMethod, |
| 1305 | measurement->pseudorange_rate_carrier_uncertainty_mps); |
| 1306 | } |
| 1307 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1308 | env->DeleteLocalRef(gnssMeasurementClass); |
| 1309 | return gnssMeasurementObject; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1310 | } |
| 1311 | |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 1312 | /** |
| 1313 | * <T> can only be GpsData or GpsData_v1. Must rewrite this function if more |
| 1314 | * types are introduced in the future releases. |
| 1315 | */ |
| 1316 | template<class T> |
| 1317 | static jobjectArray translate_gps_measurements(JNIEnv* env, void* data) { |
| 1318 | T* gps_data = reinterpret_cast<T*>(data); |
| 1319 | size_t measurementCount = gps_data->measurement_count; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1320 | if (measurementCount == 0) { |
| 1321 | return NULL; |
| 1322 | } |
| 1323 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1324 | jclass gnssMeasurementClass = env->FindClass("android/location/GnssMeasurement"); |
| 1325 | jobjectArray gnssMeasurementArray = env->NewObjectArray( |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1326 | measurementCount, |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1327 | gnssMeasurementClass, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1328 | NULL /* initialElement */); |
| 1329 | |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1330 | for (uint16_t i = 0; i < measurementCount; ++i) { |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1331 | jobject gnssMeasurement = translate_gps_measurement( |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 1332 | env, |
| 1333 | &(gps_data->measurements[i]), |
| 1334 | sizeof(gps_data->measurements[0])); |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1335 | env->SetObjectArrayElement(gnssMeasurementArray, i, gnssMeasurement); |
| 1336 | env->DeleteLocalRef(gnssMeasurement); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1337 | } |
| 1338 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1339 | env->DeleteLocalRef(gnssMeasurementClass); |
| 1340 | return gnssMeasurementArray; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | static void measurement_callback(GpsData* data) { |
| 1344 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 1345 | if (data == NULL) { |
| 1346 | ALOGE("Invalid data provided to gps_measurement_callback"); |
| 1347 | return; |
| 1348 | } |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 1349 | if (data->size != sizeof(GpsData) && data->size != sizeof(GpsData_v1)) { |
Bernhard Rosenkränzer | 46c82b4 | 2014-11-30 11:04:10 +0100 | [diff] [blame] | 1350 | ALOGE("Invalid GpsData size found in gps_measurement_callback, size=%zd", data->size); |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 1351 | return; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1352 | } |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 1353 | |
| 1354 | jobject gpsClock; |
| 1355 | jobjectArray measurementArray; |
| 1356 | if (data->size == sizeof(GpsData)) { |
| 1357 | gpsClock = translate_gps_clock(env, &data->clock, sizeof(GpsClock)); |
| 1358 | measurementArray = translate_gps_measurements<GpsData>(env, data); |
| 1359 | } else { |
| 1360 | gpsClock = translate_gps_clock(env, &data->clock, sizeof(GpsClock_v1)); |
| 1361 | measurementArray = translate_gps_measurements<GpsData_v1>(env, data); |
| 1362 | } |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1363 | jclass gnssMeasurementsEventClass = env->FindClass("android/location/GnssMeasurementsEvent"); |
| 1364 | jmethodID gnssMeasurementsEventCtor = env->GetMethodID( |
| 1365 | gnssMeasurementsEventClass, |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 1366 | "<init>", |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1367 | "(Landroid/location/GnssClock;[Landroid/location/GnssMeasurement;)V"); |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 1368 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1369 | jobject gnssMeasurementsEvent = env->NewObject( |
| 1370 | gnssMeasurementsEventClass, |
| 1371 | gnssMeasurementsEventCtor, |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 1372 | gpsClock, |
| 1373 | measurementArray); |
| 1374 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1375 | env->CallVoidMethod(mCallbacksObj, method_reportMeasurementData, gnssMeasurementsEvent); |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 1376 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 1377 | |
| 1378 | env->DeleteLocalRef(gpsClock); |
| 1379 | env->DeleteLocalRef(measurementArray); |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1380 | env->DeleteLocalRef(gnssMeasurementsEventClass); |
| 1381 | env->DeleteLocalRef(gnssMeasurementsEvent); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | GpsMeasurementCallbacks sGpsMeasurementCallbacks = { |
| 1385 | sizeof(GpsMeasurementCallbacks), |
| 1386 | measurement_callback, |
| 1387 | }; |
| 1388 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1389 | static jboolean android_location_GnssLocationProvider_is_measurement_supported( |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1390 | JNIEnv* env, |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1391 | jclass clazz) { |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1392 | if (sGpsMeasurementInterface != NULL) { |
| 1393 | return JNI_TRUE; |
| 1394 | } |
| 1395 | return JNI_FALSE; |
| 1396 | } |
| 1397 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1398 | static jboolean android_location_GnssLocationProvider_start_measurement_collection( |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1399 | JNIEnv* env, |
| 1400 | jobject obj) { |
| 1401 | if (sGpsMeasurementInterface == NULL) { |
| 1402 | ALOGE("Measurement interface is not available."); |
| 1403 | return JNI_FALSE; |
| 1404 | } |
| 1405 | |
| 1406 | int result = sGpsMeasurementInterface->init(&sGpsMeasurementCallbacks); |
| 1407 | if (result != GPS_GEOFENCE_OPERATION_SUCCESS) { |
| 1408 | ALOGE("An error has been found on GpsMeasurementInterface::init, status=%d", result); |
| 1409 | return JNI_FALSE; |
| 1410 | } |
| 1411 | |
| 1412 | return JNI_TRUE; |
| 1413 | } |
| 1414 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1415 | static jboolean android_location_GnssLocationProvider_stop_measurement_collection( |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1416 | JNIEnv* env, |
| 1417 | jobject obj) { |
| 1418 | if (sGpsMeasurementInterface == NULL) { |
| 1419 | ALOGE("Measurement interface not available"); |
| 1420 | return JNI_FALSE; |
| 1421 | } |
| 1422 | |
| 1423 | sGpsMeasurementInterface->close(); |
| 1424 | return JNI_TRUE; |
| 1425 | } |
| 1426 | |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1427 | static jobject translate_gps_navigation_message(JNIEnv* env, GpsNavigationMessage* message) { |
| 1428 | size_t dataLength = message->data_length; |
| 1429 | uint8_t* data = message->data; |
| 1430 | if (dataLength == 0 || data == NULL) { |
Bernhard Rosenkränzer | 46c82b4 | 2014-11-30 11:04:10 +0100 | [diff] [blame] | 1431 | ALOGE("Invalid Navigation Message found: data=%p, length=%zd", data, dataLength); |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1432 | return NULL; |
| 1433 | } |
| 1434 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1435 | jclass navigationMessageClass = env->FindClass("android/location/GnssNavigationMessage"); |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1436 | jmethodID navigationMessageCtor = env->GetMethodID(navigationMessageClass, "<init>", "()V"); |
| 1437 | jobject navigationMessageObject = env->NewObject(navigationMessageClass, navigationMessageCtor); |
| 1438 | |
| 1439 | jmethodID setTypeMethod = env->GetMethodID(navigationMessageClass, "setType", "(B)V"); |
| 1440 | env->CallVoidMethod(navigationMessageObject, setTypeMethod, message->type); |
| 1441 | |
| 1442 | jmethodID setPrnMethod = env->GetMethodID(navigationMessageClass, "setPrn", "(B)V"); |
| 1443 | env->CallVoidMethod(navigationMessageObject, setPrnMethod, message->prn); |
| 1444 | |
| 1445 | jmethodID setMessageIdMethod = env->GetMethodID(navigationMessageClass, "setMessageId", "(S)V"); |
| 1446 | env->CallVoidMethod(navigationMessageObject, setMessageIdMethod, message->message_id); |
| 1447 | |
| 1448 | jmethodID setSubmessageIdMethod = |
| 1449 | env->GetMethodID(navigationMessageClass, "setSubmessageId", "(S)V"); |
| 1450 | env->CallVoidMethod(navigationMessageObject, setSubmessageIdMethod, message->submessage_id); |
| 1451 | |
| 1452 | jbyteArray dataArray = env->NewByteArray(dataLength); |
| 1453 | env->SetByteArrayRegion(dataArray, 0, dataLength, (jbyte*) data); |
| 1454 | jmethodID setDataMethod = env->GetMethodID(navigationMessageClass, "setData", "([B)V"); |
| 1455 | env->CallVoidMethod(navigationMessageObject, setDataMethod, dataArray); |
| 1456 | |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1457 | env->DeleteLocalRef(navigationMessageClass); |
| 1458 | env->DeleteLocalRef(dataArray); |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1459 | return navigationMessageObject; |
| 1460 | } |
| 1461 | |
| 1462 | static void navigation_message_callback(GpsNavigationMessage* message) { |
| 1463 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 1464 | if (message == NULL) { |
| 1465 | ALOGE("Invalid Navigation Message provided to callback"); |
| 1466 | return; |
| 1467 | } |
| 1468 | |
| 1469 | if (message->size == sizeof(GpsNavigationMessage)) { |
| 1470 | jobject navigationMessage = translate_gps_navigation_message(env, message); |
| 1471 | |
| 1472 | jclass navigationMessageEventClass = |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1473 | env->FindClass("android/location/GnssNavigationMessageEvent"); |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1474 | jmethodID navigationMessageEventCtor = env->GetMethodID( |
| 1475 | navigationMessageEventClass, |
| 1476 | "<init>", |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame^] | 1477 | "(Landroid/location/GnssNavigationMessage;)V"); |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1478 | jobject navigationMessageEvent = env->NewObject( |
| 1479 | navigationMessageEventClass, |
| 1480 | navigationMessageEventCtor, |
| 1481 | navigationMessage); |
| 1482 | |
| 1483 | env->CallVoidMethod(mCallbacksObj, method_reportNavigationMessages, navigationMessageEvent); |
| 1484 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1485 | |
| 1486 | env->DeleteLocalRef(navigationMessage); |
| 1487 | env->DeleteLocalRef(navigationMessageEventClass); |
| 1488 | env->DeleteLocalRef(navigationMessageEvent); |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1489 | } else { |
Bernhard Rosenkränzer | 46c82b4 | 2014-11-30 11:04:10 +0100 | [diff] [blame] | 1490 | ALOGE("Invalid GpsNavigationMessage size found: %zd", message->size); |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1491 | } |
| 1492 | } |
| 1493 | |
| 1494 | GpsNavigationMessageCallbacks sGpsNavigationMessageCallbacks = { |
| 1495 | sizeof(GpsNavigationMessageCallbacks), |
| 1496 | navigation_message_callback, |
| 1497 | }; |
| 1498 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1499 | static jboolean android_location_GnssLocationProvider_is_navigation_message_supported( |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1500 | JNIEnv* env, |
| 1501 | jclass clazz) { |
| 1502 | if(sGpsNavigationMessageInterface != NULL) { |
| 1503 | return JNI_TRUE; |
| 1504 | } |
| 1505 | return JNI_FALSE; |
| 1506 | } |
| 1507 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1508 | static jboolean android_location_GnssLocationProvider_start_navigation_message_collection( |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1509 | JNIEnv* env, |
| 1510 | jobject obj) { |
| 1511 | if (sGpsNavigationMessageInterface == NULL) { |
| 1512 | ALOGE("Navigation Message interface is not available."); |
| 1513 | return JNI_FALSE; |
| 1514 | } |
| 1515 | |
| 1516 | int result = sGpsNavigationMessageInterface->init(&sGpsNavigationMessageCallbacks); |
| 1517 | if (result != GPS_NAVIGATION_MESSAGE_OPERATION_SUCCESS) { |
| 1518 | ALOGE("An error has been found in %s: %d", __FUNCTION__, result); |
| 1519 | return JNI_FALSE; |
| 1520 | } |
| 1521 | |
| 1522 | return JNI_TRUE; |
| 1523 | } |
| 1524 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1525 | static jboolean android_location_GnssLocationProvider_stop_navigation_message_collection( |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1526 | JNIEnv* env, |
| 1527 | jobject obj) { |
| 1528 | if (sGpsNavigationMessageInterface == NULL) { |
| 1529 | ALOGE("Navigation Message interface is not available."); |
| 1530 | return JNI_FALSE; |
| 1531 | } |
| 1532 | |
| 1533 | sGpsNavigationMessageInterface->close(); |
| 1534 | return JNI_TRUE; |
| 1535 | } |
| 1536 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1537 | static void android_location_GnssLocationProvider_configuration_update(JNIEnv* env, jobject obj, |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1538 | jstring config_content) |
| 1539 | { |
| 1540 | if (!sGnssConfigurationInterface) { |
| 1541 | ALOGE("no GPS configuration interface in configuraiton_update"); |
| 1542 | return; |
| 1543 | } |
| 1544 | const char *data = env->GetStringUTFChars(config_content, NULL); |
| 1545 | ALOGD("GPS configuration:\n %s", data); |
| 1546 | sGnssConfigurationInterface->configuration_update( |
| 1547 | data, env->GetStringUTFLength(config_content)); |
| 1548 | env->ReleaseStringUTFChars(config_content, data); |
| 1549 | } |
| 1550 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 1551 | static const JNINativeMethod sMethods[] = { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1552 | /* name, signature, funcPtr */ |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1553 | {"class_init_native", "()V", (void *)android_location_GnssLocationProvider_class_init_native}, |
| 1554 | {"native_is_supported", "()Z", (void*)android_location_GnssLocationProvider_is_supported}, |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 1555 | {"native_is_agps_ril_supported", "()Z", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1556 | (void*)android_location_GnssLocationProvider_is_agps_ril_supported}, |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 1557 | {"native_is_gnss_configuration_supported", "()Z", |
| 1558 | (void*)android_location_gpsLocationProvider_is_gnss_configuration_supported}, |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1559 | {"native_init", "()Z", (void*)android_location_GnssLocationProvider_init}, |
| 1560 | {"native_cleanup", "()V", (void*)android_location_GnssLocationProvider_cleanup}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1561 | {"native_set_position_mode", |
| 1562 | "(IIIII)Z", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1563 | (void*)android_location_GnssLocationProvider_set_position_mode}, |
| 1564 | {"native_start", "()Z", (void*)android_location_GnssLocationProvider_start}, |
| 1565 | {"native_stop", "()Z", (void*)android_location_GnssLocationProvider_stop}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1566 | {"native_delete_aiding_data", |
| 1567 | "(I)V", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1568 | (void*)android_location_GnssLocationProvider_delete_aiding_data}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1569 | {"native_read_sv_status", |
| 1570 | "([I[F[F[F[I)I", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1571 | (void*)android_location_GnssLocationProvider_read_sv_status}, |
| 1572 | {"native_read_nmea", "([BI)I", (void*)android_location_GnssLocationProvider_read_nmea}, |
| 1573 | {"native_inject_time", "(JJI)V", (void*)android_location_GnssLocationProvider_inject_time}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1574 | {"native_inject_location", |
| 1575 | "(DDF)V", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1576 | (void*)android_location_GnssLocationProvider_inject_location}, |
| 1577 | {"native_supports_xtra", "()Z", (void*)android_location_GnssLocationProvider_supports_xtra}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1578 | {"native_inject_xtra_data", |
| 1579 | "([BI)V", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1580 | (void*)android_location_GnssLocationProvider_inject_xtra_data}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1581 | {"native_agps_data_conn_open", |
| 1582 | "(Ljava/lang/String;I)V", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1583 | (void*)android_location_GnssLocationProvider_agps_data_conn_open}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1584 | {"native_agps_data_conn_closed", |
| 1585 | "()V", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1586 | (void*)android_location_GnssLocationProvider_agps_data_conn_closed}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1587 | {"native_agps_data_conn_failed", |
| 1588 | "()V", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1589 | (void*)android_location_GnssLocationProvider_agps_data_conn_failed}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1590 | {"native_agps_set_id", |
| 1591 | "(ILjava/lang/String;)V", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1592 | (void*)android_location_GnssLocationProvider_agps_set_id}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1593 | {"native_agps_set_ref_location_cellid", |
| 1594 | "(IIIII)V", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1595 | (void*)android_location_GnssLocationProvider_agps_set_reference_location_cellid}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1596 | {"native_set_agps_server", |
| 1597 | "(ILjava/lang/String;I)V", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1598 | (void*)android_location_GnssLocationProvider_set_agps_server}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1599 | {"native_send_ni_response", |
| 1600 | "(II)V", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1601 | (void*)android_location_GnssLocationProvider_send_ni_response}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1602 | {"native_agps_ni_message", |
| 1603 | "([BI)V", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1604 | (void *)android_location_GnssLocationProvider_agps_send_ni_message}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1605 | {"native_get_internal_state", |
| 1606 | "()Ljava/lang/String;", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1607 | (void*)android_location_GnssLocationProvider_get_internal_state}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1608 | {"native_update_network_state", |
| 1609 | "(ZIZZLjava/lang/String;Ljava/lang/String;)V", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1610 | (void*)android_location_GnssLocationProvider_update_network_state }, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1611 | {"native_is_geofence_supported", |
| 1612 | "()Z", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1613 | (void*) android_location_GnssLocationProvider_is_geofence_supported}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1614 | {"native_add_geofence", |
| 1615 | "(IDDDIIII)Z", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1616 | (void *)android_location_GnssLocationProvider_add_geofence}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1617 | {"native_remove_geofence", |
| 1618 | "(I)Z", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1619 | (void *)android_location_GnssLocationProvider_remove_geofence}, |
| 1620 | {"native_pause_geofence", "(I)Z", (void *)android_location_GnssLocationProvider_pause_geofence}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1621 | {"native_resume_geofence", |
| 1622 | "(II)Z", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1623 | (void *)android_location_GnssLocationProvider_resume_geofence}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1624 | {"native_is_measurement_supported", |
| 1625 | "()Z", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1626 | (void*) android_location_GnssLocationProvider_is_measurement_supported}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1627 | {"native_start_measurement_collection", |
| 1628 | "()Z", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1629 | (void*) android_location_GnssLocationProvider_start_measurement_collection}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1630 | {"native_stop_measurement_collection", |
| 1631 | "()Z", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1632 | (void*) android_location_GnssLocationProvider_stop_measurement_collection}, |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1633 | {"native_is_navigation_message_supported", |
| 1634 | "()Z", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1635 | (void*) android_location_GnssLocationProvider_is_navigation_message_supported}, |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1636 | {"native_start_navigation_message_collection", |
| 1637 | "()Z", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1638 | (void*) android_location_GnssLocationProvider_start_navigation_message_collection}, |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1639 | {"native_stop_navigation_message_collection", |
| 1640 | "()Z", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1641 | (void*) android_location_GnssLocationProvider_stop_navigation_message_collection}, |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1642 | {"native_configuration_update", |
| 1643 | "(Ljava/lang/String;)V", |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1644 | (void*)android_location_GnssLocationProvider_configuration_update}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1645 | }; |
| 1646 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1647 | int register_android_server_location_GnssLocationProvider(JNIEnv* env) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1648 | { |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1649 | return jniRegisterNativeMethods( |
| 1650 | env, |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1651 | "com/android/server/location/GnssLocationProvider", |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1652 | sMethods, |
| 1653 | NELEM(sMethods)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1654 | } |
| 1655 | |
| 1656 | } /* namespace android */ |