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