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