1 /*
2 * Copyright (C) 2022 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
17 // Define LOG_TAG before <log/log.h> to overwrite the default value.
18 #define LOG_TAG "MeasurementCorrectionsJni"
19
20 #include "MeasurementCorrections.h"
21
22 #include "Utils.h"
23
24 using IMeasurementCorrections_V1_0 =
25 android::hardware::gnss::measurement_corrections::V1_0::IMeasurementCorrections;
26 using IMeasurementCorrections_V1_1 =
27 android::hardware::gnss::measurement_corrections::V1_1::IMeasurementCorrections;
28 using IMeasurementCorrections_Aidl =
29 android::hardware::gnss::measurement_corrections::IMeasurementCorrectionsInterface;
30 using MeasurementCorrections_V1_0 =
31 android::hardware::gnss::measurement_corrections::V1_0::MeasurementCorrections;
32 using MeasurementCorrections_V1_1 =
33 android::hardware::gnss::measurement_corrections::V1_1::MeasurementCorrections;
34 using MeasurementCorrections_Aidl =
35 android::hardware::gnss::measurement_corrections::MeasurementCorrections;
36 using GnssSingleSatCorrectionFlags_V1_0 =
37 android::hardware::gnss::measurement_corrections::V1_0::GnssSingleSatCorrectionFlags;
38 using SingleSatCorrection_V1_0 =
39 android::hardware::gnss::measurement_corrections::V1_0::SingleSatCorrection;
40 using SingleSatCorrection_V1_1 =
41 android::hardware::gnss::measurement_corrections::V1_1::SingleSatCorrection;
42 using SingleSatCorrection_Aidl =
43 android::hardware::gnss::measurement_corrections::SingleSatCorrection;
44 using ReflectingPlane_V1_0 =
45 android::hardware::gnss::measurement_corrections::V1_0::ReflectingPlane;
46 using ReflectingPlane_Aidl = android::hardware::gnss::measurement_corrections::ReflectingPlane;
47 using ExcessPathInfo = SingleSatCorrection_Aidl::ExcessPathInfo;
48 using GnssConstellationType_V1_0 = android::hardware::gnss::V1_0::GnssConstellationType;
49 using GnssConstellationType_V2_0 = android::hardware::gnss::V2_0::GnssConstellationType;
50 using GnssConstellationType_Aidl = android::hardware::gnss::GnssConstellationType;
51
52 namespace android::gnss {
53
54 namespace {
55 jmethodID method_correctionsGetLatitudeDegrees;
56 jmethodID method_correctionsGetLongitudeDegrees;
57 jmethodID method_correctionsGetAltitudeMeters;
58 jmethodID method_correctionsGetHorPosUncMeters;
59 jmethodID method_correctionsGetVerPosUncMeters;
60 jmethodID method_correctionsGetToaGpsNanosecondsOfWeek;
61 jmethodID method_correctionsGetSingleSatCorrectionList;
62 jmethodID method_correctionsHasEnvironmentBearing;
63 jmethodID method_correctionsGetEnvironmentBearingDegrees;
64 jmethodID method_correctionsGetEnvironmentBearingUncertaintyDegrees;
65 jmethodID method_listSize;
66 jmethodID method_listGet;
67 jmethodID method_correctionSatFlags;
68 jmethodID method_correctionSatConstType;
69 jmethodID method_correctionSatId;
70 jmethodID method_correctionSatCarrierFreq;
71 jmethodID method_correctionSatIsLosProb;
72 jmethodID method_correctionSatEpl;
73 jmethodID method_correctionSatEplUnc;
74 jmethodID method_correctionSatRefPlane;
75 jmethodID method_correctionSatAttenuation;
76 jmethodID method_correctionSatExcessPathInfoList;
77 jmethodID method_correctionPlaneLatDeg;
78 jmethodID method_correctionPlaneLngDeg;
79 jmethodID method_correctionPlaneAltDeg;
80 jmethodID method_correctionPlaneAzimDeg;
81 jmethodID method_excessPathInfoFlags;
82 jmethodID method_excessPathInfoEpl;
83 jmethodID method_excessPathInfoEplUnc;
84 jmethodID method_excessPathInfoRefPlane;
85 jmethodID method_excessPathInfoAttenuation;
86 } // anonymous namespace
87
MeasurementCorrections_class_init_once(JNIEnv * env,jclass clazz)88 void MeasurementCorrections_class_init_once(JNIEnv* env, jclass clazz) {
89 jclass measCorrClass = env->FindClass("android/location/GnssMeasurementCorrections");
90 method_correctionsGetLatitudeDegrees =
91 env->GetMethodID(measCorrClass, "getLatitudeDegrees", "()D");
92 method_correctionsGetLongitudeDegrees =
93 env->GetMethodID(measCorrClass, "getLongitudeDegrees", "()D");
94 method_correctionsGetAltitudeMeters =
95 env->GetMethodID(measCorrClass, "getAltitudeMeters", "()D");
96 method_correctionsGetHorPosUncMeters =
97 env->GetMethodID(measCorrClass, "getHorizontalPositionUncertaintyMeters", "()D");
98 method_correctionsGetVerPosUncMeters =
99 env->GetMethodID(measCorrClass, "getVerticalPositionUncertaintyMeters", "()D");
100 method_correctionsGetToaGpsNanosecondsOfWeek =
101 env->GetMethodID(measCorrClass, "getToaGpsNanosecondsOfWeek", "()J");
102 method_correctionsGetSingleSatCorrectionList =
103 env->GetMethodID(measCorrClass, "getSingleSatelliteCorrectionList",
104 "()Ljava/util/List;");
105 method_correctionsHasEnvironmentBearing =
106 env->GetMethodID(measCorrClass, "hasEnvironmentBearing", "()Z");
107 method_correctionsGetEnvironmentBearingDegrees =
108 env->GetMethodID(measCorrClass, "getEnvironmentBearingDegrees", "()F");
109 method_correctionsGetEnvironmentBearingUncertaintyDegrees =
110 env->GetMethodID(measCorrClass, "getEnvironmentBearingUncertaintyDegrees", "()F");
111
112 jclass corrListClass = env->FindClass("java/util/List");
113 method_listSize = env->GetMethodID(corrListClass, "size", "()I");
114 method_listGet = env->GetMethodID(corrListClass, "get", "(I)Ljava/lang/Object;");
115
116 jclass singleSatCorrClass = env->FindClass("android/location/GnssSingleSatCorrection");
117 method_correctionSatFlags =
118 env->GetMethodID(singleSatCorrClass, "getSingleSatelliteCorrectionFlags", "()I");
119 method_correctionSatConstType =
120 env->GetMethodID(singleSatCorrClass, "getConstellationType", "()I");
121 method_correctionSatId = env->GetMethodID(singleSatCorrClass, "getSatelliteId", "()I");
122 method_correctionSatCarrierFreq =
123 env->GetMethodID(singleSatCorrClass, "getCarrierFrequencyHz", "()F");
124 method_correctionSatIsLosProb =
125 env->GetMethodID(singleSatCorrClass, "getProbabilityLineOfSight", "()F");
126 method_correctionSatEpl =
127 env->GetMethodID(singleSatCorrClass, "getExcessPathLengthMeters", "()F");
128 method_correctionSatEplUnc =
129 env->GetMethodID(singleSatCorrClass, "getExcessPathLengthUncertaintyMeters", "()F");
130 method_correctionSatRefPlane = env->GetMethodID(singleSatCorrClass, "getReflectingPlane",
131 "()Landroid/location/GnssReflectingPlane;");
132 method_correctionSatAttenuation =
133 env->GetMethodID(singleSatCorrClass, "getCombinedAttenuationDb", "()F");
134 method_correctionSatExcessPathInfoList =
135 env->GetMethodID(singleSatCorrClass, "getGnssExcessPathInfoList", "()Ljava/util/List;");
136
137 jclass refPlaneClass = env->FindClass("android/location/GnssReflectingPlane");
138 method_correctionPlaneLatDeg = env->GetMethodID(refPlaneClass, "getLatitudeDegrees", "()D");
139 method_correctionPlaneLngDeg = env->GetMethodID(refPlaneClass, "getLongitudeDegrees", "()D");
140 method_correctionPlaneAltDeg = env->GetMethodID(refPlaneClass, "getAltitudeMeters", "()D");
141 method_correctionPlaneAzimDeg = env->GetMethodID(refPlaneClass, "getAzimuthDegrees", "()D");
142
143 jclass excessPathInfoClass = env->FindClass("android/location/GnssExcessPathInfo");
144 method_excessPathInfoFlags = env->GetMethodID(excessPathInfoClass, "getFlags", "()I");
145 method_excessPathInfoEpl =
146 env->GetMethodID(excessPathInfoClass, "getExcessPathLengthMeters", "()F");
147 method_excessPathInfoEplUnc =
148 env->GetMethodID(excessPathInfoClass, "getExcessPathLengthUncertaintyMeters", "()F");
149 method_excessPathInfoRefPlane = env->GetMethodID(excessPathInfoClass, "getReflectingPlane",
150 "()Landroid/location/GnssReflectingPlane;");
151 method_excessPathInfoAttenuation =
152 env->GetMethodID(excessPathInfoClass, "getAttenuationDb", "()F");
153 }
154
155 template <>
translateMeasurementCorrections(JNIEnv * env,jobject correctionsObj,MeasurementCorrections_V1_0 & corrections)156 bool MeasurementCorrectionsUtil::translateMeasurementCorrections(
157 JNIEnv* env, jobject correctionsObj, MeasurementCorrections_V1_0& corrections) {
158 jobject singleSatCorrectionList =
159 env->CallObjectMethod(correctionsObj, method_correctionsGetSingleSatCorrectionList);
160 if (singleSatCorrectionList == nullptr) return false;
161 auto len = env->CallIntMethod(singleSatCorrectionList, method_listSize);
162
163 jdouble latitudeDegreesCorr =
164 env->CallDoubleMethod(correctionsObj, method_correctionsGetLatitudeDegrees);
165 jdouble longitudeDegreesCorr =
166 env->CallDoubleMethod(correctionsObj, method_correctionsGetLongitudeDegrees);
167 jdouble altitudeDegreesCorr =
168 env->CallDoubleMethod(correctionsObj, method_correctionsGetAltitudeMeters);
169 jdouble horizontalPositionUncertaintyMeters =
170 env->CallDoubleMethod(correctionsObj, method_correctionsGetHorPosUncMeters);
171 jdouble verticalPositionUncertaintyMeters =
172 env->CallDoubleMethod(correctionsObj, method_correctionsGetVerPosUncMeters);
173 jlong toaGpsNanosOfWeek =
174 env->CallLongMethod(correctionsObj, method_correctionsGetToaGpsNanosecondsOfWeek);
175
176 corrections.latitudeDegrees = latitudeDegreesCorr;
177 corrections.longitudeDegrees = longitudeDegreesCorr;
178 corrections.altitudeMeters = altitudeDegreesCorr;
179 corrections.horizontalPositionUncertaintyMeters = horizontalPositionUncertaintyMeters;
180 corrections.verticalPositionUncertaintyMeters = verticalPositionUncertaintyMeters;
181 corrections.toaGpsNanosecondsOfWeek = static_cast<uint64_t>(toaGpsNanosOfWeek);
182
183 hardware::hidl_vec<SingleSatCorrection_V1_0> list(len);
184 MeasurementCorrectionsUtil::getSingleSatCorrectionList_1_0(env, singleSatCorrectionList, list);
185 env->DeleteLocalRef(singleSatCorrectionList);
186 corrections.satCorrections = list;
187 return true;
188 }
189
190 template <>
translateMeasurementCorrections(JNIEnv * env,jobject correctionsObj,MeasurementCorrections_V1_1 & corrections)191 bool MeasurementCorrectionsUtil::translateMeasurementCorrections(
192 JNIEnv* env, jobject correctionsObj, MeasurementCorrections_V1_1& corrections) {
193 jobject singleSatCorrectionList =
194 env->CallObjectMethod(correctionsObj, method_correctionsGetSingleSatCorrectionList);
195 if (singleSatCorrectionList == nullptr) return false;
196 auto len = env->CallIntMethod(singleSatCorrectionList, method_listSize);
197
198 MeasurementCorrections_V1_0 measurementCorrections_1_0;
199 translateMeasurementCorrections<MeasurementCorrections_V1_0>(env, correctionsObj,
200 measurementCorrections_1_0);
201 measurementCorrections_1_0.satCorrections.resize(0);
202
203 jboolean hasEnvironmentBearingCorr =
204 env->CallBooleanMethod(correctionsObj, method_correctionsHasEnvironmentBearing);
205 jfloat environmentBearingDegreesCorr =
206 env->CallFloatMethod(correctionsObj, method_correctionsGetEnvironmentBearingDegrees);
207 jfloat environmentBearingUncertaintyDegreesCorr =
208 env->CallFloatMethod(correctionsObj,
209 method_correctionsGetEnvironmentBearingUncertaintyDegrees);
210
211 hardware::hidl_vec<SingleSatCorrection_V1_1> list(len);
212 MeasurementCorrectionsUtil::getSingleSatCorrectionList_1_1(env, singleSatCorrectionList, list);
213 env->DeleteLocalRef(singleSatCorrectionList);
214
215 corrections.v1_0 = measurementCorrections_1_0;
216 corrections.hasEnvironmentBearing = static_cast<bool>(hasEnvironmentBearingCorr);
217 corrections.environmentBearingDegrees = environmentBearingDegreesCorr;
218 corrections.environmentBearingUncertaintyDegrees = environmentBearingUncertaintyDegreesCorr;
219 corrections.satCorrections = list;
220 return true;
221 }
222
223 template <>
translateMeasurementCorrections(JNIEnv * env,jobject correctionsObj,MeasurementCorrections_Aidl & corrections)224 bool MeasurementCorrectionsUtil::translateMeasurementCorrections(
225 JNIEnv* env, jobject correctionsObj, MeasurementCorrections_Aidl& corrections) {
226 jobject singleSatCorrectionList =
227 env->CallObjectMethod(correctionsObj, method_correctionsGetSingleSatCorrectionList);
228 if (singleSatCorrectionList == nullptr) return false;
229 auto len = env->CallIntMethod(singleSatCorrectionList, method_listSize);
230
231 jdouble latitudeDegreesCorr =
232 env->CallDoubleMethod(correctionsObj, method_correctionsGetLatitudeDegrees);
233 jdouble longitudeDegreesCorr =
234 env->CallDoubleMethod(correctionsObj, method_correctionsGetLongitudeDegrees);
235 jdouble altitudeDegreesCorr =
236 env->CallDoubleMethod(correctionsObj, method_correctionsGetAltitudeMeters);
237 jdouble horizontalPositionUncertaintyMeters =
238 env->CallDoubleMethod(correctionsObj, method_correctionsGetHorPosUncMeters);
239 jdouble verticalPositionUncertaintyMeters =
240 env->CallDoubleMethod(correctionsObj, method_correctionsGetVerPosUncMeters);
241 jlong toaGpsNanosOfWeek =
242 env->CallLongMethod(correctionsObj, method_correctionsGetToaGpsNanosecondsOfWeek);
243
244 corrections.latitudeDegrees = static_cast<double>(latitudeDegreesCorr);
245 corrections.longitudeDegrees = static_cast<double>(longitudeDegreesCorr);
246 corrections.altitudeMeters = static_cast<double>(altitudeDegreesCorr);
247 corrections.horizontalPositionUncertaintyMeters =
248 static_cast<double>(horizontalPositionUncertaintyMeters);
249 corrections.verticalPositionUncertaintyMeters =
250 static_cast<double>(verticalPositionUncertaintyMeters);
251 corrections.toaGpsNanosecondsOfWeek = static_cast<int64_t>(toaGpsNanosOfWeek);
252
253 jboolean hasEnvironmentBearingCorr =
254 env->CallBooleanMethod(correctionsObj, method_correctionsHasEnvironmentBearing);
255 jfloat environmentBearingDegreesCorr =
256 env->CallFloatMethod(correctionsObj, method_correctionsGetEnvironmentBearingDegrees);
257 jfloat environmentBearingUncertaintyDegreesCorr =
258 env->CallFloatMethod(correctionsObj,
259 method_correctionsGetEnvironmentBearingUncertaintyDegrees);
260
261 std::vector<SingleSatCorrection_Aidl> list(len);
262 MeasurementCorrectionsUtil::getSingleSatCorrectionList_Aidl(env, singleSatCorrectionList, list);
263 env->DeleteLocalRef(singleSatCorrectionList);
264
265 corrections.hasEnvironmentBearing = static_cast<bool>(hasEnvironmentBearingCorr);
266 corrections.environmentBearingDegrees = environmentBearingDegreesCorr;
267 corrections.environmentBearingUncertaintyDegrees = environmentBearingUncertaintyDegreesCorr;
268 corrections.satCorrections = list;
269 return true;
270 }
271
272 // Implementation of MeasurementCorrections (AIDL HAL)
273
MeasurementCorrectionsIface_Aidl(const sp<IMeasurementCorrections_Aidl> & iMeasurementCorrections)274 MeasurementCorrectionsIface_Aidl::MeasurementCorrectionsIface_Aidl(
275 const sp<IMeasurementCorrections_Aidl>& iMeasurementCorrections)
276 : mIMeasurementCorrectionsAidl(iMeasurementCorrections) {
277 assert(mIMeasurementCorrectionsAidl != nullptr);
278 }
279
setCorrections(JNIEnv * env,jobject correctionsObj)280 jboolean MeasurementCorrectionsIface_Aidl::setCorrections(JNIEnv* env, jobject correctionsObj) {
281 MeasurementCorrections_Aidl measurementCorrections_aidl;
282 if (!MeasurementCorrectionsUtil::translateMeasurementCorrections<
283 MeasurementCorrections_Aidl>(env, correctionsObj, measurementCorrections_aidl)) {
284 ALOGI("Empty correction list injected....Returning with no HAL injection");
285 return JNI_TRUE;
286 }
287 auto status = mIMeasurementCorrectionsAidl->setCorrections(measurementCorrections_aidl);
288 return checkAidlStatus(status, "IMeasurementCorrectionsAidl setCorrections() failed");
289 }
290
setCallback(const std::unique_ptr<MeasurementCorrectionsCallback> & callback)291 jboolean MeasurementCorrectionsIface_Aidl::setCallback(
292 const std::unique_ptr<MeasurementCorrectionsCallback>& callback) {
293 auto status = mIMeasurementCorrectionsAidl->setCallback(callback->getAidl());
294 return checkAidlStatus(status, "IMeasurementCorrectionsAidl setCallback() failed.");
295 }
296
297 // Implementation of MeasurementCorrectionsIface_V1_0
298
MeasurementCorrectionsIface_V1_0(const sp<IMeasurementCorrections_V1_0> & iMeasurementCorrections)299 MeasurementCorrectionsIface_V1_0::MeasurementCorrectionsIface_V1_0(
300 const sp<IMeasurementCorrections_V1_0>& iMeasurementCorrections)
301 : mIMeasurementCorrections_V1_0(iMeasurementCorrections) {
302 assert(mIMeasurementCorrections_V1_0 != nullptr);
303 }
304
setCorrections(JNIEnv * env,jobject correctionsObj)305 jboolean MeasurementCorrectionsIface_V1_0::setCorrections(JNIEnv* env, jobject correctionsObj) {
306 MeasurementCorrections_V1_0 measurementCorrections_1_0;
307 if (!MeasurementCorrectionsUtil::translateMeasurementCorrections<
308 MeasurementCorrections_V1_0>(env, correctionsObj, measurementCorrections_1_0)) {
309 ALOGI("Empty correction list injected....Returning with no HAL injection");
310 return JNI_TRUE;
311 }
312 auto result = mIMeasurementCorrections_V1_0->setCorrections(measurementCorrections_1_0);
313 return checkHidlReturn(result, "IMeasurementCorrections 1.0 setCorrections() failed.");
314 }
315
setCallback(const std::unique_ptr<MeasurementCorrectionsCallback> & callback)316 jboolean MeasurementCorrectionsIface_V1_0::setCallback(
317 const std::unique_ptr<MeasurementCorrectionsCallback>& callback) {
318 auto result = mIMeasurementCorrections_V1_0->setCallback(callback->getHidl());
319 return checkHidlReturn(result, "IMeasurementCorrections_V1_0 setCallback() failed.");
320 }
321
322 // Implementation of MeasurementCorrectionsIface_V1_1
323
MeasurementCorrectionsIface_V1_1(const sp<IMeasurementCorrections_V1_1> & iMeasurementCorrections)324 MeasurementCorrectionsIface_V1_1::MeasurementCorrectionsIface_V1_1(
325 const sp<IMeasurementCorrections_V1_1>& iMeasurementCorrections)
326 : mIMeasurementCorrections_V1_1(iMeasurementCorrections) {
327 assert(mIMeasurementCorrections_V1_1 != nullptr);
328 }
329
setCorrections(JNIEnv * env,jobject correctionsObj)330 jboolean MeasurementCorrectionsIface_V1_1::setCorrections(JNIEnv* env, jobject correctionsObj) {
331 MeasurementCorrections_V1_1 measurementCorrections_1_1;
332 if (!MeasurementCorrectionsUtil::translateMeasurementCorrections<
333 MeasurementCorrections_V1_1>(env, correctionsObj, measurementCorrections_1_1)) {
334 ALOGI("Empty correction list injected....Returning with no HAL injection");
335 return JNI_TRUE;
336 }
337 auto result = mIMeasurementCorrections_V1_1->setCorrections_1_1(measurementCorrections_1_1);
338 return checkHidlReturn(result, "IMeasurementCorrections 1.1 setCorrections() failed.");
339 }
340
setCallback(const std::unique_ptr<MeasurementCorrectionsCallback> & callback)341 jboolean MeasurementCorrectionsIface_V1_1::setCallback(
342 const std::unique_ptr<MeasurementCorrectionsCallback>& callback) {
343 auto result = mIMeasurementCorrections_V1_1->setCallback(callback->getHidl());
344 return checkHidlReturn(result, "IMeasurementCorrections_V1_1 setCallback() failed.");
345 }
346
347 SingleSatCorrection_V1_0
getSingleSatCorrection_1_0_withoutConstellation(JNIEnv * env,jobject singleSatCorrectionObj)348 MeasurementCorrectionsUtil::getSingleSatCorrection_1_0_withoutConstellation(
349 JNIEnv* env, jobject singleSatCorrectionObj) {
350 uint16_t corrFlags = static_cast<uint16_t>(
351 env->CallIntMethod(singleSatCorrectionObj, method_correctionSatFlags));
352 jint satId = env->CallIntMethod(singleSatCorrectionObj, method_correctionSatId);
353 jfloat carrierFreqHz =
354 env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatCarrierFreq);
355 jfloat probSatIsLos =
356 env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatIsLosProb);
357 jfloat eplMeters = env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatEpl);
358 jfloat eplUncMeters = env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatEplUnc);
359
360 ReflectingPlane_V1_0 reflectingPlane;
361 if ((corrFlags & GnssSingleSatCorrectionFlags_V1_0::HAS_REFLECTING_PLANE) != 0) {
362 jobject reflectingPlaneObj =
363 env->CallObjectMethod(singleSatCorrectionObj, method_correctionSatRefPlane);
364 MeasurementCorrectionsUtil::setReflectingPlane<ReflectingPlane_V1_0>(env,
365 reflectingPlaneObj,
366 reflectingPlane);
367 env->DeleteLocalRef(reflectingPlaneObj);
368 }
369 SingleSatCorrection_V1_0 singleSatCorrection = {
370 .singleSatCorrectionFlags = corrFlags,
371 .svid = static_cast<uint16_t>(satId),
372 .carrierFrequencyHz = carrierFreqHz,
373 .probSatIsLos = probSatIsLos,
374 .excessPathLengthMeters = eplMeters,
375 .excessPathLengthUncertaintyMeters = eplUncMeters,
376 .reflectingPlane = reflectingPlane,
377 };
378 return singleSatCorrection;
379 }
380
getSingleSatCorrection_Aidl(JNIEnv * env,jobject singleSatCorrectionObj)381 SingleSatCorrection_Aidl MeasurementCorrectionsUtil::getSingleSatCorrection_Aidl(
382 JNIEnv* env, jobject singleSatCorrectionObj) {
383 int32_t corrFlags = static_cast<int32_t>(
384 env->CallIntMethod(singleSatCorrectionObj, method_correctionSatFlags));
385 jint constType = env->CallIntMethod(singleSatCorrectionObj, method_correctionSatConstType);
386 jint satId = env->CallIntMethod(singleSatCorrectionObj, method_correctionSatId);
387 jfloat carrierFreqHz =
388 env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatCarrierFreq);
389 jfloat probSatIsLos =
390 env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatIsLosProb);
391 jfloat eplMeters = env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatEpl);
392 jfloat eplUncMeters = env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatEplUnc);
393 jfloat attenuationDb =
394 env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatAttenuation);
395 std::vector<ExcessPathInfo> excessPathInfos =
396 MeasurementCorrectionsUtil::getExcessPathInfoList(env, singleSatCorrectionObj);
397
398 SingleSatCorrection_Aidl singleSatCorrection;
399 singleSatCorrection.singleSatCorrectionFlags = corrFlags;
400 singleSatCorrection.constellation = static_cast<GnssConstellationType_Aidl>(constType);
401 singleSatCorrection.svid = static_cast<int32_t>(satId);
402 singleSatCorrection.carrierFrequencyHz = carrierFreqHz;
403 singleSatCorrection.probSatIsLos = probSatIsLos;
404 singleSatCorrection.combinedExcessPathLengthMeters = eplMeters;
405 singleSatCorrection.combinedExcessPathLengthUncertaintyMeters = eplUncMeters;
406 singleSatCorrection.combinedAttenuationDb = attenuationDb;
407 singleSatCorrection.excessPathInfos = excessPathInfos;
408
409 return singleSatCorrection;
410 }
411
getSingleSatCorrectionList_1_0(JNIEnv * env,jobject singleSatCorrectionList,hardware::hidl_vec<SingleSatCorrection_V1_0> & list)412 void MeasurementCorrectionsUtil::getSingleSatCorrectionList_1_0(
413 JNIEnv* env, jobject singleSatCorrectionList,
414 hardware::hidl_vec<SingleSatCorrection_V1_0>& list) {
415 for (uint16_t i = 0; i < list.size(); ++i) {
416 jobject singleSatCorrectionObj =
417 env->CallObjectMethod(singleSatCorrectionList, method_listGet, i);
418 SingleSatCorrection_V1_0 singleSatCorrection =
419 getSingleSatCorrection_1_0_withoutConstellation(env, singleSatCorrectionObj);
420
421 jint constType = env->CallIntMethod(singleSatCorrectionObj, method_correctionSatConstType);
422
423 singleSatCorrection.constellation = static_cast<GnssConstellationType_V1_0>(constType),
424
425 list[i] = singleSatCorrection;
426 env->DeleteLocalRef(singleSatCorrectionObj);
427 }
428 }
429
getSingleSatCorrectionList_1_1(JNIEnv * env,jobject singleSatCorrectionList,hardware::hidl_vec<SingleSatCorrection_V1_1> & list)430 void MeasurementCorrectionsUtil::getSingleSatCorrectionList_1_1(
431 JNIEnv* env, jobject singleSatCorrectionList,
432 hardware::hidl_vec<SingleSatCorrection_V1_1>& list) {
433 for (uint16_t i = 0; i < list.size(); ++i) {
434 jobject singleSatCorrectionObj =
435 env->CallObjectMethod(singleSatCorrectionList, method_listGet, i);
436
437 SingleSatCorrection_V1_0 singleSatCorrection_1_0 =
438 getSingleSatCorrection_1_0_withoutConstellation(env, singleSatCorrectionObj);
439
440 jint constType = env->CallIntMethod(singleSatCorrectionObj, method_correctionSatConstType);
441
442 SingleSatCorrection_V1_1 singleSatCorrection_1_1 = {
443 .v1_0 = singleSatCorrection_1_0,
444 .constellation = static_cast<GnssConstellationType_V2_0>(constType),
445 };
446
447 list[i] = singleSatCorrection_1_1;
448 env->DeleteLocalRef(singleSatCorrectionObj);
449 }
450 }
451
getSingleSatCorrectionList_Aidl(JNIEnv * env,jobject singleSatCorrectionList,std::vector<SingleSatCorrection_Aidl> & list)452 void MeasurementCorrectionsUtil::getSingleSatCorrectionList_Aidl(
453 JNIEnv* env, jobject singleSatCorrectionList, std::vector<SingleSatCorrection_Aidl>& list) {
454 for (uint16_t i = 0; i < list.size(); ++i) {
455 jobject singleSatCorrectionObj =
456 env->CallObjectMethod(singleSatCorrectionList, method_listGet, i);
457
458 SingleSatCorrection_Aidl singleSatCorrection_Aidl =
459 getSingleSatCorrection_Aidl(env, singleSatCorrectionObj);
460
461 list[i] = singleSatCorrection_Aidl;
462 env->DeleteLocalRef(singleSatCorrectionObj);
463 }
464 }
465
466 template <>
setReflectingPlaneAzimuthDegrees(ReflectingPlane_V1_0 & reflectingPlane,double azimuthDegreeRefPlane)467 void MeasurementCorrectionsUtil::setReflectingPlaneAzimuthDegrees<ReflectingPlane_V1_0>(
468 ReflectingPlane_V1_0& reflectingPlane, double azimuthDegreeRefPlane) {
469 reflectingPlane.azimuthDegrees = azimuthDegreeRefPlane;
470 }
471
472 template <>
setReflectingPlaneAzimuthDegrees(ReflectingPlane_Aidl & reflectingPlane,double azimuthDegreeRefPlane)473 void MeasurementCorrectionsUtil::setReflectingPlaneAzimuthDegrees<ReflectingPlane_Aidl>(
474 ReflectingPlane_Aidl& reflectingPlane, double azimuthDegreeRefPlane) {
475 reflectingPlane.reflectingPlaneAzimuthDegrees = azimuthDegreeRefPlane;
476 }
477
getExcessPathInfoList(JNIEnv * env,jobject singleSatCorrectionObj)478 std::vector<ExcessPathInfo> MeasurementCorrectionsUtil::getExcessPathInfoList(
479 JNIEnv* env, jobject singleSatCorrectionObj) {
480 jobject excessPathInfoListObj =
481 env->CallObjectMethod(singleSatCorrectionObj, method_correctionSatExcessPathInfoList);
482
483 int len = env->CallIntMethod(excessPathInfoListObj, method_listSize);
484 std::vector<ExcessPathInfo> list(len);
485 for (int i = 0; i < len; ++i) {
486 jobject excessPathInfoObj = env->CallObjectMethod(excessPathInfoListObj, method_listGet, i);
487 list[i] = getExcessPathInfo(env, excessPathInfoObj);
488 env->DeleteLocalRef(excessPathInfoObj);
489 }
490 env->DeleteLocalRef(excessPathInfoListObj);
491 return list;
492 }
493
getExcessPathInfo(JNIEnv * env,jobject excessPathInfoObj)494 ExcessPathInfo MeasurementCorrectionsUtil::getExcessPathInfo(JNIEnv* env,
495 jobject excessPathInfoObj) {
496 ExcessPathInfo excessPathInfo;
497 jint flags = env->CallIntMethod(excessPathInfoObj, method_excessPathInfoFlags);
498 excessPathInfo.excessPathInfoFlags = flags;
499 if ((flags & ExcessPathInfo::EXCESS_PATH_INFO_HAS_EXCESS_PATH_LENGTH) != 0) {
500 jfloat epl = env->CallFloatMethod(excessPathInfoObj, method_excessPathInfoEpl);
501 excessPathInfo.excessPathLengthMeters = epl;
502 }
503 if ((flags & ExcessPathInfo::EXCESS_PATH_INFO_HAS_EXCESS_PATH_LENGTH_UNC) != 0) {
504 jfloat eplUnc = env->CallFloatMethod(excessPathInfoObj, method_excessPathInfoEplUnc);
505 excessPathInfo.excessPathLengthUncertaintyMeters = eplUnc;
506 }
507 if ((flags & ExcessPathInfo::EXCESS_PATH_INFO_HAS_REFLECTING_PLANE) != 0) {
508 ReflectingPlane_Aidl reflectingPlane;
509 jobject reflectingPlaneObj =
510 env->CallObjectMethod(excessPathInfoObj, method_excessPathInfoRefPlane);
511 MeasurementCorrectionsUtil::setReflectingPlane<ReflectingPlane_Aidl>(env,
512 reflectingPlaneObj,
513 reflectingPlane);
514 env->DeleteLocalRef(reflectingPlaneObj);
515 excessPathInfo.reflectingPlane = reflectingPlane;
516 }
517 if ((flags & ExcessPathInfo::EXCESS_PATH_INFO_HAS_ATTENUATION) != 0) {
518 jfloat attenuation =
519 env->CallFloatMethod(excessPathInfoObj, method_excessPathInfoAttenuation);
520 excessPathInfo.attenuationDb = attenuation;
521 }
522 return excessPathInfo;
523 }
524
525 } // namespace android::gnss
526