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