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 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 21 | #include <android/hardware/gnss/1.0/IGnss.h> |
| 22 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | #include "JNIHelp.h" |
| 24 | #include "jni.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> |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 37 | #include <cinttypes> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 39 | static jobject mCallbacksObj = NULL; |
| 40 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | static jmethodID method_reportLocation; |
| 42 | static jmethodID method_reportStatus; |
| 43 | static jmethodID method_reportSvStatus; |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 44 | static jmethodID method_reportAGpsStatus; |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 45 | static jmethodID method_reportNmea; |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 46 | static jmethodID method_setEngineCapabilities; |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 47 | static jmethodID method_setGnssYearOfHardware; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | static jmethodID method_xtraDownloadRequest; |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 49 | static jmethodID method_reportNiNotification; |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 50 | static jmethodID method_requestRefLocation; |
| 51 | static jmethodID method_requestSetID; |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 52 | static jmethodID method_requestUtcTime; |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 53 | static jmethodID method_reportGeofenceTransition; |
| 54 | static jmethodID method_reportGeofenceStatus; |
| 55 | static jmethodID method_reportGeofenceAddStatus; |
| 56 | static jmethodID method_reportGeofenceRemoveStatus; |
| 57 | static jmethodID method_reportGeofencePauseStatus; |
| 58 | static jmethodID method_reportGeofenceResumeStatus; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 59 | static jmethodID method_reportMeasurementData; |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 60 | static jmethodID method_reportNavigationMessages; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 62 | /* |
| 63 | * Save a pointer to JavaVm to attach/detach threads executing |
| 64 | * callback methods that need to make JNI calls. |
| 65 | */ |
| 66 | static JavaVM* sJvm; |
| 67 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 68 | using android::OK; |
| 69 | using android::sp; |
| 70 | using android::status_t; |
| 71 | using android::String16; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 73 | using android::hardware::Return; |
| 74 | using android::hardware::Void; |
| 75 | using android::hardware::hidl_vec; |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 76 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 77 | using android::hardware::gnss::V1_0::IAGnss; |
| 78 | using android::hardware::gnss::V1_0::IAGnssCallback; |
| 79 | using android::hardware::gnss::V1_0::IAGnssCallback; |
| 80 | using android::hardware::gnss::V1_0::IAGnssRil; |
| 81 | using android::hardware::gnss::V1_0::IAGnssRilCallback; |
| 82 | using android::hardware::gnss::V1_0::IGnss; |
| 83 | using android::hardware::gnss::V1_0::IGnssCallback; |
| 84 | using android::hardware::gnss::V1_0::IGnssConfiguration; |
| 85 | using android::hardware::gnss::V1_0::IGnssDebug; |
| 86 | using android::hardware::gnss::V1_0::IGnssGeofenceCallback; |
| 87 | using android::hardware::gnss::V1_0::IGnssGeofencing; |
| 88 | using android::hardware::gnss::V1_0::IGnssMeasurement; |
| 89 | using android::hardware::gnss::V1_0::IGnssMeasurementCallback; |
| 90 | using android::hardware::gnss::V1_0::IGnssNavigationMessage; |
| 91 | using android::hardware::gnss::V1_0::IGnssNavigationMessageCallback; |
| 92 | using android::hardware::gnss::V1_0::IGnssNi; |
| 93 | using android::hardware::gnss::V1_0::IGnssNiCallback; |
| 94 | using android::hardware::gnss::V1_0::IGnssXtra; |
| 95 | using android::hardware::gnss::V1_0::IGnssXtraCallback; |
Wyatt Riley | 49d9891 | 2016-05-17 16:14:48 -0700 | [diff] [blame] | 96 | |
Wyatt Riley | f6527ae | 2016-05-23 15:23:12 -0700 | [diff] [blame] | 97 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 98 | sp<IGnss> gnssHal = nullptr; |
| 99 | sp<IGnssXtra> gnssXtraIface = nullptr; |
| 100 | sp<IAGnssRil> agnssRilIface = nullptr; |
| 101 | sp<IGnssGeofencing> gnssGeofencingIface = nullptr; |
| 102 | sp<IAGnss> agnssIface = nullptr; |
| 103 | sp<IGnssDebug> gnssDebugIface = nullptr; |
| 104 | sp<IGnssConfiguration> gnssConfigurationIface = nullptr; |
| 105 | sp<IGnssNi> gnssNiIface = nullptr; |
| 106 | sp<IGnssMeasurement> gnssMeasurementIface = nullptr; |
| 107 | sp<IGnssNavigationMessage> gnssNavigationMessageIface = nullptr; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | |
Mike Lockwood | 8f5a800 | 2010-04-07 09:05:26 -0400 | [diff] [blame] | 109 | #define WAKE_LOCK_NAME "GPS" |
| 110 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | namespace android { |
| 112 | |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 113 | template<class T> |
| 114 | class JavaMethodHelper { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 115 | public: |
| 116 | // Helper function to call setter on a Java object. |
| 117 | static void callJavaMethod( |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 118 | JNIEnv* env, |
| 119 | jclass clazz, |
| 120 | jobject object, |
| 121 | const char* method_name, |
| 122 | T value); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 123 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 124 | private: |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 125 | static const char *const signature_; |
| 126 | }; |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 127 | |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 128 | template<class T> |
| 129 | void JavaMethodHelper<T>::callJavaMethod( |
| 130 | JNIEnv* env, |
| 131 | jclass clazz, |
| 132 | jobject object, |
| 133 | const char* method_name, |
| 134 | T value) { |
| 135 | jmethodID method = env->GetMethodID(clazz, method_name, signature_); |
| 136 | env->CallVoidMethod(object, method, value); |
| 137 | } |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 138 | |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 139 | class JavaObject { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 140 | public: |
| 141 | JavaObject(JNIEnv* env, const char* class_name); |
| 142 | virtual ~JavaObject(); |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 143 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 144 | template<class T> |
| 145 | void callSetter(const char* method_name, T value); |
| 146 | template<class T> |
| 147 | void callSetter(const char* method_name, T* value, size_t size); |
| 148 | jobject get(); |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 149 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 150 | private: |
| 151 | JNIEnv* env_; |
| 152 | jclass clazz_; |
| 153 | jobject object_; |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | JavaObject::JavaObject(JNIEnv* env, const char* class_name) : env_(env) { |
| 157 | clazz_ = env_->FindClass(class_name); |
| 158 | jmethodID ctor = env->GetMethodID(clazz_, "<init>", "()V"); |
| 159 | object_ = env_->NewObject(clazz_, ctor); |
| 160 | } |
| 161 | |
| 162 | JavaObject::~JavaObject() { |
| 163 | env_->DeleteLocalRef(clazz_); |
| 164 | } |
| 165 | |
| 166 | template<class T> |
| 167 | void JavaObject::callSetter(const char* method_name, T value) { |
| 168 | JavaMethodHelper<T>::callJavaMethod( |
| 169 | env_, clazz_, object_, method_name, value); |
| 170 | } |
| 171 | |
| 172 | template<> |
| 173 | void JavaObject::callSetter( |
| 174 | const char* method_name, uint8_t* value, size_t size) { |
| 175 | jbyteArray array = env_->NewByteArray(size); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 176 | env_->SetByteArrayRegion(array, 0, size, reinterpret_cast<jbyte*>(value)); |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 177 | jmethodID method = env_->GetMethodID( |
| 178 | clazz_, |
| 179 | method_name, |
| 180 | "([B)V"); |
| 181 | env_->CallVoidMethod(object_, method, array); |
Lifu Tang | fe427f2 | 2016-10-08 02:57:53 -0700 | [diff] [blame] | 182 | env_->DeleteLocalRef(array); |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | jobject JavaObject::get() { |
| 186 | return object_; |
| 187 | } |
| 188 | |
| 189 | // Define Java method signatures for all known types. |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 190 | template<> |
| 191 | const char *const JavaMethodHelper<uint8_t>::signature_ = "(B)V"; |
| 192 | template<> |
| 193 | const char *const JavaMethodHelper<int8_t>::signature_ = "(B)V"; |
| 194 | template<> |
| 195 | const char *const JavaMethodHelper<int16_t>::signature_ = "(S)V"; |
| 196 | template<> |
| 197 | const char *const JavaMethodHelper<uint16_t>::signature_ = "(S)V"; |
| 198 | template<> |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 199 | const char *const JavaMethodHelper<int32_t>::signature_ = "(I)V"; |
| 200 | template<> |
| 201 | const char *const JavaMethodHelper<uint32_t>::signature_ = "(I)V"; |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 202 | template<> |
| 203 | const char *const JavaMethodHelper<int64_t>::signature_ = "(J)V"; |
| 204 | template<> |
| 205 | const char *const JavaMethodHelper<float>::signature_ = "(F)V"; |
| 206 | template<> |
| 207 | const char *const JavaMethodHelper<double>::signature_ = "(D)V"; |
| 208 | template<> |
| 209 | const char *const JavaMethodHelper<bool>::signature_ = "(Z)V"; |
| 210 | |
| 211 | #define SET(setter, value) object.callSetter("set" # setter, (value)) |
Lifu Tang | ccb4488 | 2016-03-09 19:32:29 -0800 | [diff] [blame] | 212 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 213 | static inline jboolean boolToJbool(bool value) { |
| 214 | return value ? JNI_TRUE : JNI_FALSE; |
| 215 | } |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 216 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 217 | static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) { |
| 218 | if (env->ExceptionCheck()) { |
| 219 | ALOGE("An exception was thrown by callback '%s'.", methodName); |
| 220 | LOGE_EX(env); |
| 221 | env->ExceptionClear(); |
| 222 | } |
| 223 | } |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 224 | |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 225 | class ScopedJniThreadAttach { |
| 226 | public: |
| 227 | ScopedJniThreadAttach() { |
| 228 | /* |
| 229 | * attachResult will also be JNI_OK if the thead was already attached to |
| 230 | * JNI before the call to AttachCurrentThread(). |
| 231 | */ |
| 232 | jint attachResult = sJvm->AttachCurrentThread(&mEnv, nullptr); |
| 233 | LOG_ALWAYS_FATAL_IF(attachResult != JNI_OK, "Unable to attach thread. Error %d", |
| 234 | attachResult); |
| 235 | } |
| 236 | |
| 237 | ~ScopedJniThreadAttach() { |
| 238 | jint detachResult = sJvm->DetachCurrentThread(); |
| 239 | /* |
| 240 | * Return if the thread was already detached. Log error for any other |
| 241 | * failure. |
| 242 | */ |
| 243 | if (detachResult == JNI_EDETACHED) { |
| 244 | return; |
| 245 | } |
| 246 | |
| 247 | LOG_ALWAYS_FATAL_IF(detachResult != JNI_OK, "Unable to detach thread. Error %d", |
| 248 | detachResult); |
| 249 | } |
| 250 | |
| 251 | JNIEnv* getEnv() { |
| 252 | /* |
| 253 | * Checking validity of mEnv in case the thread was detached elsewhere. |
| 254 | */ |
| 255 | LOG_ALWAYS_FATAL_IF(AndroidRuntime::getJNIEnv() != mEnv); |
| 256 | return mEnv; |
| 257 | } |
| 258 | |
| 259 | private: |
| 260 | JNIEnv* mEnv = nullptr; |
| 261 | }; |
| 262 | |
| 263 | thread_local std::unique_ptr<ScopedJniThreadAttach> tJniThreadAttacher; |
| 264 | |
| 265 | static JNIEnv* getJniEnv() { |
| 266 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 267 | |
| 268 | /* |
| 269 | * If env is nullptr, the thread is not already attached to |
| 270 | * JNI. It is attached below and the destructor for ScopedJniThreadAttach |
| 271 | * will detach it on thread exit. |
| 272 | */ |
| 273 | if (env == nullptr) { |
| 274 | tJniThreadAttacher.reset(new ScopedJniThreadAttach()); |
| 275 | env = tJniThreadAttacher->getEnv(); |
| 276 | } |
| 277 | |
| 278 | return env; |
| 279 | } |
| 280 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 281 | /* |
| 282 | * GnssCallback class implements the callback methods for IGnss interface. |
| 283 | */ |
| 284 | struct GnssCallback : public IGnssCallback { |
| 285 | Return<void> gnssLocationCb( |
| 286 | const android::hardware::gnss::V1_0::GnssLocation& location) override; |
| 287 | Return<void> gnssStatusCb(const IGnssCallback::GnssStatusValue status) override; |
| 288 | Return<void> gnssSvStatusCb(const IGnssCallback::GnssSvStatus& svStatus) override; |
| 289 | Return<void> gnssNmeaCb(int64_t timestamp, const android::hardware::hidl_string& nmea) override; |
| 290 | Return<void> gnssSetCapabilitesCb(uint32_t capabilities) override; |
| 291 | Return<void> gnssAcquireWakelockCb() override; |
| 292 | Return<void> gnssReleaseWakelockCb() override; |
| 293 | Return<void> gnssRequestTimeCb() override; |
| 294 | Return<void> gnssSetSystemInfoCb(const IGnssCallback::GnssSystemInfo& info) override; |
Lifu Tang | 38bce79 | 2016-02-24 17:17:38 -0800 | [diff] [blame] | 295 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 296 | static GnssSvInfo sGnssSvList[static_cast<uint32_t>( |
| 297 | android::hardware::gnss::V1_0::GnssMax::SVS_COUNT)]; |
| 298 | static size_t sGnssSvListSize; |
| 299 | |
| 300 | static const char* sNmeaString; |
| 301 | static size_t sNmeaStringLength; |
| 302 | }; |
| 303 | |
| 304 | IGnssCallback::GnssSvInfo GnssCallback::sGnssSvList[static_cast<uint32_t>( |
| 305 | android::hardware::gnss::V1_0::GnssMax::SVS_COUNT)]; |
| 306 | const char* GnssCallback::sNmeaString = nullptr; |
| 307 | size_t GnssCallback::sNmeaStringLength = 0; |
| 308 | size_t GnssCallback::sGnssSvListSize = 0; |
| 309 | |
| 310 | Return<void> GnssCallback::gnssLocationCb( |
| 311 | const ::android::hardware::gnss::V1_0::GnssLocation& location) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 312 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 313 | env->CallVoidMethod(mCallbacksObj, |
| 314 | method_reportLocation, |
| 315 | location.gnssLocationFlags, |
| 316 | static_cast<jdouble>(location.latitudeDegrees), |
| 317 | static_cast<jdouble>(location.longitudeDegrees), |
| 318 | static_cast<jdouble>(location.altitudeMeters), |
| 319 | static_cast<jfloat>(location.speedMetersPerSec), |
| 320 | static_cast<jfloat>(location.bearingDegrees), |
| 321 | static_cast<jfloat>(location.accuracyMeters), |
| 322 | static_cast<jlong>(location.timestamp)); |
| 323 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 324 | return Void(); |
| 325 | } |
| 326 | |
| 327 | Return<void> GnssCallback::gnssStatusCb(const IGnssCallback::GnssStatusValue status) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 328 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 329 | env->CallVoidMethod(mCallbacksObj, method_reportStatus, status); |
| 330 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 331 | return Void(); |
| 332 | } |
| 333 | |
| 334 | Return<void> GnssCallback::gnssSvStatusCb(const IGnssCallback::GnssSvStatus& svStatus) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 335 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 336 | |
| 337 | sGnssSvListSize = svStatus.numSvs; |
| 338 | if (sGnssSvListSize > static_cast<uint32_t>( |
| 339 | android::hardware::gnss::V1_0::GnssMax::SVS_COUNT)) { |
| 340 | ALOGD("Too many satellites %zd. Clamps to %u.", sGnssSvListSize, |
| 341 | static_cast<uint32_t>(android::hardware::gnss::V1_0::GnssMax::SVS_COUNT)); |
| 342 | sGnssSvListSize = static_cast<uint32_t>(android::hardware::gnss::V1_0::GnssMax::SVS_COUNT); |
Lifu Tang | 38bce79 | 2016-02-24 17:17:38 -0800 | [diff] [blame] | 343 | } |
| 344 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 345 | // Copy GNSS SV info into sGnssSvList, if any. |
| 346 | if (svStatus.numSvs > 0) { |
| 347 | memcpy(sGnssSvList, svStatus.gnssSvList.data(), sizeof(GnssSvInfo) * sGnssSvListSize); |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 348 | } |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 349 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 350 | env->CallVoidMethod(mCallbacksObj, method_reportSvStatus); |
| 351 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 352 | return Void(); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 355 | Return<void> GnssCallback::gnssNmeaCb( |
| 356 | int64_t timestamp, const ::android::hardware::hidl_string& nmea) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 357 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 358 | /* |
| 359 | * The Java code will call back to read these values. |
| 360 | * We do this to avoid creating unnecessary String objects. |
| 361 | */ |
| 362 | sNmeaString = nmea.c_str(); |
| 363 | sNmeaStringLength = nmea.size(); |
| 364 | |
| 365 | env->CallVoidMethod(mCallbacksObj, method_reportNmea, timestamp); |
| 366 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 367 | return Void(); |
| 368 | } |
| 369 | |
| 370 | Return<void> GnssCallback::gnssSetCapabilitesCb(uint32_t capabilities) { |
| 371 | ALOGD("%s: %du\n", __func__, capabilities); |
| 372 | |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 373 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 374 | env->CallVoidMethod(mCallbacksObj, method_setEngineCapabilities, capabilities); |
| 375 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 376 | return Void(); |
| 377 | } |
| 378 | |
| 379 | Return<void> GnssCallback::gnssAcquireWakelockCb() { |
| 380 | acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_NAME); |
| 381 | return Void(); |
| 382 | } |
| 383 | |
| 384 | Return<void> GnssCallback::gnssReleaseWakelockCb() { |
| 385 | release_wake_lock(WAKE_LOCK_NAME); |
| 386 | return Void(); |
| 387 | } |
| 388 | |
| 389 | Return<void> GnssCallback::gnssRequestTimeCb() { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 390 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 391 | env->CallVoidMethod(mCallbacksObj, method_requestUtcTime); |
| 392 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 393 | return Void(); |
| 394 | } |
| 395 | |
| 396 | Return<void> GnssCallback::gnssSetSystemInfoCb(const IGnssCallback::GnssSystemInfo& info) { |
| 397 | ALOGD("%s: yearOfHw=%d\n", __func__, info.yearOfHw); |
| 398 | |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 399 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 400 | env->CallVoidMethod(mCallbacksObj, method_setGnssYearOfHardware, |
| 401 | info.yearOfHw); |
| 402 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 403 | return Void(); |
| 404 | } |
| 405 | |
| 406 | class GnssXtraCallback : public IGnssXtraCallback { |
| 407 | Return<void> downloadRequestCb() override; |
| 408 | }; |
| 409 | |
| 410 | /* |
| 411 | * GnssXtraCallback class implements the callback methods for the IGnssXtra |
| 412 | * interface. |
| 413 | */ |
| 414 | Return<void> GnssXtraCallback::downloadRequestCb() { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 415 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 416 | env->CallVoidMethod(mCallbacksObj, method_xtraDownloadRequest); |
| 417 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 418 | return Void(); |
| 419 | } |
| 420 | |
| 421 | /* |
| 422 | * GnssGeofenceCallback class implements the callback methods for the |
| 423 | * IGnssGeofence interface. |
| 424 | */ |
| 425 | struct GnssGeofenceCallback : public IGnssGeofenceCallback { |
| 426 | // Methods from ::android::hardware::gps::V1_0::IGnssGeofenceCallback follow. |
| 427 | Return<void> gnssGeofenceTransitionCb( |
| 428 | int32_t geofenceId, |
| 429 | const android::hardware::gnss::V1_0::GnssLocation& location, |
| 430 | GeofenceTransition transition, |
| 431 | hardware::gnss::V1_0::GnssUtcTime timestamp) override; |
| 432 | Return<void> gnssGeofenceStatusCb( |
| 433 | GeofenceAvailability status, |
| 434 | const android::hardware::gnss::V1_0::GnssLocation& location) override; |
| 435 | Return<void> gnssGeofenceAddCb(int32_t geofenceId, |
| 436 | GeofenceStatus status) override; |
| 437 | Return<void> gnssGeofenceRemoveCb(int32_t geofenceId, |
| 438 | GeofenceStatus status) override; |
| 439 | Return<void> gnssGeofencePauseCb(int32_t geofenceId, |
| 440 | GeofenceStatus status) override; |
| 441 | Return<void> gnssGeofenceResumeCb(int32_t geofenceId, |
| 442 | GeofenceStatus status) override; |
| 443 | }; |
| 444 | |
| 445 | Return<void> GnssGeofenceCallback::gnssGeofenceTransitionCb( |
| 446 | int32_t geofenceId, |
| 447 | const android::hardware::gnss::V1_0::GnssLocation& location, |
| 448 | GeofenceTransition transition, |
| 449 | hardware::gnss::V1_0::GnssUtcTime timestamp) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 450 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 451 | |
| 452 | env->CallVoidMethod(mCallbacksObj, |
| 453 | method_reportGeofenceTransition, |
| 454 | geofenceId, |
| 455 | location.gnssLocationFlags, |
| 456 | static_cast<jdouble>(location.latitudeDegrees), |
| 457 | static_cast<jdouble>(location.longitudeDegrees), |
| 458 | static_cast<jdouble>(location.altitudeMeters), |
| 459 | static_cast<jfloat>(location.speedMetersPerSec), |
| 460 | static_cast<jfloat>(location.bearingDegrees), |
| 461 | static_cast<jfloat>(location.accuracyMeters), |
| 462 | static_cast<jlong>(location.timestamp), |
| 463 | transition, |
| 464 | timestamp); |
| 465 | |
| 466 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 467 | return Void(); |
| 468 | } |
| 469 | |
| 470 | Return<void> GnssGeofenceCallback::gnssGeofenceStatusCb( |
| 471 | GeofenceAvailability status, |
| 472 | const android::hardware::gnss::V1_0::GnssLocation& location) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 473 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 474 | env->CallVoidMethod(mCallbacksObj, |
| 475 | method_reportGeofenceStatus, |
| 476 | status, |
| 477 | location.gnssLocationFlags, |
| 478 | static_cast<jdouble>(location.latitudeDegrees), |
| 479 | static_cast<jdouble>(location.longitudeDegrees), |
| 480 | static_cast<jdouble>(location.altitudeMeters), |
| 481 | static_cast<jfloat>(location.speedMetersPerSec), |
| 482 | static_cast<jfloat>(location.bearingDegrees), |
| 483 | static_cast<jfloat>(location.accuracyMeters), |
| 484 | static_cast<jlong>(location.timestamp)); |
| 485 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 486 | return Void(); |
| 487 | } |
| 488 | |
| 489 | Return<void> GnssGeofenceCallback::gnssGeofenceAddCb(int32_t geofenceId, |
| 490 | GeofenceStatus status) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 491 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 492 | if (status != IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS) { |
| 493 | ALOGE("%s: Error in adding a Geofence: %d\n", __func__, status); |
| 494 | } |
| 495 | |
| 496 | env->CallVoidMethod(mCallbacksObj, |
| 497 | method_reportGeofenceAddStatus, |
| 498 | geofenceId, |
| 499 | status); |
| 500 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 501 | return Void(); |
| 502 | } |
| 503 | |
| 504 | Return<void> GnssGeofenceCallback::gnssGeofenceRemoveCb(int32_t geofenceId, |
| 505 | GeofenceStatus status) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 506 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 507 | if (status != IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS) { |
| 508 | ALOGE("%s: Error in removing a Geofence: %d\n", __func__, status); |
| 509 | } |
| 510 | |
| 511 | env->CallVoidMethod(mCallbacksObj, |
| 512 | method_reportGeofenceRemoveStatus, |
| 513 | geofenceId, status); |
| 514 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 515 | return Void(); |
| 516 | } |
| 517 | |
| 518 | Return<void> GnssGeofenceCallback::gnssGeofencePauseCb(int32_t geofenceId, |
| 519 | GeofenceStatus status) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 520 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 521 | if (status != IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS) { |
| 522 | ALOGE("%s: Error in pausing Geofence: %d\n", __func__, status); |
| 523 | } |
| 524 | |
| 525 | env->CallVoidMethod(mCallbacksObj, |
| 526 | method_reportGeofencePauseStatus, |
| 527 | geofenceId, status); |
| 528 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 529 | return Void(); |
| 530 | } |
| 531 | |
| 532 | Return<void> GnssGeofenceCallback::gnssGeofenceResumeCb(int32_t geofenceId, |
| 533 | GeofenceStatus status) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 534 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 535 | if (status != IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS) { |
| 536 | ALOGE("%s: Error in resuming Geofence: %d\n", __func__, status); |
| 537 | } |
| 538 | |
| 539 | env->CallVoidMethod(mCallbacksObj, |
| 540 | method_reportGeofenceResumeStatus, |
| 541 | geofenceId, status); |
| 542 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 543 | return Void(); |
| 544 | } |
| 545 | |
| 546 | /* |
| 547 | * GnssNavigationMessageCallback interface implements the callback methods |
| 548 | * required by the IGnssNavigationMessage interface. |
| 549 | */ |
| 550 | struct GnssNavigationMessageCallback : public IGnssNavigationMessageCallback { |
| 551 | /* |
| 552 | * Methods from ::android::hardware::gps::V1_0::IGnssNavigationMessageCallback |
| 553 | * follow. |
| 554 | */ |
| 555 | Return<void> gnssNavigationMessageCb( |
| 556 | const IGnssNavigationMessageCallback::GnssNavigationMessage& message) override; |
| 557 | }; |
| 558 | |
| 559 | Return<void> GnssNavigationMessageCallback::gnssNavigationMessageCb( |
| 560 | const IGnssNavigationMessageCallback::GnssNavigationMessage& message) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 561 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 562 | |
| 563 | size_t dataLength = message.data.size(); |
| 564 | |
| 565 | std::vector<uint8_t> navigationData = message.data; |
| 566 | uint8_t* data = &(navigationData[0]); |
| 567 | if (dataLength == 0 || data == NULL) { |
| 568 | ALOGE("Invalid Navigation Message found: data=%p, length=%zd", data, |
| 569 | dataLength); |
| 570 | return Void(); |
| 571 | } |
| 572 | |
| 573 | JavaObject object(env, "android/location/GnssNavigationMessage"); |
| 574 | SET(Type, static_cast<int32_t>(message.type)); |
| 575 | SET(Svid, static_cast<int32_t>(message.svid)); |
| 576 | SET(MessageId, static_cast<int32_t>(message.messageId)); |
| 577 | SET(SubmessageId, static_cast<int32_t>(message.submessageId)); |
| 578 | object.callSetter("setData", data, dataLength); |
| 579 | SET(Status, static_cast<int32_t>(message.status)); |
| 580 | |
| 581 | jobject navigationMessage = object.get(); |
| 582 | env->CallVoidMethod(mCallbacksObj, |
| 583 | method_reportNavigationMessages, |
| 584 | navigationMessage); |
| 585 | env->DeleteLocalRef(navigationMessage); |
| 586 | return Void(); |
| 587 | } |
| 588 | |
| 589 | /* |
| 590 | * GnssMeasurementCallback implements the callback methods required for the |
| 591 | * GnssMeasurement interface. |
| 592 | */ |
| 593 | struct GnssMeasurementCallback : public IGnssMeasurementCallback { |
| 594 | Return<void> GnssMeasurementCb(const IGnssMeasurementCallback::GnssData& data); |
| 595 | private: |
| 596 | jobject translateGnssMeasurement( |
| 597 | JNIEnv* env, const IGnssMeasurementCallback::GnssMeasurement* measurement); |
| 598 | jobject translateGnssClock( |
| 599 | JNIEnv* env, const IGnssMeasurementCallback::GnssClock* clock); |
| 600 | jobjectArray translateGnssMeasurements( |
| 601 | JNIEnv* env, |
| 602 | const IGnssMeasurementCallback::GnssMeasurement* measurements, |
| 603 | size_t count); |
| 604 | void setMeasurementData(JNIEnv* env, jobject clock, jobjectArray measurementArray); |
| 605 | }; |
| 606 | |
| 607 | |
| 608 | Return<void> GnssMeasurementCallback::GnssMeasurementCb( |
| 609 | const IGnssMeasurementCallback::GnssData& data) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 610 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 611 | |
| 612 | jobject clock; |
| 613 | jobjectArray measurementArray; |
| 614 | |
| 615 | clock = translateGnssClock(env, &data.clock); |
| 616 | measurementArray = translateGnssMeasurements( |
| 617 | env, data.measurements.data(), data.measurementCount); |
| 618 | setMeasurementData(env, clock, measurementArray); |
| 619 | |
| 620 | env->DeleteLocalRef(clock); |
| 621 | env->DeleteLocalRef(measurementArray); |
| 622 | return Void(); |
| 623 | } |
| 624 | |
| 625 | jobject GnssMeasurementCallback::translateGnssMeasurement( |
| 626 | JNIEnv* env, const IGnssMeasurementCallback::GnssMeasurement* measurement) { |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 627 | JavaObject object(env, "android/location/GnssMeasurement"); |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 628 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 629 | uint32_t flags = static_cast<uint32_t>(measurement->flags); |
Mike Cailean | 96635bd | 2016-03-24 19:34:16 -0700 | [diff] [blame] | 630 | |
| 631 | SET(Svid, static_cast<int32_t>(measurement->svid)); |
Lifu Tang | 76a620f | 2016-02-26 19:53:01 -0800 | [diff] [blame] | 632 | SET(ConstellationType, static_cast<int32_t>(measurement->constellation)); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 633 | SET(TimeOffsetNanos, measurement->timeOffsetNs); |
Lifu Tang | 76a620f | 2016-02-26 19:53:01 -0800 | [diff] [blame] | 634 | SET(State, static_cast<int32_t>(measurement->state)); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 635 | SET(ReceivedSvTimeNanos, measurement->receivedSvTimeInNs); |
Lifu Tang | 76a620f | 2016-02-26 19:53:01 -0800 | [diff] [blame] | 636 | SET(ReceivedSvTimeUncertaintyNanos, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 637 | measurement->receivedSvTimeUncertaintyInNs); |
| 638 | SET(Cn0DbHz, measurement->cN0DbHz); |
| 639 | SET(PseudorangeRateMetersPerSecond, measurement->pseudorangeRateMps); |
Lifu Tang | 76a620f | 2016-02-26 19:53:01 -0800 | [diff] [blame] | 640 | SET(PseudorangeRateUncertaintyMetersPerSecond, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 641 | measurement->pseudorangeRateUncertaintyMps); |
Lifu Tang | 76a620f | 2016-02-26 19:53:01 -0800 | [diff] [blame] | 642 | SET(AccumulatedDeltaRangeState, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 643 | (static_cast<int32_t>(measurement->accumulatedDeltaRangeState))); |
| 644 | SET(AccumulatedDeltaRangeMeters, measurement->accumulatedDeltaRangeM); |
Lifu Tang | 76a620f | 2016-02-26 19:53:01 -0800 | [diff] [blame] | 645 | SET(AccumulatedDeltaRangeUncertaintyMeters, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 646 | measurement->accumulatedDeltaRangeUncertaintyM); |
| 647 | |
| 648 | if (flags & static_cast<uint32_t>(GnssMeasurementFlags::HAS_CARRIER_FREQUENCY)) { |
| 649 | SET(CarrierFrequencyHz, measurement->carrierFrequencyHz); |
| 650 | } |
| 651 | |
| 652 | if (flags & static_cast<uint32_t>(GnssMeasurementFlags::HAS_CARRIER_PHASE)) { |
| 653 | SET(CarrierPhase, measurement->carrierPhase); |
| 654 | } |
| 655 | |
| 656 | if (flags & static_cast<uint32_t>(GnssMeasurementFlags::HAS_CARRIER_PHASE_UNCERTAINTY)) { |
| 657 | SET(CarrierPhaseUncertainty, measurement->carrierPhaseUncertainty); |
| 658 | } |
| 659 | |
| 660 | SET(MultipathIndicator, static_cast<int32_t>(measurement->multipathIndicator)); |
| 661 | |
| 662 | if (flags & static_cast<uint32_t>(GnssMeasurementFlags::HAS_SNR)) { |
| 663 | SET(SnrInDb, measurement->snrDb); |
| 664 | } |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 665 | |
| 666 | return object.get(); |
| 667 | } |
| 668 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 669 | jobject GnssMeasurementCallback::translateGnssClock( |
| 670 | JNIEnv* env, const IGnssMeasurementCallback::GnssClock* clock) { |
| 671 | JavaObject object(env, "android/location/GnssClock"); |
| 672 | |
| 673 | uint32_t flags = static_cast<uint32_t>(clock->gnssClockFlags); |
| 674 | if (flags & static_cast<uint32_t>(GnssClockFlags::HAS_LEAP_SECOND)) { |
| 675 | SET(LeapSecond, static_cast<int32_t>(clock->leapSecond)); |
| 676 | } |
| 677 | |
| 678 | if (flags & static_cast<uint32_t>(GnssClockFlags::HAS_TIME_UNCERTAINTY)) { |
| 679 | SET(TimeUncertaintyNanos, clock->timeUncertaintyNs); |
| 680 | } |
| 681 | |
| 682 | if (flags & static_cast<uint32_t>(GnssClockFlags::HAS_FULL_BIAS)) { |
| 683 | SET(FullBiasNanos, clock->fullBiasNs); |
| 684 | } |
| 685 | |
| 686 | if (flags & static_cast<uint32_t>(GnssClockFlags::HAS_BIAS)) { |
| 687 | SET(BiasNanos, clock->biasNs); |
| 688 | } |
| 689 | |
| 690 | if (flags & static_cast<uint32_t>(GnssClockFlags::HAS_BIAS_UNCERTAINTY)) { |
| 691 | SET(BiasUncertaintyNanos, clock->biasUncertaintyNs); |
| 692 | } |
| 693 | |
| 694 | if (flags & static_cast<uint32_t>(GnssClockFlags::HAS_DRIFT)) { |
| 695 | SET(DriftNanosPerSecond, clock->driftNsps); |
| 696 | } |
| 697 | |
| 698 | if (flags & static_cast<uint32_t>(GnssClockFlags::HAS_DRIFT_UNCERTAINTY)) { |
| 699 | SET(DriftUncertaintyNanosPerSecond, clock->driftUncertaintyNsps); |
| 700 | } |
| 701 | |
| 702 | SET(TimeNanos, clock->timeNs); |
| 703 | SET(HardwareClockDiscontinuityCount, clock->hwClockDiscontinuityCount); |
| 704 | |
| 705 | return object.get(); |
| 706 | } |
| 707 | |
| 708 | jobjectArray GnssMeasurementCallback::translateGnssMeasurements(JNIEnv* env, |
| 709 | const IGnssMeasurementCallback::GnssMeasurement* |
| 710 | measurements, size_t count) { |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 711 | if (count == 0) { |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 712 | return NULL; |
| 713 | } |
| 714 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 715 | jclass gnssMeasurementClass = env->FindClass("android/location/GnssMeasurement"); |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 716 | jobjectArray gnssMeasurementArray = env->NewObjectArray( |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 717 | count, |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 718 | gnssMeasurementClass, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 719 | NULL /* initialElement */); |
| 720 | |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 721 | for (uint16_t i = 0; i < count; ++i) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 722 | jobject gnssMeasurement = translateGnssMeasurement( |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 723 | env, |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 724 | &measurements[i]); |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 725 | env->SetObjectArrayElement(gnssMeasurementArray, i, gnssMeasurement); |
| 726 | env->DeleteLocalRef(gnssMeasurement); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 727 | } |
| 728 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 729 | env->DeleteLocalRef(gnssMeasurementClass); |
| 730 | return gnssMeasurementArray; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 731 | } |
| 732 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 733 | void GnssMeasurementCallback::setMeasurementData(JNIEnv* env, jobject clock, |
| 734 | jobjectArray measurementArray) { |
| 735 | jclass gnssMeasurementsEventClass = |
| 736 | env->FindClass("android/location/GnssMeasurementsEvent"); |
| 737 | jmethodID gnssMeasurementsEventCtor = |
| 738 | env->GetMethodID( |
| 739 | gnssMeasurementsEventClass, |
| 740 | "<init>", |
| 741 | "(Landroid/location/GnssClock;[Landroid/location/GnssMeasurement;)V"); |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 742 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 743 | jobject gnssMeasurementsEvent = env->NewObject(gnssMeasurementsEventClass, |
| 744 | gnssMeasurementsEventCtor, |
| 745 | clock, |
| 746 | measurementArray); |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 747 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 748 | env->CallVoidMethod(mCallbacksObj, method_reportMeasurementData, |
| 749 | gnssMeasurementsEvent); |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 750 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 751 | env->DeleteLocalRef(gnssMeasurementsEventClass); |
| 752 | env->DeleteLocalRef(gnssMeasurementsEvent); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 753 | } |
| 754 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 755 | /* |
| 756 | * GnssNiCallback implements callback methods required by the IGnssNi interface. |
| 757 | */ |
| 758 | struct GnssNiCallback : public IGnssNiCallback { |
| 759 | Return<void> niNotifyCb(const IGnssNiCallback::GnssNiNotification& notification) |
| 760 | override; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 761 | }; |
| 762 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 763 | Return<void> GnssNiCallback::niNotifyCb( |
| 764 | const IGnssNiCallback::GnssNiNotification& notification) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 765 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 766 | jstring requestorId = env->NewStringUTF(notification.requestorId.c_str()); |
| 767 | jstring text = env->NewStringUTF(notification.notificationMessage.c_str()); |
| 768 | |
| 769 | if (requestorId && text) { |
| 770 | env->CallVoidMethod(mCallbacksObj, method_reportNiNotification, |
| 771 | notification.notificationId, notification.niType, |
| 772 | notification.notifyFlags, notification.timeoutSec, |
| 773 | notification.defaultResponse, requestorId, text, |
| 774 | notification.requestorIdEncoding, |
| 775 | notification.notificationIdEncoding); |
| 776 | } else { |
| 777 | ALOGE("%s: OOM Error\n", __func__); |
| 778 | } |
| 779 | |
| 780 | if (requestorId) { |
| 781 | env->DeleteLocalRef(requestorId); |
| 782 | } |
| 783 | |
| 784 | if (text) { |
| 785 | env->DeleteLocalRef(text); |
| 786 | } |
| 787 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 788 | return Void(); |
| 789 | } |
| 790 | |
| 791 | /* |
| 792 | * AGnssCallback implements callback methods required by the IAGnss interface. |
| 793 | */ |
| 794 | struct AGnssCallback : public IAGnssCallback { |
| 795 | // Methods from ::android::hardware::gps::V1_0::IAGnssCallback follow. |
| 796 | Return<void> agnssStatusIpV6Cb( |
| 797 | const IAGnssCallback::AGnssStatusIpV6& agps_status) override; |
| 798 | |
| 799 | Return<void> agnssStatusIpV4Cb( |
| 800 | const IAGnssCallback::AGnssStatusIpV4& agps_status) override; |
| 801 | private: |
| 802 | jbyteArray convertToIpV4(uint32_t ip); |
| 803 | }; |
| 804 | |
| 805 | Return<void> AGnssCallback::agnssStatusIpV6Cb( |
| 806 | const IAGnssCallback::AGnssStatusIpV6& agps_status) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 807 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 808 | jbyteArray byteArray = NULL; |
| 809 | bool isSupported = false; |
| 810 | |
| 811 | byteArray = env->NewByteArray(16); |
| 812 | if (byteArray != NULL) { |
| 813 | env->SetByteArrayRegion(byteArray, 0, 16, |
| 814 | (const jbyte*)(agps_status.ipV6Addr.data())); |
| 815 | isSupported = true; |
| 816 | } else { |
| 817 | ALOGE("Unable to allocate byte array for IPv6 address."); |
| 818 | } |
| 819 | |
| 820 | IF_ALOGD() { |
| 821 | // log the IP for reference in case there is a bogus value pushed by HAL |
| 822 | char str[INET6_ADDRSTRLEN]; |
| 823 | inet_ntop(AF_INET6, agps_status.ipV6Addr.data(), str, INET6_ADDRSTRLEN); |
| 824 | ALOGD("AGPS IP is v6: %s", str); |
| 825 | } |
| 826 | |
| 827 | jsize byteArrayLength = byteArray != NULL ? env->GetArrayLength(byteArray) : 0; |
| 828 | ALOGV("Passing AGPS IP addr: size %d", byteArrayLength); |
| 829 | env->CallVoidMethod(mCallbacksObj, method_reportAGpsStatus, |
| 830 | agps_status.type, agps_status.status, byteArray); |
| 831 | |
| 832 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 833 | |
| 834 | if (byteArray) { |
| 835 | env->DeleteLocalRef(byteArray); |
| 836 | } |
| 837 | |
| 838 | return Void(); |
| 839 | } |
| 840 | |
| 841 | Return<void> AGnssCallback::agnssStatusIpV4Cb( |
| 842 | const IAGnssCallback::AGnssStatusIpV4& agps_status) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 843 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 844 | jbyteArray byteArray = NULL; |
| 845 | |
| 846 | uint32_t ipAddr = agps_status.ipV4Addr; |
| 847 | byteArray = convertToIpV4(ipAddr); |
| 848 | |
| 849 | IF_ALOGD() { |
| 850 | /* |
| 851 | * log the IP for reference in case there is a bogus value pushed by |
| 852 | * HAL. |
| 853 | */ |
| 854 | char str[INET_ADDRSTRLEN]; |
| 855 | inet_ntop(AF_INET, &ipAddr, str, INET_ADDRSTRLEN); |
| 856 | ALOGD("AGPS IP is v4: %s", str); |
| 857 | } |
| 858 | |
| 859 | jsize byteArrayLength = |
| 860 | byteArray != NULL ? env->GetArrayLength(byteArray) : 0; |
| 861 | ALOGV("Passing AGPS IP addr: size %d", byteArrayLength); |
| 862 | env->CallVoidMethod(mCallbacksObj, method_reportAGpsStatus, |
| 863 | agps_status.type, agps_status.status, byteArray); |
| 864 | |
| 865 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 866 | |
| 867 | if (byteArray) { |
| 868 | env->DeleteLocalRef(byteArray); |
| 869 | } |
| 870 | return Void(); |
| 871 | } |
| 872 | |
| 873 | jbyteArray AGnssCallback::convertToIpV4(uint32_t ip) { |
| 874 | if (INADDR_NONE == ip) { |
| 875 | return NULL; |
| 876 | } |
| 877 | |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 878 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 879 | jbyteArray byteArray = env->NewByteArray(4); |
| 880 | if (byteArray == NULL) { |
| 881 | ALOGE("Unable to allocate byte array for IPv4 address"); |
| 882 | return NULL; |
| 883 | } |
| 884 | |
| 885 | jbyte ipv4[4]; |
| 886 | ALOGV("Converting IPv4 address byte array (net_order) %x", ip); |
| 887 | memcpy(ipv4, &ip, sizeof(ipv4)); |
| 888 | env->SetByteArrayRegion(byteArray, 0, 4, (const jbyte*)ipv4); |
| 889 | return byteArray; |
| 890 | } |
| 891 | |
| 892 | /* |
| 893 | * AGnssRilCallback implements the callback methods required by the AGnssRil |
| 894 | * interface. |
| 895 | */ |
| 896 | struct AGnssRilCallback : IAGnssRilCallback { |
| 897 | Return<void> requestSetIdCb(IAGnssRilCallback::ID setIdFlag) override; |
| 898 | Return<void> requestRefLocCb() override; |
| 899 | }; |
| 900 | |
| 901 | Return<void> AGnssRilCallback::requestSetIdCb(IAGnssRilCallback::ID setIdFlag) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 902 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 903 | env->CallVoidMethod(mCallbacksObj, method_requestSetID, setIdFlag); |
| 904 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 905 | return Void(); |
| 906 | } |
| 907 | |
| 908 | Return<void> AGnssRilCallback::requestRefLocCb() { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 909 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 910 | env->CallVoidMethod(mCallbacksObj, method_requestRefLocation); |
| 911 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 912 | return Void(); |
| 913 | } |
| 914 | |
| 915 | static void android_location_GnssLocationProvider_class_init_native(JNIEnv* env, jclass clazz) { |
| 916 | method_reportLocation = env->GetMethodID(clazz, "reportLocation", "(IDDDFFFJ)V"); |
| 917 | method_reportStatus = env->GetMethodID(clazz, "reportStatus", "(I)V"); |
| 918 | method_reportSvStatus = env->GetMethodID(clazz, "reportSvStatus", "()V"); |
| 919 | method_reportAGpsStatus = env->GetMethodID(clazz, "reportAGpsStatus", "(II[B)V"); |
| 920 | method_reportNmea = env->GetMethodID(clazz, "reportNmea", "(J)V"); |
| 921 | method_setEngineCapabilities = env->GetMethodID(clazz, "setEngineCapabilities", "(I)V"); |
| 922 | method_setGnssYearOfHardware = env->GetMethodID(clazz, "setGnssYearOfHardware", "(I)V"); |
| 923 | method_xtraDownloadRequest = env->GetMethodID(clazz, "xtraDownloadRequest", "()V"); |
| 924 | method_reportNiNotification = env->GetMethodID(clazz, "reportNiNotification", |
| 925 | "(IIIIILjava/lang/String;Ljava/lang/String;II)V"); |
| 926 | method_requestRefLocation = env->GetMethodID(clazz, "requestRefLocation", "()V"); |
| 927 | method_requestSetID = env->GetMethodID(clazz, "requestSetID", "(I)V"); |
| 928 | method_requestUtcTime = env->GetMethodID(clazz, "requestUtcTime", "()V"); |
| 929 | method_reportGeofenceTransition = env->GetMethodID(clazz, "reportGeofenceTransition", |
| 930 | "(IIDDDFFFJIJ)V"); |
| 931 | method_reportGeofenceStatus = env->GetMethodID(clazz, "reportGeofenceStatus", |
| 932 | "(IIDDDFFFJ)V"); |
| 933 | method_reportGeofenceAddStatus = env->GetMethodID(clazz, "reportGeofenceAddStatus", |
| 934 | "(II)V"); |
| 935 | method_reportGeofenceRemoveStatus = env->GetMethodID(clazz, "reportGeofenceRemoveStatus", |
| 936 | "(II)V"); |
| 937 | method_reportGeofenceResumeStatus = env->GetMethodID(clazz, "reportGeofenceResumeStatus", |
| 938 | "(II)V"); |
| 939 | method_reportGeofencePauseStatus = env->GetMethodID(clazz, "reportGeofencePauseStatus", |
| 940 | "(II)V"); |
| 941 | method_reportMeasurementData = env->GetMethodID( |
| 942 | clazz, |
| 943 | "reportMeasurementData", |
| 944 | "(Landroid/location/GnssMeasurementsEvent;)V"); |
| 945 | method_reportNavigationMessages = env->GetMethodID( |
| 946 | clazz, |
| 947 | "reportNavigationMessage", |
| 948 | "(Landroid/location/GnssNavigationMessage;)V"); |
| 949 | |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame^] | 950 | /* |
| 951 | * Save a pointer to JVM. |
| 952 | */ |
| 953 | jint jvmStatus = env->GetJavaVM(&sJvm); |
| 954 | if (jvmStatus != JNI_OK) { |
| 955 | LOG_ALWAYS_FATAL("Unable to get Java VM. Error: %d", jvmStatus); |
| 956 | } |
| 957 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 958 | // TODO(b/31632518) |
| 959 | gnssHal = IGnss::getService("gnss"); |
| 960 | if (gnssHal != nullptr) { |
Martijn Coenen | 3a3a4ac | 2017-01-04 12:57:47 +0100 | [diff] [blame] | 961 | auto gnssXtra = gnssHal->getExtensionXtra(); |
| 962 | if (!gnssXtra.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 963 | ALOGD("Unable to get a handle to Xtra"); |
Martijn Coenen | 3a3a4ac | 2017-01-04 12:57:47 +0100 | [diff] [blame] | 964 | } else { |
| 965 | gnssXtraIface = gnssXtra; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 966 | } |
| 967 | |
Martijn Coenen | 3a3a4ac | 2017-01-04 12:57:47 +0100 | [diff] [blame] | 968 | auto gnssRil = gnssHal->getExtensionAGnssRil(); |
| 969 | if (!gnssRil.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 970 | ALOGD("Unable to get a handle to AGnssRil"); |
Martijn Coenen | 3a3a4ac | 2017-01-04 12:57:47 +0100 | [diff] [blame] | 971 | } else { |
| 972 | agnssRilIface = gnssRil; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 973 | } |
| 974 | |
Martijn Coenen | 3a3a4ac | 2017-01-04 12:57:47 +0100 | [diff] [blame] | 975 | auto gnssAgnss = gnssHal->getExtensionAGnss(); |
| 976 | if (!gnssAgnss.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 977 | ALOGD("Unable to get a handle to AGnss"); |
Martijn Coenen | 3a3a4ac | 2017-01-04 12:57:47 +0100 | [diff] [blame] | 978 | } else { |
| 979 | agnssIface = gnssAgnss; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 980 | } |
| 981 | |
Martijn Coenen | 3a3a4ac | 2017-01-04 12:57:47 +0100 | [diff] [blame] | 982 | auto gnssNavigationMessage = gnssHal->getExtensionGnssNavigationMessage(); |
| 983 | if (!gnssNavigationMessage.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 984 | ALOGD("Unable to get a handle to GnssNavigationMessage"); |
Martijn Coenen | 3a3a4ac | 2017-01-04 12:57:47 +0100 | [diff] [blame] | 985 | } else { |
| 986 | gnssNavigationMessageIface = gnssNavigationMessage; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 987 | } |
| 988 | |
Martijn Coenen | 3a3a4ac | 2017-01-04 12:57:47 +0100 | [diff] [blame] | 989 | auto gnssMeasurement = gnssHal->getExtensionGnssMeasurement(); |
| 990 | if (!gnssMeasurement.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 991 | ALOGD("Unable to get a handle to GnssMeasurement"); |
Martijn Coenen | 3a3a4ac | 2017-01-04 12:57:47 +0100 | [diff] [blame] | 992 | } else { |
| 993 | gnssMeasurementIface = gnssMeasurement; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 994 | } |
| 995 | |
Martijn Coenen | 3a3a4ac | 2017-01-04 12:57:47 +0100 | [diff] [blame] | 996 | auto gnssDebug = gnssHal->getExtensionGnssDebug(); |
| 997 | if (!gnssDebug.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 998 | ALOGD("Unable to get a handle to GnssDebug"); |
Martijn Coenen | 3a3a4ac | 2017-01-04 12:57:47 +0100 | [diff] [blame] | 999 | } else { |
| 1000 | gnssDebugIface = gnssDebug; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
Martijn Coenen | 3a3a4ac | 2017-01-04 12:57:47 +0100 | [diff] [blame] | 1003 | auto gnssNi = gnssHal->getExtensionGnssNi(); |
| 1004 | if (!gnssNi.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1005 | ALOGD("Unable to get a handle to GnssNi"); |
Martijn Coenen | 3a3a4ac | 2017-01-04 12:57:47 +0100 | [diff] [blame] | 1006 | } else { |
| 1007 | gnssNiIface = gnssNi; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
Martijn Coenen | 3a3a4ac | 2017-01-04 12:57:47 +0100 | [diff] [blame] | 1010 | auto gnssConfiguration = gnssHal->getExtensionGnssConfiguration(); |
| 1011 | if (!gnssConfiguration.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1012 | ALOGD("Unable to get a handle to GnssConfiguration"); |
Martijn Coenen | 3a3a4ac | 2017-01-04 12:57:47 +0100 | [diff] [blame] | 1013 | } else { |
| 1014 | gnssConfigurationIface = gnssConfiguration; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
Martijn Coenen | 3a3a4ac | 2017-01-04 12:57:47 +0100 | [diff] [blame] | 1017 | auto gnssGeofencing = gnssHal->getExtensionGnssGeofencing(); |
| 1018 | if (!gnssGeofencing.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1019 | ALOGD("Unable to get a handle to GnssGeofencing"); |
Martijn Coenen | 3a3a4ac | 2017-01-04 12:57:47 +0100 | [diff] [blame] | 1020 | } else { |
| 1021 | gnssGeofencingIface = gnssGeofencing; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1022 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1023 | } else { |
| 1024 | ALOGE("Unable to get GPS service\n"); |
| 1025 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | static jboolean android_location_GnssLocationProvider_is_supported( |
| 1029 | JNIEnv* /* env */, jclass /* clazz */) { |
| 1030 | return (gnssHal != nullptr) ? JNI_TRUE : JNI_FALSE; |
| 1031 | } |
| 1032 | |
| 1033 | static jboolean android_location_GnssLocationProvider_is_agps_ril_supported( |
| 1034 | JNIEnv* /* env */, jclass /* clazz */) { |
| 1035 | return (agnssRilIface != nullptr) ? JNI_TRUE : JNI_FALSE; |
| 1036 | } |
| 1037 | |
| 1038 | static jboolean android_location_gpsLocationProvider_is_gnss_configuration_supported( |
| 1039 | JNIEnv* /* env */, jclass /* jclazz */) { |
| 1040 | return (gnssConfigurationIface != nullptr) ? JNI_TRUE : JNI_FALSE; |
| 1041 | } |
| 1042 | |
| 1043 | static jboolean android_location_GnssLocationProvider_init(JNIEnv* env, jobject obj) { |
| 1044 | /* |
| 1045 | * This must be set before calling into the HAL library. |
| 1046 | */ |
| 1047 | if (!mCallbacksObj) |
| 1048 | mCallbacksObj = env->NewGlobalRef(obj); |
| 1049 | |
| 1050 | sp<IGnssCallback> gnssCbIface = new GnssCallback(); |
| 1051 | /* |
| 1052 | * Fail if the main interface fails to initialize |
| 1053 | */ |
| 1054 | if (gnssHal == nullptr) { |
| 1055 | ALOGE("Unable to Initialize GNSS HAL\n"); |
| 1056 | return JNI_FALSE; |
| 1057 | } |
| 1058 | |
| 1059 | auto result = gnssHal->setCallback(gnssCbIface); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1060 | if ((!result) || (!result.isOk())) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1061 | ALOGE("SetCallback for Gnss Interface fails\n"); |
| 1062 | return JNI_FALSE; |
| 1063 | } |
| 1064 | |
| 1065 | sp<IGnssXtraCallback> gnssXtraCbIface = new GnssXtraCallback(); |
| 1066 | if (gnssXtraIface == nullptr) { |
| 1067 | ALOGE("Unable to initialize GNSS Xtra interface\n"); |
Hridya Valsaraju | e865032 | 2016-12-05 20:23:21 -0800 | [diff] [blame] | 1068 | } else { |
| 1069 | result = gnssXtraIface->setCallback(gnssXtraCbIface); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1070 | if ((!result) || (!result.isOk())) { |
Hridya Valsaraju | e865032 | 2016-12-05 20:23:21 -0800 | [diff] [blame] | 1071 | gnssXtraIface = nullptr; |
| 1072 | ALOGE("SetCallback for Gnss Xtra Interface fails\n"); |
| 1073 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | sp<IAGnssCallback> aGnssCbIface = new AGnssCallback(); |
| 1077 | if (agnssIface != nullptr) { |
| 1078 | agnssIface->setCallback(aGnssCbIface); |
| 1079 | } else { |
| 1080 | ALOGE("Unable to Initialize AGnss interface\n"); |
| 1081 | } |
| 1082 | |
| 1083 | sp<IGnssGeofenceCallback> gnssGeofencingCbIface = new GnssGeofenceCallback(); |
| 1084 | if (gnssGeofencingIface != nullptr) { |
| 1085 | gnssGeofencingIface->setCallback(gnssGeofencingCbIface); |
| 1086 | } else { |
| 1087 | ALOGE("Unable to initialize GNSS Geofencing interface\n"); |
| 1088 | } |
| 1089 | |
| 1090 | sp<IGnssNiCallback> gnssNiCbIface = new GnssNiCallback(); |
| 1091 | if (gnssNiCbIface != nullptr) { |
| 1092 | gnssNiIface->setCallback(gnssNiCbIface); |
| 1093 | } else { |
| 1094 | ALOGE("Unable to initialize GNSS NI interface\n"); |
| 1095 | } |
| 1096 | |
| 1097 | return JNI_TRUE; |
| 1098 | } |
| 1099 | |
| 1100 | static void android_location_GnssLocationProvider_cleanup(JNIEnv* /* env */, jobject /* obj */) { |
| 1101 | if (gnssHal != nullptr) { |
| 1102 | gnssHal->cleanup(); |
| 1103 | } |
| 1104 | } |
| 1105 | |
| 1106 | static jboolean android_location_GnssLocationProvider_set_position_mode(JNIEnv* /* env */, |
| 1107 | jobject /* obj */, jint mode, jint recurrence, jint min_interval, jint preferred_accuracy, |
| 1108 | jint preferred_time) { |
| 1109 | if (gnssHal != nullptr) { |
| 1110 | auto result = gnssHal->setPositionMode(static_cast<IGnss::GnssPositionMode>(mode), |
| 1111 | static_cast<IGnss::GnssPositionRecurrence>(recurrence), |
| 1112 | min_interval, |
| 1113 | preferred_accuracy, |
| 1114 | preferred_time); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1115 | if (!result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1116 | ALOGE("%s: GNSS setPositionMode failed\n", __func__); |
| 1117 | return JNI_FALSE; |
| 1118 | } else { |
| 1119 | return result; |
| 1120 | } |
| 1121 | } else { |
| 1122 | return JNI_FALSE; |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | static jboolean android_location_GnssLocationProvider_start(JNIEnv* /* env */, jobject /* obj */) { |
| 1127 | if (gnssHal != nullptr) { |
| 1128 | auto result = gnssHal->start(); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1129 | if (!result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1130 | return JNI_FALSE; |
| 1131 | } else { |
| 1132 | return result; |
| 1133 | } |
| 1134 | } else { |
| 1135 | return JNI_FALSE; |
| 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | static jboolean android_location_GnssLocationProvider_stop(JNIEnv* /* env */, jobject /* obj */) { |
| 1140 | if (gnssHal != nullptr) { |
| 1141 | auto result = gnssHal->stop(); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1142 | if (!result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1143 | return JNI_FALSE; |
| 1144 | } else { |
| 1145 | return result; |
| 1146 | } |
| 1147 | } else { |
| 1148 | return JNI_FALSE; |
| 1149 | } |
| 1150 | } |
| 1151 | static void android_location_GnssLocationProvider_delete_aiding_data(JNIEnv* /* env */, |
| 1152 | jobject /* obj */, |
| 1153 | jint flags) { |
| 1154 | if (gnssHal != nullptr) { |
| 1155 | auto result = gnssHal->deleteAidingData(static_cast<IGnss::GnssAidingData>(flags)); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1156 | if (!result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1157 | ALOGE("Error in deleting aiding data"); |
| 1158 | } |
| 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | /* |
| 1163 | * This enum is used by the read_sv_status method to combine the svid, |
| 1164 | * constellation and svFlag fields. |
| 1165 | */ |
| 1166 | enum ShiftWidth: uint8_t { |
| 1167 | SVID_SHIFT_WIDTH = 7, |
| 1168 | CONSTELLATION_TYPE_SHIFT_WIDTH = 3 |
| 1169 | }; |
| 1170 | |
| 1171 | static jint android_location_GnssLocationProvider_read_sv_status(JNIEnv* env, jobject /* obj */, |
| 1172 | jintArray svidWithFlagArray, jfloatArray cn0Array, jfloatArray elevArray, |
| 1173 | jfloatArray azumArray) { |
| 1174 | /* |
| 1175 | * This method should only be called from within a call to reportSvStatus. |
| 1176 | */ |
| 1177 | jint* svidWithFlags = env->GetIntArrayElements(svidWithFlagArray, 0); |
| 1178 | jfloat* cn0s = env->GetFloatArrayElements(cn0Array, 0); |
| 1179 | jfloat* elev = env->GetFloatArrayElements(elevArray, 0); |
| 1180 | jfloat* azim = env->GetFloatArrayElements(azumArray, 0); |
| 1181 | |
| 1182 | /* |
| 1183 | * Read GNSS SV info. |
| 1184 | */ |
| 1185 | for (size_t i = 0; i < GnssCallback::sGnssSvListSize; ++i) { |
| 1186 | const IGnssCallback::GnssSvInfo& info = GnssCallback::sGnssSvList[i]; |
| 1187 | svidWithFlags[i] = (info.svid << SVID_SHIFT_WIDTH) | |
| 1188 | (static_cast<uint32_t>(info.constellation) << CONSTELLATION_TYPE_SHIFT_WIDTH) | |
| 1189 | static_cast<uint32_t>(info.svFlag); |
| 1190 | cn0s[i] = info.cN0Dbhz; |
| 1191 | elev[i] = info.elevationDegrees; |
| 1192 | azim[i] = info.azimuthDegrees; |
| 1193 | } |
| 1194 | |
| 1195 | env->ReleaseIntArrayElements(svidWithFlagArray, svidWithFlags, 0); |
| 1196 | env->ReleaseFloatArrayElements(cn0Array, cn0s, 0); |
| 1197 | env->ReleaseFloatArrayElements(elevArray, elev, 0); |
| 1198 | env->ReleaseFloatArrayElements(azumArray, azim, 0); |
| 1199 | return static_cast<jint>(GnssCallback::sGnssSvListSize); |
| 1200 | } |
| 1201 | |
| 1202 | static void android_location_GnssLocationProvider_agps_set_reference_location_cellid( |
| 1203 | JNIEnv* /* env */, jobject /* obj */, jint type, jint mcc, jint mnc, jint lac, jint cid) { |
| 1204 | IAGnssRil::AGnssRefLocation location; |
| 1205 | |
| 1206 | if (agnssRilIface == nullptr) { |
| 1207 | ALOGE("No AGPS RIL interface in agps_set_reference_location_cellid"); |
| 1208 | return; |
| 1209 | } |
| 1210 | |
| 1211 | switch (static_cast<IAGnssRil::AGnssRefLocationType>(type)) { |
| 1212 | case IAGnssRil::AGnssRefLocationType::GSM_CELLID: |
| 1213 | case IAGnssRil::AGnssRefLocationType::UMTS_CELLID: |
| 1214 | location.type = static_cast<IAGnssRil::AGnssRefLocationType>(type); |
| 1215 | location.cellID.mcc = mcc; |
| 1216 | location.cellID.mnc = mnc; |
| 1217 | location.cellID.lac = lac; |
| 1218 | location.cellID.cid = cid; |
| 1219 | break; |
| 1220 | default: |
| 1221 | ALOGE("Neither a GSM nor a UMTS cellid (%s:%d).", __FUNCTION__, __LINE__); |
| 1222 | return; |
| 1223 | break; |
| 1224 | } |
| 1225 | |
| 1226 | agnssRilIface->setRefLocation(location); |
| 1227 | } |
| 1228 | |
| 1229 | static void android_location_GnssLocationProvider_agps_set_id(JNIEnv *env, jobject /* obj */, |
| 1230 | jint type, jstring setid_string) { |
| 1231 | if (agnssRilIface == nullptr) { |
| 1232 | ALOGE("no AGPS RIL interface in agps_set_id"); |
| 1233 | return; |
| 1234 | } |
| 1235 | |
| 1236 | const char *setid = env->GetStringUTFChars(setid_string, NULL); |
| 1237 | agnssRilIface->setSetId((IAGnssRil::SetIDType)type, setid); |
| 1238 | env->ReleaseStringUTFChars(setid_string, setid); |
| 1239 | } |
| 1240 | |
| 1241 | static jint android_location_GnssLocationProvider_read_nmea(JNIEnv* env, jobject /* obj */, |
| 1242 | jbyteArray nmeaArray, jint buffer_size) { |
| 1243 | // this should only be called from within a call to reportNmea |
| 1244 | jbyte* nmea = reinterpret_cast<jbyte *>(env->GetPrimitiveArrayCritical(nmeaArray, 0)); |
| 1245 | int length = GnssCallback::sNmeaStringLength; |
| 1246 | if (length > buffer_size) |
| 1247 | length = buffer_size; |
| 1248 | memcpy(nmea, GnssCallback::sNmeaString, length); |
| 1249 | env->ReleasePrimitiveArrayCritical(nmeaArray, nmea, JNI_ABORT); |
| 1250 | return (jint) length; |
| 1251 | } |
| 1252 | |
| 1253 | static void android_location_GnssLocationProvider_inject_time(JNIEnv* /* env */, jobject /* obj */, |
| 1254 | jlong time, jlong timeReference, jint uncertainty) { |
| 1255 | if (gnssHal != nullptr) { |
| 1256 | auto result = gnssHal->injectTime(time, timeReference, uncertainty); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1257 | if (!result || !result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1258 | ALOGE("%s: Gnss injectTime() failed", __func__); |
| 1259 | } |
| 1260 | } |
| 1261 | } |
| 1262 | |
| 1263 | static void android_location_GnssLocationProvider_inject_location(JNIEnv* /* env */, |
| 1264 | jobject /* obj */, jdouble latitude, jdouble longitude, jfloat accuracy) { |
| 1265 | if (gnssHal != nullptr) { |
| 1266 | auto result = gnssHal->injectLocation(latitude, longitude, accuracy); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1267 | if (!result || !result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1268 | ALOGE("%s: Gnss injectLocation() failed", __func__); |
| 1269 | } |
| 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | static jboolean android_location_GnssLocationProvider_supports_xtra( |
| 1274 | JNIEnv* /* env */, jobject /* obj */) { |
| 1275 | return (gnssXtraIface != nullptr) ? JNI_TRUE : JNI_FALSE; |
| 1276 | } |
| 1277 | |
| 1278 | static void android_location_GnssLocationProvider_inject_xtra_data(JNIEnv* env, jobject /* obj */, |
| 1279 | jbyteArray data, jint length) { |
| 1280 | if (gnssXtraIface == nullptr) { |
| 1281 | ALOGE("XTRA Interface not supported"); |
| 1282 | return; |
| 1283 | } |
| 1284 | |
| 1285 | jbyte* bytes = reinterpret_cast<jbyte *>(env->GetPrimitiveArrayCritical(data, 0)); |
| 1286 | gnssXtraIface->injectXtraData(std::string((const char*)bytes, length)); |
| 1287 | env->ReleasePrimitiveArrayCritical(data, bytes, JNI_ABORT); |
| 1288 | } |
| 1289 | |
| 1290 | static void android_location_GnssLocationProvider_agps_data_conn_open( |
| 1291 | JNIEnv* env, jobject /* obj */, jstring apn, jint apnIpType) { |
| 1292 | if (agnssIface == nullptr) { |
| 1293 | ALOGE("no AGPS interface in agps_data_conn_open"); |
| 1294 | return; |
| 1295 | } |
| 1296 | if (apn == NULL) { |
| 1297 | jniThrowException(env, "java/lang/IllegalArgumentException", NULL); |
| 1298 | return; |
| 1299 | } |
| 1300 | |
| 1301 | const char *apnStr = env->GetStringUTFChars(apn, NULL); |
| 1302 | |
| 1303 | auto result = agnssIface->dataConnOpen(apnStr, static_cast<IAGnss::ApnIpType>(apnIpType)); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1304 | if ((!result) || (!result.isOk())) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1305 | ALOGE("%s: Failed to set APN and its IP type", __func__); |
| 1306 | } |
| 1307 | env->ReleaseStringUTFChars(apn, apnStr); |
| 1308 | } |
| 1309 | |
| 1310 | static void android_location_GnssLocationProvider_agps_data_conn_closed(JNIEnv* /* env */, |
| 1311 | jobject /* obj */) { |
| 1312 | if (agnssIface == nullptr) { |
| 1313 | ALOGE("%s: AGPS interface not supported", __func__); |
| 1314 | return; |
| 1315 | } |
| 1316 | |
| 1317 | auto result = agnssIface->dataConnClosed(); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1318 | if ((!result) || (!result.isOk())) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1319 | ALOGE("%s: Failed to close AGnss data connection", __func__); |
| 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | static void android_location_GnssLocationProvider_agps_data_conn_failed(JNIEnv* /* env */, |
| 1324 | jobject /* obj */) { |
| 1325 | if (agnssIface == nullptr) { |
| 1326 | ALOGE("%s: AGPS interface not supported", __func__); |
| 1327 | return; |
| 1328 | } |
| 1329 | |
| 1330 | auto result = agnssIface->dataConnFailed(); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1331 | if ((!result) || (!result.isOk())) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1332 | ALOGE("%s: Failed to notify unavailability of AGnss data connection", __func__); |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | static void android_location_GnssLocationProvider_set_agps_server(JNIEnv* env, jobject /* obj */, |
| 1337 | jint type, jstring hostname, jint port) { |
| 1338 | if (agnssIface == nullptr) { |
| 1339 | ALOGE("no AGPS interface in set_agps_server"); |
| 1340 | return; |
| 1341 | } |
| 1342 | |
| 1343 | const char *c_hostname = env->GetStringUTFChars(hostname, NULL); |
| 1344 | auto result = agnssIface->setServer(static_cast<IAGnssCallback::AGnssType>(type), |
| 1345 | c_hostname, |
| 1346 | port); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1347 | if ((!result) || (!result.isOk())) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1348 | ALOGE("%s: Failed to set AGnss host name and port", __func__); |
| 1349 | } |
| 1350 | |
| 1351 | env->ReleaseStringUTFChars(hostname, c_hostname); |
| 1352 | } |
| 1353 | |
| 1354 | static void android_location_GnssLocationProvider_send_ni_response(JNIEnv* /* env */, |
| 1355 | jobject /* obj */, jint notifId, jint response) { |
| 1356 | if (gnssNiIface == nullptr) { |
| 1357 | ALOGE("no NI interface in send_ni_response"); |
| 1358 | return; |
| 1359 | } |
| 1360 | |
| 1361 | gnssNiIface->respond(notifId, static_cast<IGnssNiCallback::GnssUserResponseType>(response)); |
| 1362 | } |
| 1363 | |
| 1364 | static jstring android_location_GnssLocationProvider_get_internal_state(JNIEnv* env, |
| 1365 | jobject /* obj */) { |
| 1366 | jstring result = NULL; |
| 1367 | /* |
| 1368 | * TODO(b/33089503) : Create a jobject to represent GnssDebug. |
| 1369 | */ |
| 1370 | if (gnssDebugIface != nullptr) { |
| 1371 | IGnssDebug::DebugData data; |
| 1372 | gnssDebugIface->getDebugData([&data](const IGnssDebug::DebugData& debugData) { |
| 1373 | data = debugData; |
| 1374 | }); |
| 1375 | |
| 1376 | std::stringstream internalState; |
| 1377 | if (data.position.valid) { |
| 1378 | internalState << "Gnss Location Data:: LatitudeDegrees: " << data.position.latitudeDegrees |
| 1379 | << ", LongitudeDegrees: " << data.position.longitudeDegrees |
| 1380 | << ", altitudeMeters: " << data.position.altitudeMeters |
| 1381 | << ", accuracyMeters: " << data.position.accuracyMeters |
| 1382 | << ", ageSeconds: " << data.position.ageSeconds << std::endl; |
| 1383 | } |
| 1384 | |
| 1385 | if (data.time.valid) { |
| 1386 | internalState << "Gnss Time Data:: timeEstimate: " << data.time.timeEstimate |
| 1387 | << ", timeUncertaintyNs: " << data.time.timeUncertaintyNs << std::endl; |
| 1388 | } |
| 1389 | |
| 1390 | if (data.satelliteDataArray.size() != 0) { |
| 1391 | internalState << "Satellite Data:: "; |
| 1392 | } |
| 1393 | |
| 1394 | for (size_t i = 0; i < data.satelliteDataArray.size(); i++) { |
| 1395 | internalState << "svid: " << data.satelliteDataArray[i].svid |
| 1396 | << ", constellation: " |
| 1397 | << static_cast<uint32_t>(data.satelliteDataArray[i].constellation) |
| 1398 | << ", ephemerisType: " |
| 1399 | << static_cast<uint32_t>(data.satelliteDataArray[i].ephemerisType) |
| 1400 | << ", ephemerisAgeSeconds: " |
| 1401 | << data.satelliteDataArray[i].ephemerisAgeSeconds << std::endl; |
| 1402 | } |
| 1403 | result = env->NewStringUTF(internalState.str().c_str()); |
| 1404 | } |
| 1405 | return result; |
| 1406 | } |
| 1407 | |
| 1408 | static void android_location_GnssLocationProvider_update_network_state(JNIEnv* env, |
| 1409 | jobject /* obj */, |
| 1410 | jboolean connected, |
| 1411 | jint type, |
| 1412 | jboolean roaming, |
| 1413 | jboolean available, |
| 1414 | jstring extraInfo, |
| 1415 | jstring apn) { |
| 1416 | if (agnssRilIface != nullptr) { |
| 1417 | auto result = agnssRilIface->updateNetworkState(connected, |
| 1418 | static_cast<IAGnssRil::NetworkType>(type), |
| 1419 | roaming); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1420 | if ((!result) || (!result.isOk())) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1421 | ALOGE("updateNetworkState failed"); |
| 1422 | } |
| 1423 | |
| 1424 | const char *c_apn = env->GetStringUTFChars(apn, NULL); |
| 1425 | result = agnssRilIface->updateNetworkAvailability(available, c_apn); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1426 | if ((!result) || (!result.isOk())) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1427 | ALOGE("updateNetworkAvailability failed"); |
| 1428 | } |
| 1429 | |
| 1430 | env->ReleaseStringUTFChars(apn, c_apn); |
| 1431 | } else { |
| 1432 | ALOGE("AGnssRilInterface does not exist"); |
| 1433 | } |
| 1434 | } |
| 1435 | |
| 1436 | static jboolean android_location_GnssLocationProvider_is_geofence_supported( |
| 1437 | JNIEnv* /* env */, jobject /* obj */) { |
| 1438 | return (gnssGeofencingIface != nullptr) ? JNI_TRUE : JNI_FALSE; |
| 1439 | } |
| 1440 | |
| 1441 | static jboolean android_location_GnssLocationProvider_add_geofence(JNIEnv* /* env */, |
| 1442 | jobject /* obj */, jint geofenceId, jdouble latitude, jdouble longitude, jdouble radius, |
| 1443 | jint last_transition, jint monitor_transition, jint notification_responsiveness, |
| 1444 | jint unknown_timer) { |
| 1445 | if (gnssGeofencingIface != nullptr) { |
| 1446 | auto result = gnssGeofencingIface->addGeofence( |
| 1447 | geofenceId, latitude, longitude, radius, |
| 1448 | static_cast<IGnssGeofenceCallback::GeofenceTransition>(last_transition), |
| 1449 | monitor_transition, notification_responsiveness, unknown_timer); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1450 | return boolToJbool(result.isOk()); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1451 | } else { |
| 1452 | ALOGE("Geofence Interface not available"); |
| 1453 | } |
| 1454 | return JNI_FALSE; |
| 1455 | } |
| 1456 | |
| 1457 | static jboolean android_location_GnssLocationProvider_remove_geofence(JNIEnv* /* env */, |
| 1458 | jobject /* obj */, jint geofenceId) { |
| 1459 | if (gnssGeofencingIface != nullptr) { |
| 1460 | auto result = gnssGeofencingIface->removeGeofence(geofenceId); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1461 | return boolToJbool(result.isOk()); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1462 | } else { |
| 1463 | ALOGE("Geofence interface not available"); |
| 1464 | } |
| 1465 | return JNI_FALSE; |
| 1466 | } |
| 1467 | |
| 1468 | static jboolean android_location_GnssLocationProvider_pause_geofence(JNIEnv* /* env */, |
| 1469 | jobject /* obj */, jint geofenceId) { |
| 1470 | if (gnssGeofencingIface != nullptr) { |
| 1471 | auto result = gnssGeofencingIface->pauseGeofence(geofenceId); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1472 | return boolToJbool(result.isOk()); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1473 | } else { |
| 1474 | ALOGE("Geofence interface not available"); |
| 1475 | } |
| 1476 | return JNI_FALSE; |
| 1477 | } |
| 1478 | |
| 1479 | static jboolean android_location_GnssLocationProvider_resume_geofence(JNIEnv* /* env */, |
| 1480 | jobject /* obj */, jint geofenceId, jint monitor_transition) { |
| 1481 | if (gnssGeofencingIface != nullptr) { |
| 1482 | auto result = gnssGeofencingIface->resumeGeofence(geofenceId, monitor_transition); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1483 | return boolToJbool(result.isOk()); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1484 | } else { |
| 1485 | ALOGE("Geofence interface not available"); |
| 1486 | } |
| 1487 | return JNI_FALSE; |
| 1488 | } |
| 1489 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1490 | static jboolean android_location_GnssLocationProvider_is_measurement_supported( |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1491 | JNIEnv* env, jclass clazz) { |
| 1492 | if (gnssMeasurementIface != nullptr) { |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1493 | return JNI_TRUE; |
| 1494 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1495 | |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1496 | return JNI_FALSE; |
| 1497 | } |
| 1498 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1499 | static jboolean android_location_GnssLocationProvider_start_measurement_collection( |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1500 | JNIEnv* env, |
| 1501 | jobject obj) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1502 | if (gnssMeasurementIface == nullptr) { |
| 1503 | ALOGE("GNSS Measurement interface is not available."); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1504 | return JNI_FALSE; |
| 1505 | } |
| 1506 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1507 | sp<GnssMeasurementCallback> cbIface = new GnssMeasurementCallback(); |
| 1508 | IGnssMeasurement::GnssMeasurementStatus result = gnssMeasurementIface->setCallback(cbIface); |
| 1509 | if (result != IGnssMeasurement::GnssMeasurementStatus::SUCCESS) { |
| 1510 | ALOGE("An error has been found on GnssMeasurementInterface::init, status=%d", |
| 1511 | static_cast<int32_t>(result)); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1512 | return JNI_FALSE; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1513 | } else { |
| 1514 | ALOGD("gnss measurement infc has been enabled"); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1515 | } |
| 1516 | |
| 1517 | return JNI_TRUE; |
| 1518 | } |
| 1519 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1520 | static jboolean android_location_GnssLocationProvider_stop_measurement_collection( |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1521 | JNIEnv* env, |
| 1522 | jobject obj) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1523 | if (gnssMeasurementIface == nullptr) { |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1524 | ALOGE("Measurement interface not available"); |
| 1525 | return JNI_FALSE; |
| 1526 | } |
| 1527 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1528 | auto result = gnssMeasurementIface->close(); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1529 | return boolToJbool(result.isOk()); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1532 | static jboolean android_location_GnssLocationProvider_is_navigation_message_supported( |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1533 | JNIEnv* env, |
| 1534 | jclass clazz) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1535 | if (gnssNavigationMessageIface != nullptr) { |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1536 | return JNI_TRUE; |
| 1537 | } |
| 1538 | return JNI_FALSE; |
| 1539 | } |
| 1540 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1541 | static jboolean android_location_GnssLocationProvider_start_navigation_message_collection( |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1542 | JNIEnv* env, |
| 1543 | jobject obj) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1544 | if (gnssNavigationMessageIface == nullptr) { |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1545 | ALOGE("Navigation Message interface is not available."); |
| 1546 | return JNI_FALSE; |
| 1547 | } |
| 1548 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1549 | sp<IGnssNavigationMessageCallback> gnssNavigationMessageCbIface = |
| 1550 | new GnssNavigationMessageCallback(); |
| 1551 | IGnssNavigationMessage::GnssNavigationMessageStatus result = |
| 1552 | gnssNavigationMessageIface->setCallback(gnssNavigationMessageCbIface); |
| 1553 | |
| 1554 | if (result != IGnssNavigationMessage::GnssNavigationMessageStatus::SUCCESS) { |
| 1555 | ALOGE("An error has been found in %s: %d", __FUNCTION__, static_cast<int32_t>(result)); |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1556 | return JNI_FALSE; |
| 1557 | } |
| 1558 | |
| 1559 | return JNI_TRUE; |
| 1560 | } |
| 1561 | |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1562 | static jboolean android_location_GnssLocationProvider_stop_navigation_message_collection( |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1563 | JNIEnv* env, |
| 1564 | jobject obj) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1565 | if (gnssNavigationMessageIface == nullptr) { |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1566 | ALOGE("Navigation Message interface is not available."); |
| 1567 | return JNI_FALSE; |
| 1568 | } |
| 1569 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1570 | auto result = gnssNavigationMessageIface->close(); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1571 | return boolToJbool(result.isOk()); |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1572 | } |
| 1573 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1574 | static jboolean android_location_GnssLocationProvider_set_emergency_supl_pdn(JNIEnv*, |
| 1575 | jobject, |
| 1576 | jint emergencySuplPdn) { |
| 1577 | if (gnssConfigurationIface == nullptr) { |
| 1578 | ALOGE("no GNSS configuration interface available"); |
| 1579 | return JNI_FALSE; |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1580 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1581 | |
| 1582 | auto result = gnssConfigurationIface->setEmergencySuplPdn(emergencySuplPdn); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1583 | if (result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1584 | return result; |
| 1585 | } else { |
| 1586 | return JNI_FALSE; |
| 1587 | } |
| 1588 | } |
| 1589 | |
| 1590 | static jboolean android_location_GnssLocationProvider_set_supl_version(JNIEnv*, |
| 1591 | jobject, |
| 1592 | jint version) { |
| 1593 | if (gnssConfigurationIface == nullptr) { |
| 1594 | ALOGE("no GNSS configuration interface available"); |
| 1595 | return JNI_FALSE; |
| 1596 | } |
| 1597 | auto result = gnssConfigurationIface->setSuplVersion(version); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1598 | if (result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1599 | return result; |
| 1600 | } else { |
| 1601 | return JNI_FALSE; |
| 1602 | } |
| 1603 | } |
| 1604 | |
| 1605 | static jboolean android_location_GnssLocationProvider_set_supl_es(JNIEnv*, |
| 1606 | jobject, |
| 1607 | jint suplEs) { |
| 1608 | if (gnssConfigurationIface == nullptr) { |
| 1609 | ALOGE("no GNSS configuration interface available"); |
| 1610 | return JNI_FALSE; |
| 1611 | } |
| 1612 | |
| 1613 | auto result = gnssConfigurationIface->setSuplEs(suplEs); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1614 | if (result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1615 | return result; |
| 1616 | } else { |
| 1617 | return JNI_FALSE; |
| 1618 | } |
| 1619 | } |
| 1620 | |
| 1621 | static jboolean android_location_GnssLocationProvider_set_supl_mode(JNIEnv*, |
| 1622 | jobject, |
| 1623 | jint mode) { |
| 1624 | if (gnssConfigurationIface == nullptr) { |
| 1625 | ALOGE("no GNSS configuration interface available"); |
| 1626 | return JNI_FALSE; |
| 1627 | } |
| 1628 | |
| 1629 | auto result = gnssConfigurationIface->setSuplMode(mode); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1630 | if (result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1631 | return result; |
| 1632 | } else { |
| 1633 | return JNI_FALSE; |
| 1634 | } |
| 1635 | } |
| 1636 | |
| 1637 | static jboolean android_location_GnssLocationProvider_set_gps_lock(JNIEnv*, |
| 1638 | jobject, |
| 1639 | jint gpsLock) { |
| 1640 | if (gnssConfigurationIface == nullptr) { |
| 1641 | ALOGE("no GNSS configuration interface available"); |
| 1642 | return JNI_FALSE; |
| 1643 | } |
| 1644 | |
| 1645 | auto result = gnssConfigurationIface->setGpsLock(gpsLock); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1646 | if (result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1647 | return result; |
| 1648 | } else { |
| 1649 | return JNI_FALSE; |
| 1650 | } |
| 1651 | } |
| 1652 | |
| 1653 | static jboolean android_location_GnssLocationProvider_set_lpp_profile(JNIEnv*, |
| 1654 | jobject, |
| 1655 | jint lppProfile) { |
| 1656 | if (gnssConfigurationIface == nullptr) { |
| 1657 | ALOGE("no GNSS configuration interface available"); |
| 1658 | return JNI_FALSE; |
| 1659 | } |
| 1660 | |
| 1661 | auto result = gnssConfigurationIface->setLppProfile(lppProfile); |
| 1662 | |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1663 | if (result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1664 | return result; |
| 1665 | } else { |
| 1666 | return JNI_FALSE; |
| 1667 | } |
| 1668 | } |
| 1669 | |
| 1670 | static jboolean android_location_GnssLocationProvider_set_gnss_pos_protocol_select(JNIEnv*, |
| 1671 | jobject, |
| 1672 | jint gnssPosProtocol) { |
| 1673 | if (gnssConfigurationIface == nullptr) { |
| 1674 | ALOGE("no GNSS configuration interface available"); |
| 1675 | return JNI_FALSE; |
| 1676 | } |
| 1677 | |
| 1678 | auto result = gnssConfigurationIface->setGlonassPositioningProtocol(gnssPosProtocol); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1679 | if (result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1680 | return result; |
| 1681 | } else { |
| 1682 | return JNI_FALSE; |
| 1683 | } |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 1684 | } |
| 1685 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 1686 | static const JNINativeMethod sMethods[] = { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1687 | /* name, signature, funcPtr */ |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1688 | {"class_init_native", "()V", reinterpret_cast<void *>( |
| 1689 | android_location_GnssLocationProvider_class_init_native)}, |
| 1690 | {"native_is_supported", "()Z", reinterpret_cast<void *>( |
| 1691 | android_location_GnssLocationProvider_is_supported)}, |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 1692 | {"native_is_agps_ril_supported", "()Z", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1693 | reinterpret_cast<void *>(android_location_GnssLocationProvider_is_agps_ril_supported)}, |
destradaa | ef752b6 | 2015-04-17 13:10:47 -0700 | [diff] [blame] | 1694 | {"native_is_gnss_configuration_supported", "()Z", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1695 | reinterpret_cast<void *>( |
| 1696 | android_location_gpsLocationProvider_is_gnss_configuration_supported)}, |
| 1697 | {"native_init", "()Z", reinterpret_cast<void *>(android_location_GnssLocationProvider_init)}, |
| 1698 | {"native_cleanup", "()V", reinterpret_cast<void *>( |
| 1699 | android_location_GnssLocationProvider_cleanup)}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1700 | {"native_set_position_mode", |
| 1701 | "(IIIII)Z", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1702 | reinterpret_cast<void*>(android_location_GnssLocationProvider_set_position_mode)}, |
| 1703 | {"native_start", "()Z", reinterpret_cast<void*>(android_location_GnssLocationProvider_start)}, |
| 1704 | {"native_stop", "()Z", reinterpret_cast<void*>(android_location_GnssLocationProvider_stop)}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1705 | {"native_delete_aiding_data", |
| 1706 | "(I)V", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1707 | reinterpret_cast<void*>(android_location_GnssLocationProvider_delete_aiding_data)}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1708 | {"native_read_sv_status", |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 1709 | "([I[F[F[F)I", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1710 | reinterpret_cast<void *>(android_location_GnssLocationProvider_read_sv_status)}, |
| 1711 | {"native_read_nmea", "([BI)I", reinterpret_cast<void *>( |
| 1712 | android_location_GnssLocationProvider_read_nmea)}, |
| 1713 | {"native_inject_time", "(JJI)V", reinterpret_cast<void *>( |
| 1714 | android_location_GnssLocationProvider_inject_time)}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1715 | {"native_inject_location", |
| 1716 | "(DDF)V", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1717 | reinterpret_cast<void *>(android_location_GnssLocationProvider_inject_location)}, |
| 1718 | {"native_supports_xtra", "()Z", reinterpret_cast<void *>( |
| 1719 | android_location_GnssLocationProvider_supports_xtra)}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1720 | {"native_inject_xtra_data", |
| 1721 | "([BI)V", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1722 | reinterpret_cast<void *>(android_location_GnssLocationProvider_inject_xtra_data)}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1723 | {"native_agps_data_conn_open", |
| 1724 | "(Ljava/lang/String;I)V", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1725 | reinterpret_cast<void *>(android_location_GnssLocationProvider_agps_data_conn_open)}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1726 | {"native_agps_data_conn_closed", |
| 1727 | "()V", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1728 | reinterpret_cast<void *>(android_location_GnssLocationProvider_agps_data_conn_closed)}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1729 | {"native_agps_data_conn_failed", |
| 1730 | "()V", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1731 | reinterpret_cast<void *>(android_location_GnssLocationProvider_agps_data_conn_failed)}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1732 | {"native_agps_set_id", |
| 1733 | "(ILjava/lang/String;)V", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1734 | reinterpret_cast<void *>(android_location_GnssLocationProvider_agps_set_id)}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1735 | {"native_agps_set_ref_location_cellid", |
| 1736 | "(IIIII)V", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1737 | reinterpret_cast<void *>( |
| 1738 | android_location_GnssLocationProvider_agps_set_reference_location_cellid)}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1739 | {"native_set_agps_server", |
| 1740 | "(ILjava/lang/String;I)V", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1741 | reinterpret_cast<void *>(android_location_GnssLocationProvider_set_agps_server)}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1742 | {"native_send_ni_response", |
| 1743 | "(II)V", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1744 | reinterpret_cast<void *>(android_location_GnssLocationProvider_send_ni_response)}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1745 | {"native_get_internal_state", |
| 1746 | "()Ljava/lang/String;", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1747 | reinterpret_cast<void *>(android_location_GnssLocationProvider_get_internal_state)}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1748 | {"native_update_network_state", |
| 1749 | "(ZIZZLjava/lang/String;Ljava/lang/String;)V", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1750 | reinterpret_cast<void *>(android_location_GnssLocationProvider_update_network_state)}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1751 | {"native_is_geofence_supported", |
| 1752 | "()Z", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1753 | reinterpret_cast<void *>(android_location_GnssLocationProvider_is_geofence_supported)}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1754 | {"native_add_geofence", |
| 1755 | "(IDDDIIII)Z", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1756 | reinterpret_cast<void *>(android_location_GnssLocationProvider_add_geofence)}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1757 | {"native_remove_geofence", |
| 1758 | "(I)Z", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1759 | reinterpret_cast<void *>(android_location_GnssLocationProvider_remove_geofence)}, |
| 1760 | {"native_pause_geofence", "(I)Z", reinterpret_cast<void *>( |
| 1761 | android_location_GnssLocationProvider_pause_geofence)}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1762 | {"native_resume_geofence", |
| 1763 | "(II)Z", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1764 | reinterpret_cast<void *>(android_location_GnssLocationProvider_resume_geofence)}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1765 | {"native_is_measurement_supported", |
| 1766 | "()Z", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1767 | reinterpret_cast<void *>( |
| 1768 | android_location_GnssLocationProvider_is_measurement_supported)}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1769 | {"native_start_measurement_collection", |
| 1770 | "()Z", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1771 | reinterpret_cast<void *>( |
| 1772 | android_location_GnssLocationProvider_start_measurement_collection)}, |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1773 | {"native_stop_measurement_collection", |
| 1774 | "()Z", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1775 | reinterpret_cast<void *>( |
| 1776 | android_location_GnssLocationProvider_stop_measurement_collection)}, |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1777 | {"native_is_navigation_message_supported", |
| 1778 | "()Z", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1779 | reinterpret_cast<void *>( |
| 1780 | android_location_GnssLocationProvider_is_navigation_message_supported)}, |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1781 | {"native_start_navigation_message_collection", |
| 1782 | "()Z", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1783 | reinterpret_cast<void *>( |
| 1784 | android_location_GnssLocationProvider_start_navigation_message_collection)}, |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 1785 | {"native_stop_navigation_message_collection", |
| 1786 | "()Z", |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1787 | reinterpret_cast<void *>( |
| 1788 | android_location_GnssLocationProvider_stop_navigation_message_collection)}, |
| 1789 | {"native_set_supl_es", |
| 1790 | "(I)Z", |
| 1791 | reinterpret_cast<void *>(android_location_GnssLocationProvider_set_supl_es)}, |
| 1792 | {"native_set_supl_version", |
| 1793 | "(I)Z", |
| 1794 | reinterpret_cast<void *>(android_location_GnssLocationProvider_set_supl_version)}, |
| 1795 | {"native_set_supl_mode", |
| 1796 | "(I)Z", |
| 1797 | reinterpret_cast<void *>(android_location_GnssLocationProvider_set_supl_mode)}, |
| 1798 | {"native_set_lpp_profile", |
| 1799 | "(I)Z", |
| 1800 | reinterpret_cast<void *>(android_location_GnssLocationProvider_set_lpp_profile)}, |
| 1801 | {"native_set_gnss_pos_protocol_select", |
| 1802 | "(I)Z", |
| 1803 | reinterpret_cast<void *>( |
| 1804 | android_location_GnssLocationProvider_set_gnss_pos_protocol_select)}, |
| 1805 | {"native_set_gps_lock", |
| 1806 | "(I)Z", |
| 1807 | reinterpret_cast<void *>(android_location_GnssLocationProvider_set_gps_lock)}, |
| 1808 | {"native_set_emergency_supl_pdn", |
| 1809 | "(I)Z", |
| 1810 | reinterpret_cast<void *>(android_location_GnssLocationProvider_set_emergency_supl_pdn)}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1811 | }; |
| 1812 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1813 | int register_android_server_location_GnssLocationProvider(JNIEnv* env) { |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1814 | return jniRegisterNativeMethods( |
| 1815 | env, |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 1816 | "com/android/server/location/GnssLocationProvider", |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1817 | sMethods, |
| 1818 | NELEM(sMethods)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | } /* namespace android */ |