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> |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 23 | #include <android/hardware/gnss/2.0/IGnss.h> |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 24 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 25 | #include <android/hardware/gnss/1.0/IGnssMeasurement.h> |
| 26 | #include <android/hardware/gnss/1.1/IGnssMeasurement.h> |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 27 | #include <android/hardware/gnss/2.0/IGnssMeasurement.h> |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 28 | #include <android/hardware/gnss/measurement_corrections/1.0/IMeasurementCorrections.h> |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 29 | #include <android/hardware/gnss/visibility_control/1.0/IGnssVisibilityControl.h> |
Steven Moreland | c95dca8 | 2017-08-01 10:18:40 -0700 | [diff] [blame] | 30 | #include <nativehelper/JNIHelp.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | #include "jni.h" |
Mike Lockwood | 8f5a800 | 2010-04-07 09:05:26 -0400 | [diff] [blame] | 32 | #include "hardware_legacy/power.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | #include "utils/Log.h" |
| 34 | #include "utils/misc.h" |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 35 | #include "android_runtime/AndroidRuntime.h" |
Ruben Brunk | 87eac99 | 2013-09-09 17:44:59 -0700 | [diff] [blame] | 36 | #include "android_runtime/Log.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | |
destradaa | 931a37f | 2014-08-12 16:36:59 -0700 | [diff] [blame] | 38 | #include <arpa/inet.h> |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 39 | #include <cinttypes> |
| 40 | #include <iomanip> |
Lifu Tang | 38bce79 | 2016-02-24 17:17:38 -0800 | [diff] [blame] | 41 | #include <limits> |
destradaa | 96a1470 | 2014-06-05 11:36:30 -0700 | [diff] [blame] | 42 | #include <linux/in.h> |
| 43 | #include <linux/in6.h> |
Lifu Tang | 38bce79 | 2016-02-24 17:17:38 -0800 | [diff] [blame] | 44 | #include <pthread.h> |
| 45 | #include <string.h> |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 46 | #include <utils/SystemClock.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | |
WyattRiley | 840c0b2 | 2018-10-31 09:03:53 -0700 | [diff] [blame] | 48 | static jobject mCallbacksObj = nullptr; |
Mike Lockwood | f602d36 | 2010-06-20 14:28:16 -0700 | [diff] [blame] | 49 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | static jmethodID method_reportLocation; |
| 51 | static jmethodID method_reportStatus; |
| 52 | static jmethodID method_reportSvStatus; |
Mike Lockwood | e3635c9 | 2009-05-11 08:38:02 -0400 | [diff] [blame] | 53 | static jmethodID method_reportAGpsStatus; |
Mike Lockwood | b16e780 | 2009-08-06 09:26:02 -0400 | [diff] [blame] | 54 | static jmethodID method_reportNmea; |
Mike Lockwood | 04598b6 | 2010-04-14 17:17:24 -0400 | [diff] [blame] | 55 | static jmethodID method_setEngineCapabilities; |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 56 | static jmethodID method_setGnssYearOfHardware; |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 57 | static jmethodID method_setGnssHardwareModelName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | static jmethodID method_xtraDownloadRequest; |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 59 | static jmethodID method_reportNiNotification; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 60 | static jmethodID method_requestLocation; |
Miguel Torroja | 1e84da8 | 2010-07-27 07:02:24 +0200 | [diff] [blame] | 61 | static jmethodID method_requestRefLocation; |
| 62 | static jmethodID method_requestSetID; |
Mike Lockwood | 9b9fb5c | 2011-06-29 15:09:40 -0400 | [diff] [blame] | 63 | static jmethodID method_requestUtcTime; |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 64 | static jmethodID method_reportGeofenceTransition; |
| 65 | static jmethodID method_reportGeofenceStatus; |
| 66 | static jmethodID method_reportGeofenceAddStatus; |
| 67 | static jmethodID method_reportGeofenceRemoveStatus; |
| 68 | static jmethodID method_reportGeofencePauseStatus; |
| 69 | static jmethodID method_reportGeofenceResumeStatus; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 70 | static jmethodID method_reportMeasurementData; |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 71 | static jmethodID method_reportNavigationMessages; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 72 | static jmethodID method_reportLocationBatch; |
Yu-Han Yang | 5205762 | 2018-04-25 00:51:22 -0700 | [diff] [blame] | 73 | static jmethodID method_reportGnssServiceDied; |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 74 | static jmethodID method_correctionsGetLatitudeDegrees; |
| 75 | static jmethodID method_correctionsGetLongitudeDegrees; |
| 76 | static jmethodID method_correctionsGetAltitudeMeters; |
gomo | 6ec9538 | 2019-01-26 03:08:18 -0800 | [diff] [blame] | 77 | static jmethodID method_correctionsGetHorPosUncMeters; |
| 78 | static jmethodID method_correctionsGetVerPosUncMeters; |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 79 | static jmethodID method_correctionsGetToaGpsNanosecondsOfWeek; |
| 80 | static jmethodID method_correctionsGetSingleSatCorrectionList; |
| 81 | static jmethodID method_listSize; |
| 82 | static jmethodID method_correctionListGet; |
| 83 | static jmethodID method_correctionSatFlags; |
| 84 | static jmethodID method_correctionSatConstType; |
| 85 | static jmethodID method_correctionSatId; |
| 86 | static jmethodID method_correctionSatCarrierFreq; |
gomo | b4635ba | 2019-01-17 04:02:53 -0800 | [diff] [blame] | 87 | static jmethodID method_correctionSatIsLosProb; |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 88 | static jmethodID method_correctionSatEpl; |
| 89 | static jmethodID method_correctionSatEplUnc; |
| 90 | static jmethodID method_correctionSatRefPlane; |
| 91 | static jmethodID method_correctionPlaneLatDeg; |
| 92 | static jmethodID method_correctionPlaneLngDeg; |
| 93 | static jmethodID method_correctionPlaneAltDeg; |
| 94 | static jmethodID method_correctionPlaneAzimDeg; |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 95 | static jmethodID method_reportNfwNotification; |
| 96 | static jmethodID method_isInEmergencySession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 98 | /* |
| 99 | * Save a pointer to JavaVm to attach/detach threads executing |
| 100 | * callback methods that need to make JNI calls. |
| 101 | */ |
| 102 | static JavaVM* sJvm; |
| 103 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 104 | using android::OK; |
| 105 | using android::sp; |
gomo | 2520888 | 2017-04-15 02:05:25 -0700 | [diff] [blame] | 106 | using android::wp; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 107 | using android::status_t; |
| 108 | using android::String16; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 110 | using android::hardware::Return; |
| 111 | using android::hardware::Void; |
| 112 | using android::hardware::hidl_vec; |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 113 | using android::hardware::hidl_string; |
gomo | 2520888 | 2017-04-15 02:05:25 -0700 | [diff] [blame] | 114 | using android::hardware::hidl_death_recipient; |
Wyatt Riley | 46ac956 | 2018-03-02 20:16:58 -0800 | [diff] [blame] | 115 | |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 116 | using android::hardware::gnss::V1_0::GnssConstellationType; |
| 117 | using android::hardware::gnss::V1_0::GnssLocationFlags; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 118 | using android::hardware::gnss::V1_0::IAGnssRilCallback; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 119 | using android::hardware::gnss::V1_0::IGnssBatching; |
| 120 | using android::hardware::gnss::V1_0::IGnssBatchingCallback; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 121 | using android::hardware::gnss::V1_0::IGnssDebug; |
| 122 | using android::hardware::gnss::V1_0::IGnssGeofenceCallback; |
| 123 | using android::hardware::gnss::V1_0::IGnssGeofencing; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 124 | using android::hardware::gnss::V1_0::IGnssNavigationMessage; |
| 125 | using android::hardware::gnss::V1_0::IGnssNavigationMessageCallback; |
| 126 | using android::hardware::gnss::V1_0::IGnssNi; |
| 127 | using android::hardware::gnss::V1_0::IGnssNiCallback; |
| 128 | using android::hardware::gnss::V1_0::IGnssXtra; |
| 129 | using android::hardware::gnss::V1_0::IGnssXtraCallback; |
Wyatt Riley | bb9bc84 | 2018-02-14 08:46:00 -0800 | [diff] [blame] | 130 | |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 131 | using android::hardware::gnss::V2_0::ElapsedRealtimeFlags; |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 132 | using android::hardware::gnss::V2_0::IGnssCallback; |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 133 | |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 134 | using android::hardware::gnss::measurement_corrections::V1_0::MeasurementCorrections; |
| 135 | using android::hardware::gnss::measurement_corrections::V1_0::SingleSatCorrection; |
| 136 | using android::hardware::gnss::measurement_corrections::V1_0::ReflectingPlane; |
Wyatt Riley | 46ac956 | 2018-03-02 20:16:58 -0800 | [diff] [blame] | 137 | |
| 138 | using android::hidl::base::V1_0::IBase; |
| 139 | |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 140 | using GnssLocation_V1_0 = android::hardware::gnss::V1_0::GnssLocation; |
| 141 | using GnssLocation_V2_0 = android::hardware::gnss::V2_0::GnssLocation; |
Wyatt Riley | 46ac956 | 2018-03-02 20:16:58 -0800 | [diff] [blame] | 142 | using IGnss_V1_0 = android::hardware::gnss::V1_0::IGnss; |
| 143 | using IGnss_V1_1 = android::hardware::gnss::V1_1::IGnss; |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 144 | using IGnss_V2_0 = android::hardware::gnss::V2_0::IGnss; |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 145 | using IGnssConfiguration_V1_0 = android::hardware::gnss::V1_0::IGnssConfiguration; |
| 146 | using IGnssConfiguration_V1_1 = android::hardware::gnss::V1_1::IGnssConfiguration; |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 147 | using IGnssConfiguration_V2_0 = android::hardware::gnss::V2_0::IGnssConfiguration; |
Wyatt Riley | 46ac956 | 2018-03-02 20:16:58 -0800 | [diff] [blame] | 148 | using IGnssMeasurement_V1_0 = android::hardware::gnss::V1_0::IGnssMeasurement; |
| 149 | using IGnssMeasurement_V1_1 = android::hardware::gnss::V1_1::IGnssMeasurement; |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 150 | using IGnssMeasurement_V2_0 = android::hardware::gnss::V2_0::IGnssMeasurement; |
Wyatt Riley | 46ac956 | 2018-03-02 20:16:58 -0800 | [diff] [blame] | 151 | using IGnssMeasurementCallback_V1_0 = android::hardware::gnss::V1_0::IGnssMeasurementCallback; |
| 152 | using IGnssMeasurementCallback_V1_1 = android::hardware::gnss::V1_1::IGnssMeasurementCallback; |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 153 | using IGnssMeasurementCallback_V2_0 = android::hardware::gnss::V2_0::IGnssMeasurementCallback; |
Anil Admal | b4995e2 | 2018-11-16 17:36:21 -0800 | [diff] [blame] | 154 | using IAGnssRil_V1_0 = android::hardware::gnss::V1_0::IAGnssRil; |
| 155 | using IAGnssRil_V2_0 = android::hardware::gnss::V2_0::IAGnssRil; |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 156 | using IAGnss_V1_0 = android::hardware::gnss::V1_0::IAGnss; |
| 157 | using IAGnss_V2_0 = android::hardware::gnss::V2_0::IAGnss; |
| 158 | using IAGnssCallback_V1_0 = android::hardware::gnss::V1_0::IAGnssCallback; |
| 159 | using IAGnssCallback_V2_0 = android::hardware::gnss::V2_0::IAGnssCallback; |
Wyatt Riley | fb84092 | 2017-11-08 15:07:58 -0800 | [diff] [blame] | 160 | |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 161 | using IMeasurementCorrections = |
| 162 | android::hardware::gnss::measurement_corrections::V1_0::IMeasurementCorrections; |
gomo | 5716ab8 | 2019-02-27 22:57:56 -0800 | [diff] [blame] | 163 | using GnssSingleSatCorrectionFlags = |
| 164 | android::hardware::gnss::measurement_corrections::V1_0::GnssSingleSatCorrectionFlags; |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 165 | |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 166 | using android::hardware::gnss::visibility_control::V1_0::IGnssVisibilityControl; |
| 167 | using android::hardware::gnss::visibility_control::V1_0::IGnssVisibilityControlCallback; |
| 168 | |
gomo | 2520888 | 2017-04-15 02:05:25 -0700 | [diff] [blame] | 169 | struct GnssDeathRecipient : virtual public hidl_death_recipient |
| 170 | { |
| 171 | // hidl_death_recipient interface |
| 172 | virtual void serviceDied(uint64_t cookie, const wp<IBase>& who) override { |
Yu-Han Yang | 5205762 | 2018-04-25 00:51:22 -0700 | [diff] [blame] | 173 | ALOGE("IGNSS hidl service failed, trying to recover..."); |
| 174 | |
| 175 | JNIEnv* env = android::AndroidRuntime::getJNIEnv(); |
| 176 | env->CallVoidMethod(mCallbacksObj, method_reportGnssServiceDied); |
gomo | 2520888 | 2017-04-15 02:05:25 -0700 | [diff] [blame] | 177 | } |
| 178 | }; |
Wyatt Riley | f6527ae | 2016-05-23 15:23:12 -0700 | [diff] [blame] | 179 | |
Wyatt Riley | 4cbcb41 | 2018-01-23 18:07:05 -0800 | [diff] [blame] | 180 | // Must match the value from GnssMeasurement.java |
| 181 | static const uint32_t ADR_STATE_HALF_CYCLE_REPORTED = (1<<4); |
| 182 | |
gomo | 2520888 | 2017-04-15 02:05:25 -0700 | [diff] [blame] | 183 | sp<GnssDeathRecipient> gnssHalDeathRecipient = nullptr; |
Wyatt Riley | 46ac956 | 2018-03-02 20:16:58 -0800 | [diff] [blame] | 184 | sp<IGnss_V1_0> gnssHal = nullptr; |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 185 | sp<IGnss_V1_1> gnssHal_V1_1 = nullptr; |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 186 | sp<IGnss_V2_0> gnssHal_V2_0 = nullptr; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 187 | sp<IGnssXtra> gnssXtraIface = nullptr; |
Anil Admal | b4995e2 | 2018-11-16 17:36:21 -0800 | [diff] [blame] | 188 | sp<IAGnssRil_V1_0> agnssRilIface = nullptr; |
| 189 | sp<IAGnssRil_V2_0> agnssRilIface_V2_0 = nullptr; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 190 | sp<IGnssGeofencing> gnssGeofencingIface = nullptr; |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 191 | sp<IAGnss_V1_0> agnssIface = nullptr; |
| 192 | sp<IAGnss_V2_0> agnssIface_V2_0 = nullptr; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 193 | sp<IGnssBatching> gnssBatchingIface = nullptr; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 194 | sp<IGnssDebug> gnssDebugIface = nullptr; |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 195 | sp<IGnssConfiguration_V1_0> gnssConfigurationIface = nullptr; |
| 196 | sp<IGnssConfiguration_V1_1> gnssConfigurationIface_V1_1 = nullptr; |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 197 | sp<IGnssConfiguration_V2_0> gnssConfigurationIface_V2_0 = nullptr; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 198 | sp<IGnssNi> gnssNiIface = nullptr; |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 199 | sp<IGnssMeasurement_V1_0> gnssMeasurementIface = nullptr; |
| 200 | sp<IGnssMeasurement_V1_1> gnssMeasurementIface_V1_1 = nullptr; |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 201 | sp<IGnssMeasurement_V2_0> gnssMeasurementIface_V2_0 = nullptr; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 202 | sp<IGnssNavigationMessage> gnssNavigationMessageIface = nullptr; |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 203 | sp<IMeasurementCorrections> gnssCorrectionsIface = nullptr; |
gomo | 5716ab8 | 2019-02-27 22:57:56 -0800 | [diff] [blame] | 204 | |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 205 | sp<IGnssVisibilityControl> gnssVisibilityControlIface = nullptr; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | |
Mike Lockwood | 8f5a800 | 2010-04-07 09:05:26 -0400 | [diff] [blame] | 207 | #define WAKE_LOCK_NAME "GPS" |
| 208 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | namespace android { |
| 210 | |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 211 | namespace { |
| 212 | |
| 213 | // Returns true if location has lat/long information. |
| 214 | bool hasLatLong(const GnssLocation_V1_0& location) { |
| 215 | return (static_cast<uint32_t>(location.gnssLocationFlags) & |
| 216 | GnssLocationFlags::HAS_LAT_LONG) != 0; |
| 217 | } |
| 218 | |
| 219 | // Returns true if location has lat/long information. |
| 220 | bool hasLatLong(const GnssLocation_V2_0& location) { |
| 221 | return hasLatLong(location.v1_0); |
| 222 | } |
| 223 | |
| 224 | } // namespace |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 225 | template<class T> |
| 226 | class JavaMethodHelper { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 227 | public: |
| 228 | // Helper function to call setter on a Java object. |
| 229 | static void callJavaMethod( |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 230 | JNIEnv* env, |
| 231 | jclass clazz, |
| 232 | jobject object, |
| 233 | const char* method_name, |
| 234 | T value); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 235 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 236 | private: |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 237 | static const char* const signature_; |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 238 | }; |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 239 | |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 240 | template<class T> |
| 241 | void JavaMethodHelper<T>::callJavaMethod( |
| 242 | JNIEnv* env, |
| 243 | jclass clazz, |
| 244 | jobject object, |
| 245 | const char* method_name, |
| 246 | T value) { |
| 247 | jmethodID method = env->GetMethodID(clazz, method_name, signature_); |
| 248 | env->CallVoidMethod(object, method, value); |
| 249 | } |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 250 | |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 251 | class JavaObject { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 252 | public: |
| 253 | JavaObject(JNIEnv* env, const char* class_name); |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 254 | JavaObject(JNIEnv* env, const char* class_name, const char * sz_arg_1); |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 255 | JavaObject(JNIEnv* env, const char* class_name, jobject object); |
| 256 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 257 | virtual ~JavaObject(); |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 258 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 259 | template<class T> |
| 260 | void callSetter(const char* method_name, T value); |
| 261 | template<class T> |
| 262 | void callSetter(const char* method_name, T* value, size_t size); |
| 263 | jobject get(); |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 264 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 265 | private: |
| 266 | JNIEnv* env_; |
| 267 | jclass clazz_; |
| 268 | jobject object_; |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 269 | }; |
| 270 | |
| 271 | JavaObject::JavaObject(JNIEnv* env, const char* class_name) : env_(env) { |
| 272 | clazz_ = env_->FindClass(class_name); |
| 273 | jmethodID ctor = env->GetMethodID(clazz_, "<init>", "()V"); |
| 274 | object_ = env_->NewObject(clazz_, ctor); |
| 275 | } |
| 276 | |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 277 | JavaObject::JavaObject(JNIEnv* env, const char* class_name, const char * sz_arg_1) : env_(env) { |
| 278 | clazz_ = env_->FindClass(class_name); |
| 279 | jmethodID ctor = env->GetMethodID(clazz_, "<init>", "(Ljava/lang/String;)V"); |
| 280 | object_ = env_->NewObject(clazz_, ctor, env->NewStringUTF(sz_arg_1)); |
| 281 | } |
| 282 | |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 283 | JavaObject::JavaObject(JNIEnv* env, const char* class_name, jobject object) |
| 284 | : env_(env), object_(object) { |
| 285 | clazz_ = env_->FindClass(class_name); |
| 286 | } |
| 287 | |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 288 | JavaObject::~JavaObject() { |
| 289 | env_->DeleteLocalRef(clazz_); |
| 290 | } |
| 291 | |
| 292 | template<class T> |
| 293 | void JavaObject::callSetter(const char* method_name, T value) { |
| 294 | JavaMethodHelper<T>::callJavaMethod( |
| 295 | env_, clazz_, object_, method_name, value); |
| 296 | } |
| 297 | |
| 298 | template<> |
| 299 | void JavaObject::callSetter( |
| 300 | const char* method_name, uint8_t* value, size_t size) { |
| 301 | jbyteArray array = env_->NewByteArray(size); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 302 | env_->SetByteArrayRegion(array, 0, size, reinterpret_cast<jbyte*>(value)); |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 303 | jmethodID method = env_->GetMethodID( |
| 304 | clazz_, |
| 305 | method_name, |
| 306 | "([B)V"); |
| 307 | env_->CallVoidMethod(object_, method, array); |
Lifu Tang | fe427f2 | 2016-10-08 02:57:53 -0700 | [diff] [blame] | 308 | env_->DeleteLocalRef(array); |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | jobject JavaObject::get() { |
| 312 | return object_; |
| 313 | } |
| 314 | |
| 315 | // Define Java method signatures for all known types. |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 316 | template<> |
| 317 | const char *const JavaMethodHelper<uint8_t>::signature_ = "(B)V"; |
| 318 | template<> |
| 319 | const char *const JavaMethodHelper<int8_t>::signature_ = "(B)V"; |
| 320 | template<> |
| 321 | const char *const JavaMethodHelper<int16_t>::signature_ = "(S)V"; |
| 322 | template<> |
| 323 | const char *const JavaMethodHelper<uint16_t>::signature_ = "(S)V"; |
| 324 | template<> |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 325 | const char *const JavaMethodHelper<int32_t>::signature_ = "(I)V"; |
| 326 | template<> |
| 327 | const char *const JavaMethodHelper<uint32_t>::signature_ = "(I)V"; |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 328 | template<> |
| 329 | const char *const JavaMethodHelper<int64_t>::signature_ = "(J)V"; |
| 330 | template<> |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 331 | const char *const JavaMethodHelper<uint64_t>::signature_ = "(J)V"; |
| 332 | template<> |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 333 | const char *const JavaMethodHelper<float>::signature_ = "(F)V"; |
| 334 | template<> |
| 335 | const char *const JavaMethodHelper<double>::signature_ = "(D)V"; |
| 336 | template<> |
| 337 | const char *const JavaMethodHelper<bool>::signature_ = "(Z)V"; |
| 338 | |
| 339 | #define SET(setter, value) object.callSetter("set" # setter, (value)) |
Lifu Tang | ccb4488 | 2016-03-09 19:32:29 -0800 | [diff] [blame] | 340 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 341 | static inline jboolean boolToJbool(bool value) { |
| 342 | return value ? JNI_TRUE : JNI_FALSE; |
| 343 | } |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 344 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 345 | static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) { |
| 346 | if (env->ExceptionCheck()) { |
| 347 | ALOGE("An exception was thrown by callback '%s'.", methodName); |
| 348 | LOGE_EX(env); |
| 349 | env->ExceptionClear(); |
| 350 | } |
| 351 | } |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 352 | |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 353 | static jobject createHalInterfaceVersionJavaObject(JNIEnv* env, jint major, jint minor) { |
| 354 | jclass versionClass = |
| 355 | env->FindClass("com/android/server/location/GnssConfiguration$HalInterfaceVersion"); |
| 356 | jmethodID versionCtor = env->GetMethodID(versionClass, "<init>", "(II)V"); |
| 357 | jobject version = env->NewObject(versionClass, versionCtor, major, minor); |
| 358 | env->DeleteLocalRef(versionClass); |
| 359 | return version; |
| 360 | } |
| 361 | |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 362 | struct ScopedJniString { |
| 363 | ScopedJniString(JNIEnv* env, jstring javaString) : mEnv(env), mJavaString(javaString) { |
| 364 | mNativeString = mEnv->GetStringUTFChars(mJavaString, nullptr); |
| 365 | } |
| 366 | |
| 367 | ~ScopedJniString() { |
| 368 | if (mNativeString != nullptr) { |
| 369 | mEnv->ReleaseStringUTFChars(mJavaString, mNativeString); |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | const char* c_str() const { |
| 374 | return mNativeString; |
| 375 | } |
| 376 | |
| 377 | operator hidl_string() const { |
| 378 | return hidl_string(mNativeString); |
| 379 | } |
| 380 | |
| 381 | private: |
| 382 | ScopedJniString(const ScopedJniString&) = delete; |
| 383 | ScopedJniString& operator=(const ScopedJniString&) = delete; |
| 384 | |
| 385 | JNIEnv* mEnv; |
| 386 | jstring mJavaString; |
| 387 | const char* mNativeString; |
| 388 | }; |
| 389 | |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 390 | class ScopedJniThreadAttach { |
| 391 | public: |
| 392 | ScopedJniThreadAttach() { |
| 393 | /* |
| 394 | * attachResult will also be JNI_OK if the thead was already attached to |
| 395 | * JNI before the call to AttachCurrentThread(). |
| 396 | */ |
| 397 | jint attachResult = sJvm->AttachCurrentThread(&mEnv, nullptr); |
| 398 | LOG_ALWAYS_FATAL_IF(attachResult != JNI_OK, "Unable to attach thread. Error %d", |
| 399 | attachResult); |
| 400 | } |
| 401 | |
| 402 | ~ScopedJniThreadAttach() { |
| 403 | jint detachResult = sJvm->DetachCurrentThread(); |
| 404 | /* |
| 405 | * Return if the thread was already detached. Log error for any other |
| 406 | * failure. |
| 407 | */ |
| 408 | if (detachResult == JNI_EDETACHED) { |
| 409 | return; |
| 410 | } |
| 411 | |
| 412 | LOG_ALWAYS_FATAL_IF(detachResult != JNI_OK, "Unable to detach thread. Error %d", |
| 413 | detachResult); |
| 414 | } |
| 415 | |
| 416 | JNIEnv* getEnv() { |
| 417 | /* |
| 418 | * Checking validity of mEnv in case the thread was detached elsewhere. |
| 419 | */ |
| 420 | LOG_ALWAYS_FATAL_IF(AndroidRuntime::getJNIEnv() != mEnv); |
| 421 | return mEnv; |
| 422 | } |
| 423 | |
| 424 | private: |
| 425 | JNIEnv* mEnv = nullptr; |
| 426 | }; |
| 427 | |
| 428 | thread_local std::unique_ptr<ScopedJniThreadAttach> tJniThreadAttacher; |
| 429 | |
| 430 | static JNIEnv* getJniEnv() { |
| 431 | JNIEnv* env = AndroidRuntime::getJNIEnv(); |
| 432 | |
| 433 | /* |
| 434 | * If env is nullptr, the thread is not already attached to |
| 435 | * JNI. It is attached below and the destructor for ScopedJniThreadAttach |
| 436 | * will detach it on thread exit. |
| 437 | */ |
| 438 | if (env == nullptr) { |
| 439 | tJniThreadAttacher.reset(new ScopedJniThreadAttach()); |
| 440 | env = tJniThreadAttacher->getEnv(); |
| 441 | } |
| 442 | |
| 443 | return env; |
| 444 | } |
| 445 | |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 446 | static jobject translateGnssLocation(JNIEnv* env, |
| 447 | const GnssLocation_V1_0& location) { |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 448 | JavaObject object(env, "android/location/Location", "gps"); |
| 449 | |
| 450 | uint16_t flags = static_cast<uint32_t>(location.gnssLocationFlags); |
Wyatt Riley | fb84092 | 2017-11-08 15:07:58 -0800 | [diff] [blame] | 451 | if (flags & GnssLocationFlags::HAS_LAT_LONG) { |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 452 | SET(Latitude, location.latitudeDegrees); |
| 453 | SET(Longitude, location.longitudeDegrees); |
| 454 | } |
Wyatt Riley | fb84092 | 2017-11-08 15:07:58 -0800 | [diff] [blame] | 455 | if (flags & GnssLocationFlags::HAS_ALTITUDE) { |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 456 | SET(Altitude, location.altitudeMeters); |
| 457 | } |
Wyatt Riley | fb84092 | 2017-11-08 15:07:58 -0800 | [diff] [blame] | 458 | if (flags & GnssLocationFlags::HAS_SPEED) { |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 459 | SET(Speed, location.speedMetersPerSec); |
| 460 | } |
Wyatt Riley | fb84092 | 2017-11-08 15:07:58 -0800 | [diff] [blame] | 461 | if (flags & GnssLocationFlags::HAS_BEARING) { |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 462 | SET(Bearing, location.bearingDegrees); |
| 463 | } |
Wyatt Riley | fb84092 | 2017-11-08 15:07:58 -0800 | [diff] [blame] | 464 | if (flags & GnssLocationFlags::HAS_HORIZONTAL_ACCURACY) { |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 465 | SET(Accuracy, location.horizontalAccuracyMeters); |
| 466 | } |
Wyatt Riley | fb84092 | 2017-11-08 15:07:58 -0800 | [diff] [blame] | 467 | if (flags & GnssLocationFlags::HAS_VERTICAL_ACCURACY) { |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 468 | SET(VerticalAccuracyMeters, location.verticalAccuracyMeters); |
| 469 | } |
Wyatt Riley | fb84092 | 2017-11-08 15:07:58 -0800 | [diff] [blame] | 470 | if (flags & GnssLocationFlags::HAS_SPEED_ACCURACY) { |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 471 | SET(SpeedAccuracyMetersPerSecond, location.speedAccuracyMetersPerSecond); |
| 472 | } |
Wyatt Riley | fb84092 | 2017-11-08 15:07:58 -0800 | [diff] [blame] | 473 | if (flags & GnssLocationFlags::HAS_BEARING_ACCURACY) { |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 474 | SET(BearingAccuracyDegrees, location.bearingAccuracyDegrees); |
| 475 | } |
| 476 | SET(Time, location.timestamp); |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 477 | SET(ElapsedRealtimeNanos, android::elapsedRealtimeNano()); |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 478 | |
| 479 | return object.get(); |
| 480 | } |
| 481 | |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 482 | static jobject translateGnssLocation(JNIEnv* env, |
| 483 | const GnssLocation_V2_0& location) { |
| 484 | JavaObject object(env, "android/location/Location", |
| 485 | translateGnssLocation(env, location.v1_0)); |
| 486 | |
| 487 | const uint16_t flags = static_cast<uint16_t>(location.elapsedRealtime.flags); |
| 488 | |
| 489 | // Overwrite ElapsedRealtimeNanos when available from HAL. |
| 490 | if (flags & ElapsedRealtimeFlags::HAS_TIMESTAMP_NS) { |
| 491 | SET(ElapsedRealtimeNanos, location.elapsedRealtime.timestampNs); |
| 492 | } |
| 493 | |
Pierre Fite-georgel | 19f6cbfe | 2019-03-04 23:23:18 +0000 | [diff] [blame] | 494 | if (flags & ElapsedRealtimeFlags::HAS_TIME_UNCERTAINTY_NS) { |
| 495 | SET(ElapsedRealtimeUncertaintyNanos, location.elapsedRealtime.timeUncertaintyNs); |
| 496 | } |
| 497 | |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 498 | return object.get(); |
| 499 | } |
| 500 | |
| 501 | static GnssLocation_V1_0 createGnssLocation_V1_0( |
| 502 | jint gnssLocationFlags, jdouble latitudeDegrees, jdouble longitudeDegrees, |
| 503 | jdouble altitudeMeters, jfloat speedMetersPerSec, jfloat bearingDegrees, |
| 504 | jfloat horizontalAccuracyMeters, jfloat verticalAccuracyMeters, |
| 505 | jfloat speedAccuracyMetersPerSecond, jfloat bearingAccuracyDegrees, |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 506 | jlong timestamp) { |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 507 | GnssLocation_V1_0 location; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 508 | location.gnssLocationFlags = static_cast<uint16_t>(gnssLocationFlags); |
| 509 | location.latitudeDegrees = static_cast<double>(latitudeDegrees); |
| 510 | location.longitudeDegrees = static_cast<double>(longitudeDegrees); |
| 511 | location.altitudeMeters = static_cast<double>(altitudeMeters); |
| 512 | location.speedMetersPerSec = static_cast<float>(speedMetersPerSec); |
| 513 | location.bearingDegrees = static_cast<float>(bearingDegrees); |
| 514 | location.horizontalAccuracyMeters = static_cast<float>(horizontalAccuracyMeters); |
| 515 | location.verticalAccuracyMeters = static_cast<float>(verticalAccuracyMeters); |
| 516 | location.speedAccuracyMetersPerSecond = static_cast<float>(speedAccuracyMetersPerSecond); |
| 517 | location.bearingAccuracyDegrees = static_cast<float>(bearingAccuracyDegrees); |
| 518 | location.timestamp = static_cast<uint64_t>(timestamp); |
| 519 | |
| 520 | return location; |
| 521 | } |
| 522 | |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 523 | static GnssLocation_V2_0 createGnssLocation_V2_0( |
| 524 | jint gnssLocationFlags, jdouble latitudeDegrees, jdouble longitudeDegrees, |
| 525 | jdouble altitudeMeters, jfloat speedMetersPerSec, jfloat bearingDegrees, |
| 526 | jfloat horizontalAccuracyMeters, jfloat verticalAccuracyMeters, |
| 527 | jfloat speedAccuracyMetersPerSecond, jfloat bearingAccuracyDegrees, |
Pierre Fite-georgel | 19f6cbfe | 2019-03-04 23:23:18 +0000 | [diff] [blame] | 528 | jlong timestamp, jint elapsedRealtimeFlags, jlong elapsedRealtimeNanos, |
| 529 | jlong elapsedRealtimeUncertaintyNanos) { |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 530 | GnssLocation_V2_0 location; |
| 531 | location.v1_0 = createGnssLocation_V1_0( |
| 532 | gnssLocationFlags, latitudeDegrees, longitudeDegrees, altitudeMeters, |
| 533 | speedMetersPerSec, bearingDegrees, horizontalAccuracyMeters, |
| 534 | verticalAccuracyMeters, speedAccuracyMetersPerSecond, |
| 535 | bearingAccuracyDegrees, timestamp); |
| 536 | |
| 537 | location.elapsedRealtime.flags = static_cast<uint16_t>(elapsedRealtimeFlags); |
| 538 | location.elapsedRealtime.timestampNs = static_cast<uint64_t>(elapsedRealtimeNanos); |
Pierre Fite-georgel | 19f6cbfe | 2019-03-04 23:23:18 +0000 | [diff] [blame] | 539 | location.elapsedRealtime.timeUncertaintyNs = static_cast<uint64_t>(elapsedRealtimeUncertaintyNanos); |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 540 | |
| 541 | return location; |
| 542 | } |
| 543 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 544 | /* |
| 545 | * GnssCallback class implements the callback methods for IGnss interface. |
| 546 | */ |
| 547 | struct GnssCallback : public IGnssCallback { |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 548 | Return<void> gnssLocationCb(const GnssLocation_V1_0& location) override; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 549 | Return<void> gnssStatusCb(const IGnssCallback::GnssStatusValue status) override; |
| 550 | Return<void> gnssSvStatusCb(const IGnssCallback::GnssSvStatus& svStatus) override; |
| 551 | Return<void> gnssNmeaCb(int64_t timestamp, const android::hardware::hidl_string& nmea) override; |
| 552 | Return<void> gnssSetCapabilitesCb(uint32_t capabilities) override; |
| 553 | Return<void> gnssAcquireWakelockCb() override; |
| 554 | Return<void> gnssReleaseWakelockCb() override; |
| 555 | Return<void> gnssRequestTimeCb() override; |
Yu-Han Yang | 2198893 | 2018-01-23 15:07:37 -0800 | [diff] [blame] | 556 | Return<void> gnssRequestLocationCb(const bool independentFromGnss) override; |
Yu-Han Yang | 53f4d6d | 2019-02-13 21:47:41 -0800 | [diff] [blame] | 557 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 558 | Return<void> gnssSetSystemInfoCb(const IGnssCallback::GnssSystemInfo& info) override; |
Lifu Tang | 38bce79 | 2016-02-24 17:17:38 -0800 | [diff] [blame] | 559 | |
Wyatt Riley | fb84092 | 2017-11-08 15:07:58 -0800 | [diff] [blame] | 560 | // New in 1.1 |
| 561 | Return<void> gnssNameCb(const android::hardware::hidl_string& name) override; |
| 562 | |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 563 | // New in 2.0 |
Yu-Han Yang | 53f4d6d | 2019-02-13 21:47:41 -0800 | [diff] [blame] | 564 | Return<void> gnssRequestLocationCb_2_0(const bool independentFromGnss, const bool isUserEmergency) |
| 565 | override; |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 566 | Return<void> gnssSetCapabilitiesCb_2_0(uint32_t capabilities) override; |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 567 | Return<void> gnssLocationCb_2_0(const GnssLocation_V2_0& location) override; |
| 568 | |
| 569 | // Templated implementation for gnnsLocationCb and gnnsLocationCb_2_0. |
| 570 | template <class T> |
| 571 | Return<void> gnssLocationCbImpl(const T& location); |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 572 | |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 573 | // TODO(b/73306084): Reconsider allocation cost vs threadsafety on these statics |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 574 | static const char* sNmeaString; |
| 575 | static size_t sNmeaStringLength; |
| 576 | }; |
| 577 | |
Wyatt Riley | fb84092 | 2017-11-08 15:07:58 -0800 | [diff] [blame] | 578 | Return<void> GnssCallback::gnssNameCb(const android::hardware::hidl_string& name) { |
| 579 | ALOGD("%s: name=%s\n", __func__, name.c_str()); |
| 580 | |
Wyatt Riley | fb84092 | 2017-11-08 15:07:58 -0800 | [diff] [blame] | 581 | JNIEnv* env = getJniEnv(); |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 582 | jstring jstringName = env->NewStringUTF(name.c_str()); |
| 583 | env->CallVoidMethod(mCallbacksObj, method_setGnssHardwareModelName, jstringName); |
Wyatt Riley | fb84092 | 2017-11-08 15:07:58 -0800 | [diff] [blame] | 584 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 585 | |
Wyatt Riley | fb84092 | 2017-11-08 15:07:58 -0800 | [diff] [blame] | 586 | return Void(); |
| 587 | } |
| 588 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 589 | const char* GnssCallback::sNmeaString = nullptr; |
| 590 | size_t GnssCallback::sNmeaStringLength = 0; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 591 | |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 592 | template<class T> |
| 593 | Return<void> GnssCallback::gnssLocationCbImpl(const T& location) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 594 | JNIEnv* env = getJniEnv(); |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 595 | |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 596 | jobject jLocation = translateGnssLocation(env, location); |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 597 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 598 | env->CallVoidMethod(mCallbacksObj, |
| 599 | method_reportLocation, |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 600 | boolToJbool(hasLatLong(location)), |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 601 | jLocation); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 602 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 603 | env->DeleteLocalRef(jLocation); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 604 | return Void(); |
| 605 | } |
| 606 | |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 607 | Return<void> GnssCallback::gnssLocationCb(const GnssLocation_V1_0& location) { |
| 608 | return gnssLocationCbImpl<GnssLocation_V1_0>(location); |
| 609 | } |
| 610 | |
| 611 | Return<void> |
| 612 | GnssCallback::gnssLocationCb_2_0(const GnssLocation_V2_0& location) { |
| 613 | return gnssLocationCbImpl<GnssLocation_V2_0>(location); |
| 614 | } |
| 615 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 616 | Return<void> GnssCallback::gnssStatusCb(const IGnssCallback::GnssStatusValue status) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 617 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 618 | env->CallVoidMethod(mCallbacksObj, method_reportStatus, status); |
| 619 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 620 | return Void(); |
| 621 | } |
| 622 | |
| 623 | Return<void> GnssCallback::gnssSvStatusCb(const IGnssCallback::GnssSvStatus& svStatus) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 624 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 625 | |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 626 | uint32_t listSize = svStatus.numSvs; |
| 627 | if (listSize > static_cast<uint32_t>( |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 628 | android::hardware::gnss::V1_0::GnssMax::SVS_COUNT)) { |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 629 | ALOGD("Too many satellites %u. Clamps to %u.", listSize, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 630 | static_cast<uint32_t>(android::hardware::gnss::V1_0::GnssMax::SVS_COUNT)); |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 631 | 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] | 632 | } |
| 633 | |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 634 | jintArray svidWithFlagArray = env->NewIntArray(listSize); |
| 635 | jfloatArray cn0Array = env->NewFloatArray(listSize); |
| 636 | jfloatArray elevArray = env->NewFloatArray(listSize); |
| 637 | jfloatArray azimArray = env->NewFloatArray(listSize); |
| 638 | jfloatArray carrierFreqArray = env->NewFloatArray(listSize); |
| 639 | |
| 640 | jint* svidWithFlags = env->GetIntArrayElements(svidWithFlagArray, 0); |
| 641 | jfloat* cn0s = env->GetFloatArrayElements(cn0Array, 0); |
| 642 | jfloat* elev = env->GetFloatArrayElements(elevArray, 0); |
| 643 | jfloat* azim = env->GetFloatArrayElements(azimArray, 0); |
| 644 | jfloat* carrierFreq = env->GetFloatArrayElements(carrierFreqArray, 0); |
| 645 | |
| 646 | /* |
| 647 | * Read GNSS SV info. |
| 648 | */ |
| 649 | for (size_t i = 0; i < listSize; ++i) { |
| 650 | enum ShiftWidth: uint8_t { |
| 651 | SVID_SHIFT_WIDTH = 8, |
| 652 | CONSTELLATION_TYPE_SHIFT_WIDTH = 4 |
| 653 | }; |
| 654 | |
| 655 | const IGnssCallback::GnssSvInfo& info = svStatus.gnssSvList.data()[i]; |
| 656 | svidWithFlags[i] = (info.svid << SVID_SHIFT_WIDTH) | |
| 657 | (static_cast<uint32_t>(info.constellation) << CONSTELLATION_TYPE_SHIFT_WIDTH) | |
| 658 | static_cast<uint32_t>(info.svFlag); |
| 659 | cn0s[i] = info.cN0Dbhz; |
| 660 | elev[i] = info.elevationDegrees; |
| 661 | azim[i] = info.azimuthDegrees; |
| 662 | carrierFreq[i] = info.carrierFrequencyHz; |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 663 | } |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 664 | |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 665 | env->ReleaseIntArrayElements(svidWithFlagArray, svidWithFlags, 0); |
| 666 | env->ReleaseFloatArrayElements(cn0Array, cn0s, 0); |
| 667 | env->ReleaseFloatArrayElements(elevArray, elev, 0); |
| 668 | env->ReleaseFloatArrayElements(azimArray, azim, 0); |
| 669 | env->ReleaseFloatArrayElements(carrierFreqArray, carrierFreq, 0); |
| 670 | |
| 671 | env->CallVoidMethod(mCallbacksObj, method_reportSvStatus, |
| 672 | static_cast<jint>(listSize), svidWithFlagArray, cn0Array, elevArray, azimArray, |
| 673 | carrierFreqArray); |
| 674 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 675 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 676 | return Void(); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 677 | } |
| 678 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 679 | Return<void> GnssCallback::gnssNmeaCb( |
| 680 | int64_t timestamp, const ::android::hardware::hidl_string& nmea) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 681 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 682 | /* |
| 683 | * The Java code will call back to read these values. |
| 684 | * We do this to avoid creating unnecessary String objects. |
| 685 | */ |
| 686 | sNmeaString = nmea.c_str(); |
| 687 | sNmeaStringLength = nmea.size(); |
| 688 | |
| 689 | env->CallVoidMethod(mCallbacksObj, method_reportNmea, timestamp); |
| 690 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 691 | return Void(); |
| 692 | } |
| 693 | |
| 694 | Return<void> GnssCallback::gnssSetCapabilitesCb(uint32_t capabilities) { |
| 695 | ALOGD("%s: %du\n", __func__, capabilities); |
| 696 | |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 697 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 698 | env->CallVoidMethod(mCallbacksObj, method_setEngineCapabilities, capabilities); |
| 699 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 700 | return Void(); |
| 701 | } |
| 702 | |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 703 | Return<void> GnssCallback::gnssSetCapabilitiesCb_2_0(uint32_t capabilities) { |
| 704 | return GnssCallback::gnssSetCapabilitesCb(capabilities); |
| 705 | } |
| 706 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 707 | Return<void> GnssCallback::gnssAcquireWakelockCb() { |
| 708 | acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_NAME); |
| 709 | return Void(); |
| 710 | } |
| 711 | |
| 712 | Return<void> GnssCallback::gnssReleaseWakelockCb() { |
| 713 | release_wake_lock(WAKE_LOCK_NAME); |
| 714 | return Void(); |
| 715 | } |
| 716 | |
| 717 | Return<void> GnssCallback::gnssRequestTimeCb() { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 718 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 719 | env->CallVoidMethod(mCallbacksObj, method_requestUtcTime); |
| 720 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 721 | return Void(); |
| 722 | } |
| 723 | |
Yu-Han Yang | 2198893 | 2018-01-23 15:07:37 -0800 | [diff] [blame] | 724 | Return<void> GnssCallback::gnssRequestLocationCb(const bool independentFromGnss) { |
Yu-Han Yang | 53f4d6d | 2019-02-13 21:47:41 -0800 | [diff] [blame] | 725 | return GnssCallback::gnssRequestLocationCb_2_0(independentFromGnss, /* isUserEmergency= */ |
| 726 | false); |
| 727 | } |
| 728 | |
| 729 | Return<void> GnssCallback::gnssRequestLocationCb_2_0(const bool independentFromGnss, const bool |
| 730 | isUserEmergency) { |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 731 | JNIEnv* env = getJniEnv(); |
Yu-Han Yang | 53f4d6d | 2019-02-13 21:47:41 -0800 | [diff] [blame] | 732 | env->CallVoidMethod(mCallbacksObj, method_requestLocation, boolToJbool(independentFromGnss), |
| 733 | boolToJbool(isUserEmergency)); |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 734 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
Yu-Han Yang | 2198893 | 2018-01-23 15:07:37 -0800 | [diff] [blame] | 735 | return Void(); |
| 736 | } |
| 737 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 738 | Return<void> GnssCallback::gnssSetSystemInfoCb(const IGnssCallback::GnssSystemInfo& info) { |
| 739 | ALOGD("%s: yearOfHw=%d\n", __func__, info.yearOfHw); |
| 740 | |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 741 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 742 | env->CallVoidMethod(mCallbacksObj, method_setGnssYearOfHardware, |
| 743 | info.yearOfHw); |
| 744 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 745 | return Void(); |
| 746 | } |
| 747 | |
| 748 | class GnssXtraCallback : public IGnssXtraCallback { |
| 749 | Return<void> downloadRequestCb() override; |
| 750 | }; |
| 751 | |
| 752 | /* |
| 753 | * GnssXtraCallback class implements the callback methods for the IGnssXtra |
| 754 | * interface. |
| 755 | */ |
| 756 | Return<void> GnssXtraCallback::downloadRequestCb() { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 757 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 758 | env->CallVoidMethod(mCallbacksObj, method_xtraDownloadRequest); |
| 759 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 760 | return Void(); |
| 761 | } |
| 762 | |
| 763 | /* |
| 764 | * GnssGeofenceCallback class implements the callback methods for the |
| 765 | * IGnssGeofence interface. |
| 766 | */ |
| 767 | struct GnssGeofenceCallback : public IGnssGeofenceCallback { |
| 768 | // Methods from ::android::hardware::gps::V1_0::IGnssGeofenceCallback follow. |
| 769 | Return<void> gnssGeofenceTransitionCb( |
| 770 | int32_t geofenceId, |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 771 | const GnssLocation_V1_0& location, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 772 | GeofenceTransition transition, |
| 773 | hardware::gnss::V1_0::GnssUtcTime timestamp) override; |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 774 | Return<void> |
| 775 | gnssGeofenceStatusCb( |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 776 | GeofenceAvailability status, |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 777 | const GnssLocation_V1_0& location) override; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 778 | Return<void> gnssGeofenceAddCb(int32_t geofenceId, |
| 779 | GeofenceStatus status) override; |
| 780 | Return<void> gnssGeofenceRemoveCb(int32_t geofenceId, |
| 781 | GeofenceStatus status) override; |
| 782 | Return<void> gnssGeofencePauseCb(int32_t geofenceId, |
| 783 | GeofenceStatus status) override; |
| 784 | Return<void> gnssGeofenceResumeCb(int32_t geofenceId, |
| 785 | GeofenceStatus status) override; |
| 786 | }; |
| 787 | |
| 788 | Return<void> GnssGeofenceCallback::gnssGeofenceTransitionCb( |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 789 | int32_t geofenceId, const GnssLocation_V1_0& location, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 790 | GeofenceTransition transition, |
| 791 | hardware::gnss::V1_0::GnssUtcTime timestamp) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 792 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 793 | |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 794 | jobject jLocation = translateGnssLocation(env, location); |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 795 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 796 | env->CallVoidMethod(mCallbacksObj, |
| 797 | method_reportGeofenceTransition, |
| 798 | geofenceId, |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 799 | jLocation, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 800 | transition, |
| 801 | timestamp); |
| 802 | |
| 803 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 804 | env->DeleteLocalRef(jLocation); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 805 | return Void(); |
| 806 | } |
| 807 | |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 808 | Return<void> |
| 809 | GnssGeofenceCallback::gnssGeofenceStatusCb(GeofenceAvailability status, |
| 810 | const GnssLocation_V1_0& location) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 811 | JNIEnv* env = getJniEnv(); |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 812 | |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 813 | jobject jLocation = translateGnssLocation(env, location); |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 814 | |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 815 | env->CallVoidMethod(mCallbacksObj, method_reportGeofenceStatus, status, |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 816 | jLocation); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 817 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 818 | env->DeleteLocalRef(jLocation); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 819 | return Void(); |
| 820 | } |
| 821 | |
| 822 | Return<void> GnssGeofenceCallback::gnssGeofenceAddCb(int32_t geofenceId, |
| 823 | GeofenceStatus status) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 824 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 825 | if (status != IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS) { |
| 826 | ALOGE("%s: Error in adding a Geofence: %d\n", __func__, status); |
| 827 | } |
| 828 | |
| 829 | env->CallVoidMethod(mCallbacksObj, |
| 830 | method_reportGeofenceAddStatus, |
| 831 | geofenceId, |
| 832 | status); |
| 833 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 834 | return Void(); |
| 835 | } |
| 836 | |
| 837 | Return<void> GnssGeofenceCallback::gnssGeofenceRemoveCb(int32_t geofenceId, |
| 838 | GeofenceStatus status) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 839 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 840 | if (status != IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS) { |
| 841 | ALOGE("%s: Error in removing a Geofence: %d\n", __func__, status); |
| 842 | } |
| 843 | |
| 844 | env->CallVoidMethod(mCallbacksObj, |
| 845 | method_reportGeofenceRemoveStatus, |
| 846 | geofenceId, status); |
| 847 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 848 | return Void(); |
| 849 | } |
| 850 | |
| 851 | Return<void> GnssGeofenceCallback::gnssGeofencePauseCb(int32_t geofenceId, |
| 852 | GeofenceStatus status) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 853 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 854 | if (status != IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS) { |
| 855 | ALOGE("%s: Error in pausing Geofence: %d\n", __func__, status); |
| 856 | } |
| 857 | |
| 858 | env->CallVoidMethod(mCallbacksObj, |
| 859 | method_reportGeofencePauseStatus, |
| 860 | geofenceId, status); |
| 861 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 862 | return Void(); |
| 863 | } |
| 864 | |
| 865 | Return<void> GnssGeofenceCallback::gnssGeofenceResumeCb(int32_t geofenceId, |
| 866 | GeofenceStatus status) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 867 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 868 | if (status != IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS) { |
| 869 | ALOGE("%s: Error in resuming Geofence: %d\n", __func__, status); |
| 870 | } |
| 871 | |
| 872 | env->CallVoidMethod(mCallbacksObj, |
| 873 | method_reportGeofenceResumeStatus, |
| 874 | geofenceId, status); |
| 875 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 876 | return Void(); |
| 877 | } |
| 878 | |
| 879 | /* |
| 880 | * GnssNavigationMessageCallback interface implements the callback methods |
| 881 | * required by the IGnssNavigationMessage interface. |
| 882 | */ |
| 883 | struct GnssNavigationMessageCallback : public IGnssNavigationMessageCallback { |
| 884 | /* |
| 885 | * Methods from ::android::hardware::gps::V1_0::IGnssNavigationMessageCallback |
| 886 | * follow. |
| 887 | */ |
| 888 | Return<void> gnssNavigationMessageCb( |
| 889 | const IGnssNavigationMessageCallback::GnssNavigationMessage& message) override; |
| 890 | }; |
| 891 | |
| 892 | Return<void> GnssNavigationMessageCallback::gnssNavigationMessageCb( |
| 893 | const IGnssNavigationMessageCallback::GnssNavigationMessage& message) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 894 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 895 | |
| 896 | size_t dataLength = message.data.size(); |
| 897 | |
| 898 | std::vector<uint8_t> navigationData = message.data; |
| 899 | uint8_t* data = &(navigationData[0]); |
WyattRiley | 840c0b2 | 2018-10-31 09:03:53 -0700 | [diff] [blame] | 900 | if (dataLength == 0 || data == nullptr) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 901 | ALOGE("Invalid Navigation Message found: data=%p, length=%zd", data, |
| 902 | dataLength); |
| 903 | return Void(); |
| 904 | } |
| 905 | |
| 906 | JavaObject object(env, "android/location/GnssNavigationMessage"); |
| 907 | SET(Type, static_cast<int32_t>(message.type)); |
| 908 | SET(Svid, static_cast<int32_t>(message.svid)); |
| 909 | SET(MessageId, static_cast<int32_t>(message.messageId)); |
| 910 | SET(SubmessageId, static_cast<int32_t>(message.submessageId)); |
| 911 | object.callSetter("setData", data, dataLength); |
| 912 | SET(Status, static_cast<int32_t>(message.status)); |
| 913 | |
| 914 | jobject navigationMessage = object.get(); |
| 915 | env->CallVoidMethod(mCallbacksObj, |
| 916 | method_reportNavigationMessages, |
| 917 | navigationMessage); |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 918 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 919 | env->DeleteLocalRef(navigationMessage); |
| 920 | return Void(); |
| 921 | } |
| 922 | |
| 923 | /* |
| 924 | * GnssMeasurementCallback implements the callback methods required for the |
| 925 | * GnssMeasurement interface. |
| 926 | */ |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 927 | struct GnssMeasurementCallback : public IGnssMeasurementCallback_V2_0 { |
| 928 | Return<void> gnssMeasurementCb_2_0(const IGnssMeasurementCallback_V2_0::GnssData& data) |
| 929 | override; |
Wyatt Riley | 46ac956 | 2018-03-02 20:16:58 -0800 | [diff] [blame] | 930 | Return<void> gnssMeasurementCb(const IGnssMeasurementCallback_V1_1::GnssData& data) override; |
Wyatt Riley | bb9bc84 | 2018-02-14 08:46:00 -0800 | [diff] [blame] | 931 | Return<void> GnssMeasurementCb(const IGnssMeasurementCallback_V1_0::GnssData& data) override; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 932 | private: |
Yu-Han Yang | a397acd | 2018-12-07 10:59:48 -0800 | [diff] [blame] | 933 | template<class T> |
| 934 | void translateSingleGnssMeasurement(const T* measurement, JavaObject& object); |
| 935 | |
| 936 | template<class T> |
| 937 | jobjectArray translateAllGnssMeasurements(JNIEnv* env, const T* measurements, size_t count); |
| 938 | |
| 939 | template<class T> |
| 940 | void translateAndSetGnssData(const T& data); |
| 941 | |
| 942 | template<class T> |
| 943 | size_t getMeasurementCount(const T& data); |
| 944 | |
Wyatt Riley | bb9bc84 | 2018-02-14 08:46:00 -0800 | [diff] [blame] | 945 | jobject translateGnssClock( |
Wyatt Riley | 46ac956 | 2018-03-02 20:16:58 -0800 | [diff] [blame] | 946 | JNIEnv* env, const IGnssMeasurementCallback_V1_0::GnssClock* clock); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 947 | void setMeasurementData(JNIEnv* env, jobject clock, jobjectArray measurementArray); |
| 948 | }; |
| 949 | |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 950 | Return<void> GnssMeasurementCallback::gnssMeasurementCb_2_0( |
| 951 | const IGnssMeasurementCallback_V2_0::GnssData& data) { |
Yu-Han Yang | 3fbf6e5 | 2018-12-11 12:58:13 -0800 | [diff] [blame] | 952 | translateAndSetGnssData(data); |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 953 | return Void(); |
| 954 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 955 | |
Wyatt Riley | bb9bc84 | 2018-02-14 08:46:00 -0800 | [diff] [blame] | 956 | Return<void> GnssMeasurementCallback::gnssMeasurementCb( |
Wyatt Riley | 46ac956 | 2018-03-02 20:16:58 -0800 | [diff] [blame] | 957 | const IGnssMeasurementCallback_V1_1::GnssData& data) { |
Yu-Han Yang | a397acd | 2018-12-07 10:59:48 -0800 | [diff] [blame] | 958 | translateAndSetGnssData(data); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 959 | return Void(); |
| 960 | } |
| 961 | |
Wyatt Riley | bb9bc84 | 2018-02-14 08:46:00 -0800 | [diff] [blame] | 962 | Return<void> GnssMeasurementCallback::GnssMeasurementCb( |
| 963 | const IGnssMeasurementCallback_V1_0::GnssData& data) { |
Yu-Han Yang | a397acd | 2018-12-07 10:59:48 -0800 | [diff] [blame] | 964 | translateAndSetGnssData(data); |
| 965 | return Void(); |
| 966 | } |
| 967 | |
| 968 | template<class T> |
| 969 | void GnssMeasurementCallback::translateAndSetGnssData(const T& data) { |
Wyatt Riley | bb9bc84 | 2018-02-14 08:46:00 -0800 | [diff] [blame] | 970 | JNIEnv* env = getJniEnv(); |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 971 | |
Wyatt Riley | bb9bc84 | 2018-02-14 08:46:00 -0800 | [diff] [blame] | 972 | jobject clock; |
| 973 | jobjectArray measurementArray; |
| 974 | |
| 975 | clock = translateGnssClock(env, &data.clock); |
Yu-Han Yang | a397acd | 2018-12-07 10:59:48 -0800 | [diff] [blame] | 976 | size_t count = getMeasurementCount(data); |
| 977 | measurementArray = translateAllGnssMeasurements(env, data.measurements.data(), count); |
Wyatt Riley | bb9bc84 | 2018-02-14 08:46:00 -0800 | [diff] [blame] | 978 | setMeasurementData(env, clock, measurementArray); |
| 979 | |
| 980 | env->DeleteLocalRef(clock); |
| 981 | env->DeleteLocalRef(measurementArray); |
Wyatt Riley | bb9bc84 | 2018-02-14 08:46:00 -0800 | [diff] [blame] | 982 | } |
| 983 | |
Yu-Han Yang | a397acd | 2018-12-07 10:59:48 -0800 | [diff] [blame] | 984 | template<> |
| 985 | size_t GnssMeasurementCallback::getMeasurementCount<IGnssMeasurementCallback_V1_0::GnssData> |
| 986 | (const IGnssMeasurementCallback_V1_0::GnssData& data) { |
| 987 | return data.measurementCount; |
| 988 | } |
| 989 | |
Yu-Han Yang | 3fbf6e5 | 2018-12-11 12:58:13 -0800 | [diff] [blame] | 990 | template<class T> |
| 991 | size_t GnssMeasurementCallback::getMeasurementCount(const T& data) { |
Yu-Han Yang | a397acd | 2018-12-07 10:59:48 -0800 | [diff] [blame] | 992 | return data.measurements.size(); |
| 993 | } |
| 994 | |
| 995 | // Preallocate object as: JavaObject object(env, "android/location/GnssMeasurement"); |
| 996 | template<> |
| 997 | void GnssMeasurementCallback::translateSingleGnssMeasurement |
| 998 | <IGnssMeasurementCallback_V1_0::GnssMeasurement>( |
WyattRiley | 840c0b2 | 2018-10-31 09:03:53 -0700 | [diff] [blame] | 999 | const IGnssMeasurementCallback_V1_0::GnssMeasurement* measurement, |
Wyatt Riley | 46ac956 | 2018-03-02 20:16:58 -0800 | [diff] [blame] | 1000 | JavaObject& object) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1001 | uint32_t flags = static_cast<uint32_t>(measurement->flags); |
Mike Cailean | 96635bd | 2016-03-24 19:34:16 -0700 | [diff] [blame] | 1002 | |
| 1003 | SET(Svid, static_cast<int32_t>(measurement->svid)); |
Lifu Tang | 76a620f | 2016-02-26 19:53:01 -0800 | [diff] [blame] | 1004 | SET(ConstellationType, static_cast<int32_t>(measurement->constellation)); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1005 | SET(TimeOffsetNanos, measurement->timeOffsetNs); |
Lifu Tang | 76a620f | 2016-02-26 19:53:01 -0800 | [diff] [blame] | 1006 | SET(State, static_cast<int32_t>(measurement->state)); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1007 | SET(ReceivedSvTimeNanos, measurement->receivedSvTimeInNs); |
Lifu Tang | 76a620f | 2016-02-26 19:53:01 -0800 | [diff] [blame] | 1008 | SET(ReceivedSvTimeUncertaintyNanos, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1009 | measurement->receivedSvTimeUncertaintyInNs); |
| 1010 | SET(Cn0DbHz, measurement->cN0DbHz); |
| 1011 | SET(PseudorangeRateMetersPerSecond, measurement->pseudorangeRateMps); |
Lifu Tang | 76a620f | 2016-02-26 19:53:01 -0800 | [diff] [blame] | 1012 | SET(PseudorangeRateUncertaintyMetersPerSecond, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1013 | measurement->pseudorangeRateUncertaintyMps); |
Lifu Tang | 76a620f | 2016-02-26 19:53:01 -0800 | [diff] [blame] | 1014 | SET(AccumulatedDeltaRangeState, |
Wyatt Riley | 4cbcb41 | 2018-01-23 18:07:05 -0800 | [diff] [blame] | 1015 | (static_cast<int32_t>(measurement->accumulatedDeltaRangeState) & |
WyattRiley | 948dd6d | 2018-10-31 06:56:09 -0700 | [diff] [blame] | 1016 | ~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] | 1017 | SET(AccumulatedDeltaRangeMeters, measurement->accumulatedDeltaRangeM); |
Lifu Tang | 76a620f | 2016-02-26 19:53:01 -0800 | [diff] [blame] | 1018 | SET(AccumulatedDeltaRangeUncertaintyMeters, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1019 | measurement->accumulatedDeltaRangeUncertaintyM); |
| 1020 | |
| 1021 | if (flags & static_cast<uint32_t>(GnssMeasurementFlags::HAS_CARRIER_FREQUENCY)) { |
| 1022 | SET(CarrierFrequencyHz, measurement->carrierFrequencyHz); |
| 1023 | } |
| 1024 | |
Wyatt Riley | bb9bc84 | 2018-02-14 08:46:00 -0800 | [diff] [blame] | 1025 | // Intentionally not copying deprecated fields of carrierCycles, |
| 1026 | // carrierPhase, carrierPhaseUncertainty |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1027 | |
| 1028 | SET(MultipathIndicator, static_cast<int32_t>(measurement->multipathIndicator)); |
| 1029 | |
| 1030 | if (flags & static_cast<uint32_t>(GnssMeasurementFlags::HAS_SNR)) { |
| 1031 | SET(SnrInDb, measurement->snrDb); |
| 1032 | } |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 1033 | |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 1034 | if (flags & static_cast<uint32_t>(GnssMeasurementFlags::HAS_AUTOMATIC_GAIN_CONTROL)) { |
gomo | 127ba32 | 2017-01-15 20:26:48 -0800 | [diff] [blame] | 1035 | SET(AutomaticGainControlLevelInDb, measurement->agcLevelDb); |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 1036 | } |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 1037 | } |
| 1038 | |
Yu-Han Yang | a397acd | 2018-12-07 10:59:48 -0800 | [diff] [blame] | 1039 | // Preallocate object as: JavaObject object(env, "android/location/GnssMeasurement"); |
| 1040 | template<> |
| 1041 | void GnssMeasurementCallback::translateSingleGnssMeasurement |
| 1042 | <IGnssMeasurementCallback_V1_1::GnssMeasurement>( |
| 1043 | const IGnssMeasurementCallback_V1_1::GnssMeasurement* measurement_V1_1, |
| 1044 | JavaObject& object) { |
| 1045 | translateSingleGnssMeasurement(&(measurement_V1_1->v1_0), object); |
| 1046 | |
| 1047 | // Set the V1_1 flag, and mark that new field has valid information for Java Layer |
| 1048 | SET(AccumulatedDeltaRangeState, |
| 1049 | (static_cast<int32_t>(measurement_V1_1->accumulatedDeltaRangeState) | |
| 1050 | ADR_STATE_HALF_CYCLE_REPORTED)); |
| 1051 | } |
| 1052 | |
Yu-Han Yang | 3fbf6e5 | 2018-12-11 12:58:13 -0800 | [diff] [blame] | 1053 | // Preallocate object as: JavaObject object(env, "android/location/GnssMeasurement"); |
| 1054 | template<> |
| 1055 | void GnssMeasurementCallback::translateSingleGnssMeasurement |
| 1056 | <IGnssMeasurementCallback_V2_0::GnssMeasurement>( |
| 1057 | const IGnssMeasurementCallback_V2_0::GnssMeasurement* measurement_V2_0, |
| 1058 | JavaObject& object) { |
| 1059 | translateSingleGnssMeasurement(&(measurement_V2_0->v1_1), object); |
| 1060 | |
Yu-Han Yang | 786a2bd | 2019-02-01 19:52:28 -0800 | [diff] [blame] | 1061 | SET(CodeType, static_cast<int32_t>(measurement_V2_0->codeType)); |
| 1062 | |
| 1063 | // Overwrite with v2_0.state since v2_0->v1_1->v1_0.state is deprecated. |
| 1064 | SET(State, static_cast<int32_t>(measurement_V2_0->state)); |
Yu-Han Yang | 3fbf6e5 | 2018-12-11 12:58:13 -0800 | [diff] [blame] | 1065 | } |
| 1066 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1067 | jobject GnssMeasurementCallback::translateGnssClock( |
Wyatt Riley | 46ac956 | 2018-03-02 20:16:58 -0800 | [diff] [blame] | 1068 | JNIEnv* env, const IGnssMeasurementCallback_V1_0::GnssClock* clock) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1069 | JavaObject object(env, "android/location/GnssClock"); |
| 1070 | |
| 1071 | uint32_t flags = static_cast<uint32_t>(clock->gnssClockFlags); |
| 1072 | if (flags & static_cast<uint32_t>(GnssClockFlags::HAS_LEAP_SECOND)) { |
| 1073 | SET(LeapSecond, static_cast<int32_t>(clock->leapSecond)); |
| 1074 | } |
| 1075 | |
| 1076 | if (flags & static_cast<uint32_t>(GnssClockFlags::HAS_TIME_UNCERTAINTY)) { |
| 1077 | SET(TimeUncertaintyNanos, clock->timeUncertaintyNs); |
| 1078 | } |
| 1079 | |
| 1080 | if (flags & static_cast<uint32_t>(GnssClockFlags::HAS_FULL_BIAS)) { |
| 1081 | SET(FullBiasNanos, clock->fullBiasNs); |
| 1082 | } |
| 1083 | |
| 1084 | if (flags & static_cast<uint32_t>(GnssClockFlags::HAS_BIAS)) { |
| 1085 | SET(BiasNanos, clock->biasNs); |
| 1086 | } |
| 1087 | |
| 1088 | if (flags & static_cast<uint32_t>(GnssClockFlags::HAS_BIAS_UNCERTAINTY)) { |
| 1089 | SET(BiasUncertaintyNanos, clock->biasUncertaintyNs); |
| 1090 | } |
| 1091 | |
| 1092 | if (flags & static_cast<uint32_t>(GnssClockFlags::HAS_DRIFT)) { |
| 1093 | SET(DriftNanosPerSecond, clock->driftNsps); |
| 1094 | } |
| 1095 | |
| 1096 | if (flags & static_cast<uint32_t>(GnssClockFlags::HAS_DRIFT_UNCERTAINTY)) { |
| 1097 | SET(DriftUncertaintyNanosPerSecond, clock->driftUncertaintyNsps); |
| 1098 | } |
| 1099 | |
| 1100 | SET(TimeNanos, clock->timeNs); |
| 1101 | SET(HardwareClockDiscontinuityCount, clock->hwClockDiscontinuityCount); |
| 1102 | |
| 1103 | return object.get(); |
| 1104 | } |
| 1105 | |
Yu-Han Yang | a397acd | 2018-12-07 10:59:48 -0800 | [diff] [blame] | 1106 | template<class T> |
| 1107 | jobjectArray GnssMeasurementCallback::translateAllGnssMeasurements(JNIEnv* env, |
| 1108 | const T* measurements, |
| 1109 | size_t count) { |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 1110 | if (count == 0) { |
WyattRiley | 840c0b2 | 2018-10-31 09:03:53 -0700 | [diff] [blame] | 1111 | return nullptr; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1114 | jclass gnssMeasurementClass = env->FindClass("android/location/GnssMeasurement"); |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 1115 | jobjectArray gnssMeasurementArray = env->NewObjectArray( |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 1116 | count, |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 1117 | gnssMeasurementClass, |
WyattRiley | 840c0b2 | 2018-10-31 09:03:53 -0700 | [diff] [blame] | 1118 | nullptr /* initialElement */); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1119 | |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 1120 | for (uint16_t i = 0; i < count; ++i) { |
Wyatt Riley | bb9bc84 | 2018-02-14 08:46:00 -0800 | [diff] [blame] | 1121 | JavaObject object(env, "android/location/GnssMeasurement"); |
Yu-Han Yang | a397acd | 2018-12-07 10:59:48 -0800 | [diff] [blame] | 1122 | translateSingleGnssMeasurement(&(measurements[i]), object); |
Wyatt Riley | bb9bc84 | 2018-02-14 08:46:00 -0800 | [diff] [blame] | 1123 | env->SetObjectArrayElement(gnssMeasurementArray, i, object.get()); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 1126 | env->DeleteLocalRef(gnssMeasurementClass); |
| 1127 | return gnssMeasurementArray; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1128 | } |
| 1129 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1130 | void GnssMeasurementCallback::setMeasurementData(JNIEnv* env, jobject clock, |
| 1131 | jobjectArray measurementArray) { |
| 1132 | jclass gnssMeasurementsEventClass = |
| 1133 | env->FindClass("android/location/GnssMeasurementsEvent"); |
| 1134 | jmethodID gnssMeasurementsEventCtor = |
| 1135 | env->GetMethodID( |
| 1136 | gnssMeasurementsEventClass, |
| 1137 | "<init>", |
| 1138 | "(Landroid/location/GnssClock;[Landroid/location/GnssMeasurement;)V"); |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 1139 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1140 | jobject gnssMeasurementsEvent = env->NewObject(gnssMeasurementsEventClass, |
| 1141 | gnssMeasurementsEventCtor, |
| 1142 | clock, |
| 1143 | measurementArray); |
Lifu Tang | 120480f | 2016-02-07 18:08:19 -0800 | [diff] [blame] | 1144 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1145 | env->CallVoidMethod(mCallbacksObj, method_reportMeasurementData, |
| 1146 | gnssMeasurementsEvent); |
Lifu Tang | e5a0e21 | 2016-01-25 18:02:17 -0800 | [diff] [blame] | 1147 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
Lifu Tang | 818aa2c | 2016-02-01 01:52:00 -0800 | [diff] [blame] | 1148 | env->DeleteLocalRef(gnssMeasurementsEventClass); |
| 1149 | env->DeleteLocalRef(gnssMeasurementsEvent); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1152 | /* |
| 1153 | * GnssNiCallback implements callback methods required by the IGnssNi interface. |
| 1154 | */ |
| 1155 | struct GnssNiCallback : public IGnssNiCallback { |
| 1156 | Return<void> niNotifyCb(const IGnssNiCallback::GnssNiNotification& notification) |
| 1157 | override; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 1158 | }; |
| 1159 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1160 | Return<void> GnssNiCallback::niNotifyCb( |
| 1161 | const IGnssNiCallback::GnssNiNotification& notification) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 1162 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1163 | jstring requestorId = env->NewStringUTF(notification.requestorId.c_str()); |
| 1164 | jstring text = env->NewStringUTF(notification.notificationMessage.c_str()); |
| 1165 | |
| 1166 | if (requestorId && text) { |
| 1167 | env->CallVoidMethod(mCallbacksObj, method_reportNiNotification, |
| 1168 | notification.notificationId, notification.niType, |
| 1169 | notification.notifyFlags, notification.timeoutSec, |
| 1170 | notification.defaultResponse, requestorId, text, |
| 1171 | notification.requestorIdEncoding, |
| 1172 | notification.notificationIdEncoding); |
| 1173 | } else { |
| 1174 | ALOGE("%s: OOM Error\n", __func__); |
| 1175 | } |
| 1176 | |
| 1177 | if (requestorId) { |
| 1178 | env->DeleteLocalRef(requestorId); |
| 1179 | } |
| 1180 | |
| 1181 | if (text) { |
| 1182 | env->DeleteLocalRef(text); |
| 1183 | } |
| 1184 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 1185 | return Void(); |
| 1186 | } |
| 1187 | |
| 1188 | /* |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 1189 | * GnssVisibilityControlCallback implements callback methods of IGnssVisibilityControlCallback.hal. |
| 1190 | */ |
| 1191 | struct GnssVisibilityControlCallback : public IGnssVisibilityControlCallback { |
| 1192 | Return<void> nfwNotifyCb(const IGnssVisibilityControlCallback::NfwNotification& notification) |
| 1193 | override; |
| 1194 | Return<bool> isInEmergencySession() override; |
| 1195 | }; |
| 1196 | |
| 1197 | Return<void> GnssVisibilityControlCallback::nfwNotifyCb( |
| 1198 | const IGnssVisibilityControlCallback::NfwNotification& notification) { |
| 1199 | JNIEnv* env = getJniEnv(); |
| 1200 | jstring proxyAppPackageName = env->NewStringUTF(notification.proxyAppPackageName.c_str()); |
| 1201 | jstring otherProtocolStackName = env->NewStringUTF(notification.otherProtocolStackName.c_str()); |
| 1202 | jstring requestorId = env->NewStringUTF(notification.requestorId.c_str()); |
| 1203 | |
| 1204 | if (proxyAppPackageName && otherProtocolStackName && requestorId) { |
| 1205 | env->CallVoidMethod(mCallbacksObj, method_reportNfwNotification, proxyAppPackageName, |
| 1206 | notification.protocolStack, otherProtocolStackName, |
| 1207 | notification.requestor, requestorId, |
| 1208 | notification.inEmergencyMode, notification.isCachedLocation); |
| 1209 | } else { |
| 1210 | ALOGE("%s: OOM Error\n", __func__); |
| 1211 | } |
| 1212 | |
| 1213 | if (requestorId) { |
| 1214 | env->DeleteLocalRef(requestorId); |
| 1215 | } |
| 1216 | |
| 1217 | if (otherProtocolStackName) { |
| 1218 | env->DeleteLocalRef(otherProtocolStackName); |
| 1219 | } |
| 1220 | |
| 1221 | if (proxyAppPackageName) { |
| 1222 | env->DeleteLocalRef(proxyAppPackageName); |
| 1223 | } |
| 1224 | |
| 1225 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 1226 | return Void(); |
| 1227 | } |
| 1228 | |
| 1229 | Return<bool> GnssVisibilityControlCallback::isInEmergencySession() { |
| 1230 | JNIEnv* env = getJniEnv(); |
| 1231 | auto result = env->CallBooleanMethod(mCallbacksObj, method_isInEmergencySession); |
| 1232 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 1233 | return result; |
| 1234 | } |
| 1235 | |
| 1236 | /* |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 1237 | * AGnssCallback_V1_0 implements callback methods required by the IAGnssCallback 1.0 interface. |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1238 | */ |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 1239 | struct AGnssCallback_V1_0 : public IAGnssCallback_V1_0 { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1240 | // Methods from ::android::hardware::gps::V1_0::IAGnssCallback follow. |
| 1241 | Return<void> agnssStatusIpV6Cb( |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 1242 | const IAGnssCallback_V1_0::AGnssStatusIpV6& agps_status) override; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1243 | |
| 1244 | Return<void> agnssStatusIpV4Cb( |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 1245 | const IAGnssCallback_V1_0::AGnssStatusIpV4& agps_status) override; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1246 | private: |
| 1247 | jbyteArray convertToIpV4(uint32_t ip); |
| 1248 | }; |
| 1249 | |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 1250 | Return<void> AGnssCallback_V1_0::agnssStatusIpV6Cb( |
| 1251 | const IAGnssCallback_V1_0::AGnssStatusIpV6& agps_status) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 1252 | JNIEnv* env = getJniEnv(); |
WyattRiley | 840c0b2 | 2018-10-31 09:03:53 -0700 | [diff] [blame] | 1253 | jbyteArray byteArray = nullptr; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1254 | |
| 1255 | byteArray = env->NewByteArray(16); |
WyattRiley | 840c0b2 | 2018-10-31 09:03:53 -0700 | [diff] [blame] | 1256 | if (byteArray != nullptr) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1257 | env->SetByteArrayRegion(byteArray, 0, 16, |
| 1258 | (const jbyte*)(agps_status.ipV6Addr.data())); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1259 | } else { |
| 1260 | ALOGE("Unable to allocate byte array for IPv6 address."); |
| 1261 | } |
| 1262 | |
| 1263 | IF_ALOGD() { |
| 1264 | // log the IP for reference in case there is a bogus value pushed by HAL |
| 1265 | char str[INET6_ADDRSTRLEN]; |
| 1266 | inet_ntop(AF_INET6, agps_status.ipV6Addr.data(), str, INET6_ADDRSTRLEN); |
| 1267 | ALOGD("AGPS IP is v6: %s", str); |
| 1268 | } |
| 1269 | |
WyattRiley | 840c0b2 | 2018-10-31 09:03:53 -0700 | [diff] [blame] | 1270 | jsize byteArrayLength = byteArray != nullptr ? env->GetArrayLength(byteArray) : 0; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1271 | ALOGV("Passing AGPS IP addr: size %d", byteArrayLength); |
| 1272 | env->CallVoidMethod(mCallbacksObj, method_reportAGpsStatus, |
| 1273 | agps_status.type, agps_status.status, byteArray); |
| 1274 | |
| 1275 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 1276 | |
| 1277 | if (byteArray) { |
| 1278 | env->DeleteLocalRef(byteArray); |
| 1279 | } |
| 1280 | |
| 1281 | return Void(); |
| 1282 | } |
| 1283 | |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 1284 | Return<void> AGnssCallback_V1_0::agnssStatusIpV4Cb( |
| 1285 | const IAGnssCallback_V1_0::AGnssStatusIpV4& agps_status) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 1286 | JNIEnv* env = getJniEnv(); |
WyattRiley | 840c0b2 | 2018-10-31 09:03:53 -0700 | [diff] [blame] | 1287 | jbyteArray byteArray = nullptr; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1288 | |
| 1289 | uint32_t ipAddr = agps_status.ipV4Addr; |
| 1290 | byteArray = convertToIpV4(ipAddr); |
| 1291 | |
| 1292 | IF_ALOGD() { |
| 1293 | /* |
| 1294 | * log the IP for reference in case there is a bogus value pushed by |
| 1295 | * HAL. |
| 1296 | */ |
| 1297 | char str[INET_ADDRSTRLEN]; |
| 1298 | inet_ntop(AF_INET, &ipAddr, str, INET_ADDRSTRLEN); |
| 1299 | ALOGD("AGPS IP is v4: %s", str); |
| 1300 | } |
| 1301 | |
| 1302 | jsize byteArrayLength = |
WyattRiley | 840c0b2 | 2018-10-31 09:03:53 -0700 | [diff] [blame] | 1303 | byteArray != nullptr ? env->GetArrayLength(byteArray) : 0; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1304 | ALOGV("Passing AGPS IP addr: size %d", byteArrayLength); |
| 1305 | env->CallVoidMethod(mCallbacksObj, method_reportAGpsStatus, |
| 1306 | agps_status.type, agps_status.status, byteArray); |
| 1307 | |
| 1308 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 1309 | |
| 1310 | if (byteArray) { |
| 1311 | env->DeleteLocalRef(byteArray); |
| 1312 | } |
| 1313 | return Void(); |
| 1314 | } |
| 1315 | |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 1316 | jbyteArray AGnssCallback_V1_0::convertToIpV4(uint32_t ip) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1317 | if (INADDR_NONE == ip) { |
WyattRiley | 840c0b2 | 2018-10-31 09:03:53 -0700 | [diff] [blame] | 1318 | return nullptr; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1319 | } |
| 1320 | |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 1321 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1322 | jbyteArray byteArray = env->NewByteArray(4); |
WyattRiley | 840c0b2 | 2018-10-31 09:03:53 -0700 | [diff] [blame] | 1323 | if (byteArray == nullptr) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1324 | ALOGE("Unable to allocate byte array for IPv4 address"); |
WyattRiley | 840c0b2 | 2018-10-31 09:03:53 -0700 | [diff] [blame] | 1325 | return nullptr; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | jbyte ipv4[4]; |
| 1329 | ALOGV("Converting IPv4 address byte array (net_order) %x", ip); |
| 1330 | memcpy(ipv4, &ip, sizeof(ipv4)); |
| 1331 | env->SetByteArrayRegion(byteArray, 0, 4, (const jbyte*)ipv4); |
| 1332 | return byteArray; |
| 1333 | } |
| 1334 | |
| 1335 | /* |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 1336 | * AGnssCallback_V2_0 implements callback methods required by the IAGnssCallback 2.0 interface. |
| 1337 | */ |
| 1338 | struct AGnssCallback_V2_0 : public IAGnssCallback_V2_0 { |
| 1339 | // Methods from ::android::hardware::gps::V2_0::IAGnssCallback follow. |
| 1340 | Return<void> agnssStatusCb(IAGnssCallback_V2_0::AGnssType type, |
| 1341 | IAGnssCallback_V2_0::AGnssStatusValue status) override; |
| 1342 | }; |
| 1343 | |
| 1344 | Return<void> AGnssCallback_V2_0::agnssStatusCb(IAGnssCallback_V2_0::AGnssType type, |
| 1345 | IAGnssCallback_V2_0::AGnssStatusValue status) { |
| 1346 | JNIEnv* env = getJniEnv(); |
| 1347 | env->CallVoidMethod(mCallbacksObj, method_reportAGpsStatus, type, status, nullptr); |
| 1348 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 1349 | return Void(); |
| 1350 | } |
| 1351 | |
| 1352 | /* |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1353 | * AGnssRilCallback implements the callback methods required by the AGnssRil |
| 1354 | * interface. |
| 1355 | */ |
| 1356 | struct AGnssRilCallback : IAGnssRilCallback { |
Hridya Valsaraju | b39eb40 | 2017-01-11 08:07:40 -0800 | [diff] [blame] | 1357 | Return<void> requestSetIdCb(uint32_t setIdFlag) override; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1358 | Return<void> requestRefLocCb() override; |
| 1359 | }; |
| 1360 | |
Hridya Valsaraju | b39eb40 | 2017-01-11 08:07:40 -0800 | [diff] [blame] | 1361 | Return<void> AGnssRilCallback::requestSetIdCb(uint32_t setIdFlag) { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 1362 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1363 | env->CallVoidMethod(mCallbacksObj, method_requestSetID, setIdFlag); |
| 1364 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 1365 | return Void(); |
| 1366 | } |
| 1367 | |
| 1368 | Return<void> AGnssRilCallback::requestRefLocCb() { |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 1369 | JNIEnv* env = getJniEnv(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1370 | env->CallVoidMethod(mCallbacksObj, method_requestRefLocation); |
| 1371 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 1372 | return Void(); |
| 1373 | } |
| 1374 | |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1375 | /* |
| 1376 | * GnssBatchingCallback interface implements the callback methods |
| 1377 | * required by the IGnssBatching interface. |
| 1378 | */ |
| 1379 | struct GnssBatchingCallback : public IGnssBatchingCallback { |
| 1380 | /* |
| 1381 | * Methods from ::android::hardware::gps::V1_0::IGnssBatchingCallback |
| 1382 | * follow. |
| 1383 | */ |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 1384 | Return<void> gnssLocationBatchCb(const hidl_vec<GnssLocation_V1_0>& locations) override; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1385 | }; |
| 1386 | |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 1387 | Return<void> GnssBatchingCallback::gnssLocationBatchCb( |
| 1388 | const hidl_vec<GnssLocation_V1_0>& locations) { |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1389 | JNIEnv* env = getJniEnv(); |
| 1390 | |
| 1391 | jobjectArray jLocations = env->NewObjectArray(locations.size(), |
| 1392 | env->FindClass("android/location/Location"), nullptr); |
| 1393 | |
| 1394 | for (uint16_t i = 0; i < locations.size(); ++i) { |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 1395 | jobject jLocation = translateGnssLocation(env, locations[i]); |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1396 | env->SetObjectArrayElement(jLocations, i, jLocation); |
| 1397 | env->DeleteLocalRef(jLocation); |
| 1398 | } |
| 1399 | |
| 1400 | env->CallVoidMethod(mCallbacksObj, method_reportLocationBatch, jLocations); |
| 1401 | checkAndClearExceptionFromCallback(env, __FUNCTION__); |
| 1402 | |
| 1403 | env->DeleteLocalRef(jLocations); |
| 1404 | |
| 1405 | return Void(); |
| 1406 | } |
| 1407 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1408 | static void android_location_GnssLocationProvider_class_init_native(JNIEnv* env, jclass clazz) { |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 1409 | gnssHal_V2_0 = IGnss_V2_0::getService(); |
| 1410 | if (gnssHal_V2_0 != nullptr) { |
| 1411 | gnssHal = gnssHal_V2_0; |
| 1412 | gnssHal_V1_1 = gnssHal_V2_0; |
| 1413 | return; |
Yu-Han Yang | 6d31735 | 2018-03-15 11:53:01 -0700 | [diff] [blame] | 1414 | } |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 1415 | |
| 1416 | ALOGD("gnssHal 2.0 was null, trying 1.1"); |
| 1417 | gnssHal_V1_1 = IGnss_V1_1::getService(); |
| 1418 | if (gnssHal_V1_1 != nullptr) { |
| 1419 | gnssHal = gnssHal_V1_1; |
| 1420 | return; |
| 1421 | } |
| 1422 | |
| 1423 | ALOGD("gnssHal 1.1 was null, trying 1.0"); |
| 1424 | gnssHal = IGnss_V1_0::getService(); |
Yu-Han Yang | 6d31735 | 2018-03-15 11:53:01 -0700 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | static void android_location_GnssLocationProvider_init_once(JNIEnv* env, jclass clazz) { |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1428 | method_reportLocation = env->GetMethodID(clazz, "reportLocation", |
| 1429 | "(ZLandroid/location/Location;)V"); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1430 | method_reportStatus = env->GetMethodID(clazz, "reportStatus", "(I)V"); |
Wyatt Riley | 26465d2 | 2018-02-12 13:44:24 -0800 | [diff] [blame] | 1431 | 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] | 1432 | method_reportAGpsStatus = env->GetMethodID(clazz, "reportAGpsStatus", "(II[B)V"); |
| 1433 | method_reportNmea = env->GetMethodID(clazz, "reportNmea", "(J)V"); |
| 1434 | method_setEngineCapabilities = env->GetMethodID(clazz, "setEngineCapabilities", "(I)V"); |
| 1435 | method_setGnssYearOfHardware = env->GetMethodID(clazz, "setGnssYearOfHardware", "(I)V"); |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1436 | method_setGnssHardwareModelName = env->GetMethodID(clazz, "setGnssHardwareModelName", |
| 1437 | "(Ljava/lang/String;)V"); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1438 | method_xtraDownloadRequest = env->GetMethodID(clazz, "xtraDownloadRequest", "()V"); |
| 1439 | method_reportNiNotification = env->GetMethodID(clazz, "reportNiNotification", |
| 1440 | "(IIIIILjava/lang/String;Ljava/lang/String;II)V"); |
Yu-Han Yang | 53f4d6d | 2019-02-13 21:47:41 -0800 | [diff] [blame] | 1441 | method_requestLocation = env->GetMethodID(clazz, "requestLocation", "(ZZ)V"); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1442 | method_requestRefLocation = env->GetMethodID(clazz, "requestRefLocation", "()V"); |
| 1443 | method_requestSetID = env->GetMethodID(clazz, "requestSetID", "(I)V"); |
| 1444 | method_requestUtcTime = env->GetMethodID(clazz, "requestUtcTime", "()V"); |
| 1445 | method_reportGeofenceTransition = env->GetMethodID(clazz, "reportGeofenceTransition", |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1446 | "(ILandroid/location/Location;IJ)V"); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1447 | method_reportGeofenceStatus = env->GetMethodID(clazz, "reportGeofenceStatus", |
Wyatt Riley | 5d22983 | 2017-02-10 17:06:00 -0800 | [diff] [blame] | 1448 | "(ILandroid/location/Location;)V"); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1449 | method_reportGeofenceAddStatus = env->GetMethodID(clazz, "reportGeofenceAddStatus", |
| 1450 | "(II)V"); |
| 1451 | method_reportGeofenceRemoveStatus = env->GetMethodID(clazz, "reportGeofenceRemoveStatus", |
| 1452 | "(II)V"); |
| 1453 | method_reportGeofenceResumeStatus = env->GetMethodID(clazz, "reportGeofenceResumeStatus", |
| 1454 | "(II)V"); |
| 1455 | method_reportGeofencePauseStatus = env->GetMethodID(clazz, "reportGeofencePauseStatus", |
| 1456 | "(II)V"); |
| 1457 | method_reportMeasurementData = env->GetMethodID( |
| 1458 | clazz, |
| 1459 | "reportMeasurementData", |
| 1460 | "(Landroid/location/GnssMeasurementsEvent;)V"); |
| 1461 | method_reportNavigationMessages = env->GetMethodID( |
| 1462 | clazz, |
| 1463 | "reportNavigationMessage", |
| 1464 | "(Landroid/location/GnssNavigationMessage;)V"); |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1465 | method_reportLocationBatch = env->GetMethodID( |
| 1466 | clazz, |
| 1467 | "reportLocationBatch", |
| 1468 | "([Landroid/location/Location;)V"); |
Yu-Han Yang | 5205762 | 2018-04-25 00:51:22 -0700 | [diff] [blame] | 1469 | method_reportGnssServiceDied = env->GetMethodID(clazz, "reportGnssServiceDied", "()V"); |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 1470 | method_reportNfwNotification = env->GetMethodID(clazz, "reportNfwNotification", |
| 1471 | "(Ljava/lang/String;BLjava/lang/String;BLjava/lang/String;BZZ)V"); |
| 1472 | method_isInEmergencySession = env->GetMethodID(clazz, "isInEmergencySession", "()Z"); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1473 | |
gomo | 5716ab8 | 2019-02-27 22:57:56 -0800 | [diff] [blame] | 1474 | jclass measCorrClass = env->FindClass("android/location/GnssMeasurementCorrections"); |
| 1475 | method_correctionsGetLatitudeDegrees = env->GetMethodID( |
| 1476 | measCorrClass,"getLatitudeDegrees", "()D"); |
| 1477 | method_correctionsGetLongitudeDegrees = env->GetMethodID( |
| 1478 | measCorrClass, "getLongitudeDegrees", "()D"); |
| 1479 | method_correctionsGetAltitudeMeters = env->GetMethodID( |
| 1480 | measCorrClass, "getAltitudeMeters", "()D"); |
| 1481 | method_correctionsGetHorPosUncMeters = env->GetMethodID( |
| 1482 | measCorrClass, "getHorizontalPositionUncertaintyMeters", "()D"); |
| 1483 | method_correctionsGetVerPosUncMeters = env->GetMethodID( |
| 1484 | measCorrClass, "getVerticalPositionUncertaintyMeters", "()D"); |
| 1485 | method_correctionsGetToaGpsNanosecondsOfWeek = env->GetMethodID( |
| 1486 | measCorrClass, "getToaGpsNanosecondsOfWeek", "()J"); |
| 1487 | |
| 1488 | method_correctionsGetSingleSatCorrectionList = env->GetMethodID( |
| 1489 | measCorrClass, "getSingleSatelliteCorrectionList", "()Ljava/util/List;"); |
| 1490 | |
| 1491 | jclass corrListClass = env->FindClass("java/util/List"); |
| 1492 | method_listSize = env->GetMethodID(corrListClass, "size", "()I"); |
| 1493 | method_correctionListGet = env->GetMethodID(corrListClass, "get", "(I)Ljava/lang/Object;"); |
| 1494 | |
| 1495 | jclass singleSatCorrClass = env->FindClass("android/location/GnssSingleSatCorrection"); |
| 1496 | method_correctionSatFlags = env->GetMethodID( |
| 1497 | singleSatCorrClass, "getSingleSatelliteCorrectionFlags", "()I"); |
| 1498 | method_correctionSatConstType = env->GetMethodID( |
| 1499 | singleSatCorrClass, "getConstellationType", "()I"); |
| 1500 | method_correctionSatId= env->GetMethodID( |
| 1501 | singleSatCorrClass, "getSatelliteId", "()I"); |
| 1502 | method_correctionSatCarrierFreq = env->GetMethodID( |
| 1503 | singleSatCorrClass, "getCarrierFrequencyHz", "()F"); |
| 1504 | method_correctionSatIsLosProb = env->GetMethodID( |
| 1505 | singleSatCorrClass,"getProbabilityLineOfSight", "()F"); |
| 1506 | method_correctionSatEpl = env->GetMethodID( |
| 1507 | singleSatCorrClass, "getExcessPathLengthMeters", "()F"); |
| 1508 | method_correctionSatEplUnc = env->GetMethodID( |
| 1509 | singleSatCorrClass, "getExcessPathLengthUncertaintyMeters", "()F"); |
| 1510 | method_correctionSatRefPlane = env->GetMethodID( |
| 1511 | singleSatCorrClass, "getReflectingPlane", "()Landroid/location/GnssReflectingPlane;"); |
| 1512 | |
| 1513 | jclass refPlaneClass = env->FindClass("android/location/GnssReflectingPlane"); |
| 1514 | method_correctionPlaneLatDeg = env->GetMethodID(refPlaneClass, "getLatitudeDegrees", "()D"); |
| 1515 | method_correctionPlaneLngDeg = env->GetMethodID(refPlaneClass, "getLongitudeDegrees", "()D"); |
| 1516 | method_correctionPlaneAltDeg = env->GetMethodID(refPlaneClass, "getAltitudeMeters", "()D"); |
| 1517 | method_correctionPlaneAzimDeg = env->GetMethodID(refPlaneClass, "getAzimuthDegrees", "()D"); |
| 1518 | |
Hridya Valsaraju | b5b6ffe | 2017-01-05 15:13:34 -0800 | [diff] [blame] | 1519 | /* |
| 1520 | * Save a pointer to JVM. |
| 1521 | */ |
| 1522 | jint jvmStatus = env->GetJavaVM(&sJvm); |
| 1523 | if (jvmStatus != JNI_OK) { |
| 1524 | LOG_ALWAYS_FATAL("Unable to get Java VM. Error: %d", jvmStatus); |
| 1525 | } |
| 1526 | |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 1527 | if (gnssHal == nullptr) { |
| 1528 | ALOGE("Unable to get GPS service\n"); |
| 1529 | return; |
| 1530 | } |
gomo | 2520888 | 2017-04-15 02:05:25 -0700 | [diff] [blame] | 1531 | |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 1532 | gnssHalDeathRecipient = new GnssDeathRecipient(); |
| 1533 | hardware::Return<bool> linked = gnssHal->linkToDeath(gnssHalDeathRecipient, /*cookie*/ 0); |
| 1534 | if (!linked.isOk()) { |
| 1535 | ALOGE("Transaction error in linking to GnssHAL death: %s", |
| 1536 | linked.description().c_str()); |
| 1537 | } else if (!linked) { |
| 1538 | ALOGW("Unable to link to GnssHal death notifications"); |
| 1539 | } else { |
| 1540 | ALOGD("Link to death notification successful"); |
| 1541 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1542 | |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 1543 | auto gnssXtra = gnssHal->getExtensionXtra(); |
| 1544 | if (!gnssXtra.isOk()) { |
| 1545 | ALOGD("Unable to get a handle to Xtra"); |
| 1546 | } else { |
| 1547 | gnssXtraIface = gnssXtra; |
| 1548 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1549 | |
Anil Admal | b4995e2 | 2018-11-16 17:36:21 -0800 | [diff] [blame] | 1550 | if (gnssHal_V2_0 != nullptr) { |
| 1551 | auto agnssRil_V2_0 = gnssHal_V2_0->getExtensionAGnssRil_2_0(); |
| 1552 | if (!agnssRil_V2_0.isOk()) { |
| 1553 | ALOGD("Unable to get a handle to AGnssRil_V2_0"); |
| 1554 | } else { |
| 1555 | agnssRilIface_V2_0 = agnssRil_V2_0; |
| 1556 | agnssRilIface = agnssRilIface_V2_0; |
| 1557 | } |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 1558 | } else { |
Anil Admal | b4995e2 | 2018-11-16 17:36:21 -0800 | [diff] [blame] | 1559 | auto agnssRil_V1_0 = gnssHal->getExtensionAGnssRil(); |
| 1560 | if (!agnssRil_V1_0.isOk()) { |
| 1561 | ALOGD("Unable to get a handle to AGnssRil"); |
| 1562 | } else { |
| 1563 | agnssRilIface = agnssRil_V1_0; |
| 1564 | } |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 1565 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1566 | |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 1567 | if (gnssHal_V2_0 != nullptr) { |
| 1568 | auto agnss_V2_0 = gnssHal_V2_0->getExtensionAGnss_2_0(); |
| 1569 | if (!agnss_V2_0.isOk()) { |
| 1570 | ALOGD("Unable to get a handle to AGnss_V2_0"); |
| 1571 | } else { |
| 1572 | agnssIface_V2_0 = agnss_V2_0; |
| 1573 | } |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 1574 | } else { |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 1575 | auto agnss_V1_0 = gnssHal->getExtensionAGnss(); |
| 1576 | if (!agnss_V1_0.isOk()) { |
| 1577 | ALOGD("Unable to get a handle to AGnss"); |
| 1578 | } else { |
| 1579 | agnssIface = agnss_V1_0; |
| 1580 | } |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 1581 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1582 | |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 1583 | auto gnssNavigationMessage = gnssHal->getExtensionGnssNavigationMessage(); |
| 1584 | if (!gnssNavigationMessage.isOk()) { |
| 1585 | ALOGD("Unable to get a handle to GnssNavigationMessage"); |
| 1586 | } else { |
| 1587 | gnssNavigationMessageIface = gnssNavigationMessage; |
| 1588 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1589 | |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 1590 | if (gnssHal_V2_0 != nullptr) { |
| 1591 | // TODO(b/119638366): getExtensionGnssMeasurement_1_1 from gnssHal_V2_0 |
| 1592 | auto gnssMeasurement = gnssHal_V2_0->getExtensionGnssMeasurement_2_0(); |
| 1593 | if (!gnssMeasurement.isOk()) { |
| 1594 | ALOGD("Unable to get a handle to GnssMeasurement_V2_0"); |
Martijn Coenen | 3a3a4ac | 2017-01-04 12:57:47 +0100 | [diff] [blame] | 1595 | } else { |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 1596 | gnssMeasurementIface_V2_0 = gnssMeasurement; |
| 1597 | gnssMeasurementIface_V1_1 = gnssMeasurementIface_V2_0; |
| 1598 | gnssMeasurementIface = gnssMeasurementIface_V2_0; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1599 | } |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 1600 | auto gnssCorrections = gnssHal_V2_0->getExtensionMeasurementCorrections(); |
| 1601 | if (!gnssCorrections.isOk()) { |
| 1602 | ALOGD("Unable to get a handle to GnssMeasurementCorrections interface"); |
| 1603 | } else { |
| 1604 | gnssCorrectionsIface = gnssCorrections; |
| 1605 | } |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 1606 | } else if (gnssHal_V1_1 != nullptr) { |
| 1607 | auto gnssMeasurement = gnssHal_V1_1->getExtensionGnssMeasurement_1_1(); |
| 1608 | if (!gnssMeasurement.isOk()) { |
| 1609 | ALOGD("Unable to get a handle to GnssMeasurement_V1_1"); |
| 1610 | } else { |
| 1611 | gnssMeasurementIface_V1_1 = gnssMeasurement; |
| 1612 | gnssMeasurementIface = gnssMeasurementIface_V1_1; |
| 1613 | } |
| 1614 | } else { |
| 1615 | auto gnssMeasurement_V1_0 = gnssHal->getExtensionGnssMeasurement(); |
| 1616 | if (!gnssMeasurement_V1_0.isOk()) { |
| 1617 | ALOGD("Unable to get a handle to GnssMeasurement"); |
| 1618 | } else { |
| 1619 | gnssMeasurementIface = gnssMeasurement_V1_0; |
| 1620 | } |
| 1621 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1622 | |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 1623 | auto gnssDebug = gnssHal->getExtensionGnssDebug(); |
| 1624 | if (!gnssDebug.isOk()) { |
| 1625 | ALOGD("Unable to get a handle to GnssDebug"); |
| 1626 | } else { |
| 1627 | gnssDebugIface = gnssDebug; |
| 1628 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1629 | |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 1630 | auto gnssNi = gnssHal->getExtensionGnssNi(); |
| 1631 | if (!gnssNi.isOk()) { |
| 1632 | ALOGD("Unable to get a handle to GnssNi"); |
| 1633 | } else { |
| 1634 | gnssNiIface = gnssNi; |
| 1635 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1636 | |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 1637 | if (gnssHal_V2_0 != nullptr) { |
| 1638 | auto gnssConfiguration = gnssHal_V2_0->getExtensionGnssConfiguration_2_0(); |
| 1639 | if (!gnssConfiguration.isOk()) { |
| 1640 | ALOGD("Unable to get a handle to GnssConfiguration_V2_0"); |
| 1641 | } else { |
| 1642 | gnssConfigurationIface_V2_0 = gnssConfiguration; |
| 1643 | gnssConfigurationIface_V1_1 = gnssConfigurationIface_V2_0; |
| 1644 | gnssConfigurationIface = gnssConfigurationIface_V2_0; |
| 1645 | } |
| 1646 | } else if (gnssHal_V1_1 != nullptr) { |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 1647 | auto gnssConfiguration = gnssHal_V1_1->getExtensionGnssConfiguration_1_1(); |
| 1648 | if (!gnssConfiguration.isOk()) { |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 1649 | ALOGD("Unable to get a handle to GnssConfiguration_V1_1"); |
Martijn Coenen | 3a3a4ac | 2017-01-04 12:57:47 +0100 | [diff] [blame] | 1650 | } else { |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 1651 | gnssConfigurationIface_V1_1 = gnssConfiguration; |
| 1652 | gnssConfigurationIface = gnssConfigurationIface_V1_1; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1653 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1654 | } else { |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 1655 | auto gnssConfiguration_V1_0 = gnssHal->getExtensionGnssConfiguration(); |
| 1656 | if (!gnssConfiguration_V1_0.isOk()) { |
| 1657 | ALOGD("Unable to get a handle to GnssConfiguration"); |
| 1658 | } else { |
| 1659 | gnssConfigurationIface = gnssConfiguration_V1_0; |
| 1660 | } |
| 1661 | } |
| 1662 | |
| 1663 | auto gnssGeofencing = gnssHal->getExtensionGnssGeofencing(); |
| 1664 | if (!gnssGeofencing.isOk()) { |
| 1665 | ALOGD("Unable to get a handle to GnssGeofencing"); |
| 1666 | } else { |
| 1667 | gnssGeofencingIface = gnssGeofencing; |
| 1668 | } |
| 1669 | |
| 1670 | auto gnssBatching = gnssHal->getExtensionGnssBatching(); |
| 1671 | if (!gnssBatching.isOk()) { |
| 1672 | ALOGD("Unable to get a handle to gnssBatching"); |
| 1673 | } else { |
| 1674 | gnssBatchingIface = gnssBatching; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1675 | } |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 1676 | |
| 1677 | if (gnssHal_V2_0 != nullptr) { |
| 1678 | auto gnssVisibilityControl = gnssHal_V2_0->getExtensionVisibilityControl(); |
| 1679 | if (!gnssVisibilityControl.isOk()) { |
| 1680 | ALOGD("Unable to get a handle to GnssVisibilityControl interface"); |
| 1681 | } else { |
| 1682 | gnssVisibilityControlIface = gnssVisibilityControl; |
| 1683 | } |
| 1684 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | static jboolean android_location_GnssLocationProvider_is_supported( |
| 1688 | JNIEnv* /* env */, jclass /* clazz */) { |
| 1689 | return (gnssHal != nullptr) ? JNI_TRUE : JNI_FALSE; |
| 1690 | } |
| 1691 | |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 1692 | static jboolean android_location_GnssNetworkConnectivityHandler_is_agps_ril_supported( |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1693 | JNIEnv* /* env */, jclass /* clazz */) { |
| 1694 | return (agnssRilIface != nullptr) ? JNI_TRUE : JNI_FALSE; |
| 1695 | } |
| 1696 | |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 1697 | static jobject android_location_GnssConfiguration_get_gnss_configuration_version( |
| 1698 | JNIEnv* env, jclass /* jclazz */) { |
| 1699 | jint major, minor; |
| 1700 | if (gnssConfigurationIface_V2_0 != nullptr) { |
| 1701 | major = 2; |
| 1702 | minor = 0; |
| 1703 | } else if (gnssConfigurationIface_V1_1 != nullptr) { |
| 1704 | major = 1; |
| 1705 | minor = 1; |
| 1706 | } else if (gnssConfigurationIface != nullptr) { |
| 1707 | major = 1; |
| 1708 | minor = 0; |
| 1709 | } else { |
| 1710 | return nullptr; |
| 1711 | } |
| 1712 | |
| 1713 | return createHalInterfaceVersionJavaObject(env, major, minor); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | static jboolean android_location_GnssLocationProvider_init(JNIEnv* env, jobject obj) { |
| 1717 | /* |
| 1718 | * This must be set before calling into the HAL library. |
| 1719 | */ |
| 1720 | if (!mCallbacksObj) |
| 1721 | mCallbacksObj = env->NewGlobalRef(obj); |
| 1722 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1723 | /* |
| 1724 | * Fail if the main interface fails to initialize |
| 1725 | */ |
| 1726 | if (gnssHal == nullptr) { |
| 1727 | ALOGE("Unable to Initialize GNSS HAL\n"); |
| 1728 | return JNI_FALSE; |
| 1729 | } |
| 1730 | |
Wyatt Riley | fb84092 | 2017-11-08 15:07:58 -0800 | [diff] [blame] | 1731 | sp<IGnssCallback> gnssCbIface = new GnssCallback(); |
| 1732 | |
| 1733 | Return<bool> result = false; |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 1734 | if (gnssHal_V2_0 != nullptr) { |
| 1735 | result = gnssHal_V2_0->setCallback_2_0(gnssCbIface); |
| 1736 | } else if (gnssHal_V1_1 != nullptr) { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1737 | result = gnssHal_V1_1->setCallback_1_1(gnssCbIface); |
Wyatt Riley | fb84092 | 2017-11-08 15:07:58 -0800 | [diff] [blame] | 1738 | } else { |
| 1739 | result = gnssHal->setCallback(gnssCbIface); |
| 1740 | } |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 1741 | |
Hridya Valsaraju | f6423ba | 2017-02-28 09:40:48 -0800 | [diff] [blame] | 1742 | if (!result.isOk() || !result) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1743 | ALOGE("SetCallback for Gnss Interface fails\n"); |
| 1744 | return JNI_FALSE; |
| 1745 | } |
| 1746 | |
| 1747 | sp<IGnssXtraCallback> gnssXtraCbIface = new GnssXtraCallback(); |
| 1748 | if (gnssXtraIface == nullptr) { |
WyattRiley | bc5a8b0 | 2018-10-31 13:06:34 -0700 | [diff] [blame] | 1749 | ALOGI("Unable to initialize GNSS Xtra interface\n"); |
Hridya Valsaraju | e865032 | 2016-12-05 20:23:21 -0800 | [diff] [blame] | 1750 | } else { |
| 1751 | result = gnssXtraIface->setCallback(gnssXtraCbIface); |
Hridya Valsaraju | f6423ba | 2017-02-28 09:40:48 -0800 | [diff] [blame] | 1752 | if (!result.isOk() || !result) { |
Hridya Valsaraju | e865032 | 2016-12-05 20:23:21 -0800 | [diff] [blame] | 1753 | gnssXtraIface = nullptr; |
Wyatt Riley | fb84092 | 2017-11-08 15:07:58 -0800 | [diff] [blame] | 1754 | ALOGI("SetCallback for Gnss Xtra Interface fails\n"); |
Hridya Valsaraju | e865032 | 2016-12-05 20:23:21 -0800 | [diff] [blame] | 1755 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1756 | } |
| 1757 | |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 1758 | if (agnssIface_V2_0 != nullptr) { |
| 1759 | sp<IAGnssCallback_V2_0> aGnssCbIface = new AGnssCallback_V2_0(); |
| 1760 | agnssIface_V2_0->setCallback(aGnssCbIface); |
| 1761 | } else if (agnssIface != nullptr) { |
| 1762 | sp<IAGnssCallback_V1_0> aGnssCbIface = new AGnssCallback_V1_0(); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1763 | agnssIface->setCallback(aGnssCbIface); |
| 1764 | } else { |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 1765 | ALOGI("Unable to initialize AGnss interface\n"); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | sp<IGnssGeofenceCallback> gnssGeofencingCbIface = new GnssGeofenceCallback(); |
| 1769 | if (gnssGeofencingIface != nullptr) { |
| 1770 | gnssGeofencingIface->setCallback(gnssGeofencingCbIface); |
| 1771 | } else { |
Wyatt Riley | fb84092 | 2017-11-08 15:07:58 -0800 | [diff] [blame] | 1772 | ALOGI("Unable to initialize GNSS Geofencing interface\n"); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | sp<IGnssNiCallback> gnssNiCbIface = new GnssNiCallback(); |
Hridya Valsaraju | 388e968 | 2017-03-08 10:57:06 -0800 | [diff] [blame] | 1776 | if (gnssNiIface != nullptr) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1777 | gnssNiIface->setCallback(gnssNiCbIface); |
| 1778 | } else { |
Wyatt Riley | fb84092 | 2017-11-08 15:07:58 -0800 | [diff] [blame] | 1779 | ALOGI("Unable to initialize GNSS NI interface\n"); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1780 | } |
| 1781 | |
Jaekyun Seok | f9038ad | 2017-11-13 15:03:21 +0900 | [diff] [blame] | 1782 | sp<IAGnssRilCallback> aGnssRilCbIface = new AGnssRilCallback(); |
| 1783 | if (agnssRilIface != nullptr) { |
| 1784 | agnssRilIface->setCallback(aGnssRilCbIface); |
| 1785 | } else { |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 1786 | ALOGI("Unable to initialize AGnss Ril interface\n"); |
| 1787 | } |
| 1788 | |
| 1789 | if (gnssVisibilityControlIface != nullptr) { |
| 1790 | sp<IGnssVisibilityControlCallback> gnssVisibilityControlCbIface = |
| 1791 | new GnssVisibilityControlCallback(); |
| 1792 | gnssVisibilityControlIface->setCallback(gnssVisibilityControlCbIface); |
Jaekyun Seok | f9038ad | 2017-11-13 15:03:21 +0900 | [diff] [blame] | 1793 | } |
| 1794 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1795 | return JNI_TRUE; |
| 1796 | } |
| 1797 | |
| 1798 | static void android_location_GnssLocationProvider_cleanup(JNIEnv* /* env */, jobject /* obj */) { |
| 1799 | if (gnssHal != nullptr) { |
| 1800 | gnssHal->cleanup(); |
| 1801 | } |
| 1802 | } |
| 1803 | |
| 1804 | static jboolean android_location_GnssLocationProvider_set_position_mode(JNIEnv* /* env */, |
| 1805 | jobject /* obj */, jint mode, jint recurrence, jint min_interval, jint preferred_accuracy, |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1806 | jint preferred_time, jboolean low_power_mode) { |
| 1807 | Return<bool> result = false; |
| 1808 | if (gnssHal_V1_1 != nullptr) { |
Wyatt Riley | 46ac956 | 2018-03-02 20:16:58 -0800 | [diff] [blame] | 1809 | result = gnssHal_V1_1->setPositionMode_1_1(static_cast<IGnss_V1_0::GnssPositionMode>(mode), |
| 1810 | static_cast<IGnss_V1_0::GnssPositionRecurrence>(recurrence), |
| 1811 | min_interval, |
| 1812 | preferred_accuracy, |
| 1813 | preferred_time, |
| 1814 | low_power_mode); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1815 | } else if (gnssHal != nullptr) { |
Wyatt Riley | 46ac956 | 2018-03-02 20:16:58 -0800 | [diff] [blame] | 1816 | result = gnssHal->setPositionMode(static_cast<IGnss_V1_0::GnssPositionMode>(mode), |
| 1817 | static_cast<IGnss_V1_0::GnssPositionRecurrence>(recurrence), |
| 1818 | min_interval, |
| 1819 | preferred_accuracy, |
| 1820 | preferred_time); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1821 | } |
| 1822 | if (!result.isOk()) { |
| 1823 | ALOGE("%s: GNSS setPositionMode failed\n", __func__); |
| 1824 | return JNI_FALSE; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1825 | } else { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1826 | return result; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1827 | } |
| 1828 | } |
| 1829 | |
| 1830 | static jboolean android_location_GnssLocationProvider_start(JNIEnv* /* env */, jobject /* obj */) { |
| 1831 | if (gnssHal != nullptr) { |
| 1832 | auto result = gnssHal->start(); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1833 | if (!result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1834 | return JNI_FALSE; |
| 1835 | } else { |
| 1836 | return result; |
| 1837 | } |
| 1838 | } else { |
| 1839 | return JNI_FALSE; |
| 1840 | } |
| 1841 | } |
| 1842 | |
| 1843 | static jboolean android_location_GnssLocationProvider_stop(JNIEnv* /* env */, jobject /* obj */) { |
| 1844 | if (gnssHal != nullptr) { |
| 1845 | auto result = gnssHal->stop(); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1846 | if (!result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1847 | return JNI_FALSE; |
| 1848 | } else { |
| 1849 | return result; |
| 1850 | } |
| 1851 | } else { |
| 1852 | return JNI_FALSE; |
| 1853 | } |
| 1854 | } |
| 1855 | static void android_location_GnssLocationProvider_delete_aiding_data(JNIEnv* /* env */, |
| 1856 | jobject /* obj */, |
| 1857 | jint flags) { |
| 1858 | if (gnssHal != nullptr) { |
Wyatt Riley | 46ac956 | 2018-03-02 20:16:58 -0800 | [diff] [blame] | 1859 | auto result = gnssHal->deleteAidingData(static_cast<IGnss_V1_0::GnssAidingData>(flags)); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 1860 | if (!result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1861 | ALOGE("Error in deleting aiding data"); |
| 1862 | } |
| 1863 | } |
| 1864 | } |
| 1865 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1866 | static void android_location_GnssLocationProvider_agps_set_reference_location_cellid( |
| 1867 | JNIEnv* /* env */, jobject /* obj */, jint type, jint mcc, jint mnc, jint lac, jint cid) { |
Anil Admal | b4995e2 | 2018-11-16 17:36:21 -0800 | [diff] [blame] | 1868 | IAGnssRil_V1_0::AGnssRefLocation location; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1869 | |
| 1870 | if (agnssRilIface == nullptr) { |
| 1871 | ALOGE("No AGPS RIL interface in agps_set_reference_location_cellid"); |
| 1872 | return; |
| 1873 | } |
| 1874 | |
Anil Admal | b4995e2 | 2018-11-16 17:36:21 -0800 | [diff] [blame] | 1875 | switch (static_cast<IAGnssRil_V1_0::AGnssRefLocationType>(type)) { |
| 1876 | case IAGnssRil_V1_0::AGnssRefLocationType::GSM_CELLID: |
| 1877 | case IAGnssRil_V1_0::AGnssRefLocationType::UMTS_CELLID: |
| 1878 | location.type = static_cast<IAGnssRil_V1_0::AGnssRefLocationType>(type); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1879 | location.cellID.mcc = mcc; |
| 1880 | location.cellID.mnc = mnc; |
| 1881 | location.cellID.lac = lac; |
| 1882 | location.cellID.cid = cid; |
| 1883 | break; |
| 1884 | default: |
| 1885 | ALOGE("Neither a GSM nor a UMTS cellid (%s:%d).", __FUNCTION__, __LINE__); |
| 1886 | return; |
| 1887 | break; |
| 1888 | } |
| 1889 | |
| 1890 | agnssRilIface->setRefLocation(location); |
| 1891 | } |
| 1892 | |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 1893 | static void android_location_GnssLocationProvider_agps_set_id(JNIEnv* env, jobject /* obj */, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1894 | jint type, jstring setid_string) { |
| 1895 | if (agnssRilIface == nullptr) { |
| 1896 | ALOGE("no AGPS RIL interface in agps_set_id"); |
| 1897 | return; |
| 1898 | } |
| 1899 | |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 1900 | ScopedJniString jniSetId{env, setid_string}; |
| 1901 | agnssRilIface->setSetId((IAGnssRil_V1_0::SetIDType)type, jniSetId); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1902 | } |
| 1903 | |
| 1904 | static jint android_location_GnssLocationProvider_read_nmea(JNIEnv* env, jobject /* obj */, |
| 1905 | jbyteArray nmeaArray, jint buffer_size) { |
| 1906 | // this should only be called from within a call to reportNmea |
| 1907 | jbyte* nmea = reinterpret_cast<jbyte *>(env->GetPrimitiveArrayCritical(nmeaArray, 0)); |
| 1908 | int length = GnssCallback::sNmeaStringLength; |
| 1909 | if (length > buffer_size) |
| 1910 | length = buffer_size; |
| 1911 | memcpy(nmea, GnssCallback::sNmeaString, length); |
| 1912 | env->ReleasePrimitiveArrayCritical(nmeaArray, nmea, JNI_ABORT); |
| 1913 | return (jint) length; |
| 1914 | } |
| 1915 | |
| 1916 | static void android_location_GnssLocationProvider_inject_time(JNIEnv* /* env */, jobject /* obj */, |
| 1917 | jlong time, jlong timeReference, jint uncertainty) { |
| 1918 | if (gnssHal != nullptr) { |
| 1919 | auto result = gnssHal->injectTime(time, timeReference, uncertainty); |
Hridya Valsaraju | f6423ba | 2017-02-28 09:40:48 -0800 | [diff] [blame] | 1920 | if (!result.isOk() || !result) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1921 | ALOGE("%s: Gnss injectTime() failed", __func__); |
| 1922 | } |
| 1923 | } |
| 1924 | } |
| 1925 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 1926 | static void android_location_GnssLocationProvider_inject_best_location( |
| 1927 | JNIEnv*, |
| 1928 | jobject, |
| 1929 | jint gnssLocationFlags, |
| 1930 | jdouble latitudeDegrees, |
| 1931 | jdouble longitudeDegrees, |
| 1932 | jdouble altitudeMeters, |
| 1933 | jfloat speedMetersPerSec, |
| 1934 | jfloat bearingDegrees, |
| 1935 | jfloat horizontalAccuracyMeters, |
| 1936 | jfloat verticalAccuracyMeters, |
| 1937 | jfloat speedAccuracyMetersPerSecond, |
| 1938 | jfloat bearingAccuracyDegrees, |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 1939 | jlong timestamp, |
| 1940 | jint elapsedRealtimeFlags, |
Pierre Fite-georgel | 19f6cbfe | 2019-03-04 23:23:18 +0000 | [diff] [blame] | 1941 | jlong elapsedRealtimeNanos, |
| 1942 | jlong elapsedRealtimeUncertaintyNanos) { |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 1943 | if (gnssHal_V2_0 != nullptr) { |
| 1944 | GnssLocation_V2_0 location = createGnssLocation_V2_0( |
| 1945 | gnssLocationFlags, |
| 1946 | latitudeDegrees, |
| 1947 | longitudeDegrees, |
| 1948 | altitudeMeters, |
| 1949 | speedMetersPerSec, |
| 1950 | bearingDegrees, |
| 1951 | horizontalAccuracyMeters, |
| 1952 | verticalAccuracyMeters, |
| 1953 | speedAccuracyMetersPerSecond, |
| 1954 | bearingAccuracyDegrees, |
| 1955 | timestamp, |
| 1956 | elapsedRealtimeFlags, |
Pierre Fite-georgel | 19f6cbfe | 2019-03-04 23:23:18 +0000 | [diff] [blame] | 1957 | elapsedRealtimeNanos, |
| 1958 | elapsedRealtimeUncertaintyNanos); |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 1959 | auto result = gnssHal_V2_0->injectBestLocation_2_0(location); |
| 1960 | |
| 1961 | if (!result.isOk() || !result) { |
| 1962 | ALOGE("%s: Gnss injectBestLocation() failed.", __func__); |
| 1963 | } |
| 1964 | return; |
| 1965 | } |
| 1966 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 1967 | if (gnssHal_V1_1 != nullptr) { |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 1968 | GnssLocation_V1_0 location = createGnssLocation_V1_0( |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 1969 | gnssLocationFlags, |
| 1970 | latitudeDegrees, |
| 1971 | longitudeDegrees, |
| 1972 | altitudeMeters, |
| 1973 | speedMetersPerSec, |
| 1974 | bearingDegrees, |
| 1975 | horizontalAccuracyMeters, |
| 1976 | verticalAccuracyMeters, |
| 1977 | speedAccuracyMetersPerSecond, |
| 1978 | bearingAccuracyDegrees, |
| 1979 | timestamp); |
| 1980 | auto result = gnssHal_V1_1->injectBestLocation(location); |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 1981 | |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 1982 | if (!result.isOk() || !result) { |
| 1983 | ALOGE("%s: Gnss injectBestLocation() failed.", __func__); |
| 1984 | } |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 1985 | return; |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 1986 | } |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 1987 | |
| 1988 | ALOGE("%s: injectBestLocation() is called but gnssHal_V1_1 is not available.", __func__); |
Yu-Han Yang | e7baef3 | 2018-02-09 13:58:17 -0800 | [diff] [blame] | 1989 | } |
| 1990 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1991 | static void android_location_GnssLocationProvider_inject_location(JNIEnv* /* env */, |
| 1992 | jobject /* obj */, jdouble latitude, jdouble longitude, jfloat accuracy) { |
| 1993 | if (gnssHal != nullptr) { |
| 1994 | auto result = gnssHal->injectLocation(latitude, longitude, accuracy); |
Hridya Valsaraju | f6423ba | 2017-02-28 09:40:48 -0800 | [diff] [blame] | 1995 | if (!result.isOk() || !result) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 1996 | ALOGE("%s: Gnss injectLocation() failed", __func__); |
| 1997 | } |
| 1998 | } |
| 1999 | } |
| 2000 | |
| 2001 | static jboolean android_location_GnssLocationProvider_supports_xtra( |
| 2002 | JNIEnv* /* env */, jobject /* obj */) { |
| 2003 | return (gnssXtraIface != nullptr) ? JNI_TRUE : JNI_FALSE; |
| 2004 | } |
| 2005 | |
| 2006 | static void android_location_GnssLocationProvider_inject_xtra_data(JNIEnv* env, jobject /* obj */, |
| 2007 | jbyteArray data, jint length) { |
| 2008 | if (gnssXtraIface == nullptr) { |
| 2009 | ALOGE("XTRA Interface not supported"); |
| 2010 | return; |
| 2011 | } |
| 2012 | |
| 2013 | jbyte* bytes = reinterpret_cast<jbyte *>(env->GetPrimitiveArrayCritical(data, 0)); |
| 2014 | gnssXtraIface->injectXtraData(std::string((const char*)bytes, length)); |
| 2015 | env->ReleasePrimitiveArrayCritical(data, bytes, JNI_ABORT); |
| 2016 | } |
| 2017 | |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 2018 | struct AGnssDispatcher { |
| 2019 | static void dataConnOpen(sp<IAGnss_V1_0> agnssIface, JNIEnv* env, jstring apn, jint apnIpType); |
| 2020 | static void dataConnOpen(sp<IAGnss_V2_0> agnssIface_V2_0, JNIEnv* env, jlong networkHandle, |
| 2021 | jstring apn, jint apnIpType); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2022 | |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 2023 | template <class T> |
| 2024 | static void dataConnClosed(sp<T> agnssIface); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2025 | |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 2026 | template <class T> |
| 2027 | static void dataConnFailed(sp<T> agnssIface); |
| 2028 | |
| 2029 | template <class T, class U> |
| 2030 | static void setServer(sp<T> agnssIface, JNIEnv* env, jint type, jstring hostname, jint port); |
| 2031 | |
| 2032 | private: |
| 2033 | AGnssDispatcher() = delete; |
| 2034 | AGnssDispatcher(const AGnssDispatcher&) = delete; |
| 2035 | AGnssDispatcher& operator=(const AGnssDispatcher&) = delete; |
| 2036 | }; |
| 2037 | |
| 2038 | void AGnssDispatcher::dataConnOpen(sp<IAGnss_V1_0> agnssIface, JNIEnv* env, jstring apn, |
| 2039 | jint apnIpType) { |
| 2040 | ScopedJniString jniApn{env, apn}; |
| 2041 | auto result = agnssIface->dataConnOpen(jniApn, |
| 2042 | static_cast<IAGnss_V1_0::ApnIpType>(apnIpType)); |
Hridya Valsaraju | f6423ba | 2017-02-28 09:40:48 -0800 | [diff] [blame] | 2043 | if (!result.isOk() || !result){ |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2044 | ALOGE("%s: Failed to set APN and its IP type", __func__); |
| 2045 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2046 | } |
| 2047 | |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 2048 | void AGnssDispatcher::dataConnOpen(sp<IAGnss_V2_0> agnssIface_V2_0, JNIEnv* env, |
| 2049 | jlong networkHandle, jstring apn, jint apnIpType) { |
| 2050 | ScopedJniString jniApn{env, apn}; |
| 2051 | auto result = agnssIface_V2_0->dataConnOpen(static_cast<uint64_t>(networkHandle), jniApn, |
| 2052 | static_cast<IAGnss_V2_0::ApnIpType>(apnIpType)); |
| 2053 | if (!result.isOk() || !result){ |
| 2054 | ALOGE("%s: Failed to set APN and its IP type", __func__); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2055 | } |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 2056 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2057 | |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 2058 | template<class T> |
| 2059 | void AGnssDispatcher::dataConnClosed(sp<T> agnssIface) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2060 | auto result = agnssIface->dataConnClosed(); |
Hridya Valsaraju | f6423ba | 2017-02-28 09:40:48 -0800 | [diff] [blame] | 2061 | if (!result.isOk() || !result) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2062 | ALOGE("%s: Failed to close AGnss data connection", __func__); |
| 2063 | } |
| 2064 | } |
| 2065 | |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 2066 | template<class T> |
| 2067 | void AGnssDispatcher::dataConnFailed(sp<T> agnssIface) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2068 | auto result = agnssIface->dataConnFailed(); |
Hridya Valsaraju | f6423ba | 2017-02-28 09:40:48 -0800 | [diff] [blame] | 2069 | if (!result.isOk() || !result) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2070 | ALOGE("%s: Failed to notify unavailability of AGnss data connection", __func__); |
| 2071 | } |
| 2072 | } |
| 2073 | |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 2074 | template <class T, class U> |
| 2075 | void AGnssDispatcher::setServer(sp<T> agnssIface, JNIEnv* env, jint type, jstring hostname, |
| 2076 | jint port) { |
| 2077 | ScopedJniString jniHostName{env, hostname}; |
| 2078 | auto result = agnssIface->setServer(static_cast<typename U::AGnssType>(type), |
| 2079 | jniHostName, port); |
Hridya Valsaraju | f6423ba | 2017-02-28 09:40:48 -0800 | [diff] [blame] | 2080 | if (!result.isOk() || !result) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2081 | ALOGE("%s: Failed to set AGnss host name and port", __func__); |
| 2082 | } |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 2083 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2084 | |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 2085 | static void android_location_GnssNetworkConnectivityHandler_agps_data_conn_open( |
| 2086 | JNIEnv* env, jobject /* obj */, jlong networkHandle, jstring apn, jint apnIpType) { |
| 2087 | if (apn == nullptr) { |
| 2088 | jniThrowException(env, "java/lang/IllegalArgumentException", nullptr); |
| 2089 | return; |
| 2090 | } |
| 2091 | |
| 2092 | if (agnssIface_V2_0 != nullptr) { |
| 2093 | AGnssDispatcher::dataConnOpen(agnssIface_V2_0, env, networkHandle, apn, apnIpType); |
| 2094 | } else if (agnssIface != nullptr) { |
| 2095 | AGnssDispatcher::dataConnOpen(agnssIface, env, apn, apnIpType); |
| 2096 | } else { |
| 2097 | ALOGE("%s: AGPS interface not supported", __func__); |
| 2098 | return; |
| 2099 | } |
| 2100 | } |
| 2101 | |
| 2102 | static void android_location_GnssNetworkConnectivityHandler_agps_data_conn_closed(JNIEnv* /* env */, |
| 2103 | jobject /* obj */) { |
| 2104 | if (agnssIface_V2_0 != nullptr) { |
| 2105 | AGnssDispatcher::dataConnClosed(agnssIface_V2_0); |
| 2106 | } else if (agnssIface != nullptr) { |
| 2107 | AGnssDispatcher::dataConnClosed(agnssIface); |
| 2108 | } else { |
| 2109 | ALOGE("%s: AGPS interface not supported", __func__); |
| 2110 | return; |
| 2111 | } |
| 2112 | } |
| 2113 | |
| 2114 | static void android_location_GnssNetworkConnectivityHandler_agps_data_conn_failed(JNIEnv* /* env */, |
| 2115 | jobject /* obj */) { |
| 2116 | if (agnssIface_V2_0 != nullptr) { |
| 2117 | AGnssDispatcher::dataConnFailed(agnssIface_V2_0); |
| 2118 | } else if (agnssIface != nullptr) { |
| 2119 | AGnssDispatcher::dataConnFailed(agnssIface); |
| 2120 | } else { |
| 2121 | ALOGE("%s: AGPS interface not supported", __func__); |
| 2122 | return; |
| 2123 | } |
| 2124 | } |
| 2125 | |
| 2126 | static void android_location_GnssLocationProvider_set_agps_server(JNIEnv* env, jobject /* obj */, |
| 2127 | jint type, jstring hostname, jint port) { |
| 2128 | if (agnssIface_V2_0 != nullptr) { |
| 2129 | AGnssDispatcher::setServer<IAGnss_V2_0, IAGnssCallback_V2_0>(agnssIface_V2_0, env, type, |
| 2130 | hostname, port); |
| 2131 | } else if (agnssIface != nullptr) { |
| 2132 | AGnssDispatcher::setServer<IAGnss_V1_0, IAGnssCallback_V1_0>(agnssIface, env, type, |
| 2133 | hostname, port); |
| 2134 | } else { |
| 2135 | ALOGE("%s: AGPS interface not supported", __func__); |
| 2136 | return; |
| 2137 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2138 | } |
| 2139 | |
| 2140 | static void android_location_GnssLocationProvider_send_ni_response(JNIEnv* /* env */, |
| 2141 | jobject /* obj */, jint notifId, jint response) { |
| 2142 | if (gnssNiIface == nullptr) { |
| 2143 | ALOGE("no NI interface in send_ni_response"); |
| 2144 | return; |
| 2145 | } |
| 2146 | |
| 2147 | gnssNiIface->respond(notifId, static_cast<IGnssNiCallback::GnssUserResponseType>(response)); |
| 2148 | } |
| 2149 | |
| 2150 | static jstring android_location_GnssLocationProvider_get_internal_state(JNIEnv* env, |
| 2151 | jobject /* obj */) { |
WyattRiley | 840c0b2 | 2018-10-31 09:03:53 -0700 | [diff] [blame] | 2152 | jstring result = nullptr; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2153 | /* |
| 2154 | * TODO(b/33089503) : Create a jobject to represent GnssDebug. |
| 2155 | */ |
Wyatt Riley | 268c6e0 | 2017-03-29 10:21:46 -0700 | [diff] [blame] | 2156 | |
| 2157 | std::stringstream internalState; |
| 2158 | |
| 2159 | if (gnssDebugIface == nullptr) { |
| 2160 | internalState << "Gnss Debug Interface not available" << std::endl; |
| 2161 | } else { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2162 | IGnssDebug::DebugData data; |
| 2163 | gnssDebugIface->getDebugData([&data](const IGnssDebug::DebugData& debugData) { |
| 2164 | data = debugData; |
| 2165 | }); |
| 2166 | |
Wyatt Riley | 268c6e0 | 2017-03-29 10:21:46 -0700 | [diff] [blame] | 2167 | internalState << "Gnss Location Data:: "; |
| 2168 | if (!data.position.valid) { |
| 2169 | internalState << "not valid"; |
| 2170 | } else { |
| 2171 | internalState << "LatitudeDegrees: " << data.position.latitudeDegrees |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2172 | << ", LongitudeDegrees: " << data.position.longitudeDegrees |
| 2173 | << ", altitudeMeters: " << data.position.altitudeMeters |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 2174 | << ", speedMetersPerSecond: " << data.position.speedMetersPerSec |
| 2175 | << ", bearingDegrees: " << data.position.bearingDegrees |
Wyatt Riley | 268c6e0 | 2017-03-29 10:21:46 -0700 | [diff] [blame] | 2176 | << ", horizontalAccuracyMeters: " |
| 2177 | << data.position.horizontalAccuracyMeters |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 2178 | << ", verticalAccuracyMeters: " << data.position.verticalAccuracyMeters |
Wyatt Riley | 268c6e0 | 2017-03-29 10:21:46 -0700 | [diff] [blame] | 2179 | << ", speedAccuracyMetersPerSecond: " |
| 2180 | << data.position.speedAccuracyMetersPerSecond |
gomo | 4402af6 | 2017-01-11 13:20:13 -0800 | [diff] [blame] | 2181 | << ", bearingAccuracyDegrees: " << data.position.bearingAccuracyDegrees |
Wyatt Riley | 268c6e0 | 2017-03-29 10:21:46 -0700 | [diff] [blame] | 2182 | << ", ageSeconds: " << data.position.ageSeconds; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2183 | } |
Wyatt Riley | 268c6e0 | 2017-03-29 10:21:46 -0700 | [diff] [blame] | 2184 | internalState << std::endl; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2185 | |
Wyatt Riley | 268c6e0 | 2017-03-29 10:21:46 -0700 | [diff] [blame] | 2186 | internalState << "Gnss Time Data:: timeEstimate: " << data.time.timeEstimate |
| 2187 | << ", timeUncertaintyNs: " << data.time.timeUncertaintyNs |
| 2188 | << ", frequencyUncertaintyNsPerSec: " |
| 2189 | << data.time.frequencyUncertaintyNsPerSec << std::endl; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2190 | |
| 2191 | if (data.satelliteDataArray.size() != 0) { |
Wyatt Riley | 268c6e0 | 2017-03-29 10:21:46 -0700 | [diff] [blame] | 2192 | internalState << "Satellite Data for " << data.satelliteDataArray.size() |
| 2193 | << " satellites:: " << std::endl; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2194 | } |
| 2195 | |
Wyatt Riley | b6a50f0 | 2018-05-03 13:59:04 -0700 | [diff] [blame] | 2196 | internalState << "constell: 1=GPS, 2=SBAS, 3=GLO, 4=QZSS, 5=BDS, 6=GAL; " |
| 2197 | << "ephType: 0=Eph, 1=Alm, 2=Unk; " |
| 2198 | << "ephSource: 0=Demod, 1=Supl, 2=Server, 3=Unk; " |
| 2199 | << "ephHealth: 0=Good, 1=Bad, 2=Unk" << std::endl; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2200 | for (size_t i = 0; i < data.satelliteDataArray.size(); i++) { |
Wyatt Riley | b6a50f0 | 2018-05-03 13:59:04 -0700 | [diff] [blame] | 2201 | internalState << "constell: " |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2202 | << static_cast<uint32_t>(data.satelliteDataArray[i].constellation) |
Wyatt Riley | b6a50f0 | 2018-05-03 13:59:04 -0700 | [diff] [blame] | 2203 | << ", svid: " << std::setw(3) << data.satelliteDataArray[i].svid |
| 2204 | << ", serverPredAvail: " |
Wyatt Riley | 268c6e0 | 2017-03-29 10:21:46 -0700 | [diff] [blame] | 2205 | << data.satelliteDataArray[i].serverPredictionIsAvailable |
Wyatt Riley | b6a50f0 | 2018-05-03 13:59:04 -0700 | [diff] [blame] | 2206 | << ", serverPredAgeSec: " << std::setw(7) |
Wyatt Riley | 268c6e0 | 2017-03-29 10:21:46 -0700 | [diff] [blame] | 2207 | << data.satelliteDataArray[i].serverPredictionAgeSeconds |
Wyatt Riley | b6a50f0 | 2018-05-03 13:59:04 -0700 | [diff] [blame] | 2208 | << ", ephType: " |
| 2209 | << static_cast<uint32_t>(data.satelliteDataArray[i].ephemerisType) |
| 2210 | << ", ephSource: " |
| 2211 | << static_cast<uint32_t>(data.satelliteDataArray[i].ephemerisSource) |
| 2212 | << ", ephHealth: " |
| 2213 | << static_cast<uint32_t>(data.satelliteDataArray[i].ephemerisHealth) |
| 2214 | << ", ephAgeSec: " << std::setw(7) |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2215 | << data.satelliteDataArray[i].ephemerisAgeSeconds << std::endl; |
| 2216 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2217 | } |
Wyatt Riley | 268c6e0 | 2017-03-29 10:21:46 -0700 | [diff] [blame] | 2218 | |
| 2219 | result = env->NewStringUTF(internalState.str().c_str()); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2220 | return result; |
| 2221 | } |
| 2222 | |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 2223 | static jboolean android_location_GnssLocationProvider_is_gnss_visibility_control_supported( |
| 2224 | JNIEnv* /* env */, jclass /* clazz */) { |
| 2225 | return (gnssVisibilityControlIface != nullptr) ? JNI_TRUE : JNI_FALSE; |
| 2226 | } |
| 2227 | |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 2228 | static void android_location_GnssNetworkConnectivityHandler_update_network_state(JNIEnv* env, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2229 | jobject /* obj */, |
| 2230 | jboolean connected, |
| 2231 | jint type, |
| 2232 | jboolean roaming, |
| 2233 | jboolean available, |
Anil Admal | b4995e2 | 2018-11-16 17:36:21 -0800 | [diff] [blame] | 2234 | jstring apn, |
| 2235 | jlong networkHandle, |
| 2236 | jshort capabilities) { |
Anil Admal | b4995e2 | 2018-11-16 17:36:21 -0800 | [diff] [blame] | 2237 | if (agnssRilIface_V2_0 != nullptr) { |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 2238 | ScopedJniString jniApn{env, apn}; |
Anil Admal | b4995e2 | 2018-11-16 17:36:21 -0800 | [diff] [blame] | 2239 | IAGnssRil_V2_0::NetworkAttributes networkAttributes = { |
| 2240 | .networkHandle = static_cast<uint64_t>(networkHandle), |
| 2241 | .isConnected = static_cast<bool>(connected), |
| 2242 | .capabilities = static_cast<uint16_t>(capabilities), |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 2243 | .apn = jniApn |
Anil Admal | b4995e2 | 2018-11-16 17:36:21 -0800 | [diff] [blame] | 2244 | }; |
| 2245 | |
| 2246 | auto result = agnssRilIface_V2_0->updateNetworkState_2_0(networkAttributes); |
| 2247 | if (!result.isOk() || !result) { |
| 2248 | ALOGE("updateNetworkState_2_0 failed"); |
| 2249 | } |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 2250 | } else if (agnssRilIface != nullptr) { |
| 2251 | ScopedJniString jniApn{env, apn}; |
| 2252 | hidl_string hidlApn{jniApn}; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2253 | auto result = agnssRilIface->updateNetworkState(connected, |
Anil Admal | b4995e2 | 2018-11-16 17:36:21 -0800 | [diff] [blame] | 2254 | static_cast<IAGnssRil_V1_0::NetworkType>(type), roaming); |
Hridya Valsaraju | f6423ba | 2017-02-28 09:40:48 -0800 | [diff] [blame] | 2255 | if (!result.isOk() || !result) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2256 | ALOGE("updateNetworkState failed"); |
| 2257 | } |
| 2258 | |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 2259 | if (!hidlApn.empty()) { |
| 2260 | result = agnssRilIface->updateNetworkAvailability(available, hidlApn); |
Anil Admal | b4995e2 | 2018-11-16 17:36:21 -0800 | [diff] [blame] | 2261 | if (!result.isOk() || !result) { |
| 2262 | ALOGE("updateNetworkAvailability failed"); |
| 2263 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2264 | } |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 2265 | } else { |
| 2266 | ALOGE("AGnssRilInterface does not exist"); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2267 | } |
| 2268 | } |
| 2269 | |
Yu-Han Yang | 890ca8b | 2018-04-16 22:11:31 -0700 | [diff] [blame] | 2270 | static jboolean android_location_GnssGeofenceProvider_is_geofence_supported( |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2271 | JNIEnv* /* env */, jobject /* obj */) { |
| 2272 | return (gnssGeofencingIface != nullptr) ? JNI_TRUE : JNI_FALSE; |
| 2273 | } |
| 2274 | |
Yu-Han Yang | 890ca8b | 2018-04-16 22:11:31 -0700 | [diff] [blame] | 2275 | static jboolean android_location_GnssGeofenceProvider_add_geofence(JNIEnv* /* env */, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2276 | jobject /* obj */, jint geofenceId, jdouble latitude, jdouble longitude, jdouble radius, |
| 2277 | jint last_transition, jint monitor_transition, jint notification_responsiveness, |
| 2278 | jint unknown_timer) { |
| 2279 | if (gnssGeofencingIface != nullptr) { |
| 2280 | auto result = gnssGeofencingIface->addGeofence( |
| 2281 | geofenceId, latitude, longitude, radius, |
| 2282 | static_cast<IGnssGeofenceCallback::GeofenceTransition>(last_transition), |
| 2283 | monitor_transition, notification_responsiveness, unknown_timer); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 2284 | return boolToJbool(result.isOk()); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2285 | } else { |
| 2286 | ALOGE("Geofence Interface not available"); |
| 2287 | } |
| 2288 | return JNI_FALSE; |
| 2289 | } |
| 2290 | |
Yu-Han Yang | 890ca8b | 2018-04-16 22:11:31 -0700 | [diff] [blame] | 2291 | static jboolean android_location_GnssGeofenceProvider_remove_geofence(JNIEnv* /* env */, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2292 | jobject /* obj */, jint geofenceId) { |
| 2293 | if (gnssGeofencingIface != nullptr) { |
| 2294 | auto result = gnssGeofencingIface->removeGeofence(geofenceId); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 2295 | return boolToJbool(result.isOk()); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2296 | } else { |
| 2297 | ALOGE("Geofence interface not available"); |
| 2298 | } |
| 2299 | return JNI_FALSE; |
| 2300 | } |
| 2301 | |
Yu-Han Yang | 890ca8b | 2018-04-16 22:11:31 -0700 | [diff] [blame] | 2302 | static jboolean android_location_GnssGeofenceProvider_pause_geofence(JNIEnv* /* env */, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2303 | jobject /* obj */, jint geofenceId) { |
| 2304 | if (gnssGeofencingIface != nullptr) { |
| 2305 | auto result = gnssGeofencingIface->pauseGeofence(geofenceId); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 2306 | return boolToJbool(result.isOk()); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2307 | } else { |
| 2308 | ALOGE("Geofence interface not available"); |
| 2309 | } |
| 2310 | return JNI_FALSE; |
| 2311 | } |
| 2312 | |
Yu-Han Yang | 890ca8b | 2018-04-16 22:11:31 -0700 | [diff] [blame] | 2313 | static jboolean android_location_GnssGeofenceProvider_resume_geofence(JNIEnv* /* env */, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2314 | jobject /* obj */, jint geofenceId, jint monitor_transition) { |
| 2315 | if (gnssGeofencingIface != nullptr) { |
| 2316 | auto result = gnssGeofencingIface->resumeGeofence(geofenceId, monitor_transition); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 2317 | return boolToJbool(result.isOk()); |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2318 | } else { |
| 2319 | ALOGE("Geofence interface not available"); |
| 2320 | } |
| 2321 | return JNI_FALSE; |
| 2322 | } |
| 2323 | |
Yu-Han Yang | 8de2150 | 2018-04-23 01:40:25 -0700 | [diff] [blame] | 2324 | static jboolean android_location_GnssMeasurementsProvider_is_measurement_supported( |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2325 | JNIEnv* env, jclass clazz) { |
| 2326 | if (gnssMeasurementIface != nullptr) { |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 2327 | return JNI_TRUE; |
| 2328 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2329 | |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 2330 | return JNI_FALSE; |
| 2331 | } |
| 2332 | |
Yu-Han Yang | 8de2150 | 2018-04-23 01:40:25 -0700 | [diff] [blame] | 2333 | static jboolean android_location_GnssMeasurementsProvider_start_measurement_collection( |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2334 | JNIEnv* /* env */, |
| 2335 | jobject /* obj */, |
| 2336 | jboolean enableFullTracking) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2337 | if (gnssMeasurementIface == nullptr) { |
| 2338 | ALOGE("GNSS Measurement interface is not available."); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 2339 | return JNI_FALSE; |
| 2340 | } |
| 2341 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2342 | sp<GnssMeasurementCallback> cbIface = new GnssMeasurementCallback(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2343 | IGnssMeasurement_V1_0::GnssMeasurementStatus result = |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 2344 | IGnssMeasurement_V1_0::GnssMeasurementStatus::ERROR_GENERIC; |
| 2345 | if (gnssMeasurementIface_V2_0 != nullptr) { |
| 2346 | result = gnssMeasurementIface_V2_0->setCallback_2_0(cbIface, enableFullTracking); |
| 2347 | } else if (gnssMeasurementIface_V1_1 != nullptr) { |
| 2348 | result = gnssMeasurementIface_V1_1->setCallback_1_1(cbIface, enableFullTracking); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2349 | } else { |
| 2350 | if (enableFullTracking == JNI_TRUE) { |
| 2351 | // full tracking mode not supported in 1.0 HAL |
| 2352 | return JNI_FALSE; |
| 2353 | } |
| 2354 | result = gnssMeasurementIface->setCallback(cbIface); |
| 2355 | } |
| 2356 | |
| 2357 | if (result != IGnssMeasurement_V1_0::GnssMeasurementStatus::SUCCESS) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2358 | ALOGE("An error has been found on GnssMeasurementInterface::init, status=%d", |
| 2359 | static_cast<int32_t>(result)); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 2360 | return JNI_FALSE; |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2361 | } else { |
Yu-Han Yang | 88d7910 | 2018-11-14 14:20:57 -0800 | [diff] [blame] | 2362 | ALOGD("gnss measurement infc has been enabled"); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 2363 | } |
| 2364 | |
| 2365 | return JNI_TRUE; |
| 2366 | } |
| 2367 | |
Yu-Han Yang | 8de2150 | 2018-04-23 01:40:25 -0700 | [diff] [blame] | 2368 | static jboolean android_location_GnssMeasurementsProvider_stop_measurement_collection( |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 2369 | JNIEnv* env, |
| 2370 | jobject obj) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2371 | if (gnssMeasurementIface == nullptr) { |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 2372 | ALOGE("Measurement interface not available"); |
| 2373 | return JNI_FALSE; |
| 2374 | } |
| 2375 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2376 | auto result = gnssMeasurementIface->close(); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 2377 | return boolToJbool(result.isOk()); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 2378 | } |
| 2379 | |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 2380 | static jboolean android_location_GnssMeasurementsProvider_inject_gnss_measurement_corrections( |
| 2381 | JNIEnv* env, |
| 2382 | jobject obj /* clazz*/, |
| 2383 | jobject correctionsObj) { |
| 2384 | |
| 2385 | if (gnssCorrectionsIface == nullptr) { |
| 2386 | ALOGW("Trying to inject GNSS corrections on a chipset that does not support them."); |
| 2387 | return JNI_FALSE; |
| 2388 | } |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 2389 | |
| 2390 | jdouble latitudeDegreesCorr = env->CallDoubleMethod( |
| 2391 | correctionsObj, method_correctionsGetLatitudeDegrees); |
| 2392 | jdouble longitudeDegreesCorr = env->CallDoubleMethod( |
| 2393 | correctionsObj, method_correctionsGetLongitudeDegrees); |
| 2394 | jdouble altitudeDegreesCorr = env->CallDoubleMethod( |
| 2395 | correctionsObj, method_correctionsGetAltitudeMeters); |
gomo | 6ec9538 | 2019-01-26 03:08:18 -0800 | [diff] [blame] | 2396 | jdouble horizontalPositionUncertaintyMeters = env->CallDoubleMethod( |
| 2397 | correctionsObj, method_correctionsGetHorPosUncMeters); |
| 2398 | jdouble verticalPositionUncertaintyMeters = env->CallDoubleMethod( |
| 2399 | correctionsObj, method_correctionsGetVerPosUncMeters); |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 2400 | jlong toaGpsNanosOfWeek = env->CallLongMethod( |
| 2401 | correctionsObj, method_correctionsGetToaGpsNanosecondsOfWeek); |
| 2402 | jobject singleSatCorrectionList = env->CallObjectMethod(correctionsObj, |
| 2403 | method_correctionsGetSingleSatCorrectionList); |
| 2404 | |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 2405 | auto len = (singleSatCorrectionList == nullptr) |
| 2406 | ? 0 |
| 2407 | : env->CallIntMethod(singleSatCorrectionList, method_listSize); |
gomo | 5716ab8 | 2019-02-27 22:57:56 -0800 | [diff] [blame] | 2408 | if (len == 0) { |
| 2409 | ALOGI("Empty correction list injected....Returning with no HAL injection"); |
| 2410 | return JNI_TRUE; |
| 2411 | } |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 2412 | hidl_vec<SingleSatCorrection> list(len); |
| 2413 | |
| 2414 | for (uint16_t i = 0; i < len; ++i) { |
| 2415 | jobject singleSatCorrectionObj = env->CallObjectMethod( |
gomo | 5716ab8 | 2019-02-27 22:57:56 -0800 | [diff] [blame] | 2416 | singleSatCorrectionList, method_correctionListGet, i); |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 2417 | |
| 2418 | jint correctionFlags = |
| 2419 | env->CallIntMethod(singleSatCorrectionObj, method_correctionSatFlags); |
| 2420 | jint constType = env->CallIntMethod(singleSatCorrectionObj, |
| 2421 | method_correctionSatConstType); |
| 2422 | jint satId = |
| 2423 | env->CallIntMethod(singleSatCorrectionObj, method_correctionSatId); |
| 2424 | jfloat carrierFreqHz = env->CallFloatMethod( |
| 2425 | singleSatCorrectionObj, method_correctionSatCarrierFreq); |
gomo | b4635ba | 2019-01-17 04:02:53 -0800 | [diff] [blame] | 2426 | jfloat probSatIsLos = env->CallFloatMethod(singleSatCorrectionObj, |
| 2427 | method_correctionSatIsLosProb); |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 2428 | jfloat eplMeters = |
| 2429 | env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatEpl); |
| 2430 | jfloat eplUncMeters = env->CallFloatMethod(singleSatCorrectionObj, |
| 2431 | method_correctionSatEplUnc); |
gomo | 5716ab8 | 2019-02-27 22:57:56 -0800 | [diff] [blame] | 2432 | uint16_t corrFlags = static_cast<uint16_t>(correctionFlags); |
| 2433 | jobject reflectingPlaneObj; |
| 2434 | bool has_ref_plane = (corrFlags & GnssSingleSatCorrectionFlags::HAS_REFLECTING_PLANE) != 0; |
| 2435 | if (has_ref_plane) { |
| 2436 | reflectingPlaneObj = env->CallObjectMethod( |
| 2437 | singleSatCorrectionObj, method_correctionSatRefPlane); |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 2438 | } |
| 2439 | |
gomo | 5716ab8 | 2019-02-27 22:57:56 -0800 | [diff] [blame] | 2440 | ReflectingPlane reflectingPlane; |
| 2441 | if (has_ref_plane) { |
| 2442 | jdouble latitudeDegreesRefPlane = env->CallDoubleMethod( |
| 2443 | reflectingPlaneObj, method_correctionPlaneLatDeg); |
| 2444 | jdouble longitudeDegreesRefPlane = env->CallDoubleMethod( |
| 2445 | reflectingPlaneObj, method_correctionPlaneLngDeg); |
| 2446 | jdouble altitudeDegreesRefPlane = env->CallDoubleMethod( |
| 2447 | reflectingPlaneObj, method_correctionPlaneAltDeg); |
| 2448 | jdouble azimuthDegreeRefPlane = env->CallDoubleMethod( |
| 2449 | reflectingPlaneObj, method_correctionPlaneAzimDeg); |
| 2450 | reflectingPlane = { |
| 2451 | .latitudeDegrees = latitudeDegreesRefPlane, |
| 2452 | .longitudeDegrees = longitudeDegreesRefPlane, |
| 2453 | .altitudeMeters = altitudeDegreesRefPlane, |
| 2454 | .azimuthDegrees = azimuthDegreeRefPlane, |
| 2455 | }; |
| 2456 | } |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 2457 | |
| 2458 | SingleSatCorrection singleSatCorrection = { |
gomo | 5716ab8 | 2019-02-27 22:57:56 -0800 | [diff] [blame] | 2459 | .singleSatCorrectionFlags = corrFlags, |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 2460 | .constellation = static_cast<GnssConstellationType>(constType), |
| 2461 | .svid = static_cast<uint16_t>(satId), |
| 2462 | .carrierFrequencyHz = carrierFreqHz, |
gomo | b4635ba | 2019-01-17 04:02:53 -0800 | [diff] [blame] | 2463 | .probSatIsLos = probSatIsLos, |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 2464 | .excessPathLengthMeters = eplMeters, |
| 2465 | .excessPathLengthUncertaintyMeters = eplUncMeters, |
| 2466 | .reflectingPlane = reflectingPlane, |
| 2467 | }; |
| 2468 | list[i] = singleSatCorrection; |
| 2469 | } |
| 2470 | MeasurementCorrections measurementCorrections = { |
| 2471 | .latitudeDegrees = latitudeDegreesCorr, |
| 2472 | .longitudeDegrees = longitudeDegreesCorr, |
| 2473 | .altitudeMeters = altitudeDegreesCorr, |
gomo | 6ec9538 | 2019-01-26 03:08:18 -0800 | [diff] [blame] | 2474 | .horizontalPositionUncertaintyMeters = horizontalPositionUncertaintyMeters, |
| 2475 | .verticalPositionUncertaintyMeters = verticalPositionUncertaintyMeters, |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 2476 | .toaGpsNanosecondsOfWeek = static_cast<uint64_t>(toaGpsNanosOfWeek), |
| 2477 | .satCorrections = list, |
| 2478 | }; |
| 2479 | |
| 2480 | gnssCorrectionsIface->setCorrections(measurementCorrections); |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 2481 | return JNI_TRUE; |
| 2482 | } |
| 2483 | |
Yu-Han Yang | 23d9216 | 2018-04-19 06:03:00 -0700 | [diff] [blame] | 2484 | static jboolean android_location_GnssNavigationMessageProvider_is_navigation_message_supported( |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 2485 | JNIEnv* env, |
| 2486 | jclass clazz) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2487 | if (gnssNavigationMessageIface != nullptr) { |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 2488 | return JNI_TRUE; |
| 2489 | } |
| 2490 | return JNI_FALSE; |
| 2491 | } |
| 2492 | |
Yu-Han Yang | 23d9216 | 2018-04-19 06:03:00 -0700 | [diff] [blame] | 2493 | static jboolean android_location_GnssNavigationMessageProvider_start_navigation_message_collection( |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 2494 | JNIEnv* env, |
| 2495 | jobject obj) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2496 | if (gnssNavigationMessageIface == nullptr) { |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 2497 | ALOGE("Navigation Message interface is not available."); |
| 2498 | return JNI_FALSE; |
| 2499 | } |
| 2500 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2501 | sp<IGnssNavigationMessageCallback> gnssNavigationMessageCbIface = |
| 2502 | new GnssNavigationMessageCallback(); |
| 2503 | IGnssNavigationMessage::GnssNavigationMessageStatus result = |
| 2504 | gnssNavigationMessageIface->setCallback(gnssNavigationMessageCbIface); |
| 2505 | |
| 2506 | if (result != IGnssNavigationMessage::GnssNavigationMessageStatus::SUCCESS) { |
| 2507 | 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] | 2508 | return JNI_FALSE; |
| 2509 | } |
| 2510 | |
| 2511 | return JNI_TRUE; |
| 2512 | } |
| 2513 | |
Yu-Han Yang | 23d9216 | 2018-04-19 06:03:00 -0700 | [diff] [blame] | 2514 | static jboolean android_location_GnssNavigationMessageProvider_stop_navigation_message_collection( |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 2515 | JNIEnv* env, |
| 2516 | jobject obj) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2517 | if (gnssNavigationMessageIface == nullptr) { |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 2518 | ALOGE("Navigation Message interface is not available."); |
| 2519 | return JNI_FALSE; |
| 2520 | } |
| 2521 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2522 | auto result = gnssNavigationMessageIface->close(); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 2523 | return boolToJbool(result.isOk()); |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 2524 | } |
| 2525 | |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 2526 | static jboolean android_location_GnssConfiguration_set_emergency_supl_pdn(JNIEnv*, |
| 2527 | jobject, |
| 2528 | jint emergencySuplPdn) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2529 | if (gnssConfigurationIface == nullptr) { |
| 2530 | ALOGE("no GNSS configuration interface available"); |
| 2531 | return JNI_FALSE; |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 2532 | } |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2533 | |
| 2534 | auto result = gnssConfigurationIface->setEmergencySuplPdn(emergencySuplPdn); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 2535 | if (result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2536 | return result; |
| 2537 | } else { |
| 2538 | return JNI_FALSE; |
| 2539 | } |
| 2540 | } |
| 2541 | |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 2542 | static jboolean android_location_GnssConfiguration_set_supl_version(JNIEnv*, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2543 | jobject, |
| 2544 | jint version) { |
| 2545 | if (gnssConfigurationIface == nullptr) { |
| 2546 | ALOGE("no GNSS configuration interface available"); |
| 2547 | return JNI_FALSE; |
| 2548 | } |
| 2549 | auto result = gnssConfigurationIface->setSuplVersion(version); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 2550 | if (result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2551 | return result; |
| 2552 | } else { |
| 2553 | return JNI_FALSE; |
| 2554 | } |
| 2555 | } |
| 2556 | |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 2557 | static jboolean android_location_GnssConfiguration_set_supl_es(JNIEnv*, |
| 2558 | jobject, |
| 2559 | jint suplEs) { |
| 2560 | if (gnssConfigurationIface_V2_0 != nullptr) { |
| 2561 | ALOGI("Config parameter SUPL_ES is deprecated in IGnssConfiguration.hal version 2.0."); |
| 2562 | return JNI_FALSE; |
| 2563 | } |
| 2564 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2565 | if (gnssConfigurationIface == nullptr) { |
| 2566 | ALOGE("no GNSS configuration interface available"); |
| 2567 | return JNI_FALSE; |
| 2568 | } |
| 2569 | |
| 2570 | auto result = gnssConfigurationIface->setSuplEs(suplEs); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 2571 | if (result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2572 | return result; |
| 2573 | } else { |
| 2574 | return JNI_FALSE; |
| 2575 | } |
| 2576 | } |
| 2577 | |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 2578 | static jboolean android_location_GnssConfiguration_set_supl_mode(JNIEnv*, |
| 2579 | jobject, |
| 2580 | jint mode) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2581 | if (gnssConfigurationIface == nullptr) { |
| 2582 | ALOGE("no GNSS configuration interface available"); |
| 2583 | return JNI_FALSE; |
| 2584 | } |
| 2585 | |
| 2586 | auto result = gnssConfigurationIface->setSuplMode(mode); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 2587 | if (result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2588 | return result; |
| 2589 | } else { |
| 2590 | return JNI_FALSE; |
| 2591 | } |
| 2592 | } |
| 2593 | |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 2594 | static jboolean android_location_GnssConfiguration_set_gps_lock(JNIEnv*, |
| 2595 | jobject, |
| 2596 | jint gpsLock) { |
| 2597 | if (gnssConfigurationIface_V2_0 != nullptr) { |
| 2598 | ALOGI("Config parameter GPS_LOCK is deprecated in IGnssConfiguration.hal version 2.0."); |
| 2599 | return JNI_FALSE; |
| 2600 | } |
| 2601 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2602 | if (gnssConfigurationIface == nullptr) { |
| 2603 | ALOGE("no GNSS configuration interface available"); |
| 2604 | return JNI_FALSE; |
| 2605 | } |
| 2606 | |
| 2607 | auto result = gnssConfigurationIface->setGpsLock(gpsLock); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 2608 | if (result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2609 | return result; |
| 2610 | } else { |
| 2611 | return JNI_FALSE; |
| 2612 | } |
| 2613 | } |
| 2614 | |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 2615 | static jboolean android_location_GnssConfiguration_set_lpp_profile(JNIEnv*, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2616 | jobject, |
| 2617 | jint lppProfile) { |
| 2618 | if (gnssConfigurationIface == nullptr) { |
| 2619 | ALOGE("no GNSS configuration interface available"); |
| 2620 | return JNI_FALSE; |
| 2621 | } |
| 2622 | |
| 2623 | auto result = gnssConfigurationIface->setLppProfile(lppProfile); |
| 2624 | |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 2625 | if (result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2626 | return result; |
| 2627 | } else { |
| 2628 | return JNI_FALSE; |
| 2629 | } |
| 2630 | } |
| 2631 | |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 2632 | static jboolean android_location_GnssConfiguration_set_gnss_pos_protocol_select(JNIEnv*, |
| 2633 | jobject, |
| 2634 | jint gnssPosProtocol) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2635 | if (gnssConfigurationIface == nullptr) { |
| 2636 | ALOGE("no GNSS configuration interface available"); |
| 2637 | return JNI_FALSE; |
| 2638 | } |
| 2639 | |
| 2640 | auto result = gnssConfigurationIface->setGlonassPositioningProtocol(gnssPosProtocol); |
Steven Moreland | d002a8b | 2017-01-03 17:18:24 -0800 | [diff] [blame] | 2641 | if (result.isOk()) { |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2642 | return result; |
| 2643 | } else { |
| 2644 | return JNI_FALSE; |
| 2645 | } |
Tsuwei Chen | 52617bb | 2014-08-25 11:49:11 -0700 | [diff] [blame] | 2646 | } |
| 2647 | |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 2648 | static jboolean android_location_GnssConfiguration_set_satellite_blacklist( |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 2649 | JNIEnv* env, jobject, jintArray constellations, jintArray sv_ids) { |
| 2650 | if (gnssConfigurationIface_V1_1 == nullptr) { |
| 2651 | ALOGI("No GNSS Satellite Blacklist interface available"); |
| 2652 | return JNI_FALSE; |
| 2653 | } |
| 2654 | |
| 2655 | jint *constellation_array = env->GetIntArrayElements(constellations, 0); |
WyattRiley | 840c0b2 | 2018-10-31 09:03:53 -0700 | [diff] [blame] | 2656 | if (nullptr == constellation_array) { |
| 2657 | ALOGI("GetIntArrayElements returns nullptr."); |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 2658 | return JNI_FALSE; |
| 2659 | } |
| 2660 | jsize length = env->GetArrayLength(constellations); |
| 2661 | |
| 2662 | jint *sv_id_array = env->GetIntArrayElements(sv_ids, 0); |
WyattRiley | 840c0b2 | 2018-10-31 09:03:53 -0700 | [diff] [blame] | 2663 | if (nullptr == sv_id_array) { |
| 2664 | ALOGI("GetIntArrayElements returns nullptr."); |
Yu-Han Yang | 66c7ea9 | 2018-03-11 17:17:15 -0700 | [diff] [blame] | 2665 | return JNI_FALSE; |
| 2666 | } |
| 2667 | |
| 2668 | if (length != env->GetArrayLength(sv_ids)) { |
| 2669 | ALOGI("Lengths of constellations and sv_ids are inconsistent."); |
| 2670 | return JNI_FALSE; |
| 2671 | } |
| 2672 | |
| 2673 | hidl_vec<IGnssConfiguration_V1_1::BlacklistedSource> sources; |
| 2674 | sources.resize(length); |
| 2675 | |
| 2676 | for (int i = 0; i < length; i++) { |
| 2677 | sources[i].constellation = static_cast<GnssConstellationType>(constellation_array[i]); |
| 2678 | sources[i].svid = sv_id_array[i]; |
| 2679 | } |
| 2680 | |
| 2681 | auto result = gnssConfigurationIface_V1_1->setBlacklist(sources); |
| 2682 | if (result.isOk()) { |
| 2683 | return result; |
| 2684 | } else { |
| 2685 | return JNI_FALSE; |
| 2686 | } |
| 2687 | } |
| 2688 | |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 2689 | static jboolean android_location_GnssConfiguration_set_es_extension_sec( |
| 2690 | JNIEnv*, jobject, jint emergencyExtensionSeconds) { |
| 2691 | if (gnssConfigurationIface == nullptr) { |
| 2692 | ALOGE("no GNSS configuration interface available"); |
| 2693 | return JNI_FALSE; |
| 2694 | } |
| 2695 | |
| 2696 | if (gnssConfigurationIface_V2_0 == nullptr) { |
| 2697 | ALOGI("Config parameter ES_EXTENSION_SEC is not supported in IGnssConfiguration.hal" |
| 2698 | " versions earlier than 2.0."); |
| 2699 | return JNI_FALSE; |
| 2700 | } |
| 2701 | |
| 2702 | auto result = gnssConfigurationIface_V2_0->setEsExtensionSec(emergencyExtensionSeconds); |
| 2703 | if (result.isOk()) { |
| 2704 | return result; |
| 2705 | } else { |
| 2706 | return JNI_FALSE; |
| 2707 | } |
| 2708 | } |
| 2709 | |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 2710 | static jint android_location_GnssBatchingProvider_get_batch_size(JNIEnv*, jclass) { |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2711 | if (gnssBatchingIface == nullptr) { |
| 2712 | return 0; // batching not supported, size = 0 |
| 2713 | } |
| 2714 | auto result = gnssBatchingIface->getBatchSize(); |
| 2715 | if (result.isOk()) { |
| 2716 | return static_cast<jint>(result); |
| 2717 | } else { |
| 2718 | return 0; // failure in binder, don't support batching |
| 2719 | } |
| 2720 | } |
| 2721 | |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 2722 | static jboolean android_location_GnssBatchingProvider_init_batching(JNIEnv*, jclass) { |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2723 | if (gnssBatchingIface == nullptr) { |
| 2724 | return JNI_FALSE; // batching not supported |
| 2725 | } |
| 2726 | sp<IGnssBatchingCallback> gnssBatchingCbIface = new GnssBatchingCallback(); |
| 2727 | |
| 2728 | return static_cast<jboolean>(gnssBatchingIface->init(gnssBatchingCbIface)); |
| 2729 | } |
| 2730 | |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 2731 | static void android_location_GnssBatchingProvider_cleanup_batching(JNIEnv*, jclass) { |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2732 | if (gnssBatchingIface == nullptr) { |
| 2733 | return; // batching not supported |
| 2734 | } |
| 2735 | gnssBatchingIface->cleanup(); |
| 2736 | } |
| 2737 | |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 2738 | static jboolean android_location_GnssBatchingProvider_start_batch(JNIEnv*, jclass, |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2739 | jlong periodNanos, jboolean wakeOnFifoFull) { |
| 2740 | if (gnssBatchingIface == nullptr) { |
| 2741 | return JNI_FALSE; // batching not supported |
| 2742 | } |
| 2743 | |
| 2744 | IGnssBatching::Options options; |
| 2745 | options.periodNanos = periodNanos; |
| 2746 | if (wakeOnFifoFull) { |
| 2747 | options.flags = static_cast<uint8_t>(IGnssBatching::Flag::WAKEUP_ON_FIFO_FULL); |
| 2748 | } else { |
| 2749 | options.flags = 0; |
| 2750 | } |
| 2751 | |
| 2752 | return static_cast<jboolean>(gnssBatchingIface->start(options)); |
| 2753 | } |
| 2754 | |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 2755 | static void android_location_GnssBatchingProvider_flush_batch(JNIEnv*, jclass) { |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2756 | if (gnssBatchingIface == nullptr) { |
| 2757 | return; // batching not supported |
| 2758 | } |
| 2759 | |
| 2760 | gnssBatchingIface->flush(); |
| 2761 | } |
| 2762 | |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 2763 | static jboolean android_location_GnssBatchingProvider_stop_batch(JNIEnv*, jclass) { |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2764 | if (gnssBatchingIface == nullptr) { |
| 2765 | return JNI_FALSE; // batching not supported |
| 2766 | } |
| 2767 | |
| 2768 | return gnssBatchingIface->stop(); |
| 2769 | } |
| 2770 | |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 2771 | static jboolean android_location_GnssVisibilityControl_enable_nfw_location_access( |
| 2772 | JNIEnv* env, jobject, jobjectArray proxyApps) { |
| 2773 | if (gnssVisibilityControlIface == nullptr) { |
| 2774 | ALOGI("No GNSS Visibility Control interface available"); |
| 2775 | return JNI_FALSE; |
| 2776 | } |
| 2777 | |
| 2778 | const jsize length = env->GetArrayLength(proxyApps); |
| 2779 | hidl_vec<hidl_string> hidlProxyApps(length); |
| 2780 | for (int i = 0; i < length; ++i) { |
| 2781 | jstring proxyApp = (jstring) (env->GetObjectArrayElement(proxyApps, i)); |
| 2782 | ScopedJniString jniProxyApp(env, proxyApp); |
| 2783 | hidlProxyApps[i] = jniProxyApp; |
| 2784 | } |
| 2785 | |
| 2786 | auto result = gnssVisibilityControlIface->enableNfwLocationAccess(hidlProxyApps); |
| 2787 | if (result.isOk()) { |
| 2788 | return result; |
| 2789 | } else { |
| 2790 | return JNI_FALSE; |
| 2791 | } |
| 2792 | } |
| 2793 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 2794 | static const JNINativeMethod sMethods[] = { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2795 | /* name, signature, funcPtr */ |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2796 | {"class_init_native", "()V", reinterpret_cast<void *>( |
| 2797 | android_location_GnssLocationProvider_class_init_native)}, |
| 2798 | {"native_is_supported", "()Z", reinterpret_cast<void *>( |
| 2799 | android_location_GnssLocationProvider_is_supported)}, |
Yu-Han Yang | 6d31735 | 2018-03-15 11:53:01 -0700 | [diff] [blame] | 2800 | {"native_init_once", "()V", reinterpret_cast<void *>( |
| 2801 | android_location_GnssLocationProvider_init_once)}, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2802 | {"native_init", "()Z", reinterpret_cast<void *>(android_location_GnssLocationProvider_init)}, |
| 2803 | {"native_cleanup", "()V", reinterpret_cast<void *>( |
| 2804 | android_location_GnssLocationProvider_cleanup)}, |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 2805 | {"native_set_position_mode", "(IIIIIZ)Z", reinterpret_cast<void *>( |
| 2806 | android_location_GnssLocationProvider_set_position_mode)}, |
| 2807 | {"native_start", "()Z", reinterpret_cast<void *>( |
| 2808 | android_location_GnssLocationProvider_start)}, |
| 2809 | {"native_stop", "()Z", reinterpret_cast<void *>( |
| 2810 | android_location_GnssLocationProvider_stop)}, |
| 2811 | {"native_delete_aiding_data", "(I)V", reinterpret_cast<void *>( |
| 2812 | android_location_GnssLocationProvider_delete_aiding_data)}, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2813 | {"native_read_nmea", "([BI)I", reinterpret_cast<void *>( |
| 2814 | android_location_GnssLocationProvider_read_nmea)}, |
| 2815 | {"native_inject_time", "(JJI)V", reinterpret_cast<void *>( |
| 2816 | android_location_GnssLocationProvider_inject_time)}, |
Pierre Fite-georgel | 19f6cbfe | 2019-03-04 23:23:18 +0000 | [diff] [blame] | 2817 | {"native_inject_best_location", "(IDDDFFFFFFJIJJ)V", reinterpret_cast<void *>( |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 2818 | android_location_GnssLocationProvider_inject_best_location)}, |
| 2819 | {"native_inject_location", "(DDF)V", reinterpret_cast<void *>( |
| 2820 | android_location_GnssLocationProvider_inject_location)}, |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2821 | {"native_supports_xtra", "()Z", reinterpret_cast<void *>( |
| 2822 | android_location_GnssLocationProvider_supports_xtra)}, |
Pierre Fite-Georgel | b50cdaf | 2019-02-25 15:42:45 -0800 | [diff] [blame] | 2823 | {"native_inject_xtra_data", "([BI)V", reinterpret_cast<void *>( |
| 2824 | android_location_GnssLocationProvider_inject_xtra_data)}, |
| 2825 | {"native_agps_set_id", "(ILjava/lang/String;)V", reinterpret_cast<void *>( |
| 2826 | android_location_GnssLocationProvider_agps_set_id)}, |
| 2827 | {"native_agps_set_ref_location_cellid", "(IIIII)V", reinterpret_cast<void *>( |
| 2828 | android_location_GnssLocationProvider_agps_set_reference_location_cellid)}, |
| 2829 | {"native_set_agps_server", "(ILjava/lang/String;I)V", reinterpret_cast<void *>( |
| 2830 | android_location_GnssLocationProvider_set_agps_server)}, |
| 2831 | {"native_send_ni_response", "(II)V", reinterpret_cast<void *>( |
| 2832 | android_location_GnssLocationProvider_send_ni_response)}, |
| 2833 | {"native_get_internal_state", "()Ljava/lang/String;", reinterpret_cast<void *>( |
| 2834 | android_location_GnssLocationProvider_get_internal_state)}, |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 2835 | {"native_is_gnss_visibility_control_supported", "()Z", reinterpret_cast<void *>( |
| 2836 | android_location_GnssLocationProvider_is_gnss_visibility_control_supported)}, |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 2837 | }; |
| 2838 | |
| 2839 | static const JNINativeMethod sMethodsBatching[] = { |
| 2840 | /* name, signature, funcPtr */ |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2841 | {"native_get_batch_size", |
| 2842 | "()I", |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 2843 | reinterpret_cast<void *>(android_location_GnssBatchingProvider_get_batch_size)}, |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2844 | {"native_start_batch", |
| 2845 | "(JZ)Z", |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 2846 | reinterpret_cast<void *>(android_location_GnssBatchingProvider_start_batch)}, |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2847 | {"native_flush_batch", |
| 2848 | "()V", |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 2849 | reinterpret_cast<void *>(android_location_GnssBatchingProvider_flush_batch)}, |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2850 | {"native_stop_batch", |
| 2851 | "()Z", |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 2852 | reinterpret_cast<void *>(android_location_GnssBatchingProvider_stop_batch)}, |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2853 | {"native_init_batching", |
| 2854 | "()Z", |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 2855 | reinterpret_cast<void *>(android_location_GnssBatchingProvider_init_batching)}, |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 2856 | {"native_cleanup_batching", |
| 2857 | "()V", |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 2858 | reinterpret_cast<void *>(android_location_GnssBatchingProvider_cleanup_batching)}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2859 | }; |
| 2860 | |
Yu-Han Yang | 890ca8b | 2018-04-16 22:11:31 -0700 | [diff] [blame] | 2861 | static const JNINativeMethod sGeofenceMethods[] = { |
| 2862 | /* name, signature, funcPtr */ |
| 2863 | {"native_is_geofence_supported", |
| 2864 | "()Z", |
| 2865 | reinterpret_cast<void *>(android_location_GnssGeofenceProvider_is_geofence_supported)}, |
| 2866 | {"native_add_geofence", |
| 2867 | "(IDDDIIII)Z", |
| 2868 | reinterpret_cast<void *>(android_location_GnssGeofenceProvider_add_geofence)}, |
| 2869 | {"native_remove_geofence", |
| 2870 | "(I)Z", |
| 2871 | reinterpret_cast<void *>(android_location_GnssGeofenceProvider_remove_geofence)}, |
| 2872 | {"native_pause_geofence", "(I)Z", reinterpret_cast<void *>( |
| 2873 | android_location_GnssGeofenceProvider_pause_geofence)}, |
| 2874 | {"native_resume_geofence", |
| 2875 | "(II)Z", |
| 2876 | reinterpret_cast<void *>(android_location_GnssGeofenceProvider_resume_geofence)}, |
| 2877 | }; |
| 2878 | |
Yu-Han Yang | 8de2150 | 2018-04-23 01:40:25 -0700 | [diff] [blame] | 2879 | static const JNINativeMethod sMeasurementMethods[] = { |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 2880 | /* name, signature, funcPtr */ |
| 2881 | {"native_is_measurement_supported", "()Z", |
| 2882 | reinterpret_cast<void*>( |
| 2883 | android_location_GnssMeasurementsProvider_is_measurement_supported)}, |
| 2884 | {"native_start_measurement_collection", "(Z)Z", |
| 2885 | reinterpret_cast<void*>( |
| 2886 | android_location_GnssMeasurementsProvider_start_measurement_collection)}, |
| 2887 | {"native_stop_measurement_collection", "()Z", |
| 2888 | reinterpret_cast<void*>( |
| 2889 | android_location_GnssMeasurementsProvider_stop_measurement_collection)}, |
| 2890 | {"native_inject_gnss_measurement_corrections", |
| 2891 | "(Landroid/location/GnssMeasurementCorrections;)Z", |
| 2892 | reinterpret_cast<void*>( |
| 2893 | android_location_GnssMeasurementsProvider_inject_gnss_measurement_corrections)}, |
Yu-Han Yang | 8de2150 | 2018-04-23 01:40:25 -0700 | [diff] [blame] | 2894 | }; |
| 2895 | |
Yu-Han Yang | 23d9216 | 2018-04-19 06:03:00 -0700 | [diff] [blame] | 2896 | static const JNINativeMethod sNavigationMessageMethods[] = { |
| 2897 | /* name, signature, funcPtr */ |
| 2898 | {"native_is_navigation_message_supported", |
| 2899 | "()Z", |
| 2900 | reinterpret_cast<void *>( |
| 2901 | android_location_GnssNavigationMessageProvider_is_navigation_message_supported)}, |
| 2902 | {"native_start_navigation_message_collection", |
| 2903 | "()Z", |
| 2904 | reinterpret_cast<void *>( |
| 2905 | android_location_GnssNavigationMessageProvider_start_navigation_message_collection)}, |
| 2906 | {"native_stop_navigation_message_collection", |
| 2907 | "()Z", |
| 2908 | reinterpret_cast<void *>( |
| 2909 | android_location_GnssNavigationMessageProvider_stop_navigation_message_collection)}, |
| 2910 | }; |
| 2911 | |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 2912 | static const JNINativeMethod sNetworkConnectivityMethods[] = { |
| 2913 | /* name, signature, funcPtr */ |
| 2914 | {"native_is_agps_ril_supported", "()Z", |
| 2915 | reinterpret_cast<void *>(android_location_GnssNetworkConnectivityHandler_is_agps_ril_supported)}, |
| 2916 | {"native_update_network_state", |
Anil Admal | b4995e2 | 2018-11-16 17:36:21 -0800 | [diff] [blame] | 2917 | "(ZIZZLjava/lang/String;JS)V", |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 2918 | reinterpret_cast<void *>(android_location_GnssNetworkConnectivityHandler_update_network_state)}, |
| 2919 | {"native_agps_data_conn_open", |
Anil Admal | c70344b | 2018-11-16 14:22:38 -0800 | [diff] [blame] | 2920 | "(JLjava/lang/String;I)V", |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 2921 | reinterpret_cast<void *>(android_location_GnssNetworkConnectivityHandler_agps_data_conn_open)}, |
| 2922 | {"native_agps_data_conn_closed", |
| 2923 | "()V", |
| 2924 | reinterpret_cast<void *>(android_location_GnssNetworkConnectivityHandler_agps_data_conn_closed)}, |
| 2925 | {"native_agps_data_conn_failed", |
| 2926 | "()V", |
| 2927 | reinterpret_cast<void *>(android_location_GnssNetworkConnectivityHandler_agps_data_conn_failed)}, |
| 2928 | }; |
| 2929 | |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 2930 | static const JNINativeMethod sConfigurationMethods[] = { |
| 2931 | /* name, signature, funcPtr */ |
| 2932 | {"native_get_gnss_configuration_version", |
| 2933 | "()Lcom/android/server/location/GnssConfiguration$HalInterfaceVersion;", |
| 2934 | reinterpret_cast<void *>( |
| 2935 | android_location_GnssConfiguration_get_gnss_configuration_version)}, |
| 2936 | {"native_set_supl_es", |
| 2937 | "(I)Z", |
| 2938 | reinterpret_cast<void *>(android_location_GnssConfiguration_set_supl_es)}, |
| 2939 | {"native_set_supl_version", |
| 2940 | "(I)Z", |
| 2941 | reinterpret_cast<void *>(android_location_GnssConfiguration_set_supl_version)}, |
| 2942 | {"native_set_supl_mode", |
| 2943 | "(I)Z", |
| 2944 | reinterpret_cast<void *>(android_location_GnssConfiguration_set_supl_mode)}, |
| 2945 | {"native_set_lpp_profile", |
| 2946 | "(I)Z", |
| 2947 | reinterpret_cast<void *>(android_location_GnssConfiguration_set_lpp_profile)}, |
| 2948 | {"native_set_gnss_pos_protocol_select", |
| 2949 | "(I)Z", |
| 2950 | reinterpret_cast<void *>( |
| 2951 | android_location_GnssConfiguration_set_gnss_pos_protocol_select)}, |
| 2952 | {"native_set_gps_lock", |
| 2953 | "(I)Z", |
| 2954 | reinterpret_cast<void *>(android_location_GnssConfiguration_set_gps_lock)}, |
| 2955 | {"native_set_emergency_supl_pdn", |
| 2956 | "(I)Z", |
| 2957 | reinterpret_cast<void *>(android_location_GnssConfiguration_set_emergency_supl_pdn)}, |
| 2958 | {"native_set_satellite_blacklist", |
| 2959 | "([I[I)Z", |
| 2960 | reinterpret_cast<void *>(android_location_GnssConfiguration_set_satellite_blacklist)}, |
| 2961 | {"native_set_es_extension_sec", |
| 2962 | "(I)Z", |
| 2963 | reinterpret_cast<void *>(android_location_GnssConfiguration_set_es_extension_sec)}, |
| 2964 | }; |
| 2965 | |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 2966 | static const JNINativeMethod sVisibilityControlMethods[] = { |
| 2967 | /* name, signature, funcPtr */ |
| 2968 | {"native_enable_nfw_location_access", |
| 2969 | "([Ljava/lang/String;)Z", |
| 2970 | reinterpret_cast<void *>( |
| 2971 | android_location_GnssVisibilityControl_enable_nfw_location_access)}, |
| 2972 | }; |
| 2973 | |
Hridya Valsaraju | 2ea2960 | 2016-09-13 08:38:09 -0700 | [diff] [blame] | 2974 | int register_android_server_location_GnssLocationProvider(JNIEnv* env) { |
Yu-Han Yang | 3557cc7 | 2018-03-21 12:48:36 -0700 | [diff] [blame] | 2975 | jniRegisterNativeMethods( |
| 2976 | env, |
| 2977 | "com/android/server/location/GnssBatchingProvider", |
| 2978 | sMethodsBatching, |
| 2979 | NELEM(sMethodsBatching)); |
Yu-Han Yang | 890ca8b | 2018-04-16 22:11:31 -0700 | [diff] [blame] | 2980 | jniRegisterNativeMethods( |
| 2981 | env, |
| 2982 | "com/android/server/location/GnssGeofenceProvider", |
| 2983 | sGeofenceMethods, |
| 2984 | NELEM(sGeofenceMethods)); |
Yu-Han Yang | 8de2150 | 2018-04-23 01:40:25 -0700 | [diff] [blame] | 2985 | jniRegisterNativeMethods( |
| 2986 | env, |
| 2987 | "com/android/server/location/GnssMeasurementsProvider", |
| 2988 | sMeasurementMethods, |
| 2989 | NELEM(sMeasurementMethods)); |
Yu-Han Yang | 23d9216 | 2018-04-19 06:03:00 -0700 | [diff] [blame] | 2990 | jniRegisterNativeMethods( |
| 2991 | env, |
| 2992 | "com/android/server/location/GnssNavigationMessageProvider", |
| 2993 | sNavigationMessageMethods, |
| 2994 | NELEM(sNavigationMessageMethods)); |
Anil Admal | 50ba15e | 2018-11-01 16:42:42 -0700 | [diff] [blame] | 2995 | jniRegisterNativeMethods( |
| 2996 | env, |
| 2997 | "com/android/server/location/GnssNetworkConnectivityHandler", |
| 2998 | sNetworkConnectivityMethods, |
| 2999 | NELEM(sNetworkConnectivityMethods)); |
Anil Admal | d71cf14 | 2018-12-21 14:59:36 -0800 | [diff] [blame] | 3000 | jniRegisterNativeMethods( |
| 3001 | env, |
| 3002 | "com/android/server/location/GnssConfiguration", |
| 3003 | sConfigurationMethods, |
| 3004 | NELEM(sConfigurationMethods)); |
Anil Admal | 94ec76a | 2019-01-15 09:42:01 -0800 | [diff] [blame] | 3005 | jniRegisterNativeMethods( |
| 3006 | env, |
| 3007 | "com/android/server/location/GnssVisibilityControl", |
| 3008 | sVisibilityControlMethods, |
| 3009 | NELEM(sVisibilityControlMethods)); |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 3010 | return jniRegisterNativeMethods( |
| 3011 | env, |
Lifu Tang | 30f95a7 | 2016-01-07 23:20:38 -0800 | [diff] [blame] | 3012 | "com/android/server/location/GnssLocationProvider", |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 3013 | sMethods, |
| 3014 | NELEM(sMethods)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3015 | } |
| 3016 | |
| 3017 | } /* namespace android */ |