Merge "Refactor IGnss JNI" into tm-dev
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -28,6 +28,8 @@ cc_library_shared {
|
||||
"AGnssRil.cpp",
|
||||
"AGnssRilCallback.cpp",
|
||||
"GnssAntennaInfo.cpp",
|
||||
"Gnss.cpp",
|
||||
"GnssCallback.cpp",
|
||||
"GnssAntennaInfoCallback.cpp",
|
||||
"GnssBatching.cpp",
|
||||
"GnssBatchingCallback.cpp",
|
||||
@@ -39,6 +41,8 @@ cc_library_shared {
|
||||
"GnssMeasurementCallback.cpp",
|
||||
"GnssNavigationMessage.cpp",
|
||||
"GnssNavigationMessageCallback.cpp",
|
||||
"GnssPsds.cpp",
|
||||
"GnssPsdsCallback.cpp",
|
||||
"GnssVisibilityControl.cpp",
|
||||
"GnssVisibilityControlCallback.cpp",
|
||||
"MeasurementCorrections.cpp",
|
||||
@@ -55,6 +59,7 @@ cc_defaults {
|
||||
"libhidlbase",
|
||||
"liblog",
|
||||
"libnativehelper",
|
||||
"libhardware_legacy",
|
||||
"libutils",
|
||||
"android.hardware.gnss-V2-cpp",
|
||||
"android.hardware.gnss@1.0",
|
||||
|
||||
759
services/core/jni/gnss/Gnss.cpp
Normal file
759
services/core/jni/gnss/Gnss.cpp
Normal file
@@ -0,0 +1,759 @@
|
||||
/*
|
||||
* 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 "GnssJni"
|
||||
|
||||
#include "Gnss.h"
|
||||
|
||||
#include <binder/IServiceManager.h>
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
namespace android::gnss {
|
||||
|
||||
using hardware::Return;
|
||||
|
||||
using GnssLocationAidl = hardware::gnss::GnssLocation;
|
||||
using GnssLocation_V1_0 = hardware::gnss::V1_0::GnssLocation;
|
||||
using GnssLocation_V2_0 = hardware::gnss::V2_0::GnssLocation;
|
||||
using IAGnssAidl = hardware::gnss::IAGnss;
|
||||
using IAGnssRilAidl = hardware::gnss::IAGnssRil;
|
||||
using IGnssAidl = hardware::gnss::IGnss;
|
||||
using IGnss_V1_0 = hardware::gnss::V1_0::IGnss;
|
||||
using IGnss_V1_1 = hardware::gnss::V1_1::IGnss;
|
||||
using IGnss_V2_0 = hardware::gnss::V2_0::IGnss;
|
||||
using IGnss_V2_1 = hardware::gnss::V2_1::IGnss;
|
||||
using IGnssAntennaInfoAidl = hardware::gnss::IGnssAntennaInfo;
|
||||
using IGnssCallbackAidl = hardware::gnss::IGnssCallback;
|
||||
using IGnssCallback_V1_0 = hardware::gnss::V1_0::IGnssCallback;
|
||||
using IGnssCallback_V2_0 = hardware::gnss::V2_0::IGnssCallback;
|
||||
using IGnssCallback_V2_1 = hardware::gnss::V2_1::IGnssCallback;
|
||||
using IGnssConfigurationAidl = android::hardware::gnss::IGnssConfiguration;
|
||||
using IGnssDebugAidl = hardware::gnss::IGnssDebug;
|
||||
using android::hardware::gnss::IGnssPsds;
|
||||
|
||||
namespace {
|
||||
|
||||
GnssLocationAidl createGnssLocation(jint gnssLocationFlags, jdouble latitudeDegrees,
|
||||
jdouble longitudeDegrees, jdouble altitudeMeters,
|
||||
jfloat speedMetersPerSec, jfloat bearingDegrees,
|
||||
jfloat horizontalAccuracyMeters, jfloat verticalAccuracyMeters,
|
||||
jfloat speedAccuracyMetersPerSecond,
|
||||
jfloat bearingAccuracyDegrees, jlong timestamp,
|
||||
jint elapsedRealtimeFlags, jlong elapsedRealtimeNanos,
|
||||
jdouble elapsedRealtimeUncertaintyNanos) {
|
||||
GnssLocationAidl location;
|
||||
location.gnssLocationFlags = static_cast<int>(gnssLocationFlags);
|
||||
location.latitudeDegrees = static_cast<double>(latitudeDegrees);
|
||||
location.longitudeDegrees = static_cast<double>(longitudeDegrees);
|
||||
location.altitudeMeters = static_cast<double>(altitudeMeters);
|
||||
location.speedMetersPerSec = static_cast<double>(speedMetersPerSec);
|
||||
location.bearingDegrees = static_cast<double>(bearingDegrees);
|
||||
location.horizontalAccuracyMeters = static_cast<double>(horizontalAccuracyMeters);
|
||||
location.verticalAccuracyMeters = static_cast<double>(verticalAccuracyMeters);
|
||||
location.speedAccuracyMetersPerSecond = static_cast<double>(speedAccuracyMetersPerSecond);
|
||||
location.bearingAccuracyDegrees = static_cast<double>(bearingAccuracyDegrees);
|
||||
location.timestampMillis = static_cast<uint64_t>(timestamp);
|
||||
|
||||
location.elapsedRealtime.flags = static_cast<int>(elapsedRealtimeFlags);
|
||||
location.elapsedRealtime.timestampNs = static_cast<uint64_t>(elapsedRealtimeNanos);
|
||||
location.elapsedRealtime.timeUncertaintyNs =
|
||||
static_cast<double>(elapsedRealtimeUncertaintyNanos);
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
GnssLocation_V1_0 createGnssLocation_V1_0(jint gnssLocationFlags, jdouble latitudeDegrees,
|
||||
jdouble longitudeDegrees, jdouble altitudeMeters,
|
||||
jfloat speedMetersPerSec, jfloat bearingDegrees,
|
||||
jfloat horizontalAccuracyMeters,
|
||||
jfloat verticalAccuracyMeters,
|
||||
jfloat speedAccuracyMetersPerSecond,
|
||||
jfloat bearingAccuracyDegrees, jlong timestamp) {
|
||||
GnssLocation_V1_0 location;
|
||||
location.gnssLocationFlags = static_cast<uint16_t>(gnssLocationFlags);
|
||||
location.latitudeDegrees = static_cast<double>(latitudeDegrees);
|
||||
location.longitudeDegrees = static_cast<double>(longitudeDegrees);
|
||||
location.altitudeMeters = static_cast<double>(altitudeMeters);
|
||||
location.speedMetersPerSec = static_cast<float>(speedMetersPerSec);
|
||||
location.bearingDegrees = static_cast<float>(bearingDegrees);
|
||||
location.horizontalAccuracyMeters = static_cast<float>(horizontalAccuracyMeters);
|
||||
location.verticalAccuracyMeters = static_cast<float>(verticalAccuracyMeters);
|
||||
location.speedAccuracyMetersPerSecond = static_cast<float>(speedAccuracyMetersPerSecond);
|
||||
location.bearingAccuracyDegrees = static_cast<float>(bearingAccuracyDegrees);
|
||||
location.timestamp = static_cast<uint64_t>(timestamp);
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
GnssLocation_V2_0 createGnssLocation_V2_0(jint gnssLocationFlags, jdouble latitudeDegrees,
|
||||
jdouble longitudeDegrees, jdouble altitudeMeters,
|
||||
jfloat speedMetersPerSec, jfloat bearingDegrees,
|
||||
jfloat horizontalAccuracyMeters,
|
||||
jfloat verticalAccuracyMeters,
|
||||
jfloat speedAccuracyMetersPerSecond,
|
||||
jfloat bearingAccuracyDegrees, jlong timestamp,
|
||||
jint elapsedRealtimeFlags, jlong elapsedRealtimeNanos,
|
||||
jdouble elapsedRealtimeUncertaintyNanos) {
|
||||
GnssLocation_V2_0 location;
|
||||
location.v1_0 = createGnssLocation_V1_0(gnssLocationFlags, latitudeDegrees, longitudeDegrees,
|
||||
altitudeMeters, speedMetersPerSec, bearingDegrees,
|
||||
horizontalAccuracyMeters, verticalAccuracyMeters,
|
||||
speedAccuracyMetersPerSecond, bearingAccuracyDegrees,
|
||||
timestamp);
|
||||
|
||||
location.elapsedRealtime.flags = static_cast<uint16_t>(elapsedRealtimeFlags);
|
||||
location.elapsedRealtime.timestampNs = static_cast<uint64_t>(elapsedRealtimeNanos);
|
||||
location.elapsedRealtime.timeUncertaintyNs =
|
||||
static_cast<uint64_t>(elapsedRealtimeUncertaintyNanos);
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
// Implementation of GnssHal, which unifies all versions of GNSS HALs
|
||||
|
||||
GnssHal::GnssHal() {
|
||||
gnssHalAidl = waitForVintfService<IGnssAidl>();
|
||||
if (gnssHalAidl != nullptr) {
|
||||
ALOGD("Successfully got GNSS AIDL handle. Version=%d.", gnssHalAidl->getInterfaceVersion());
|
||||
if (gnssHalAidl->getInterfaceVersion() >= 2) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ALOGD("Trying IGnss_V2_1::getService()");
|
||||
gnssHal_V2_1 = IGnss_V2_1::getService();
|
||||
if (gnssHal_V2_1 != nullptr) {
|
||||
gnssHal_V2_0 = gnssHal_V2_1;
|
||||
gnssHal_V1_1 = gnssHal_V2_1;
|
||||
gnssHal = gnssHal_V2_1;
|
||||
return;
|
||||
}
|
||||
|
||||
ALOGD("gnssHal 2.1 was null, trying 2.0");
|
||||
gnssHal_V2_0 = IGnss_V2_0::getService();
|
||||
if (gnssHal_V2_0 != nullptr) {
|
||||
gnssHal_V1_1 = gnssHal_V2_0;
|
||||
gnssHal = gnssHal_V2_0;
|
||||
return;
|
||||
}
|
||||
|
||||
ALOGD("gnssHal 2.0 was null, trying 1.1");
|
||||
gnssHal_V1_1 = IGnss_V1_1::getService();
|
||||
if (gnssHal_V1_1 != nullptr) {
|
||||
gnssHal = gnssHal_V1_1;
|
||||
return;
|
||||
}
|
||||
|
||||
ALOGD("gnssHal 1.1 was null, trying 1.0");
|
||||
gnssHal = IGnss_V1_0::getService();
|
||||
}
|
||||
|
||||
jboolean GnssHal::isSupported() {
|
||||
return (gnssHalAidl != nullptr || gnssHal != nullptr) ? JNI_TRUE : JNI_FALSE;
|
||||
}
|
||||
|
||||
void GnssHal::linkToDeath() {
|
||||
// TODO: linkToDeath for AIDL HAL
|
||||
|
||||
if (gnssHal != nullptr) {
|
||||
gnssHalDeathRecipient = new GnssDeathRecipient();
|
||||
hardware::Return<bool> linked = gnssHal->linkToDeath(gnssHalDeathRecipient, /*cookie*/ 0);
|
||||
if (!linked.isOk()) {
|
||||
ALOGE("Transaction error in linking to GnssHAL death: %s",
|
||||
linked.description().c_str());
|
||||
} else if (!linked) {
|
||||
ALOGW("Unable to link to GnssHal death notifications");
|
||||
} else {
|
||||
ALOGD("Link to death notification successful");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jboolean GnssHal::setCallback() {
|
||||
if (gnssHalAidl != nullptr) {
|
||||
sp<IGnssCallbackAidl> gnssCbIfaceAidl = new GnssCallbackAidl();
|
||||
auto status = gnssHalAidl->setCallback(gnssCbIfaceAidl);
|
||||
if (!checkAidlStatus(status, "IGnssAidl setCallback() failed.")) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
}
|
||||
if (gnssHal != nullptr) {
|
||||
Return<bool> result = false;
|
||||
sp<IGnssCallback_V2_1> gnssCbIface = new GnssCallbackHidl();
|
||||
if (gnssHal_V2_1 != nullptr) {
|
||||
result = gnssHal_V2_1->setCallback_2_1(gnssCbIface);
|
||||
} else if (gnssHal_V2_0 != nullptr) {
|
||||
result = gnssHal_V2_0->setCallback_2_0(gnssCbIface);
|
||||
} else if (gnssHal_V1_1 != nullptr) {
|
||||
result = gnssHal_V1_1->setCallback_1_1(gnssCbIface);
|
||||
} else {
|
||||
result = gnssHal->setCallback(gnssCbIface);
|
||||
}
|
||||
if (!checkHidlReturn(result, "IGnss setCallback() failed.")) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
}
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
void GnssHal::close() {
|
||||
if (gnssHalAidl != nullptr) {
|
||||
auto status = gnssHalAidl->close();
|
||||
checkAidlStatus(status, "IGnssAidl close() failed.");
|
||||
}
|
||||
|
||||
if (gnssHal != nullptr) {
|
||||
auto result = gnssHal->cleanup();
|
||||
checkHidlReturn(result, "IGnss cleanup() failed.");
|
||||
}
|
||||
}
|
||||
|
||||
jboolean GnssHal::start() {
|
||||
if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
|
||||
auto status = gnssHalAidl->start();
|
||||
return checkAidlStatus(status, "IGnssAidl start() failed.");
|
||||
}
|
||||
|
||||
if (gnssHal == nullptr) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
auto result = gnssHal->start();
|
||||
return checkHidlReturn(result, "IGnss start() failed.");
|
||||
}
|
||||
|
||||
jboolean GnssHal::stop() {
|
||||
if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
|
||||
auto status = gnssHalAidl->stop();
|
||||
return checkAidlStatus(status, "IGnssAidl stop() failed.");
|
||||
}
|
||||
|
||||
if (gnssHal == nullptr) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
auto result = gnssHal->stop();
|
||||
return checkHidlReturn(result, "IGnss stop() failed.");
|
||||
}
|
||||
|
||||
jboolean GnssHal::startSvStatus() {
|
||||
isSvStatusRegistered = true;
|
||||
if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
|
||||
auto status = gnssHalAidl->startSvStatus();
|
||||
return checkAidlStatus(status, "IGnssAidl startSvStatus() failed.");
|
||||
}
|
||||
if (gnssHal == nullptr) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
jboolean GnssHal::stopSvStatus() {
|
||||
isSvStatusRegistered = false;
|
||||
if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
|
||||
auto status = gnssHalAidl->stopSvStatus();
|
||||
return checkAidlStatus(status, "IGnssAidl stopSvStatus() failed.");
|
||||
}
|
||||
if (gnssHal == nullptr) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
jboolean GnssHal::startNmea() {
|
||||
isNmeaRegistered = true;
|
||||
if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
|
||||
auto status = gnssHalAidl->startNmea();
|
||||
return checkAidlStatus(status, "IGnssAidl startNmea() failed.");
|
||||
}
|
||||
if (gnssHal == nullptr) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
jboolean GnssHal::stopNmea() {
|
||||
isNmeaRegistered = false;
|
||||
if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
|
||||
auto status = gnssHalAidl->stopNmea();
|
||||
return checkAidlStatus(status, "IGnssAidl stopNmea() failed.");
|
||||
}
|
||||
if (gnssHal == nullptr) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
jint GnssHal::readNmea(jbyteArray& nmeaArray, jint& buffer_size) {
|
||||
// this should only be called from within a call to reportNmea
|
||||
JNIEnv* env = getJniEnv();
|
||||
jbyte* nmea = reinterpret_cast<jbyte*>(env->GetPrimitiveArrayCritical(nmeaArray, 0));
|
||||
int length = GnssCallbackHidl::sNmeaStringLength;
|
||||
if (length > buffer_size) {
|
||||
length = buffer_size;
|
||||
}
|
||||
memcpy(nmea, GnssCallbackHidl::sNmeaString, length);
|
||||
env->ReleasePrimitiveArrayCritical(nmeaArray, nmea, JNI_ABORT);
|
||||
return (jint)length;
|
||||
}
|
||||
|
||||
jboolean GnssHal::setPositionMode(jint mode, jint recurrence, jint min_interval,
|
||||
jint preferred_accuracy, jint preferred_time,
|
||||
jboolean low_power_mode) {
|
||||
if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
|
||||
IGnssAidl::PositionModeOptions options;
|
||||
options.mode = static_cast<IGnssAidl::GnssPositionMode>(mode);
|
||||
options.recurrence = static_cast<IGnssAidl::GnssPositionRecurrence>(recurrence);
|
||||
options.minIntervalMs = min_interval;
|
||||
options.preferredAccuracyMeters = preferred_accuracy;
|
||||
options.preferredTimeMs = preferred_time;
|
||||
options.lowPowerMode = low_power_mode;
|
||||
auto status = gnssHalAidl->setPositionMode(options);
|
||||
return checkAidlStatus(status, "IGnssAidl setPositionMode() failed.");
|
||||
}
|
||||
|
||||
Return<bool> result = false;
|
||||
if (gnssHal_V1_1 != nullptr) {
|
||||
result = gnssHal_V1_1->setPositionMode_1_1(static_cast<IGnss_V1_0::GnssPositionMode>(mode),
|
||||
static_cast<IGnss_V1_0::GnssPositionRecurrence>(
|
||||
recurrence),
|
||||
min_interval, preferred_accuracy, preferred_time,
|
||||
low_power_mode);
|
||||
} else if (gnssHal != nullptr) {
|
||||
result = gnssHal->setPositionMode(static_cast<IGnss_V1_0::GnssPositionMode>(mode),
|
||||
static_cast<IGnss_V1_0::GnssPositionRecurrence>(
|
||||
recurrence),
|
||||
min_interval, preferred_accuracy, preferred_time);
|
||||
}
|
||||
return checkHidlReturn(result, "IGnss setPositionMode() failed.");
|
||||
}
|
||||
|
||||
void GnssHal::deleteAidingData(jint flags) {
|
||||
if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
|
||||
auto status = gnssHalAidl->deleteAidingData(static_cast<IGnssAidl::GnssAidingData>(flags));
|
||||
checkAidlStatus(status, "IGnssAidl deleteAidingData() failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (gnssHal == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto result = gnssHal->deleteAidingData(static_cast<IGnss_V1_0::GnssAidingData>(flags));
|
||||
checkHidlReturn(result, "IGnss deleteAidingData() failed.");
|
||||
}
|
||||
|
||||
void GnssHal::injectTime(jlong time, jlong timeReference, jint uncertainty) {
|
||||
if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
|
||||
auto status = gnssHalAidl->injectTime(time, timeReference, uncertainty);
|
||||
checkAidlStatus(status, "IGnssAidl injectTime() failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (gnssHal == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto result = gnssHal->injectTime(time, timeReference, uncertainty);
|
||||
checkHidlReturn(result, "IGnss injectTime() failed.");
|
||||
}
|
||||
|
||||
void GnssHal::injectLocation(jint gnssLocationFlags, jdouble latitudeDegrees,
|
||||
jdouble longitudeDegrees, jdouble altitudeMeters,
|
||||
jfloat speedMetersPerSec, jfloat bearingDegrees,
|
||||
jfloat horizontalAccuracyMeters, jfloat verticalAccuracyMeters,
|
||||
jfloat speedAccuracyMetersPerSecond, jfloat bearingAccuracyDegrees,
|
||||
jlong timestamp, jint elapsedRealtimeFlags, jlong elapsedRealtimeNanos,
|
||||
jdouble elapsedRealtimeUncertaintyNanos) {
|
||||
if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
|
||||
GnssLocationAidl location =
|
||||
createGnssLocation(gnssLocationFlags, latitudeDegrees, longitudeDegrees,
|
||||
altitudeMeters, speedMetersPerSec, bearingDegrees,
|
||||
horizontalAccuracyMeters, verticalAccuracyMeters,
|
||||
speedAccuracyMetersPerSecond, bearingAccuracyDegrees, timestamp,
|
||||
elapsedRealtimeFlags, elapsedRealtimeNanos,
|
||||
elapsedRealtimeUncertaintyNanos);
|
||||
auto status = gnssHalAidl->injectLocation(location);
|
||||
checkAidlStatus(status, "IGnssAidl injectLocation() failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (gnssHal == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto result =
|
||||
gnssHal->injectLocation(latitudeDegrees, longitudeDegrees, horizontalAccuracyMeters);
|
||||
checkHidlReturn(result, "IGnss injectLocation() failed.");
|
||||
}
|
||||
|
||||
void GnssHal::injectBestLocation(jint gnssLocationFlags, jdouble latitudeDegrees,
|
||||
jdouble longitudeDegrees, jdouble altitudeMeters,
|
||||
jfloat speedMetersPerSec, jfloat bearingDegrees,
|
||||
jfloat horizontalAccuracyMeters, jfloat verticalAccuracyMeters,
|
||||
jfloat speedAccuracyMetersPerSecond, jfloat bearingAccuracyDegrees,
|
||||
jlong timestamp, jint elapsedRealtimeFlags,
|
||||
jlong elapsedRealtimeNanos,
|
||||
jdouble elapsedRealtimeUncertaintyNanos) {
|
||||
if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
|
||||
GnssLocationAidl location =
|
||||
createGnssLocation(gnssLocationFlags, latitudeDegrees, longitudeDegrees,
|
||||
altitudeMeters, speedMetersPerSec, bearingDegrees,
|
||||
horizontalAccuracyMeters, verticalAccuracyMeters,
|
||||
speedAccuracyMetersPerSecond, bearingAccuracyDegrees, timestamp,
|
||||
elapsedRealtimeFlags, elapsedRealtimeNanos,
|
||||
elapsedRealtimeUncertaintyNanos);
|
||||
auto status = gnssHalAidl->injectBestLocation(location);
|
||||
checkAidlStatus(status, "IGnssAidl injectBestLocation() failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (gnssHal_V2_0 != nullptr) {
|
||||
GnssLocation_V2_0 location =
|
||||
createGnssLocation_V2_0(gnssLocationFlags, latitudeDegrees, longitudeDegrees,
|
||||
altitudeMeters, speedMetersPerSec, bearingDegrees,
|
||||
horizontalAccuracyMeters, verticalAccuracyMeters,
|
||||
speedAccuracyMetersPerSecond, bearingAccuracyDegrees,
|
||||
timestamp, elapsedRealtimeFlags, elapsedRealtimeNanos,
|
||||
elapsedRealtimeUncertaintyNanos);
|
||||
auto result = gnssHal_V2_0->injectBestLocation_2_0(location);
|
||||
checkHidlReturn(result, "IGnss injectBestLocation_2_0() failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (gnssHal_V1_1 != nullptr) {
|
||||
GnssLocation_V1_0 location =
|
||||
createGnssLocation_V1_0(gnssLocationFlags, latitudeDegrees, longitudeDegrees,
|
||||
altitudeMeters, speedMetersPerSec, bearingDegrees,
|
||||
horizontalAccuracyMeters, verticalAccuracyMeters,
|
||||
speedAccuracyMetersPerSecond, bearingAccuracyDegrees,
|
||||
timestamp);
|
||||
auto result = gnssHal_V1_1->injectBestLocation(location);
|
||||
checkHidlReturn(result, "IGnss injectBestLocation() failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
ALOGE("IGnss injectBestLocation() is called but gnssHal_V1_1 is not available.");
|
||||
}
|
||||
|
||||
std::unique_ptr<AGnssInterface> GnssHal::getAGnssInterface() {
|
||||
if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
|
||||
sp<IAGnssAidl> agnssAidl;
|
||||
auto status = gnssHalAidl->getExtensionAGnss(&agnssAidl);
|
||||
if (checkAidlStatus(status, "Unable to get a handle to AGnss interface.")) {
|
||||
return std::make_unique<gnss::AGnss>(agnssAidl);
|
||||
}
|
||||
} else if (gnssHal_V2_0 != nullptr) {
|
||||
auto agnss_V2_0 = gnssHal_V2_0->getExtensionAGnss_2_0();
|
||||
if (checkHidlReturn(agnss_V2_0, "Unable to get a handle to AGnss_V2_0")) {
|
||||
return std::make_unique<gnss::AGnss_V2_0>(agnss_V2_0);
|
||||
}
|
||||
} else if (gnssHal != nullptr) {
|
||||
auto agnss_V1_0 = gnssHal->getExtensionAGnss();
|
||||
if (checkHidlReturn(agnss_V1_0, "Unable to get a handle to AGnss_V1_0")) {
|
||||
return std::make_unique<gnss::AGnss_V1_0>(agnss_V1_0);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<AGnssRilInterface> GnssHal::getAGnssRilInterface() {
|
||||
if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
|
||||
sp<IAGnssRilAidl> agnssRilAidl;
|
||||
auto status = gnssHalAidl->getExtensionAGnssRil(&agnssRilAidl);
|
||||
if (checkAidlStatus(status, "Unable to get a handle to AGnssRil interface.")) {
|
||||
return std::make_unique<gnss::AGnssRil>(agnssRilAidl);
|
||||
}
|
||||
} else if (gnssHal_V2_0 != nullptr) {
|
||||
auto agnssRil_V2_0 = gnssHal_V2_0->getExtensionAGnssRil_2_0();
|
||||
if (checkHidlReturn(agnssRil_V2_0, "Unable to get a handle to AGnssRil_V2_0")) {
|
||||
return std::make_unique<gnss::AGnssRil_V2_0>(agnssRil_V2_0);
|
||||
}
|
||||
} else if (gnssHal != nullptr) {
|
||||
auto agnssRil_V1_0 = gnssHal->getExtensionAGnssRil();
|
||||
if (checkHidlReturn(agnssRil_V1_0, "Unable to get a handle to AGnssRil_V1_0")) {
|
||||
return std::make_unique<gnss::AGnssRil_V1_0>(agnssRil_V1_0);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<GnssNavigationMessageInterface> GnssHal::getGnssNavigationMessageInterface() {
|
||||
if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
|
||||
sp<hardware::gnss::IGnssNavigationMessageInterface> gnssNavigationMessage;
|
||||
auto status = gnssHalAidl->getExtensionGnssNavigationMessage(&gnssNavigationMessage);
|
||||
if (checkAidlStatus(status,
|
||||
"Unable to get a handle to GnssNavigationMessage AIDL interface.")) {
|
||||
return std::make_unique<gnss::GnssNavigationMessageAidl>(gnssNavigationMessage);
|
||||
}
|
||||
} else if (gnssHal != nullptr) {
|
||||
auto gnssNavigationMessage = gnssHal->getExtensionGnssNavigationMessage();
|
||||
if (checkHidlReturn(gnssNavigationMessage,
|
||||
"Unable to get a handle to GnssNavigationMessage interface.")) {
|
||||
return std::make_unique<gnss::GnssNavigationMessageHidl>(gnssNavigationMessage);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<GnssMeasurementInterface> GnssHal::getGnssMeasurementInterface() {
|
||||
// Allow all causal combinations between IGnss.hal and IGnssMeasurement.hal. That means,
|
||||
// 2.1@IGnss can be paired with {1.0, 1,1, 2.0, 2.1}@IGnssMeasurement
|
||||
// 2.0@IGnss can be paired with {1.0, 1,1, 2.0}@IGnssMeasurement
|
||||
// 1.1@IGnss can be paired {1.0, 1.1}@IGnssMeasurement
|
||||
// 1.0@IGnss is paired with 1.0@IGnssMeasurement
|
||||
if (gnssHalAidl != nullptr) {
|
||||
sp<hardware::gnss::IGnssMeasurementInterface> gnssMeasurement;
|
||||
auto status = gnssHalAidl->getExtensionGnssMeasurement(&gnssMeasurement);
|
||||
if (checkAidlStatus(status, "Unable to get a handle to GnssMeasurement AIDL interface.")) {
|
||||
return std::make_unique<android::gnss::GnssMeasurement>(gnssMeasurement);
|
||||
}
|
||||
}
|
||||
if (gnssHal_V2_1 != nullptr) {
|
||||
auto gnssMeasurement = gnssHal_V2_1->getExtensionGnssMeasurement_2_1();
|
||||
if (checkHidlReturn(gnssMeasurement, "Unable to get a handle to GnssMeasurement_V2_1")) {
|
||||
return std::make_unique<android::gnss::GnssMeasurement_V2_1>(gnssMeasurement);
|
||||
}
|
||||
}
|
||||
if (gnssHal_V2_0 != nullptr) {
|
||||
auto gnssMeasurement = gnssHal_V2_0->getExtensionGnssMeasurement_2_0();
|
||||
if (checkHidlReturn(gnssMeasurement, "Unable to get a handle to GnssMeasurement_V2_0")) {
|
||||
return std::make_unique<android::gnss::GnssMeasurement_V2_0>(gnssMeasurement);
|
||||
}
|
||||
}
|
||||
if (gnssHal_V1_1 != nullptr) {
|
||||
auto gnssMeasurement = gnssHal_V1_1->getExtensionGnssMeasurement_1_1();
|
||||
if (checkHidlReturn(gnssMeasurement, "Unable to get a handle to GnssMeasurement_V1_1")) {
|
||||
return std::make_unique<android::gnss::GnssMeasurement_V1_1>(gnssMeasurement);
|
||||
}
|
||||
}
|
||||
if (gnssHal != nullptr) {
|
||||
auto gnssMeasurement = gnssHal->getExtensionGnssMeasurement();
|
||||
if (checkHidlReturn(gnssMeasurement, "Unable to get a handle to GnssMeasurement_V1_0")) {
|
||||
return std::make_unique<android::gnss::GnssMeasurement_V1_0>(gnssMeasurement);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<GnssDebugInterface> GnssHal::getGnssDebugInterface() {
|
||||
// Allow all causal combinations between IGnss.hal and IGnssDebug.hal. That means,
|
||||
// 2.0@IGnss can be paired with {1.0, 2.0}@IGnssDebug
|
||||
// 1.0@IGnss is paired with 1.0@IGnssDebug
|
||||
if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
|
||||
sp<IGnssDebugAidl> gnssDebugAidl;
|
||||
auto status = gnssHalAidl->getExtensionGnssDebug(&gnssDebugAidl);
|
||||
if (checkAidlStatus(status, "Unable to get a handle to GnssDebug interface.")) {
|
||||
return std::make_unique<gnss::GnssDebug>(gnssDebugAidl);
|
||||
}
|
||||
}
|
||||
if (gnssHal_V2_0 != nullptr) {
|
||||
auto gnssDebug_V2_0 = gnssHal_V2_0->getExtensionGnssDebug_2_0();
|
||||
if (checkHidlReturn(gnssDebug_V2_0, "Unable to get a handle to GnssDebug_V2_0.")) {
|
||||
return std::make_unique<gnss::GnssDebug_V2_0>(gnssDebug_V2_0);
|
||||
}
|
||||
}
|
||||
if (gnssHal != nullptr) {
|
||||
auto gnssDebug_V1_0 = gnssHal->getExtensionGnssDebug();
|
||||
if (checkHidlReturn(gnssDebug_V1_0, "Unable to get a handle to GnssDebug_V1_0.")) {
|
||||
return std::make_unique<gnss::GnssDebug_V1_0>(gnssDebug_V1_0);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<GnssConfigurationInterface> GnssHal::getGnssConfigurationInterface() {
|
||||
if (gnssHalAidl != nullptr) {
|
||||
sp<IGnssConfigurationAidl> gnssConfigurationAidl;
|
||||
auto status = gnssHalAidl->getExtensionGnssConfiguration(&gnssConfigurationAidl);
|
||||
if (checkAidlStatus(status,
|
||||
"Unable to get a handle to GnssConfiguration AIDL interface.")) {
|
||||
return std::make_unique<android::gnss::GnssConfiguration>(gnssConfigurationAidl);
|
||||
}
|
||||
} else if (gnssHal_V2_1 != nullptr) {
|
||||
auto gnssConfiguration = gnssHal_V2_1->getExtensionGnssConfiguration_2_1();
|
||||
if (checkHidlReturn(gnssConfiguration,
|
||||
"Unable to get a handle to GnssConfiguration_V2_1")) {
|
||||
return std::make_unique<android::gnss::GnssConfiguration_V2_1>(gnssConfiguration);
|
||||
}
|
||||
} else if (gnssHal_V2_0 != nullptr) {
|
||||
auto gnssConfiguration = gnssHal_V2_0->getExtensionGnssConfiguration_2_0();
|
||||
if (checkHidlReturn(gnssConfiguration,
|
||||
"Unable to get a handle to GnssConfiguration_V2_0")) {
|
||||
return std::make_unique<android::gnss::GnssConfiguration_V2_0>(gnssConfiguration);
|
||||
}
|
||||
} else if (gnssHal_V1_1 != nullptr) {
|
||||
auto gnssConfiguration = gnssHal_V1_1->getExtensionGnssConfiguration_1_1();
|
||||
if (checkHidlReturn(gnssConfiguration,
|
||||
"Unable to get a handle to GnssConfiguration_V1_1")) {
|
||||
return std::make_unique<gnss::GnssConfiguration_V1_1>(gnssConfiguration);
|
||||
}
|
||||
} else if (gnssHal != nullptr) {
|
||||
auto gnssConfiguration = gnssHal->getExtensionGnssConfiguration();
|
||||
if (checkHidlReturn(gnssConfiguration,
|
||||
"Unable to get a handle to GnssConfiguration_V1_0")) {
|
||||
return std::make_unique<gnss::GnssConfiguration_V1_0>(gnssConfiguration);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<GnssGeofenceInterface> GnssHal::getGnssGeofenceInterface() {
|
||||
if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
|
||||
sp<hardware::gnss::IGnssGeofence> gnssGeofence;
|
||||
auto status = gnssHalAidl->getExtensionGnssGeofence(&gnssGeofence);
|
||||
if (checkAidlStatus(status, "Unable to get a handle to GnssGeofence AIDL interface.")) {
|
||||
return std::make_unique<gnss::GnssGeofenceAidl>(gnssGeofence);
|
||||
}
|
||||
} else if (gnssHal != nullptr) {
|
||||
auto gnssGeofencing = gnssHal->getExtensionGnssGeofencing();
|
||||
if (checkHidlReturn(gnssGeofencing, "Unable to get a handle to GnssGeofencing")) {
|
||||
return std::make_unique<gnss::GnssGeofenceHidl>(gnssGeofencing);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<GnssBatchingInterface> GnssHal::getGnssBatchingInterface() {
|
||||
if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
|
||||
sp<android::hardware::gnss::IGnssBatching> gnssBatchingAidl;
|
||||
auto status = gnssHalAidl->getExtensionGnssBatching(&gnssBatchingAidl);
|
||||
if (checkAidlStatus(status, "Unable to get a handle to GnssBatching interface.")) {
|
||||
return std::make_unique<gnss::GnssBatching>(gnssBatchingAidl);
|
||||
}
|
||||
}
|
||||
if (gnssHal_V2_0 != nullptr) {
|
||||
auto gnssBatching_V2_0 = gnssHal_V2_0->getExtensionGnssBatching_2_0();
|
||||
if (checkHidlReturn(gnssBatching_V2_0, "Unable to get a handle to GnssBatching_V2_0")) {
|
||||
return std::make_unique<gnss::GnssBatching_V2_0>(gnssBatching_V2_0);
|
||||
}
|
||||
}
|
||||
if (gnssHal != nullptr) {
|
||||
auto gnssBatching_V1_0 = gnssHal->getExtensionGnssBatching();
|
||||
if (checkHidlReturn(gnssBatching_V1_0, "Unable to get a handle to GnssBatching")) {
|
||||
return std::make_unique<gnss::GnssBatching_V1_0>(gnssBatching_V1_0);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<MeasurementCorrectionsInterface> GnssHal::getMeasurementCorrectionsInterface() {
|
||||
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.")) {
|
||||
return std::make_unique<gnss::MeasurementCorrectionsIface_Aidl>(
|
||||
gnssMeasurementCorrectionsAidl);
|
||||
}
|
||||
}
|
||||
if (gnssHal_V2_1 != nullptr) {
|
||||
auto gnssCorrections = gnssHal_V2_1->getExtensionMeasurementCorrections_1_1();
|
||||
if (checkHidlReturn(gnssCorrections,
|
||||
"Unable to get a handle to GnssMeasurementCorrections HIDL "
|
||||
"interface")) {
|
||||
return std::make_unique<gnss::MeasurementCorrectionsIface_V1_1>(gnssCorrections);
|
||||
}
|
||||
}
|
||||
if (gnssHal_V2_0 != nullptr) {
|
||||
auto gnssCorrections = gnssHal_V2_0->getExtensionMeasurementCorrections();
|
||||
if (checkHidlReturn(gnssCorrections,
|
||||
"Unable to get a handle to GnssMeasurementCorrections HIDL "
|
||||
"interface")) {
|
||||
return std::make_unique<gnss::MeasurementCorrectionsIface_V1_0>(gnssCorrections);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<GnssVisibilityControlInterface> GnssHal::getGnssVisibilityControlInterface() {
|
||||
if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
|
||||
sp<android::hardware::gnss::visibility_control::IGnssVisibilityControl>
|
||||
gnssVisibilityControlAidl;
|
||||
auto status = gnssHalAidl->getExtensionGnssVisibilityControl(&gnssVisibilityControlAidl);
|
||||
if (checkAidlStatus(status,
|
||||
"Unable to get a handle to GnssVisibilityControl AIDL interface.")) {
|
||||
return std::make_unique<gnss::GnssVisibilityControlAidl>(gnssVisibilityControlAidl);
|
||||
}
|
||||
} else if (gnssHal_V2_0 != nullptr) {
|
||||
auto gnssVisibilityControlHidl = gnssHal_V2_0->getExtensionVisibilityControl();
|
||||
if (checkHidlReturn(gnssVisibilityControlHidl,
|
||||
"Unable to get a handle to GnssVisibilityControl HIDL interface")) {
|
||||
return std::make_unique<gnss::GnssVisibilityControlHidl>(gnssVisibilityControlHidl);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<GnssAntennaInfoInterface> GnssHal::getGnssAntennaInfoInterface() {
|
||||
if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) {
|
||||
sp<IGnssAntennaInfoAidl> gnssAntennaInfoAidl;
|
||||
auto status = gnssHalAidl->getExtensionGnssAntennaInfo(&gnssAntennaInfoAidl);
|
||||
if (checkAidlStatus(status, "Unable to get a handle to GnssAntennaInfo interface.")) {
|
||||
return std::make_unique<gnss::GnssAntennaInfoAidl>(gnssAntennaInfoAidl);
|
||||
}
|
||||
} else if (gnssHal_V2_1 != nullptr) {
|
||||
auto gnssAntennaInfo_V2_1 = gnssHal_V2_1->getExtensionGnssAntennaInfo();
|
||||
if (checkHidlReturn(gnssAntennaInfo_V2_1,
|
||||
"Unable to get a handle to GnssAntennaInfo_V2_1")) {
|
||||
return std::make_unique<gnss::GnssAntennaInfo_V2_1>(gnssAntennaInfo_V2_1);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<GnssPsdsInterface> GnssHal::getGnssPsdsInterface() {
|
||||
if (gnssHalAidl != nullptr) {
|
||||
sp<IGnssPsds> gnssPsdsAidl;
|
||||
auto status = gnssHalAidl->getExtensionPsds(&gnssPsdsAidl);
|
||||
if (checkAidlStatus(status, "Unable to get a handle to PSDS interface.")) {
|
||||
return std::make_unique<gnss::GnssPsdsAidl>(gnssPsdsAidl);
|
||||
}
|
||||
} else if (gnssHal != nullptr) {
|
||||
auto gnssXtra = gnssHal->getExtensionXtra();
|
||||
if (checkHidlReturn(gnssXtra, "Unable to get a handle to XTRA interface.")) {
|
||||
return std::make_unique<gnss::GnssPsdsHidl>(gnssXtra);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sp<hardware::gnss::IGnssPowerIndication> GnssHal::getGnssPowerIndicationInterface() {
|
||||
if (gnssHalAidl != nullptr) {
|
||||
sp<hardware::gnss::IGnssPowerIndication> gnssPowerIndication;
|
||||
auto status = gnssHalAidl->getExtensionGnssPowerIndication(&gnssPowerIndication);
|
||||
if (checkAidlStatus(status, "Unable to get a handle to GnssPowerIndication")) {
|
||||
return gnssPowerIndication;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sp<hardware::gnss::V1_0::IGnssNi> GnssHal::getGnssNiInterface() {
|
||||
if (gnssHal != nullptr) {
|
||||
auto gnssNi = gnssHal->getExtensionGnssNi();
|
||||
if (checkHidlReturn(gnssNi, "Unable to get a handle to GnssNi")) {
|
||||
return gnssNi;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace android::gnss
|
||||
121
services/core/jni/gnss/Gnss.h
Normal file
121
services/core/jni/gnss/Gnss.h
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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_GNSS_H
|
||||
#define _ANDROID_SERVER_GNSS_GNSS_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef LOG_TAG
|
||||
#error LOG_TAG must be defined before including this file.
|
||||
#endif
|
||||
|
||||
#include <android/hardware/gnss/1.0/IGnss.h>
|
||||
#include <android/hardware/gnss/1.1/IGnss.h>
|
||||
#include <android/hardware/gnss/2.0/IGnss.h>
|
||||
#include <android/hardware/gnss/2.1/IGnss.h>
|
||||
#include <android/hardware/gnss/BnGnss.h>
|
||||
#include <log/log.h>
|
||||
|
||||
#include "AGnss.h"
|
||||
#include "AGnssRil.h"
|
||||
#include "GnssAntennaInfo.h"
|
||||
#include "GnssBatching.h"
|
||||
#include "GnssCallback.h"
|
||||
#include "GnssConfiguration.h"
|
||||
#include "GnssDebug.h"
|
||||
#include "GnssGeofence.h"
|
||||
#include "GnssMeasurement.h"
|
||||
#include "GnssNavigationMessage.h"
|
||||
#include "GnssPsds.h"
|
||||
#include "GnssVisibilityControl.h"
|
||||
#include "MeasurementCorrections.h"
|
||||
#include "jni.h"
|
||||
|
||||
namespace android::gnss {
|
||||
|
||||
struct GnssDeathRecipient : virtual public hardware::hidl_death_recipient {
|
||||
// hidl_death_recipient interface
|
||||
virtual void serviceDied(uint64_t cookie, const wp<hidl::base::V1_0::IBase>& who) override {
|
||||
ALOGE("IGNSS hidl service failed, trying to recover...");
|
||||
|
||||
JNIEnv* env = android::AndroidRuntime::getJNIEnv();
|
||||
env->CallVoidMethod(android::mCallbacksObj, method_reportGnssServiceDied);
|
||||
}
|
||||
};
|
||||
|
||||
class GnssHal {
|
||||
public:
|
||||
GnssHal();
|
||||
~GnssHal() {}
|
||||
|
||||
jboolean isSupported();
|
||||
jboolean setCallback();
|
||||
jboolean start();
|
||||
jboolean stop();
|
||||
jboolean setPositionMode(jint mode, jint recurrence, jint min_interval, jint preferred_accuracy,
|
||||
jint preferred_time, jboolean low_power_mode);
|
||||
jboolean startSvStatus();
|
||||
jboolean stopSvStatus();
|
||||
jboolean startNmea();
|
||||
jboolean stopNmea();
|
||||
jint readNmea(jbyteArray& nmeaArray, jint& buffer_size);
|
||||
void linkToDeath();
|
||||
void close();
|
||||
void deleteAidingData(jint flags);
|
||||
void injectTime(jlong time, jlong timeReference, jint uncertainty);
|
||||
void injectLocation(jint gnssLocationFlags, jdouble latitudeDegrees, jdouble longitudeDegrees,
|
||||
jdouble altitudeMeters, jfloat speedMetersPerSec, jfloat bearingDegrees,
|
||||
jfloat horizontalAccuracyMeters, jfloat verticalAccuracyMeters,
|
||||
jfloat speedAccuracyMetersPerSecond, jfloat bearingAccuracyDegrees,
|
||||
jlong timestamp, jint elapsedRealtimeFlags, jlong elapsedRealtimeNanos,
|
||||
jdouble elapsedRealtimeUncertaintyNanos);
|
||||
void injectBestLocation(jint gnssLocationFlags, jdouble latitudeDegrees,
|
||||
jdouble longitudeDegrees, jdouble altitudeMeters,
|
||||
jfloat speedMetersPerSec, jfloat bearingDegrees,
|
||||
jfloat horizontalAccuracyMeters, jfloat verticalAccuracyMeters,
|
||||
jfloat speedAccuracyMetersPerSecond, jfloat bearingAccuracyDegrees,
|
||||
jlong timestamp, jint elapsedRealtimeFlags, jlong elapsedRealtimeNanos,
|
||||
jdouble elapsedRealtimeUncertaintyNanos);
|
||||
|
||||
std::unique_ptr<AGnssInterface> getAGnssInterface();
|
||||
std::unique_ptr<AGnssRilInterface> getAGnssRilInterface();
|
||||
std::unique_ptr<GnssNavigationMessageInterface> getGnssNavigationMessageInterface();
|
||||
std::unique_ptr<GnssMeasurementInterface> getGnssMeasurementInterface();
|
||||
std::unique_ptr<GnssDebugInterface> getGnssDebugInterface();
|
||||
std::unique_ptr<GnssConfigurationInterface> getGnssConfigurationInterface();
|
||||
std::unique_ptr<GnssGeofenceInterface> getGnssGeofenceInterface();
|
||||
std::unique_ptr<GnssBatchingInterface> getGnssBatchingInterface();
|
||||
std::unique_ptr<MeasurementCorrectionsInterface> getMeasurementCorrectionsInterface();
|
||||
std::unique_ptr<GnssVisibilityControlInterface> getGnssVisibilityControlInterface();
|
||||
std::unique_ptr<GnssAntennaInfoInterface> getGnssAntennaInfoInterface();
|
||||
std::unique_ptr<GnssPsdsInterface> getGnssPsdsInterface();
|
||||
|
||||
sp<hardware::gnss::IGnssPowerIndication> getGnssPowerIndicationInterface();
|
||||
sp<hardware::gnss::V1_0::IGnssNi> getGnssNiInterface();
|
||||
|
||||
private:
|
||||
sp<GnssDeathRecipient> gnssHalDeathRecipient = nullptr;
|
||||
sp<hardware::gnss::V1_0::IGnss> gnssHal = nullptr;
|
||||
sp<hardware::gnss::V1_1::IGnss> gnssHal_V1_1 = nullptr;
|
||||
sp<hardware::gnss::V2_0::IGnss> gnssHal_V2_0 = nullptr;
|
||||
sp<hardware::gnss::V2_1::IGnss> gnssHal_V2_1 = nullptr;
|
||||
sp<hardware::gnss::IGnss> gnssHalAidl = nullptr;
|
||||
};
|
||||
|
||||
} // namespace android::gnss
|
||||
|
||||
#endif // _ANDROID_SERVER_GNSS_Gnss_H
|
||||
413
services/core/jni/gnss/GnssCallback.cpp
Normal file
413
services/core/jni/gnss/GnssCallback.cpp
Normal file
@@ -0,0 +1,413 @@
|
||||
/*
|
||||
* 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 "GnssCallbckJni"
|
||||
|
||||
#include "GnssCallback.h"
|
||||
|
||||
#include <hardware_legacy/power.h>
|
||||
|
||||
#define WAKE_LOCK_NAME "GPS"
|
||||
|
||||
namespace android::gnss {
|
||||
|
||||
using android::hardware::gnss::V1_0::GnssLocationFlags;
|
||||
using binder::Status;
|
||||
using hardware::hidl_vec;
|
||||
using hardware::Return;
|
||||
using hardware::Void;
|
||||
|
||||
using GnssLocationAidl = android::hardware::gnss::GnssLocation;
|
||||
using GnssLocation_V1_0 = android::hardware::gnss::V1_0::GnssLocation;
|
||||
using GnssLocation_V2_0 = android::hardware::gnss::V2_0::GnssLocation;
|
||||
using IGnssCallbackAidl = android::hardware::gnss::IGnssCallback;
|
||||
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;
|
||||
|
||||
jmethodID method_reportGnssServiceDied;
|
||||
|
||||
namespace {
|
||||
|
||||
jmethodID method_reportLocation;
|
||||
jmethodID method_reportStatus;
|
||||
jmethodID method_reportSvStatus;
|
||||
jmethodID method_reportNmea;
|
||||
jmethodID method_setTopHalCapabilities;
|
||||
jmethodID method_setGnssYearOfHardware;
|
||||
jmethodID method_setGnssHardwareModelName;
|
||||
jmethodID method_requestLocation;
|
||||
jmethodID method_requestUtcTime;
|
||||
|
||||
// Returns true if location has lat/long information.
|
||||
inline bool hasLatLong(const GnssLocationAidl& location) {
|
||||
return (location.gnssLocationFlags & hardware::gnss::GnssLocation::HAS_LAT_LONG) != 0;
|
||||
}
|
||||
|
||||
// Returns true if location has lat/long information.
|
||||
inline bool hasLatLong(const GnssLocation_V1_0& location) {
|
||||
return (static_cast<uint32_t>(location.gnssLocationFlags) & GnssLocationFlags::HAS_LAT_LONG) !=
|
||||
0;
|
||||
}
|
||||
|
||||
// Returns true if location has lat/long information.
|
||||
inline bool hasLatLong(const GnssLocation_V2_0& location) {
|
||||
return hasLatLong(location.v1_0);
|
||||
}
|
||||
|
||||
inline jboolean boolToJbool(bool value) {
|
||||
return value ? JNI_TRUE : JNI_FALSE;
|
||||
}
|
||||
|
||||
// Must match the value from GnssMeasurement.java
|
||||
const uint32_t SVID_FLAGS_HAS_BASEBAND_CN0 = (1 << 4);
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
bool isSvStatusRegistered = false;
|
||||
bool isNmeaRegistered = false;
|
||||
|
||||
void Gnss_class_init_once(JNIEnv* env, jclass& clazz) {
|
||||
method_reportLocation =
|
||||
env->GetMethodID(clazz, "reportLocation", "(ZLandroid/location/Location;)V");
|
||||
method_reportStatus = env->GetMethodID(clazz, "reportStatus", "(I)V");
|
||||
method_reportSvStatus = env->GetMethodID(clazz, "reportSvStatus", "(I[I[F[F[F[F[F)V");
|
||||
method_reportNmea = env->GetMethodID(clazz, "reportNmea", "(J)V");
|
||||
|
||||
method_setTopHalCapabilities = env->GetMethodID(clazz, "setTopHalCapabilities", "(I)V");
|
||||
method_setGnssYearOfHardware = env->GetMethodID(clazz, "setGnssYearOfHardware", "(I)V");
|
||||
method_setGnssHardwareModelName =
|
||||
env->GetMethodID(clazz, "setGnssHardwareModelName", "(Ljava/lang/String;)V");
|
||||
|
||||
method_requestLocation = env->GetMethodID(clazz, "requestLocation", "(ZZ)V");
|
||||
method_requestUtcTime = env->GetMethodID(clazz, "requestUtcTime", "()V");
|
||||
method_reportGnssServiceDied = env->GetMethodID(clazz, "reportGnssServiceDied", "()V");
|
||||
}
|
||||
|
||||
Status GnssCallbackAidl::gnssSetCapabilitiesCb(const int capabilities) {
|
||||
ALOGD("GnssCallbackAidl::%s: %du\n", __func__, capabilities);
|
||||
JNIEnv* env = getJniEnv();
|
||||
env->CallVoidMethod(mCallbacksObj, method_setTopHalCapabilities, capabilities);
|
||||
checkAndClearExceptionFromCallback(env, __FUNCTION__);
|
||||
return Status::ok();
|
||||
}
|
||||
|
||||
Status GnssCallbackAidl::gnssStatusCb(const GnssStatusValue status) {
|
||||
JNIEnv* env = getJniEnv();
|
||||
env->CallVoidMethod(mCallbacksObj, method_reportStatus, status);
|
||||
checkAndClearExceptionFromCallback(env, __FUNCTION__);
|
||||
return Status::ok();
|
||||
}
|
||||
|
||||
Status GnssCallbackAidl::gnssSvStatusCb(const std::vector<GnssSvInfo>& svInfoList) {
|
||||
GnssCallbackHidl::gnssSvStatusCbImpl<std::vector<GnssSvInfo>, GnssSvInfo>(svInfoList);
|
||||
return Status::ok();
|
||||
}
|
||||
|
||||
Status GnssCallbackAidl::gnssLocationCb(const hardware::gnss::GnssLocation& location) {
|
||||
GnssCallbackHidl::gnssLocationCbImpl<hardware::gnss::GnssLocation>(location);
|
||||
return Status::ok();
|
||||
}
|
||||
|
||||
Status GnssCallbackAidl::gnssNmeaCb(const int64_t timestamp, const std::string& nmea) {
|
||||
// In AIDL v1, if no listener is registered, do not report nmea to the framework.
|
||||
if (getInterfaceVersion() <= 1) {
|
||||
if (!isNmeaRegistered) {
|
||||
return Status::ok();
|
||||
}
|
||||
}
|
||||
JNIEnv* env = getJniEnv();
|
||||
/*
|
||||
* The Java code will call back to read these values.
|
||||
* We do this to avoid creating unnecessary String objects.
|
||||
*/
|
||||
GnssCallbackHidl::sNmeaString = nmea.c_str();
|
||||
GnssCallbackHidl::sNmeaStringLength = nmea.size();
|
||||
|
||||
env->CallVoidMethod(mCallbacksObj, method_reportNmea, timestamp);
|
||||
checkAndClearExceptionFromCallback(env, __FUNCTION__);
|
||||
return Status::ok();
|
||||
}
|
||||
|
||||
Status GnssCallbackAidl::gnssAcquireWakelockCb() {
|
||||
acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_NAME);
|
||||
return Status::ok();
|
||||
}
|
||||
|
||||
Status GnssCallbackAidl::gnssReleaseWakelockCb() {
|
||||
release_wake_lock(WAKE_LOCK_NAME);
|
||||
return Status::ok();
|
||||
}
|
||||
|
||||
Status GnssCallbackAidl::gnssSetSystemInfoCb(const GnssSystemInfo& info) {
|
||||
ALOGD("%s: yearOfHw=%d, name=%s\n", __func__, info.yearOfHw, info.name.c_str());
|
||||
JNIEnv* env = getJniEnv();
|
||||
env->CallVoidMethod(mCallbacksObj, method_setGnssYearOfHardware, info.yearOfHw);
|
||||
jstring jstringName = env->NewStringUTF(info.name.c_str());
|
||||
env->CallVoidMethod(mCallbacksObj, method_setGnssHardwareModelName, jstringName);
|
||||
if (jstringName) {
|
||||
env->DeleteLocalRef(jstringName);
|
||||
}
|
||||
checkAndClearExceptionFromCallback(env, __FUNCTION__);
|
||||
return Status::ok();
|
||||
}
|
||||
|
||||
Status GnssCallbackAidl::gnssRequestTimeCb() {
|
||||
JNIEnv* env = getJniEnv();
|
||||
env->CallVoidMethod(mCallbacksObj, method_requestUtcTime);
|
||||
checkAndClearExceptionFromCallback(env, __FUNCTION__);
|
||||
return Status::ok();
|
||||
}
|
||||
|
||||
Status GnssCallbackAidl::gnssRequestLocationCb(const bool independentFromGnss,
|
||||
const bool isUserEmergency) {
|
||||
JNIEnv* env = getJniEnv();
|
||||
env->CallVoidMethod(mCallbacksObj, method_requestLocation, boolToJbool(independentFromGnss),
|
||||
boolToJbool(isUserEmergency));
|
||||
checkAndClearExceptionFromCallback(env, __FUNCTION__);
|
||||
return Status::ok();
|
||||
}
|
||||
|
||||
// Implementation of IGnssCallbackHidl
|
||||
|
||||
Return<void> GnssCallbackHidl::gnssNameCb(const android::hardware::hidl_string& name) {
|
||||
ALOGD("%s: name=%s\n", __func__, name.c_str());
|
||||
|
||||
JNIEnv* env = getJniEnv();
|
||||
jstring jstringName = env->NewStringUTF(name.c_str());
|
||||
env->CallVoidMethod(mCallbacksObj, method_setGnssHardwareModelName, jstringName);
|
||||
if (jstringName) {
|
||||
env->DeleteLocalRef(jstringName);
|
||||
}
|
||||
checkAndClearExceptionFromCallback(env, __FUNCTION__);
|
||||
|
||||
return Void();
|
||||
}
|
||||
|
||||
const char* GnssCallbackHidl::sNmeaString = nullptr;
|
||||
size_t GnssCallbackHidl::sNmeaStringLength = 0;
|
||||
|
||||
template <class T>
|
||||
Return<void> GnssCallbackHidl::gnssLocationCbImpl(const T& location) {
|
||||
JNIEnv* env = getJniEnv();
|
||||
|
||||
jobject jLocation = translateGnssLocation(env, location);
|
||||
|
||||
env->CallVoidMethod(mCallbacksObj, method_reportLocation, boolToJbool(hasLatLong(location)),
|
||||
jLocation);
|
||||
checkAndClearExceptionFromCallback(env, __FUNCTION__);
|
||||
env->DeleteLocalRef(jLocation);
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> GnssCallbackHidl::gnssLocationCb(const GnssLocation_V1_0& location) {
|
||||
return gnssLocationCbImpl<GnssLocation_V1_0>(location);
|
||||
}
|
||||
|
||||
Return<void> GnssCallbackHidl::gnssLocationCb_2_0(const GnssLocation_V2_0& location) {
|
||||
return gnssLocationCbImpl<GnssLocation_V2_0>(location);
|
||||
}
|
||||
|
||||
Return<void> GnssCallbackHidl::gnssStatusCb(const IGnssCallback_V2_0::GnssStatusValue status) {
|
||||
JNIEnv* env = getJniEnv();
|
||||
env->CallVoidMethod(mCallbacksObj, method_reportStatus, status);
|
||||
checkAndClearExceptionFromCallback(env, __FUNCTION__);
|
||||
return Void();
|
||||
}
|
||||
|
||||
template <>
|
||||
uint32_t GnssCallbackHidl::getHasBasebandCn0DbHzFlag(
|
||||
const hidl_vec<IGnssCallback_V2_1::GnssSvInfo>& svStatus) {
|
||||
return SVID_FLAGS_HAS_BASEBAND_CN0;
|
||||
}
|
||||
|
||||
template <>
|
||||
uint32_t GnssCallbackHidl::getHasBasebandCn0DbHzFlag(
|
||||
const std::vector<IGnssCallbackAidl::GnssSvInfo>& svStatus) {
|
||||
return SVID_FLAGS_HAS_BASEBAND_CN0;
|
||||
}
|
||||
|
||||
template <>
|
||||
double GnssCallbackHidl::getBasebandCn0DbHz(
|
||||
const std::vector<IGnssCallbackAidl::GnssSvInfo>& svInfoList, size_t i) {
|
||||
return svInfoList[i].basebandCN0DbHz;
|
||||
}
|
||||
|
||||
template <>
|
||||
double GnssCallbackHidl::getBasebandCn0DbHz(
|
||||
const hidl_vec<IGnssCallback_V2_1::GnssSvInfo>& svInfoList, size_t i) {
|
||||
return svInfoList[i].basebandCN0DbHz;
|
||||
}
|
||||
|
||||
template <>
|
||||
uint32_t GnssCallbackHidl::getGnssSvInfoListSize(const IGnssCallback_V1_0::GnssSvStatus& svStatus) {
|
||||
return svStatus.numSvs;
|
||||
}
|
||||
|
||||
template <>
|
||||
uint32_t GnssCallbackHidl::getConstellationType(const IGnssCallback_V1_0::GnssSvStatus& svStatus,
|
||||
size_t i) {
|
||||
return static_cast<uint32_t>(svStatus.gnssSvList.data()[i].constellation);
|
||||
}
|
||||
|
||||
template <>
|
||||
uint32_t GnssCallbackHidl::getConstellationType(
|
||||
const hidl_vec<IGnssCallback_V2_1::GnssSvInfo>& svInfoList, size_t i) {
|
||||
return static_cast<uint32_t>(svInfoList[i].v2_0.constellation);
|
||||
}
|
||||
|
||||
template <class T_list, class T_sv_info>
|
||||
Return<void> GnssCallbackHidl::gnssSvStatusCbImpl(const T_list& svStatus) {
|
||||
// In HIDL or AIDL v1, if no listener is registered, do not report svInfoList to the framework.
|
||||
if (!isSvStatusRegistered) {
|
||||
return Void();
|
||||
}
|
||||
|
||||
JNIEnv* env = getJniEnv();
|
||||
|
||||
uint32_t listSize = getGnssSvInfoListSize(svStatus);
|
||||
|
||||
jintArray svidWithFlagArray = env->NewIntArray(listSize);
|
||||
jfloatArray cn0Array = env->NewFloatArray(listSize);
|
||||
jfloatArray elevArray = env->NewFloatArray(listSize);
|
||||
jfloatArray azimArray = env->NewFloatArray(listSize);
|
||||
jfloatArray carrierFreqArray = env->NewFloatArray(listSize);
|
||||
jfloatArray basebandCn0Array = env->NewFloatArray(listSize);
|
||||
|
||||
jint* svidWithFlags = env->GetIntArrayElements(svidWithFlagArray, 0);
|
||||
jfloat* cn0s = env->GetFloatArrayElements(cn0Array, 0);
|
||||
jfloat* elev = env->GetFloatArrayElements(elevArray, 0);
|
||||
jfloat* azim = env->GetFloatArrayElements(azimArray, 0);
|
||||
jfloat* carrierFreq = env->GetFloatArrayElements(carrierFreqArray, 0);
|
||||
jfloat* basebandCn0s = env->GetFloatArrayElements(basebandCn0Array, 0);
|
||||
|
||||
/*
|
||||
* Read GNSS SV info.
|
||||
*/
|
||||
for (size_t i = 0; i < listSize; ++i) {
|
||||
enum ShiftWidth : uint8_t { SVID_SHIFT_WIDTH = 12, CONSTELLATION_TYPE_SHIFT_WIDTH = 8 };
|
||||
|
||||
const T_sv_info& info = getGnssSvInfoOfIndex(svStatus, i);
|
||||
svidWithFlags[i] = (info.svid << SVID_SHIFT_WIDTH) |
|
||||
(getConstellationType(svStatus, i) << CONSTELLATION_TYPE_SHIFT_WIDTH) |
|
||||
static_cast<uint32_t>(info.svFlag);
|
||||
cn0s[i] = info.cN0Dbhz;
|
||||
elev[i] = info.elevationDegrees;
|
||||
azim[i] = info.azimuthDegrees;
|
||||
carrierFreq[i] = info.carrierFrequencyHz;
|
||||
svidWithFlags[i] |= getHasBasebandCn0DbHzFlag(svStatus);
|
||||
basebandCn0s[i] = getBasebandCn0DbHz(svStatus, i);
|
||||
}
|
||||
|
||||
env->ReleaseIntArrayElements(svidWithFlagArray, svidWithFlags, 0);
|
||||
env->ReleaseFloatArrayElements(cn0Array, cn0s, 0);
|
||||
env->ReleaseFloatArrayElements(elevArray, elev, 0);
|
||||
env->ReleaseFloatArrayElements(azimArray, azim, 0);
|
||||
env->ReleaseFloatArrayElements(carrierFreqArray, carrierFreq, 0);
|
||||
env->ReleaseFloatArrayElements(basebandCn0Array, basebandCn0s, 0);
|
||||
|
||||
env->CallVoidMethod(mCallbacksObj, method_reportSvStatus, static_cast<jint>(listSize),
|
||||
svidWithFlagArray, cn0Array, elevArray, azimArray, carrierFreqArray,
|
||||
basebandCn0Array);
|
||||
|
||||
env->DeleteLocalRef(svidWithFlagArray);
|
||||
env->DeleteLocalRef(cn0Array);
|
||||
env->DeleteLocalRef(elevArray);
|
||||
env->DeleteLocalRef(azimArray);
|
||||
env->DeleteLocalRef(carrierFreqArray);
|
||||
env->DeleteLocalRef(basebandCn0Array);
|
||||
|
||||
checkAndClearExceptionFromCallback(env, __FUNCTION__);
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> GnssCallbackHidl::gnssNmeaCb(int64_t timestamp,
|
||||
const ::android::hardware::hidl_string& nmea) {
|
||||
// In HIDL, if no listener is registered, do not report nmea to the framework.
|
||||
if (!isNmeaRegistered) {
|
||||
return Void();
|
||||
}
|
||||
JNIEnv* env = getJniEnv();
|
||||
/*
|
||||
* The Java code will call back to read these values.
|
||||
* We do this to avoid creating unnecessary String objects.
|
||||
*/
|
||||
sNmeaString = nmea.c_str();
|
||||
sNmeaStringLength = nmea.size();
|
||||
|
||||
env->CallVoidMethod(mCallbacksObj, method_reportNmea, timestamp);
|
||||
checkAndClearExceptionFromCallback(env, __FUNCTION__);
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> GnssCallbackHidl::gnssSetCapabilitesCb(uint32_t capabilities) {
|
||||
ALOGD("%s: %du\n", __func__, capabilities);
|
||||
|
||||
JNIEnv* env = getJniEnv();
|
||||
env->CallVoidMethod(mCallbacksObj, method_setTopHalCapabilities, capabilities);
|
||||
checkAndClearExceptionFromCallback(env, __FUNCTION__);
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> GnssCallbackHidl::gnssSetCapabilitiesCb_2_0(uint32_t capabilities) {
|
||||
return GnssCallbackHidl::gnssSetCapabilitesCb(capabilities);
|
||||
}
|
||||
|
||||
Return<void> GnssCallbackHidl::gnssSetCapabilitiesCb_2_1(uint32_t capabilities) {
|
||||
return GnssCallbackHidl::gnssSetCapabilitesCb(capabilities);
|
||||
}
|
||||
|
||||
Return<void> GnssCallbackHidl::gnssAcquireWakelockCb() {
|
||||
acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_NAME);
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> GnssCallbackHidl::gnssReleaseWakelockCb() {
|
||||
release_wake_lock(WAKE_LOCK_NAME);
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> GnssCallbackHidl::gnssRequestTimeCb() {
|
||||
JNIEnv* env = getJniEnv();
|
||||
env->CallVoidMethod(mCallbacksObj, method_requestUtcTime);
|
||||
checkAndClearExceptionFromCallback(env, __FUNCTION__);
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> GnssCallbackHidl::gnssRequestLocationCb(const bool independentFromGnss) {
|
||||
return GnssCallbackHidl::gnssRequestLocationCb_2_0(independentFromGnss, /* isUserEmergency= */
|
||||
false);
|
||||
}
|
||||
|
||||
Return<void> GnssCallbackHidl::gnssRequestLocationCb_2_0(const bool independentFromGnss,
|
||||
const bool isUserEmergency) {
|
||||
JNIEnv* env = getJniEnv();
|
||||
env->CallVoidMethod(mCallbacksObj, method_requestLocation, boolToJbool(independentFromGnss),
|
||||
boolToJbool(isUserEmergency));
|
||||
checkAndClearExceptionFromCallback(env, __FUNCTION__);
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> GnssCallbackHidl::gnssSetSystemInfoCb(const IGnssCallback_V2_0::GnssSystemInfo& info) {
|
||||
ALOGD("%s: yearOfHw=%d\n", __func__, info.yearOfHw);
|
||||
|
||||
JNIEnv* env = getJniEnv();
|
||||
env->CallVoidMethod(mCallbacksObj, method_setGnssYearOfHardware, info.yearOfHw);
|
||||
checkAndClearExceptionFromCallback(env, __FUNCTION__);
|
||||
return Void();
|
||||
}
|
||||
|
||||
} // namespace android::gnss
|
||||
183
services/core/jni/gnss/GnssCallback.h
Normal file
183
services/core/jni/gnss/GnssCallback.h
Normal file
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* 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_GNSSCALLBACK_H
|
||||
#define _ANDROID_SERVER_GNSS_GNSSCALLBACK_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef LOG_TAG
|
||||
#error LOG_TAG must be defined before including this file.
|
||||
#endif
|
||||
|
||||
#include <android/hardware/gnss/2.1/IGnss.h>
|
||||
#include <android/hardware/gnss/BnGnssCallback.h>
|
||||
#include <log/log.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "Utils.h"
|
||||
#include "jni.h"
|
||||
|
||||
namespace android::gnss {
|
||||
|
||||
namespace {
|
||||
|
||||
extern jmethodID method_reportLocation;
|
||||
extern jmethodID method_reportStatus;
|
||||
extern jmethodID method_reportSvStatus;
|
||||
extern jmethodID method_reportNmea;
|
||||
extern jmethodID method_setTopHalCapabilities;
|
||||
extern jmethodID method_setGnssYearOfHardware;
|
||||
extern jmethodID method_setGnssHardwareModelName;
|
||||
extern jmethodID method_requestLocation;
|
||||
extern jmethodID method_requestUtcTime;
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
extern bool isSvStatusRegistered;
|
||||
extern bool isNmeaRegistered;
|
||||
|
||||
extern jmethodID method_reportGnssServiceDied;
|
||||
|
||||
void Gnss_class_init_once(JNIEnv* env, jclass& clazz);
|
||||
|
||||
/*
|
||||
* GnssCallbackAidl class implements the callback methods for AIDL IGnssCallback interface.
|
||||
*/
|
||||
class GnssCallbackAidl : public hardware::gnss::BnGnssCallback {
|
||||
public:
|
||||
binder::Status gnssSetCapabilitiesCb(const int capabilities) override;
|
||||
binder::Status gnssStatusCb(const GnssStatusValue status) override;
|
||||
binder::Status gnssSvStatusCb(const std::vector<GnssSvInfo>& svInfoList) override;
|
||||
binder::Status gnssLocationCb(const hardware::gnss::GnssLocation& location) override;
|
||||
binder::Status gnssNmeaCb(const int64_t timestamp, const std::string& nmea) override;
|
||||
binder::Status gnssAcquireWakelockCb() override;
|
||||
binder::Status gnssReleaseWakelockCb() override;
|
||||
binder::Status gnssSetSystemInfoCb(const GnssSystemInfo& info) override;
|
||||
binder::Status gnssRequestTimeCb() override;
|
||||
binder::Status gnssRequestLocationCb(const bool independentFromGnss,
|
||||
const bool isUserEmergency) override;
|
||||
};
|
||||
|
||||
/*
|
||||
* GnssCallbackHidl class implements the callback methods for HIDL IGnssCallback interface.
|
||||
*/
|
||||
struct GnssCallbackHidl : public hardware::gnss::V2_1::IGnssCallback {
|
||||
hardware::Return<void> gnssLocationCb(
|
||||
const hardware::gnss::V1_0::GnssLocation& location) override;
|
||||
hardware::Return<void> gnssStatusCb(
|
||||
const hardware::gnss::V1_0::IGnssCallback::GnssStatusValue status) override;
|
||||
hardware::Return<void> gnssSvStatusCb(
|
||||
const hardware::gnss::V1_0::IGnssCallback::GnssSvStatus& svStatus) override {
|
||||
return gnssSvStatusCbImpl<hardware::gnss::V1_0::IGnssCallback::GnssSvStatus,
|
||||
hardware::gnss::V1_0::IGnssCallback::GnssSvInfo>(svStatus);
|
||||
}
|
||||
hardware::Return<void> gnssNmeaCb(int64_t timestamp,
|
||||
const hardware::hidl_string& nmea) override;
|
||||
hardware::Return<void> gnssSetCapabilitesCb(uint32_t capabilities) override;
|
||||
hardware::Return<void> gnssAcquireWakelockCb() override;
|
||||
hardware::Return<void> gnssReleaseWakelockCb() override;
|
||||
hardware::Return<void> gnssRequestTimeCb() override;
|
||||
hardware::Return<void> gnssRequestLocationCb(const bool independentFromGnss) override;
|
||||
|
||||
hardware::Return<void> gnssSetSystemInfoCb(
|
||||
const hardware::gnss::V1_0::IGnssCallback::GnssSystemInfo& info) override;
|
||||
|
||||
// New in 1.1
|
||||
hardware::Return<void> gnssNameCb(const hardware::hidl_string& name) override;
|
||||
|
||||
// New in 2.0
|
||||
hardware::Return<void> gnssRequestLocationCb_2_0(const bool independentFromGnss,
|
||||
const bool isUserEmergency) override;
|
||||
hardware::Return<void> gnssSetCapabilitiesCb_2_0(uint32_t capabilities) override;
|
||||
hardware::Return<void> gnssLocationCb_2_0(
|
||||
const hardware::gnss::V2_0::GnssLocation& location) override;
|
||||
hardware::Return<void> gnssSvStatusCb_2_0(
|
||||
const hardware::hidl_vec<hardware::gnss::V2_0::IGnssCallback::GnssSvInfo>& svInfoList)
|
||||
override {
|
||||
return gnssSvStatusCbImpl<
|
||||
hardware::hidl_vec<hardware::gnss::V2_0::IGnssCallback::GnssSvInfo>,
|
||||
hardware::gnss::V1_0::IGnssCallback::GnssSvInfo>(svInfoList);
|
||||
}
|
||||
|
||||
// New in 2.1
|
||||
hardware::Return<void> gnssSvStatusCb_2_1(
|
||||
const hardware::hidl_vec<hardware::gnss::V2_1::IGnssCallback::GnssSvInfo>& svInfoList)
|
||||
override {
|
||||
return gnssSvStatusCbImpl<
|
||||
hardware::hidl_vec<hardware::gnss::V2_1::IGnssCallback::GnssSvInfo>,
|
||||
hardware::gnss::V1_0::IGnssCallback::GnssSvInfo>(svInfoList);
|
||||
}
|
||||
hardware::Return<void> gnssSetCapabilitiesCb_2_1(uint32_t capabilities) override;
|
||||
|
||||
// TODO: Reconsider allocation cost vs threadsafety on these statics
|
||||
static const char* sNmeaString;
|
||||
static size_t sNmeaStringLength;
|
||||
|
||||
template <class T>
|
||||
static hardware::Return<void> gnssLocationCbImpl(const T& location);
|
||||
|
||||
template <class T_list, class T_sv_info>
|
||||
static hardware::Return<void> gnssSvStatusCbImpl(const T_list& svStatus);
|
||||
|
||||
private:
|
||||
template <class T>
|
||||
static uint32_t getHasBasebandCn0DbHzFlag(const T& svStatus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static double getBasebandCn0DbHz(const T& svStatus, size_t i) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static uint32_t getGnssSvInfoListSize(const T& svInfoList) {
|
||||
return svInfoList.size();
|
||||
}
|
||||
|
||||
static const hardware::gnss::IGnssCallback::GnssSvInfo& getGnssSvInfoOfIndex(
|
||||
const std::vector<hardware::gnss::IGnssCallback::GnssSvInfo>& svInfoList, size_t i) {
|
||||
return svInfoList[i];
|
||||
}
|
||||
|
||||
static const hardware::gnss::V1_0::IGnssCallback::GnssSvInfo& getGnssSvInfoOfIndex(
|
||||
const hardware::gnss::V1_0::IGnssCallback::GnssSvStatus& svStatus, size_t i) {
|
||||
return svStatus.gnssSvList.data()[i];
|
||||
}
|
||||
|
||||
static const hardware::gnss::V1_0::IGnssCallback::GnssSvInfo& getGnssSvInfoOfIndex(
|
||||
const hardware::hidl_vec<hardware::gnss::V2_0::IGnssCallback::GnssSvInfo>& svInfoList,
|
||||
size_t i) {
|
||||
return svInfoList[i].v1_0;
|
||||
}
|
||||
|
||||
static const hardware::gnss::V1_0::IGnssCallback::GnssSvInfo& getGnssSvInfoOfIndex(
|
||||
const hardware::hidl_vec<hardware::gnss::V2_1::IGnssCallback::GnssSvInfo>& svInfoList,
|
||||
size_t i) {
|
||||
return svInfoList[i].v2_0.v1_0;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static uint32_t getConstellationType(const T& svInfoList, size_t i) {
|
||||
return static_cast<uint32_t>(svInfoList[i].constellation);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace android::gnss
|
||||
|
||||
#endif // _ANDROID_SERVER_GNSS_GNSSCALLBACK_H
|
||||
@@ -104,4 +104,10 @@ const android::hardware::gnss::IGnssDebug::SatelliteData& GnssDebugUtil::getSate
|
||||
return satelliteDataArray[i];
|
||||
}
|
||||
|
||||
template <>
|
||||
int64_t GnssDebugUtil::getTimeEstimateMs(
|
||||
const android::hardware::gnss::IGnssDebug::DebugData& data) {
|
||||
return data.time.timeEstimateMs;
|
||||
}
|
||||
|
||||
} // namespace android::gnss
|
||||
|
||||
@@ -113,12 +113,6 @@ int64_t GnssDebugUtil::getTimeEstimateMs(const T& data) {
|
||||
return data.time.timeEstimate;
|
||||
}
|
||||
|
||||
template <>
|
||||
int64_t GnssDebugUtil::getTimeEstimateMs(
|
||||
const android::hardware::gnss::IGnssDebug::DebugData& data) {
|
||||
return data.time.timeEstimateMs;
|
||||
}
|
||||
|
||||
template <class T_DebugData, class T_SatelliteData>
|
||||
jstring GnssDebugUtil::parseDebugData(JNIEnv* env, std::stringstream& internalState,
|
||||
const T_DebugData& data) {
|
||||
|
||||
73
services/core/jni/gnss/GnssPsds.cpp
Normal file
73
services/core/jni/gnss/GnssPsds.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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 "GnssPsdsJni"
|
||||
|
||||
#include "GnssPsds.h"
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
using android::hardware::hidl_bitfield;
|
||||
using android::hardware::gnss::PsdsType;
|
||||
using IGnssPsdsAidl = android::hardware::gnss::IGnssPsds;
|
||||
using IGnssPsdsHidl = android::hardware::gnss::V1_0::IGnssXtra;
|
||||
|
||||
namespace android::gnss {
|
||||
|
||||
// Implementation of GnssPsds (AIDL HAL)
|
||||
|
||||
GnssPsdsAidl::GnssPsdsAidl(const sp<IGnssPsdsAidl>& iGnssPsds) : mIGnssPsds(iGnssPsds) {
|
||||
assert(mIGnssPsds != nullptr);
|
||||
}
|
||||
|
||||
jboolean GnssPsdsAidl::setCallback(const std::unique_ptr<GnssPsdsCallback>& callback) {
|
||||
auto status = mIGnssPsds->setCallback(callback->getAidl());
|
||||
return checkAidlStatus(status, "IGnssPsdsAidl setCallback() failed.");
|
||||
}
|
||||
|
||||
void GnssPsdsAidl::injectPsdsData(const jbyteArray& data, const jint& length,
|
||||
const jint& psdsType) {
|
||||
JNIEnv* env = getJniEnv();
|
||||
jbyte* bytes = reinterpret_cast<jbyte*>(env->GetPrimitiveArrayCritical(data, 0));
|
||||
auto status = mIGnssPsds->injectPsdsData(static_cast<PsdsType>(psdsType),
|
||||
std::vector<uint8_t>((const uint8_t*)bytes,
|
||||
(const uint8_t*)bytes + length));
|
||||
checkAidlStatus(status, "IGnssPsdsAidl injectPsdsData() failed.");
|
||||
env->ReleasePrimitiveArrayCritical(data, bytes, JNI_ABORT);
|
||||
}
|
||||
|
||||
// Implementation of GnssPsdsHidl
|
||||
|
||||
GnssPsdsHidl::GnssPsdsHidl(const sp<android::hardware::gnss::V1_0::IGnssXtra>& iGnssXtra)
|
||||
: mIGnssXtra(iGnssXtra) {
|
||||
assert(mIGnssXtra != nullptr);
|
||||
}
|
||||
|
||||
jboolean GnssPsdsHidl::setCallback(const std::unique_ptr<GnssPsdsCallback>& callback) {
|
||||
auto result = mIGnssXtra->setCallback(callback->getHidl());
|
||||
return checkHidlReturn(result, "IGnssPsdsHidl setCallback() failed.");
|
||||
}
|
||||
|
||||
void GnssPsdsHidl::injectPsdsData(const jbyteArray& data, const jint& length, const jint&) {
|
||||
JNIEnv* env = getJniEnv();
|
||||
jbyte* bytes = reinterpret_cast<jbyte*>(env->GetPrimitiveArrayCritical(data, 0));
|
||||
auto result = mIGnssXtra->injectXtraData(std::string((const char*)bytes, length));
|
||||
checkHidlReturn(result, "IGnssXtra injectXtraData() failed.");
|
||||
env->ReleasePrimitiveArrayCritical(data, bytes, JNI_ABORT);
|
||||
}
|
||||
|
||||
} // namespace android::gnss
|
||||
64
services/core/jni/gnss/GnssPsds.h
Normal file
64
services/core/jni/gnss/GnssPsds.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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_GNSSPSDS_H
|
||||
#define _ANDROID_SERVER_GNSS_GNSSPSDS_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef LOG_TAG
|
||||
#error LOG_TAG must be defined before including this file.
|
||||
#endif
|
||||
|
||||
#include <android/hardware/gnss/1.0/IGnssXtra.h>
|
||||
#include <android/hardware/gnss/BnGnssPsds.h>
|
||||
#include <log/log.h>
|
||||
|
||||
#include "GnssPsdsCallback.h"
|
||||
#include "jni.h"
|
||||
|
||||
namespace android::gnss {
|
||||
|
||||
class GnssPsdsInterface {
|
||||
public:
|
||||
virtual ~GnssPsdsInterface() {}
|
||||
virtual jboolean setCallback(const std::unique_ptr<GnssPsdsCallback>& callback);
|
||||
virtual void injectPsdsData(const jbyteArray& data, const jint& length, const jint& psdsType);
|
||||
};
|
||||
|
||||
class GnssPsdsAidl : public GnssPsdsInterface {
|
||||
public:
|
||||
GnssPsdsAidl(const sp<android::hardware::gnss::IGnssPsds>& iGnssPsds);
|
||||
jboolean setCallback(const std::unique_ptr<GnssPsdsCallback>& callback) override;
|
||||
void injectPsdsData(const jbyteArray& data, const jint& length, const jint& psdsType) override;
|
||||
|
||||
private:
|
||||
const sp<android::hardware::gnss::IGnssPsds> mIGnssPsds;
|
||||
};
|
||||
|
||||
class GnssPsdsHidl : public GnssPsdsInterface {
|
||||
public:
|
||||
GnssPsdsHidl(const sp<android::hardware::gnss::V1_0::IGnssXtra>& iGnssXtra);
|
||||
jboolean setCallback(const std::unique_ptr<GnssPsdsCallback>& callback) override;
|
||||
void injectPsdsData(const jbyteArray& data, const jint& length, const jint& psdsType) override;
|
||||
|
||||
private:
|
||||
const sp<android::hardware::gnss::V1_0::IGnssXtra> mIGnssXtra;
|
||||
};
|
||||
|
||||
} // namespace android::gnss
|
||||
|
||||
#endif // _ANDROID_SERVER_GNSS_GNSSPSDS_H
|
||||
59
services/core/jni/gnss/GnssPsdsCallback.cpp
Normal file
59
services/core/jni/gnss/GnssPsdsCallback.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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 "GnssPsdsCbJni"
|
||||
|
||||
#include "GnssPsdsCallback.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
namespace android::gnss {
|
||||
|
||||
namespace {
|
||||
jmethodID method_psdsDownloadRequest;
|
||||
} // anonymous namespace
|
||||
|
||||
using binder::Status;
|
||||
using hardware::Return;
|
||||
using hardware::Void;
|
||||
using hardware::gnss::PsdsType;
|
||||
|
||||
void GnssPsds_class_init_once(JNIEnv* env, jclass clazz) {
|
||||
method_psdsDownloadRequest = env->GetMethodID(clazz, "psdsDownloadRequest", "(I)V");
|
||||
}
|
||||
|
||||
// Implementation of android::hardware::gnss::IGnssPsdsCallback
|
||||
|
||||
Status GnssPsdsCallbackAidl::downloadRequestCb(PsdsType psdsType) {
|
||||
ALOGD("%s. psdsType: %d", __func__, static_cast<int32_t>(psdsType));
|
||||
JNIEnv* env = getJniEnv();
|
||||
env->CallVoidMethod(mCallbacksObj, method_psdsDownloadRequest, psdsType);
|
||||
checkAndClearExceptionFromCallback(env, __FUNCTION__);
|
||||
return Status::ok();
|
||||
}
|
||||
|
||||
// Implementation of android::hardware::gnss::V1_0::IGnssPsdsCallback
|
||||
|
||||
Return<void> GnssPsdsCallbackHidl::downloadRequestCb() {
|
||||
JNIEnv* env = getJniEnv();
|
||||
env->CallVoidMethod(mCallbacksObj, method_psdsDownloadRequest, /* psdsType= */ 1);
|
||||
checkAndClearExceptionFromCallback(env, __FUNCTION__);
|
||||
return Void();
|
||||
}
|
||||
|
||||
} // namespace android::gnss
|
||||
76
services/core/jni/gnss/GnssPsdsCallback.h
Normal file
76
services/core/jni/gnss/GnssPsdsCallback.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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_GNSSPSDSCALLBACK_H
|
||||
#define _ANDROID_SERVER_GNSS_GNSSPSDSCALLBACK_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef LOG_TAG
|
||||
#error LOG_TAG must be defined before including this file.
|
||||
#endif
|
||||
|
||||
#include <android/hardware/gnss/1.0/IGnssXtraCallback.h>
|
||||
#include <android/hardware/gnss/BnGnssPsdsCallback.h>
|
||||
#include <log/log.h>
|
||||
|
||||
#include "jni.h"
|
||||
|
||||
namespace android::gnss {
|
||||
|
||||
namespace {
|
||||
extern jmethodID method_psdsDownloadRequest;
|
||||
} // anonymous namespace
|
||||
|
||||
void GnssPsds_class_init_once(JNIEnv* env, jclass clazz);
|
||||
|
||||
class GnssPsdsCallbackAidl : public hardware::gnss::BnGnssPsdsCallback {
|
||||
public:
|
||||
GnssPsdsCallbackAidl() {}
|
||||
binder::Status downloadRequestCb(hardware::gnss::PsdsType psdsType) override;
|
||||
};
|
||||
|
||||
class GnssPsdsCallbackHidl : public hardware::gnss::V1_0::IGnssXtraCallback {
|
||||
public:
|
||||
GnssPsdsCallbackHidl() {}
|
||||
hardware::Return<void> downloadRequestCb() override;
|
||||
};
|
||||
|
||||
class GnssPsdsCallback {
|
||||
public:
|
||||
GnssPsdsCallback() {}
|
||||
sp<GnssPsdsCallbackAidl> getAidl() {
|
||||
if (callbackAidl == nullptr) {
|
||||
callbackAidl = sp<GnssPsdsCallbackAidl>::make();
|
||||
}
|
||||
return callbackAidl;
|
||||
}
|
||||
|
||||
sp<GnssPsdsCallbackHidl> getHidl() {
|
||||
if (callbackHidl == nullptr) {
|
||||
callbackHidl = sp<GnssPsdsCallbackHidl>::make();
|
||||
}
|
||||
return callbackHidl;
|
||||
}
|
||||
|
||||
private:
|
||||
sp<GnssPsdsCallbackAidl> callbackAidl;
|
||||
sp<GnssPsdsCallbackHidl> callbackHidl;
|
||||
};
|
||||
|
||||
} // namespace android::gnss
|
||||
|
||||
#endif // _ANDROID_SERVER_GNSS_GNSSPSDSCALLBACK_H
|
||||
Reference in New Issue
Block a user