Merge "Add MeasurementCorrections AIDL HAL (framework/base)"

This commit is contained in:
Edwin Tung
2022-02-09 07:51:39 +00:00
committed by Android (Google) Code Review
6 changed files with 797 additions and 295 deletions

View File

@@ -36,8 +36,6 @@
#include <android/hardware/gnss/BnGnssMeasurementCallback.h>
#include <android/hardware/gnss/BnGnssPowerIndicationCallback.h>
#include <android/hardware/gnss/BnGnssPsdsCallback.h>
#include <android/hardware/gnss/measurement_corrections/1.0/IMeasurementCorrections.h>
#include <android/hardware/gnss/measurement_corrections/1.1/IMeasurementCorrections.h>
#include <binder/IServiceManager.h>
#include <nativehelper/JNIHelp.h>
#include <pthread.h>
@@ -61,6 +59,7 @@
#include "gnss/GnssMeasurement.h"
#include "gnss/GnssNavigationMessage.h"
#include "gnss/GnssVisibilityControl.h"
#include "gnss/MeasurementCorrections.h"
#include "gnss/Utils.h"
#include "hardware_legacy/power.h"
#include "jni.h"
@@ -82,31 +81,6 @@ static jmethodID method_requestLocation;
static jmethodID method_requestUtcTime;
static jmethodID method_reportGnssServiceDied;
static jmethodID method_reportGnssPowerStats;
static jmethodID method_setSubHalMeasurementCorrectionsCapabilities;
static jmethodID method_correctionsGetLatitudeDegrees;
static jmethodID method_correctionsGetLongitudeDegrees;
static jmethodID method_correctionsGetAltitudeMeters;
static jmethodID method_correctionsGetHorPosUncMeters;
static jmethodID method_correctionsGetVerPosUncMeters;
static jmethodID method_correctionsGetToaGpsNanosecondsOfWeek;
static jmethodID method_correctionsGetSingleSatCorrectionList;
static jmethodID method_correctionsHasEnvironmentBearing;
static jmethodID method_correctionsGetEnvironmentBearingDegrees;
static jmethodID method_correctionsGetEnvironmentBearingUncertaintyDegrees;
static jmethodID method_listSize;
static jmethodID method_correctionListGet;
static jmethodID method_correctionSatFlags;
static jmethodID method_correctionSatConstType;
static jmethodID method_correctionSatId;
static jmethodID method_correctionSatCarrierFreq;
static jmethodID method_correctionSatIsLosProb;
static jmethodID method_correctionSatEpl;
static jmethodID method_correctionSatEplUnc;
static jmethodID method_correctionSatRefPlane;
static jmethodID method_correctionPlaneLatDeg;
static jmethodID method_correctionPlaneLngDeg;
static jmethodID method_correctionPlaneAltDeg;
static jmethodID method_correctionPlaneAzimDeg;
static jmethodID method_reportNfwNotification;
static jmethodID method_isInEmergencySession;
static jmethodID method_gnssPowerStatsCtor;
@@ -135,15 +109,6 @@ using android::hardware::gnss::V1_0::IGnssXtra;
using android::hardware::gnss::V1_0::IGnssXtraCallback;
using android::hardware::gnss::V2_0::ElapsedRealtimeFlags;
using MeasurementCorrections_V1_0 = android::hardware::gnss::measurement_corrections::V1_0::MeasurementCorrections;
using MeasurementCorrections_V1_1 = android::hardware::gnss::measurement_corrections::V1_1::MeasurementCorrections;
using SingleSatCorrection_V1_0 =
android::hardware::gnss::measurement_corrections::V1_0::SingleSatCorrection;
using SingleSatCorrection_V1_1 =
android::hardware::gnss::measurement_corrections::V1_1::SingleSatCorrection;
using android::hardware::gnss::measurement_corrections::V1_0::ReflectingPlane;
using android::hidl::base::V1_0::IBase;
using GnssConstellationType_V1_0 = android::hardware::gnss::V1_0::GnssConstellationType;
@@ -158,11 +123,6 @@ using IGnssCallback_V1_0 = android::hardware::gnss::V1_0::IGnssCallback;
using IGnssCallback_V2_0 = android::hardware::gnss::V2_0::IGnssCallback;
using IGnssCallback_V2_1 = android::hardware::gnss::V2_1::IGnssCallback;
using IMeasurementCorrections_V1_0 = android::hardware::gnss::measurement_corrections::V1_0::IMeasurementCorrections;
using IMeasurementCorrections_V1_1 = android::hardware::gnss::measurement_corrections::V1_1::IMeasurementCorrections;
using android::hardware::gnss::measurement_corrections::V1_0::IMeasurementCorrectionsCallback;
using android::hardware::gnss::measurement_corrections::V1_0::GnssSingleSatCorrectionFlags;
using android::hardware::gnss::BlocklistedSource;
using android::hardware::gnss::GnssConstellationType;
using android::hardware::gnss::GnssPowerStats;
@@ -207,8 +167,6 @@ sp<IGnssPsdsAidl> gnssPsdsAidlIface = nullptr;
sp<IGnssXtra> gnssXtraIface = nullptr;
sp<IGnssNi> gnssNiIface = nullptr;
sp<IGnssPowerIndication> gnssPowerIndicationIface = nullptr;
sp<IMeasurementCorrections_V1_0> gnssCorrectionsIface_V1_0 = nullptr;
sp<IMeasurementCorrections_V1_1> gnssCorrectionsIface_V1_1 = nullptr;
std::unique_ptr<GnssConfigurationInterface> gnssConfigurationIface = nullptr;
std::unique_ptr<android::gnss::GnssMeasurementInterface> gnssMeasurementIface = nullptr;
@@ -220,6 +178,8 @@ std::unique_ptr<android::gnss::GnssDebugInterface> gnssDebugIface = nullptr;
std::unique_ptr<android::gnss::AGnssRilInterface> agnssRilIface = nullptr;
std::unique_ptr<android::gnss::GnssVisibilityControlInterface> gnssVisibilityControlIface = nullptr;
std::unique_ptr<android::gnss::GnssAntennaInfoInterface> gnssAntennaInfoIface = nullptr;
std::unique_ptr<android::gnss::MeasurementCorrectionsInterface> gnssMeasurementCorrectionsIface =
nullptr;
#define WAKE_LOCK_NAME "GPS"
@@ -824,23 +784,6 @@ Return<void> GnssXtraCallback::downloadRequestCb() {
return Void();
}
/*
* MeasurementCorrectionsCallback implements callback methods of interface
* IMeasurementCorrectionsCallback.hal.
*/
struct MeasurementCorrectionsCallback : public IMeasurementCorrectionsCallback {
Return<void> setCapabilitiesCb(uint32_t capabilities) override;
};
Return<void> MeasurementCorrectionsCallback::setCapabilitiesCb(uint32_t capabilities) {
ALOGD("%s: %du\n", __func__, capabilities);
JNIEnv* env = getJniEnv();
env->CallVoidMethod(mCallbacksObj, method_setSubHalMeasurementCorrectionsCapabilities,
capabilities);
checkAndClearExceptionFromCallback(env, __FUNCTION__);
return Void();
}
/*
* GnssNiCallback implements callback methods required by the IGnssNi interface.
*/
@@ -944,63 +887,9 @@ static void android_location_gnss_hal_GnssNative_class_init_once(JNIEnv* env, jc
"(Lcom/android/server/location/gnss/GnssPowerStats;)V");
method_isInEmergencySession = env->GetMethodID(clazz, "isInEmergencySession", "()Z");
method_setSubHalMeasurementCorrectionsCapabilities = env->GetMethodID(clazz,
"setSubHalMeasurementCorrectionsCapabilities", "(I)V");
method_setSubHalPowerIndicationCapabilities =
env->GetMethodID(clazz, "setSubHalPowerIndicationCapabilities", "(I)V");
jclass measCorrClass = env->FindClass("android/location/GnssMeasurementCorrections");
method_correctionsGetLatitudeDegrees = env->GetMethodID(
measCorrClass,"getLatitudeDegrees", "()D");
method_correctionsGetLongitudeDegrees = env->GetMethodID(
measCorrClass, "getLongitudeDegrees", "()D");
method_correctionsGetAltitudeMeters = env->GetMethodID(
measCorrClass, "getAltitudeMeters", "()D");
method_correctionsGetHorPosUncMeters = env->GetMethodID(
measCorrClass, "getHorizontalPositionUncertaintyMeters", "()D");
method_correctionsGetVerPosUncMeters = env->GetMethodID(
measCorrClass, "getVerticalPositionUncertaintyMeters", "()D");
method_correctionsGetToaGpsNanosecondsOfWeek = env->GetMethodID(
measCorrClass, "getToaGpsNanosecondsOfWeek", "()J");
method_correctionsGetSingleSatCorrectionList = env->GetMethodID(
measCorrClass, "getSingleSatelliteCorrectionList", "()Ljava/util/List;");
method_correctionsHasEnvironmentBearing = env->GetMethodID(
measCorrClass, "hasEnvironmentBearing", "()Z");
method_correctionsGetEnvironmentBearingDegrees = env->GetMethodID(
measCorrClass, "getEnvironmentBearingDegrees", "()F");
method_correctionsGetEnvironmentBearingUncertaintyDegrees = env->GetMethodID(
measCorrClass, "getEnvironmentBearingUncertaintyDegrees", "()F");
jclass corrListClass = env->FindClass("java/util/List");
method_listSize = env->GetMethodID(corrListClass, "size", "()I");
method_correctionListGet = env->GetMethodID(corrListClass, "get", "(I)Ljava/lang/Object;");
jclass singleSatCorrClass = env->FindClass("android/location/GnssSingleSatCorrection");
method_correctionSatFlags = env->GetMethodID(
singleSatCorrClass, "getSingleSatelliteCorrectionFlags", "()I");
method_correctionSatConstType = env->GetMethodID(
singleSatCorrClass, "getConstellationType", "()I");
method_correctionSatId= env->GetMethodID(
singleSatCorrClass, "getSatelliteId", "()I");
method_correctionSatCarrierFreq = env->GetMethodID(
singleSatCorrClass, "getCarrierFrequencyHz", "()F");
method_correctionSatIsLosProb = env->GetMethodID(
singleSatCorrClass,"getProbabilityLineOfSight", "()F");
method_correctionSatEpl = env->GetMethodID(
singleSatCorrClass, "getExcessPathLengthMeters", "()F");
method_correctionSatEplUnc = env->GetMethodID(
singleSatCorrClass, "getExcessPathLengthUncertaintyMeters", "()F");
method_correctionSatRefPlane = env->GetMethodID(
singleSatCorrClass, "getReflectingPlane", "()Landroid/location/GnssReflectingPlane;");
jclass refPlaneClass = env->FindClass("android/location/GnssReflectingPlane");
method_correctionPlaneLatDeg = env->GetMethodID(refPlaneClass, "getLatitudeDegrees", "()D");
method_correctionPlaneLngDeg = env->GetMethodID(refPlaneClass, "getLongitudeDegrees", "()D");
method_correctionPlaneAltDeg = env->GetMethodID(refPlaneClass, "getAltitudeMeters", "()D");
method_correctionPlaneAzimDeg = env->GetMethodID(refPlaneClass, "getAzimuthDegrees", "()D");
jclass gnssPowerStatsClass = env->FindClass("com/android/server/location/gnss/GnssPowerStats");
class_gnssPowerStats = (jclass)env->NewGlobalRef(gnssPowerStatsClass);
method_gnssPowerStatsCtor = env->GetMethodID(class_gnssPowerStats, "<init>", "(IJDDDDDD[D)V");
@@ -1012,6 +901,8 @@ static void android_location_gnss_hal_GnssNative_class_init_once(JNIEnv* env, jc
gnss::GnssMeasurement_class_init_once(env, clazz);
gnss::GnssNavigationMessage_class_init_once(env, clazz);
gnss::GnssVisibilityControl_class_init_once(env, clazz);
gnss::MeasurementCorrections_class_init_once(env, clazz);
gnss::MeasurementCorrectionsCallback_class_init_once(env, clazz);
gnss::AGnss_class_init_once(env, clazz);
gnss::AGnssRil_class_init_once(env, clazz);
gnss::Utils_class_init_once(env);
@@ -1180,20 +1071,34 @@ static void android_location_gnss_hal_GnssNative_init_once(JNIEnv* env, jobject
}
}
if (gnssHal_V2_1 != nullptr) {
auto gnssCorrections = gnssHal_V2_1->getExtensionMeasurementCorrections_1_1();
if (!gnssCorrections.isOk()) {
ALOGD("Unable to get a handle to GnssMeasurementCorrections 1.1 interface");
} else {
gnssCorrectionsIface_V1_1 = gnssCorrections;
gnssCorrectionsIface_V1_0 = gnssCorrectionsIface_V1_1;
if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
sp<android::hardware::gnss::measurement_corrections::IMeasurementCorrectionsInterface>
gnssMeasurementCorrectionsAidl;
auto status =
gnssHalAidl->getExtensionMeasurementCorrections(&gnssMeasurementCorrectionsAidl);
if (checkAidlStatus(status,
"Unable to get a handle to GnssVisibilityControl AIDL interface.")) {
gnssMeasurementCorrectionsIface =
std::make_unique<gnss::MeasurementCorrectionsIface_Aidl>(
gnssMeasurementCorrectionsAidl);
}
} else if (gnssHal_V2_0 != nullptr) {
}
if (gnssHal_V2_1 != nullptr && gnssMeasurementCorrectionsIface == nullptr) {
auto gnssCorrections = gnssHal_V2_1->getExtensionMeasurementCorrections_1_1();
if (checkHidlReturn(gnssCorrections,
"Unable to get a handle to GnssMeasurementCorrections HIDL "
"interface")) {
gnssMeasurementCorrectionsIface =
std::make_unique<gnss::MeasurementCorrectionsIface_V1_1>(gnssCorrections);
}
}
if (gnssHal_V2_0 != nullptr && gnssMeasurementCorrectionsIface == nullptr) {
auto gnssCorrections = gnssHal_V2_0->getExtensionMeasurementCorrections();
if (!gnssCorrections.isOk()) {
ALOGD("Unable to get a handle to GnssMeasurementCorrections interface");
} else {
gnssCorrectionsIface_V1_0 = gnssCorrections;
if (checkHidlReturn(gnssCorrections,
"Unable to get a handle to GnssMeasurementCorrections HIDL "
"interface")) {
gnssMeasurementCorrectionsIface =
std::make_unique<gnss::MeasurementCorrectionsIface_V1_0>(gnssCorrections);
}
}
@@ -1447,19 +1352,11 @@ static jboolean android_location_gnss_hal_GnssNative_init(JNIEnv* /* env */, jcl
ALOGI("Unable to initialize IGnssVisibilityControl interface.");
}
// Set IMeasurementCorrections.hal callback.
if (gnssCorrectionsIface_V1_1 != nullptr) {
sp<IMeasurementCorrectionsCallback> gnssCorrectionsIfaceCbIface =
new MeasurementCorrectionsCallback();
auto result = gnssCorrectionsIface_V1_1->setCallback(gnssCorrectionsIfaceCbIface);
checkHidlReturn(result, "IMeasurementCorrections 1.1 setCallback() failed.");
} else if (gnssCorrectionsIface_V1_0 != nullptr) {
sp<IMeasurementCorrectionsCallback> gnssCorrectionsIfaceCbIface =
new MeasurementCorrectionsCallback();
auto result = gnssCorrectionsIface_V1_0->setCallback(gnssCorrectionsIfaceCbIface);
checkHidlReturn(result, "IMeasurementCorrections 1.0 setCallback() failed.");
} else {
ALOGI("Unable to find IMeasurementCorrections.");
// Set IMeasurementCorrection callback.
if (gnssMeasurementCorrectionsIface == nullptr ||
!gnssMeasurementCorrectionsIface->setCallback(
std::make_unique<gnss::MeasurementCorrectionsCallback>())) {
ALOGI("Unable to initialize IGnssMeasurementCorrections interface.");
}
// Set IGnssPowerIndication.hal callback.
@@ -1990,174 +1887,21 @@ static jboolean android_location_gnss_hal_GnssNative_stop_measurement_collection
static jboolean android_location_gnss_hal_GnssNative_is_measurement_corrections_supported(
JNIEnv* env, jclass) {
if (gnssCorrectionsIface_V1_0 != nullptr || gnssCorrectionsIface_V1_1 != nullptr) {
if (gnssMeasurementCorrectionsIface != nullptr) {
return JNI_TRUE;
}
return JNI_FALSE;
}
static SingleSatCorrection_V1_0 getSingleSatCorrection_1_0_withoutConstellation(
JNIEnv* env, jobject singleSatCorrectionObj) {
jint correctionFlags = env->CallIntMethod(singleSatCorrectionObj, method_correctionSatFlags);
jint satId = env->CallIntMethod(singleSatCorrectionObj, method_correctionSatId);
jfloat carrierFreqHz =
env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatCarrierFreq);
jfloat probSatIsLos =
env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatIsLosProb);
jfloat eplMeters = env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatEpl);
jfloat eplUncMeters = env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatEplUnc);
uint16_t corrFlags = static_cast<uint16_t>(correctionFlags);
jobject reflectingPlaneObj = nullptr;
bool has_ref_plane = (corrFlags & GnssSingleSatCorrectionFlags::HAS_REFLECTING_PLANE) != 0;
if (has_ref_plane) {
reflectingPlaneObj =
env->CallObjectMethod(singleSatCorrectionObj, method_correctionSatRefPlane);
}
ReflectingPlane reflectingPlane;
if (has_ref_plane) {
jdouble latitudeDegreesRefPlane =
env->CallDoubleMethod(reflectingPlaneObj, method_correctionPlaneLatDeg);
jdouble longitudeDegreesRefPlane =
env->CallDoubleMethod(reflectingPlaneObj, method_correctionPlaneLngDeg);
jdouble altitudeDegreesRefPlane =
env->CallDoubleMethod(reflectingPlaneObj, method_correctionPlaneAltDeg);
jdouble azimuthDegreeRefPlane =
env->CallDoubleMethod(reflectingPlaneObj, method_correctionPlaneAzimDeg);
reflectingPlane = {
.latitudeDegrees = latitudeDegreesRefPlane,
.longitudeDegrees = longitudeDegreesRefPlane,
.altitudeMeters = altitudeDegreesRefPlane,
.azimuthDegrees = azimuthDegreeRefPlane,
};
}
env->DeleteLocalRef(reflectingPlaneObj);
SingleSatCorrection_V1_0 singleSatCorrection = {
.singleSatCorrectionFlags = corrFlags,
.svid = static_cast<uint16_t>(satId),
.carrierFrequencyHz = carrierFreqHz,
.probSatIsLos = probSatIsLos,
.excessPathLengthMeters = eplMeters,
.excessPathLengthUncertaintyMeters = eplUncMeters,
.reflectingPlane = reflectingPlane,
};
return singleSatCorrection;
}
static void getSingleSatCorrectionList_1_1(JNIEnv* env, jobject singleSatCorrectionList,
hidl_vec<SingleSatCorrection_V1_1>& list) {
for (uint16_t i = 0; i < list.size(); ++i) {
jobject singleSatCorrectionObj =
env->CallObjectMethod(singleSatCorrectionList, method_correctionListGet, i);
SingleSatCorrection_V1_0 singleSatCorrection_1_0 =
getSingleSatCorrection_1_0_withoutConstellation(env, singleSatCorrectionObj);
jint constType = env->CallIntMethod(singleSatCorrectionObj, method_correctionSatConstType);
SingleSatCorrection_V1_1 singleSatCorrection_1_1 = {
.v1_0 = singleSatCorrection_1_0,
.constellation = static_cast<GnssConstellationType_V2_0>(constType),
};
list[i] = singleSatCorrection_1_1;
env->DeleteLocalRef(singleSatCorrectionObj);
}
}
static void getSingleSatCorrectionList_1_0(JNIEnv* env, jobject singleSatCorrectionList,
hidl_vec<SingleSatCorrection_V1_0>& list) {
for (uint16_t i = 0; i < list.size(); ++i) {
jobject singleSatCorrectionObj =
env->CallObjectMethod(singleSatCorrectionList, method_correctionListGet, i);
SingleSatCorrection_V1_0 singleSatCorrection =
getSingleSatCorrection_1_0_withoutConstellation(env, singleSatCorrectionObj);
jint constType = env->CallIntMethod(singleSatCorrectionObj, method_correctionSatConstType);
singleSatCorrection.constellation = static_cast<GnssConstellationType_V1_0>(constType),
list[i] = singleSatCorrection;
env->DeleteLocalRef(singleSatCorrectionObj);
}
}
static jboolean android_location_gnss_hal_GnssNative_inject_measurement_corrections(
JNIEnv* env, jclass, jobject correctionsObj) {
if (gnssCorrectionsIface_V1_0 == nullptr && gnssCorrectionsIface_V1_1 == nullptr) {
if (gnssMeasurementCorrectionsIface == nullptr) {
ALOGW("Trying to inject GNSS measurement corrections on a chipset that does not"
" support them.");
return JNI_FALSE;
}
jobject singleSatCorrectionList = env->CallObjectMethod(correctionsObj,
method_correctionsGetSingleSatCorrectionList);
auto len = (singleSatCorrectionList == nullptr)
? 0
: env->CallIntMethod(singleSatCorrectionList, method_listSize);
if (len == 0) {
ALOGI("Empty correction list injected....Returning with no HAL injection");
return JNI_TRUE;
}
jdouble latitudeDegreesCorr = env->CallDoubleMethod(
correctionsObj, method_correctionsGetLatitudeDegrees);
jdouble longitudeDegreesCorr = env->CallDoubleMethod(
correctionsObj, method_correctionsGetLongitudeDegrees);
jdouble altitudeDegreesCorr = env->CallDoubleMethod(
correctionsObj, method_correctionsGetAltitudeMeters);
jdouble horizontalPositionUncertaintyMeters = env->CallDoubleMethod(
correctionsObj, method_correctionsGetHorPosUncMeters);
jdouble verticalPositionUncertaintyMeters = env->CallDoubleMethod(
correctionsObj, method_correctionsGetVerPosUncMeters);
jlong toaGpsNanosOfWeek = env->CallLongMethod(
correctionsObj, method_correctionsGetToaGpsNanosecondsOfWeek);
MeasurementCorrections_V1_0 measurementCorrections_1_0 = {
.latitudeDegrees = latitudeDegreesCorr,
.longitudeDegrees = longitudeDegreesCorr,
.altitudeMeters = altitudeDegreesCorr,
.horizontalPositionUncertaintyMeters = horizontalPositionUncertaintyMeters,
.verticalPositionUncertaintyMeters = verticalPositionUncertaintyMeters,
.toaGpsNanosecondsOfWeek = static_cast<uint64_t>(toaGpsNanosOfWeek),
};
if (gnssCorrectionsIface_V1_1 != nullptr) {
jboolean hasEnvironmentBearingCorr = env->CallBooleanMethod(
correctionsObj, method_correctionsHasEnvironmentBearing);
jfloat environmentBearingDegreesCorr = env->CallFloatMethod(
correctionsObj, method_correctionsGetEnvironmentBearingDegrees);
jfloat environmentBearingUncertaintyDegreesCorr = env->CallFloatMethod(
correctionsObj, method_correctionsGetEnvironmentBearingUncertaintyDegrees);
hidl_vec<SingleSatCorrection_V1_1> list(len);
getSingleSatCorrectionList_1_1(env, singleSatCorrectionList, list);
MeasurementCorrections_V1_1 measurementCorrections_1_1 = {
.v1_0 = measurementCorrections_1_0,
.hasEnvironmentBearing = static_cast<bool>(hasEnvironmentBearingCorr),
.environmentBearingDegrees = environmentBearingDegreesCorr,
.environmentBearingUncertaintyDegrees = environmentBearingUncertaintyDegreesCorr,
.satCorrections = list,
};
auto result = gnssCorrectionsIface_V1_1->setCorrections_1_1(measurementCorrections_1_1);
return checkHidlReturn(result, "IMeasurementCorrections 1.1 setCorrections() failed.");
}
hidl_vec<SingleSatCorrection_V1_0> list(len);
getSingleSatCorrectionList_1_0(env, singleSatCorrectionList, list);
env->DeleteLocalRef(singleSatCorrectionList);
measurementCorrections_1_0.satCorrections = list;
auto result = gnssCorrectionsIface_V1_0->setCorrections(measurementCorrections_1_0);
return checkHidlReturn(result, "IMeasurementCorrections 1.0 setCorrections() failed.");
return gnssMeasurementCorrectionsIface->setCorrections(env, correctionsObj);
}
static jboolean android_location_gnss_hal_GnssNative_is_navigation_message_supported(JNIEnv* env,

View File

@@ -41,6 +41,8 @@ cc_library_shared {
"GnssNavigationMessageCallback.cpp",
"GnssVisibilityControl.cpp",
"GnssVisibilityControlCallback.cpp",
"MeasurementCorrections.cpp",
"MeasurementCorrectionsCallback.cpp",
"Utils.cpp",
],
}

View File

@@ -0,0 +1,444 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Define LOG_TAG before <log/log.h> to overwrite the default value.
#define LOG_TAG "MeasurementCorrectionsJni"
#include "MeasurementCorrections.h"
#include "Utils.h"
using IMeasurementCorrections_V1_0 =
android::hardware::gnss::measurement_corrections::V1_0::IMeasurementCorrections;
using IMeasurementCorrections_V1_1 =
android::hardware::gnss::measurement_corrections::V1_1::IMeasurementCorrections;
using IMeasurementCorrections_Aidl =
android::hardware::gnss::measurement_corrections::IMeasurementCorrectionsInterface;
using MeasurementCorrections_V1_0 =
android::hardware::gnss::measurement_corrections::V1_0::MeasurementCorrections;
using MeasurementCorrections_V1_1 =
android::hardware::gnss::measurement_corrections::V1_1::MeasurementCorrections;
using MeasurementCorrections_Aidl =
android::hardware::gnss::measurement_corrections::MeasurementCorrections;
using GnssSingleSatCorrectionFlags_V1_0 =
android::hardware::gnss::measurement_corrections::V1_0::GnssSingleSatCorrectionFlags;
using SingleSatCorrection_V1_0 =
android::hardware::gnss::measurement_corrections::V1_0::SingleSatCorrection;
using SingleSatCorrection_V1_1 =
android::hardware::gnss::measurement_corrections::V1_1::SingleSatCorrection;
using SingleSatCorrection_Aidl =
android::hardware::gnss::measurement_corrections::SingleSatCorrection;
using ReflectingPlane_V1_0 =
android::hardware::gnss::measurement_corrections::V1_0::ReflectingPlane;
using ReflectingPlane_Aidl = android::hardware::gnss::measurement_corrections::ReflectingPlane;
using GnssConstellationType_V1_0 = android::hardware::gnss::V1_0::GnssConstellationType;
using GnssConstellationType_V2_0 = android::hardware::gnss::V2_0::GnssConstellationType;
using GnssConstellationType_Aidl = android::hardware::gnss::GnssConstellationType;
namespace android::gnss {
namespace {
jmethodID method_correctionsGetLatitudeDegrees;
jmethodID method_correctionsGetLongitudeDegrees;
jmethodID method_correctionsGetAltitudeMeters;
jmethodID method_correctionsGetHorPosUncMeters;
jmethodID method_correctionsGetVerPosUncMeters;
jmethodID method_correctionsGetToaGpsNanosecondsOfWeek;
jmethodID method_correctionsGetSingleSatCorrectionList;
jmethodID method_correctionsHasEnvironmentBearing;
jmethodID method_correctionsGetEnvironmentBearingDegrees;
jmethodID method_correctionsGetEnvironmentBearingUncertaintyDegrees;
jmethodID method_listSize;
jmethodID method_correctionListGet;
jmethodID method_correctionSatFlags;
jmethodID method_correctionSatConstType;
jmethodID method_correctionSatId;
jmethodID method_correctionSatCarrierFreq;
jmethodID method_correctionSatIsLosProb;
jmethodID method_correctionSatEpl;
jmethodID method_correctionSatEplUnc;
jmethodID method_correctionSatRefPlane;
jmethodID method_correctionPlaneLatDeg;
jmethodID method_correctionPlaneLngDeg;
jmethodID method_correctionPlaneAltDeg;
jmethodID method_correctionPlaneAzimDeg;
} // anonymous namespace
void MeasurementCorrections_class_init_once(JNIEnv* env, jclass clazz) {
jclass measCorrClass = env->FindClass("android/location/GnssMeasurementCorrections");
method_correctionsGetLatitudeDegrees =
env->GetMethodID(measCorrClass, "getLatitudeDegrees", "()D");
method_correctionsGetLongitudeDegrees =
env->GetMethodID(measCorrClass, "getLongitudeDegrees", "()D");
method_correctionsGetAltitudeMeters =
env->GetMethodID(measCorrClass, "getAltitudeMeters", "()D");
method_correctionsGetHorPosUncMeters =
env->GetMethodID(measCorrClass, "getHorizontalPositionUncertaintyMeters", "()D");
method_correctionsGetVerPosUncMeters =
env->GetMethodID(measCorrClass, "getVerticalPositionUncertaintyMeters", "()D");
method_correctionsGetToaGpsNanosecondsOfWeek =
env->GetMethodID(measCorrClass, "getToaGpsNanosecondsOfWeek", "()J");
method_correctionsGetSingleSatCorrectionList =
env->GetMethodID(measCorrClass, "getSingleSatelliteCorrectionList",
"()Ljava/util/List;");
method_correctionsHasEnvironmentBearing =
env->GetMethodID(measCorrClass, "hasEnvironmentBearing", "()Z");
method_correctionsGetEnvironmentBearingDegrees =
env->GetMethodID(measCorrClass, "getEnvironmentBearingDegrees", "()F");
method_correctionsGetEnvironmentBearingUncertaintyDegrees =
env->GetMethodID(measCorrClass, "getEnvironmentBearingUncertaintyDegrees", "()F");
jclass corrListClass = env->FindClass("java/util/List");
method_listSize = env->GetMethodID(corrListClass, "size", "()I");
method_correctionListGet = env->GetMethodID(corrListClass, "get", "(I)Ljava/lang/Object;");
jclass singleSatCorrClass = env->FindClass("android/location/GnssSingleSatCorrection");
method_correctionSatFlags =
env->GetMethodID(singleSatCorrClass, "getSingleSatelliteCorrectionFlags", "()I");
method_correctionSatConstType =
env->GetMethodID(singleSatCorrClass, "getConstellationType", "()I");
method_correctionSatId = env->GetMethodID(singleSatCorrClass, "getSatelliteId", "()I");
method_correctionSatCarrierFreq =
env->GetMethodID(singleSatCorrClass, "getCarrierFrequencyHz", "()F");
method_correctionSatIsLosProb =
env->GetMethodID(singleSatCorrClass, "getProbabilityLineOfSight", "()F");
method_correctionSatEpl =
env->GetMethodID(singleSatCorrClass, "getExcessPathLengthMeters", "()F");
method_correctionSatEplUnc =
env->GetMethodID(singleSatCorrClass, "getExcessPathLengthUncertaintyMeters", "()F");
method_correctionSatRefPlane = env->GetMethodID(singleSatCorrClass, "getReflectingPlane",
"()Landroid/location/GnssReflectingPlane;");
jclass refPlaneClass = env->FindClass("android/location/GnssReflectingPlane");
method_correctionPlaneLatDeg = env->GetMethodID(refPlaneClass, "getLatitudeDegrees", "()D");
method_correctionPlaneLngDeg = env->GetMethodID(refPlaneClass, "getLongitudeDegrees", "()D");
method_correctionPlaneAltDeg = env->GetMethodID(refPlaneClass, "getAltitudeMeters", "()D");
method_correctionPlaneAzimDeg = env->GetMethodID(refPlaneClass, "getAzimuthDegrees", "()D");
}
template <>
bool MeasurementCorrectionsUtil::translateMeasurementCorrections(
JNIEnv* env, jobject correctionsObj, MeasurementCorrections_V1_0& corrections) {
jobject singleSatCorrectionList =
env->CallObjectMethod(correctionsObj, method_correctionsGetSingleSatCorrectionList);
if (singleSatCorrectionList == nullptr) return false;
auto len = env->CallIntMethod(singleSatCorrectionList, method_listSize);
jdouble latitudeDegreesCorr =
env->CallDoubleMethod(correctionsObj, method_correctionsGetLatitudeDegrees);
jdouble longitudeDegreesCorr =
env->CallDoubleMethod(correctionsObj, method_correctionsGetLongitudeDegrees);
jdouble altitudeDegreesCorr =
env->CallDoubleMethod(correctionsObj, method_correctionsGetAltitudeMeters);
jdouble horizontalPositionUncertaintyMeters =
env->CallDoubleMethod(correctionsObj, method_correctionsGetHorPosUncMeters);
jdouble verticalPositionUncertaintyMeters =
env->CallDoubleMethod(correctionsObj, method_correctionsGetVerPosUncMeters);
jlong toaGpsNanosOfWeek =
env->CallLongMethod(correctionsObj, method_correctionsGetToaGpsNanosecondsOfWeek);
corrections.latitudeDegrees = latitudeDegreesCorr;
corrections.longitudeDegrees = longitudeDegreesCorr;
corrections.altitudeMeters = altitudeDegreesCorr;
corrections.horizontalPositionUncertaintyMeters = horizontalPositionUncertaintyMeters;
corrections.verticalPositionUncertaintyMeters = verticalPositionUncertaintyMeters;
corrections.toaGpsNanosecondsOfWeek = static_cast<uint64_t>(toaGpsNanosOfWeek);
hardware::hidl_vec<SingleSatCorrection_V1_0> list(len);
MeasurementCorrectionsUtil::getSingleSatCorrectionList_1_0(env, singleSatCorrectionList, list);
env->DeleteLocalRef(singleSatCorrectionList);
corrections.satCorrections = list;
return true;
}
template <>
bool MeasurementCorrectionsUtil::translateMeasurementCorrections(
JNIEnv* env, jobject correctionsObj, MeasurementCorrections_V1_1& corrections) {
jobject singleSatCorrectionList =
env->CallObjectMethod(correctionsObj, method_correctionsGetSingleSatCorrectionList);
if (singleSatCorrectionList == nullptr) return false;
auto len = env->CallIntMethod(singleSatCorrectionList, method_listSize);
MeasurementCorrections_V1_0 measurementCorrections_1_0;
translateMeasurementCorrections<MeasurementCorrections_V1_0>(env, correctionsObj,
measurementCorrections_1_0);
measurementCorrections_1_0.satCorrections.resize(0);
jboolean hasEnvironmentBearingCorr =
env->CallBooleanMethod(correctionsObj, method_correctionsHasEnvironmentBearing);
jfloat environmentBearingDegreesCorr =
env->CallFloatMethod(correctionsObj, method_correctionsGetEnvironmentBearingDegrees);
jfloat environmentBearingUncertaintyDegreesCorr =
env->CallFloatMethod(correctionsObj,
method_correctionsGetEnvironmentBearingUncertaintyDegrees);
hardware::hidl_vec<SingleSatCorrection_V1_1> list(len);
MeasurementCorrectionsUtil::getSingleSatCorrectionList_1_1(env, singleSatCorrectionList, list);
env->DeleteLocalRef(singleSatCorrectionList);
corrections.v1_0 = measurementCorrections_1_0;
corrections.hasEnvironmentBearing = static_cast<bool>(hasEnvironmentBearingCorr);
corrections.environmentBearingDegrees = environmentBearingDegreesCorr;
corrections.environmentBearingUncertaintyDegrees = environmentBearingUncertaintyDegreesCorr;
corrections.satCorrections = list;
return true;
}
template <>
bool MeasurementCorrectionsUtil::translateMeasurementCorrections(
JNIEnv* env, jobject correctionsObj, MeasurementCorrections_Aidl& corrections) {
jobject singleSatCorrectionList =
env->CallObjectMethod(correctionsObj, method_correctionsGetSingleSatCorrectionList);
if (singleSatCorrectionList == nullptr) return false;
auto len = env->CallIntMethod(singleSatCorrectionList, method_listSize);
jdouble latitudeDegreesCorr =
env->CallDoubleMethod(correctionsObj, method_correctionsGetLatitudeDegrees);
jdouble longitudeDegreesCorr =
env->CallDoubleMethod(correctionsObj, method_correctionsGetLongitudeDegrees);
jdouble altitudeDegreesCorr =
env->CallDoubleMethod(correctionsObj, method_correctionsGetAltitudeMeters);
jdouble horizontalPositionUncertaintyMeters =
env->CallDoubleMethod(correctionsObj, method_correctionsGetHorPosUncMeters);
jdouble verticalPositionUncertaintyMeters =
env->CallDoubleMethod(correctionsObj, method_correctionsGetVerPosUncMeters);
jlong toaGpsNanosOfWeek =
env->CallLongMethod(correctionsObj, method_correctionsGetToaGpsNanosecondsOfWeek);
corrections.latitudeDegrees = static_cast<double>(latitudeDegreesCorr);
corrections.longitudeDegrees = static_cast<double>(longitudeDegreesCorr);
corrections.altitudeMeters = static_cast<double>(altitudeDegreesCorr);
corrections.horizontalPositionUncertaintyMeters =
static_cast<double>(horizontalPositionUncertaintyMeters);
corrections.verticalPositionUncertaintyMeters =
static_cast<double>(verticalPositionUncertaintyMeters);
corrections.toaGpsNanosecondsOfWeek = static_cast<int64_t>(toaGpsNanosOfWeek);
jboolean hasEnvironmentBearingCorr =
env->CallBooleanMethod(correctionsObj, method_correctionsHasEnvironmentBearing);
jfloat environmentBearingDegreesCorr =
env->CallFloatMethod(correctionsObj, method_correctionsGetEnvironmentBearingDegrees);
jfloat environmentBearingUncertaintyDegreesCorr =
env->CallFloatMethod(correctionsObj,
method_correctionsGetEnvironmentBearingUncertaintyDegrees);
std::vector<SingleSatCorrection_Aidl> list(len);
MeasurementCorrectionsUtil::getSingleSatCorrectionList_Aidl(env, singleSatCorrectionList, list);
env->DeleteLocalRef(singleSatCorrectionList);
corrections.hasEnvironmentBearing = static_cast<bool>(hasEnvironmentBearingCorr);
corrections.environmentBearingDegrees = environmentBearingDegreesCorr;
corrections.environmentBearingUncertaintyDegrees = environmentBearingUncertaintyDegreesCorr;
corrections.satCorrections = list;
return true;
}
// Implementation of MeasurementCorrections (AIDL HAL)
MeasurementCorrectionsIface_Aidl::MeasurementCorrectionsIface_Aidl(
const sp<IMeasurementCorrections_Aidl>& iMeasurementCorrections)
: mIMeasurementCorrectionsAidl(iMeasurementCorrections) {
assert(mIMeasurementCorrectionsAidl != nullptr);
}
jboolean MeasurementCorrectionsIface_Aidl::setCorrections(JNIEnv* env, jobject correctionsObj) {
MeasurementCorrections_Aidl measurementCorrections_aidl;
if (!MeasurementCorrectionsUtil::translateMeasurementCorrections<
MeasurementCorrections_Aidl>(env, correctionsObj, measurementCorrections_aidl)) {
ALOGI("Empty correction list injected....Returning with no HAL injection");
return JNI_TRUE;
}
auto status = mIMeasurementCorrectionsAidl->setCorrections(measurementCorrections_aidl);
return checkAidlStatus(status, "IMeasurementCorrectionsAidl setCorrections() failed");
}
jboolean MeasurementCorrectionsIface_Aidl::setCallback(
const std::unique_ptr<MeasurementCorrectionsCallback>& callback) {
auto status = mIMeasurementCorrectionsAidl->setCallback(callback->getAidl());
return checkAidlStatus(status, "IMeasurementCorrectionsAidl setCallback() failed.");
}
// Implementation of MeasurementCorrectionsIface_V1_0
MeasurementCorrectionsIface_V1_0::MeasurementCorrectionsIface_V1_0(
const sp<IMeasurementCorrections_V1_0>& iMeasurementCorrections)
: mIMeasurementCorrections_V1_0(iMeasurementCorrections) {
assert(mIMeasurementCorrections_V1_0 != nullptr);
}
jboolean MeasurementCorrectionsIface_V1_0::setCorrections(JNIEnv* env, jobject correctionsObj) {
MeasurementCorrections_V1_0 measurementCorrections_1_0;
if (!MeasurementCorrectionsUtil::translateMeasurementCorrections<
MeasurementCorrections_V1_0>(env, correctionsObj, measurementCorrections_1_0)) {
ALOGI("Empty correction list injected....Returning with no HAL injection");
return JNI_TRUE;
}
auto result = mIMeasurementCorrections_V1_0->setCorrections(measurementCorrections_1_0);
return checkHidlReturn(result, "IMeasurementCorrections 1.0 setCorrections() failed.");
}
jboolean MeasurementCorrectionsIface_V1_0::setCallback(
const std::unique_ptr<MeasurementCorrectionsCallback>& callback) {
auto result = mIMeasurementCorrections_V1_0->setCallback(callback->getHidl());
return checkHidlReturn(result, "IMeasurementCorrections_V1_0 setCallback() failed.");
}
// Implementation of MeasurementCorrectionsIface_V1_1
MeasurementCorrectionsIface_V1_1::MeasurementCorrectionsIface_V1_1(
const sp<IMeasurementCorrections_V1_1>& iMeasurementCorrections)
: mIMeasurementCorrections_V1_1(iMeasurementCorrections) {
assert(mIMeasurementCorrections_V1_1 != nullptr);
}
jboolean MeasurementCorrectionsIface_V1_1::setCorrections(JNIEnv* env, jobject correctionsObj) {
MeasurementCorrections_V1_1 measurementCorrections_1_1;
if (!MeasurementCorrectionsUtil::translateMeasurementCorrections<
MeasurementCorrections_V1_1>(env, correctionsObj, measurementCorrections_1_1)) {
ALOGI("Empty correction list injected....Returning with no HAL injection");
return JNI_TRUE;
}
auto result = mIMeasurementCorrections_V1_1->setCorrections_1_1(measurementCorrections_1_1);
return checkHidlReturn(result, "IMeasurementCorrections 1.1 setCorrections() failed.");
}
jboolean MeasurementCorrectionsIface_V1_1::setCallback(
const std::unique_ptr<MeasurementCorrectionsCallback>& callback) {
auto result = mIMeasurementCorrections_V1_1->setCallback(callback->getHidl());
return checkHidlReturn(result, "IMeasurementCorrections_V1_1 setCallback() failed.");
}
SingleSatCorrection_V1_0
MeasurementCorrectionsUtil::getSingleSatCorrection_1_0_withoutConstellation(
JNIEnv* env, jobject singleSatCorrectionObj) {
jint correctionFlags = env->CallIntMethod(singleSatCorrectionObj, method_correctionSatFlags);
jint satId = env->CallIntMethod(singleSatCorrectionObj, method_correctionSatId);
jfloat carrierFreqHz =
env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatCarrierFreq);
jfloat probSatIsLos =
env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatIsLosProb);
jfloat eplMeters = env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatEpl);
jfloat eplUncMeters = env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatEplUnc);
uint16_t corrFlags = static_cast<uint16_t>(correctionFlags);
ReflectingPlane_V1_0 reflectingPlane;
if ((corrFlags & GnssSingleSatCorrectionFlags_V1_0::HAS_REFLECTING_PLANE) != 0)
MeasurementCorrectionsUtil::getReflectingPlane<ReflectingPlane_V1_0>(env,
singleSatCorrectionObj,
reflectingPlane);
SingleSatCorrection_V1_0 singleSatCorrection = {
.singleSatCorrectionFlags = corrFlags,
.svid = static_cast<uint16_t>(satId),
.carrierFrequencyHz = carrierFreqHz,
.probSatIsLos = probSatIsLos,
.excessPathLengthMeters = eplMeters,
.excessPathLengthUncertaintyMeters = eplUncMeters,
.reflectingPlane = reflectingPlane,
};
return singleSatCorrection;
}
SingleSatCorrection_Aidl MeasurementCorrectionsUtil::getSingleSatCorrection_Aidl(
JNIEnv* env, jobject singleSatCorrectionObj) {
jint correctionFlags = env->CallIntMethod(singleSatCorrectionObj, method_correctionSatFlags);
jint satId = env->CallIntMethod(singleSatCorrectionObj, method_correctionSatId);
jfloat carrierFreqHz =
env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatCarrierFreq);
jfloat probSatIsLos =
env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatIsLosProb);
jfloat eplMeters = env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatEpl);
jfloat eplUncMeters = env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatEplUnc);
int32_t corrFlags = static_cast<int32_t>(correctionFlags);
ReflectingPlane_Aidl reflectingPlane;
if ((corrFlags & SingleSatCorrection_Aidl::SINGLE_SAT_CORRECTION_HAS_REFLECTING_PLANE) != 0)
MeasurementCorrectionsUtil::getReflectingPlane<ReflectingPlane_Aidl>(env,
singleSatCorrectionObj,
reflectingPlane);
jint constType = env->CallIntMethod(singleSatCorrectionObj, method_correctionSatConstType);
SingleSatCorrection_Aidl singleSatCorrection;
singleSatCorrection.singleSatCorrectionFlags = corrFlags;
singleSatCorrection.constellation = static_cast<GnssConstellationType_Aidl>(constType);
singleSatCorrection.svid = static_cast<int32_t>(satId);
singleSatCorrection.carrierFrequencyHz = carrierFreqHz;
singleSatCorrection.probSatIsLos = probSatIsLos;
singleSatCorrection.excessPathLengthMeters = eplMeters;
singleSatCorrection.excessPathLengthUncertaintyMeters = eplUncMeters;
singleSatCorrection.reflectingPlane = reflectingPlane;
return singleSatCorrection;
}
void MeasurementCorrectionsUtil::getSingleSatCorrectionList_1_0(
JNIEnv* env, jobject singleSatCorrectionList,
hardware::hidl_vec<SingleSatCorrection_V1_0>& list) {
for (uint16_t i = 0; i < list.size(); ++i) {
jobject singleSatCorrectionObj =
env->CallObjectMethod(singleSatCorrectionList, method_correctionListGet, i);
SingleSatCorrection_V1_0 singleSatCorrection =
getSingleSatCorrection_1_0_withoutConstellation(env, singleSatCorrectionObj);
jint constType = env->CallIntMethod(singleSatCorrectionObj, method_correctionSatConstType);
singleSatCorrection.constellation = static_cast<GnssConstellationType_V1_0>(constType),
list[i] = singleSatCorrection;
env->DeleteLocalRef(singleSatCorrectionObj);
}
}
void MeasurementCorrectionsUtil::getSingleSatCorrectionList_1_1(
JNIEnv* env, jobject singleSatCorrectionList,
hardware::hidl_vec<SingleSatCorrection_V1_1>& list) {
for (uint16_t i = 0; i < list.size(); ++i) {
jobject singleSatCorrectionObj =
env->CallObjectMethod(singleSatCorrectionList, method_correctionListGet, i);
SingleSatCorrection_V1_0 singleSatCorrection_1_0 =
getSingleSatCorrection_1_0_withoutConstellation(env, singleSatCorrectionObj);
jint constType = env->CallIntMethod(singleSatCorrectionObj, method_correctionSatConstType);
SingleSatCorrection_V1_1 singleSatCorrection_1_1 = {
.v1_0 = singleSatCorrection_1_0,
.constellation = static_cast<GnssConstellationType_V2_0>(constType),
};
list[i] = singleSatCorrection_1_1;
env->DeleteLocalRef(singleSatCorrectionObj);
}
}
void MeasurementCorrectionsUtil::getSingleSatCorrectionList_Aidl(
JNIEnv* env, jobject singleSatCorrectionList, std::vector<SingleSatCorrection_Aidl>& list) {
for (uint16_t i = 0; i < list.size(); ++i) {
jobject singleSatCorrectionObj =
env->CallObjectMethod(singleSatCorrectionList, method_correctionListGet, i);
SingleSatCorrection_Aidl singleSatCorrection_Aidl =
getSingleSatCorrection_Aidl(env, singleSatCorrectionObj);
list[i] = singleSatCorrection_Aidl;
env->DeleteLocalRef(singleSatCorrectionObj);
}
}
} // namespace android::gnss

View File

@@ -0,0 +1,158 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _ANDROID_SERVER_MEASUREMENTCORRECTIONS_H
#define _ANDROID_SERVER_MEASUREMENTCORRECTIONS_H
#pragma once
#ifndef LOG_TAG
#error LOG_TAG must be defined before including this file.
#endif
#include <android/hardware/gnss/measurement_corrections/BnMeasurementCorrectionsInterface.h>
#include <log/log.h>
#include "MeasurementCorrectionsCallback.h"
#include "jni.h"
namespace android::gnss {
namespace {
extern jmethodID method_correctionsGetLatitudeDegrees;
extern jmethodID method_correctionsGetLongitudeDegrees;
extern jmethodID method_correctionsGetAltitudeMeters;
extern jmethodID method_correctionsGetHorPosUncMeters;
extern jmethodID method_correctionsGetVerPosUncMeters;
extern jmethodID method_correctionsGetToaGpsNanosecondsOfWeek;
extern jmethodID method_correctionsGetSingleSatCorrectionList;
extern jmethodID method_correctionsHasEnvironmentBearing;
extern jmethodID method_correctionsGetEnvironmentBearingDegrees;
extern jmethodID method_correctionsGetEnvironmentBearingUncertaintyDegrees;
extern jmethodID method_listSize;
extern jmethodID method_correctionListGet;
extern jmethodID method_correctionSatFlags;
extern jmethodID method_correctionSatConstType;
extern jmethodID method_correctionSatId;
extern jmethodID method_correctionSatCarrierFreq;
extern jmethodID method_correctionSatIsLosProb;
extern jmethodID method_correctionSatEpl;
extern jmethodID method_correctionSatEplUnc;
extern jmethodID method_correctionSatRefPlane;
extern jmethodID method_correctionPlaneLatDeg;
extern jmethodID method_correctionPlaneLngDeg;
extern jmethodID method_correctionPlaneAltDeg;
extern jmethodID method_correctionPlaneAzimDeg;
} // anonymous namespace
void MeasurementCorrections_class_init_once(JNIEnv* env, jclass clazz);
class MeasurementCorrectionsInterface {
public:
virtual ~MeasurementCorrectionsInterface() {}
virtual jboolean setCorrections(JNIEnv* env, jobject correctionsObj) = 0;
virtual jboolean setCallback(
const std::unique_ptr<MeasurementCorrectionsCallback>& callback) = 0;
};
class MeasurementCorrectionsIface_Aidl : public MeasurementCorrectionsInterface {
public:
MeasurementCorrectionsIface_Aidl(
const sp<android::hardware::gnss::measurement_corrections::
IMeasurementCorrectionsInterface>& iMeasurementCorrections);
jboolean setCorrections(JNIEnv* env, jobject correctionsObj) override;
jboolean setCallback(const std::unique_ptr<MeasurementCorrectionsCallback>& callback) override;
private:
const sp<android::hardware::gnss::measurement_corrections::IMeasurementCorrectionsInterface>
mIMeasurementCorrectionsAidl;
};
class MeasurementCorrectionsIface_V1_0 : public MeasurementCorrectionsInterface {
public:
MeasurementCorrectionsIface_V1_0(
const sp<android::hardware::gnss::measurement_corrections::V1_0::
IMeasurementCorrections>& iMeasurementCorrections);
jboolean setCorrections(JNIEnv* env, jobject correctionsObj) override;
jboolean setCallback(const std::unique_ptr<MeasurementCorrectionsCallback>& callback) override;
private:
const sp<android::hardware::gnss::measurement_corrections::V1_0::IMeasurementCorrections>
mIMeasurementCorrections_V1_0;
};
class MeasurementCorrectionsIface_V1_1 : public MeasurementCorrectionsInterface {
public:
MeasurementCorrectionsIface_V1_1(
const sp<android::hardware::gnss::measurement_corrections::V1_1::
IMeasurementCorrections>& iMeasurementCorrections);
jboolean setCorrections(JNIEnv* env, jobject correctionsObj) override;
jboolean setCallback(const std::unique_ptr<MeasurementCorrectionsCallback>& callback) override;
private:
const sp<android::hardware::gnss::measurement_corrections::V1_1::IMeasurementCorrections>
mIMeasurementCorrections_V1_1;
};
struct MeasurementCorrectionsUtil {
static android::hardware::gnss::measurement_corrections::V1_0::SingleSatCorrection
getSingleSatCorrection_1_0_withoutConstellation(JNIEnv* env, jobject singleSatCorrectionObj);
static android::hardware::gnss::measurement_corrections::SingleSatCorrection
getSingleSatCorrection_Aidl(JNIEnv* env, jobject singleSatCorrectionObj);
static void getSingleSatCorrectionList_1_1(
JNIEnv* env, jobject singleSatCorrectionList,
hardware::hidl_vec<
android::hardware::gnss::measurement_corrections::V1_1::SingleSatCorrection>&
list);
static void getSingleSatCorrectionList_1_0(
JNIEnv* env, jobject singleSatCorrectionList,
hardware::hidl_vec<
android::hardware::gnss::measurement_corrections::V1_0::SingleSatCorrection>&
list);
static void getSingleSatCorrectionList_Aidl(
JNIEnv* env, jobject singleSatCorrectionList,
std::vector<android::hardware::gnss::measurement_corrections::SingleSatCorrection>&
list);
template <class T>
static bool translateMeasurementCorrections(JNIEnv* env, jobject correctionsObj,
T& corrections);
template <class T>
static void getReflectingPlane(JNIEnv* env, jobject singleSatCorrectionObj, T& reflectingPlane);
};
template <class T>
void MeasurementCorrectionsUtil::getReflectingPlane(JNIEnv* env, jobject singleSatCorrectionObj,
T& reflectingPlane) {
jobject reflectingPlaneObj =
env->CallObjectMethod(singleSatCorrectionObj, method_correctionSatRefPlane);
jdouble latitudeDegreesRefPlane =
env->CallDoubleMethod(reflectingPlaneObj, method_correctionPlaneLatDeg);
jdouble longitudeDegreesRefPlane =
env->CallDoubleMethod(reflectingPlaneObj, method_correctionPlaneLngDeg);
jdouble altitudeDegreesRefPlane =
env->CallDoubleMethod(reflectingPlaneObj, method_correctionPlaneAltDeg);
jdouble azimuthDegreeRefPlane =
env->CallDoubleMethod(reflectingPlaneObj, method_correctionPlaneAzimDeg);
reflectingPlane.latitudeDegrees = latitudeDegreesRefPlane;
reflectingPlane.longitudeDegrees = longitudeDegreesRefPlane;
reflectingPlane.altitudeMeters = altitudeDegreesRefPlane;
reflectingPlane.azimuthDegrees = azimuthDegreeRefPlane;
env->DeleteLocalRef(reflectingPlaneObj);
}
} // namespace android::gnss
#endif // _ANDROID_SERVER_MEASUREMENTCORRECTIONS_H

View File

@@ -0,0 +1,59 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "MeasurementCorrectionsCbJni"
#include "MeasurementCorrectionsCallback.h"
namespace android::gnss {
namespace {
jmethodID method_setSubHalMeasurementCorrectionsCapabilities;
}
void MeasurementCorrectionsCallback_class_init_once(JNIEnv* env, jclass clazz) {
method_setSubHalMeasurementCorrectionsCapabilities =
env->GetMethodID(clazz, "setSubHalMeasurementCorrectionsCapabilities", "(I)V");
}
using binder::Status;
using hardware::Return;
// Implementation of MeasurementCorrectionsCallbackAidl class.
Status MeasurementCorrectionsCallbackAidl::setCapabilitiesCb(const int capabilities) {
MeasurementCorrectionsCallbackUtil::setCapabilitiesCb(capabilities);
return Status::ok();
}
// Implementation of MeasurementCorrectionsCallbackHidl class.
Return<void> MeasurementCorrectionsCallbackHidl::setCapabilitiesCb(uint32_t capabilities) {
MeasurementCorrectionsCallbackUtil::setCapabilitiesCb(capabilities);
return hardware::Void();
}
// Implementation of MeasurementCorrectionsCallbackUtil class.
void MeasurementCorrectionsCallbackUtil::setCapabilitiesCb(uint32_t capabilities) {
ALOGD("%s: %du\n", __func__, capabilities);
JNIEnv* env = getJniEnv();
env->CallVoidMethod(mCallbacksObj, method_setSubHalMeasurementCorrectionsCapabilities,
capabilities);
checkAndClearExceptionFromCallback(env, __FUNCTION__);
}
} // namespace android::gnss

View File

@@ -0,0 +1,95 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _ANDROID_SERVER_GNSS_MEASUREMENTCORRECTIONSCALLBACK_H
#define _ANDROID_SERVER_GNSS_MEASUREMENTCORRECTIONSCALLBACK_H
#pragma once
#ifndef LOG_TAG
#error LOG_TAG must be defined before including this file.
#endif
#include <android/hardware/gnss/measurement_corrections/1.0/IMeasurementCorrections.h>
#include <android/hardware/gnss/measurement_corrections/1.1/IMeasurementCorrections.h>
#include <android/hardware/gnss/measurement_corrections/BnMeasurementCorrectionsCallback.h>
#include <log/log.h>
#include "Utils.h"
#include "jni.h"
namespace android::gnss {
namespace {
extern jmethodID method_setSubHalMeasurementCorrectionsCapabilities;
}
void MeasurementCorrectionsCallback_class_init_once(JNIEnv* env, jclass clazz);
/*
* MeasurementCorrectionsCallbackAidl class implements the callback methods required by the
* android::hardware::gnss::measurement_corrections::IMeasurementCorrectionsCallback interface.
*/
class MeasurementCorrectionsCallbackAidl
: public hardware::gnss::measurement_corrections::BnMeasurementCorrectionsCallback {
public:
MeasurementCorrectionsCallbackAidl() {}
binder::Status setCapabilitiesCb(const int capabilities) override;
};
/*
* MeasurementCorrectionsCallbackHidl implements callback methods of
* IMeasurementCorrectionsCallback.hal interface.
*/
class MeasurementCorrectionsCallbackHidl : public android::hardware::gnss::measurement_corrections::
V1_0::IMeasurementCorrectionsCallback {
public:
MeasurementCorrectionsCallbackHidl() {}
hardware::Return<void> setCapabilitiesCb(uint32_t capabilities) override;
};
class MeasurementCorrectionsCallback {
public:
MeasurementCorrectionsCallback() {}
sp<MeasurementCorrectionsCallbackAidl> getAidl() {
if (callbackAidl == nullptr) {
callbackAidl = sp<MeasurementCorrectionsCallbackAidl>::make();
}
return callbackAidl;
}
sp<MeasurementCorrectionsCallbackHidl> getHidl() {
if (callbackHidl == nullptr) {
callbackHidl = sp<MeasurementCorrectionsCallbackHidl>::make();
}
return callbackHidl;
}
private:
sp<MeasurementCorrectionsCallbackAidl> callbackAidl;
sp<MeasurementCorrectionsCallbackHidl> callbackHidl;
};
struct MeasurementCorrectionsCallbackUtil {
static void setCapabilitiesCb(uint32_t capabilities);
private:
MeasurementCorrectionsCallbackUtil() = delete;
};
} // namespace android::gnss
#endif // _ANDROID_SERVER_GNSS_MEASUREMENTCORRECTIONSCALLBACK_H