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