From 42b2d0a65f4ba512004cf86c1e8ebd8898cd423d Mon Sep 17 00:00:00 2001 From: Yuchen He Date: Wed, 12 Jan 2022 04:39:37 +0000 Subject: [PATCH] Support the location injection in AIDL HAL Bug: 213225295 Test: atest VtsHalGnssTargetTest Change-Id: Iff9fca55722af9bad6cc50f0170e4e1a069d05d6 --- gnss/aidl/default/Gnss.cpp | 19 +++++++++- gnss/aidl/default/Gnss.h | 1 + gnss/common/utils/default/GnssReplayUtils.cpp | 2 +- gnss/common/utils/default/NmeaFixInfo.cpp | 37 +++++++++++++++++++ .../utils/default/include/NmeaFixInfo.h | 3 ++ 5 files changed, 59 insertions(+), 3 deletions(-) diff --git a/gnss/aidl/default/Gnss.cpp b/gnss/aidl/default/Gnss.cpp index e296351d95..657877898f 100644 --- a/gnss/aidl/default/Gnss.cpp +++ b/gnss/aidl/default/Gnss.cpp @@ -20,6 +20,7 @@ #include #include #include "AGnss.h" +#include "DeviceFileReader.h" #include "GnssBatching.h" #include "GnssConfiguration.h" #include "GnssDebug.h" @@ -28,10 +29,13 @@ #include "GnssNavigationMessageInterface.h" #include "GnssPsds.h" #include "GnssVisibilityControl.h" +#include "NmeaFixInfo.h" #include "Utils.h" namespace aidl::android::hardware::gnss { +using ::android::hardware::gnss::common::NmeaFixInfo; using ::android::hardware::gnss::common::Utils; + using ndk::ScopedAStatus; using GnssSvInfo = IGnssCallback::GnssSvInfo; @@ -62,6 +66,12 @@ ScopedAStatus Gnss::setCallback(const std::shared_ptr& callback) return ScopedAStatus::ok(); } +std::unique_ptr Gnss::getLocationFromHW() { + std::string inputStr = + ::android::hardware::gnss::common::DeviceFileReader::Instance().getLocationData(); + return ::android::hardware::gnss::common::NmeaFixInfo::getAidlLocationFromInputStr(inputStr); +} + ScopedAStatus Gnss::start() { ALOGD("start()"); if (mIsActive) { @@ -82,9 +92,14 @@ ScopedAStatus Gnss::start() { auto svStatus = filterBlocklistedSatellites(Utils::getMockSvInfoList()); this->reportSvStatus(svStatus); + auto currentLocation = getLocationFromHW(); mGnssPowerIndication->notePowerConsumption(); - const auto location = Utils::getMockLocation(); - this->reportLocation(location); + if (currentLocation != nullptr) { + this->reportLocation(*currentLocation); + } else { + const auto location = Utils::getMockLocation(); + this->reportLocation(location); + } std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMs)); } }); diff --git a/gnss/aidl/default/Gnss.h b/gnss/aidl/default/Gnss.h index 384c8629a2..f21d756c24 100644 --- a/gnss/aidl/default/Gnss.h +++ b/gnss/aidl/default/Gnss.h @@ -79,6 +79,7 @@ class Gnss : public BnGnss { std::vector filterBlocklistedSatellites( std::vector gnssSvInfoList); void reportGnssStatusValue(const IGnssCallback::GnssStatusValue gnssStatusValue) const; + std::unique_ptr getLocationFromHW(); static std::shared_ptr sGnssCallback; diff --git a/gnss/common/utils/default/GnssReplayUtils.cpp b/gnss/common/utils/default/GnssReplayUtils.cpp index e3f4ff82a0..535647716b 100644 --- a/gnss/common/utils/default/GnssReplayUtils.cpp +++ b/gnss/common/utils/default/GnssReplayUtils.cpp @@ -41,7 +41,7 @@ bool ReplayUtils::isGnssRawMeasurement(const std::string& inputStr) { bool ReplayUtils::isNMEA(const std::string& inputStr) { return !inputStr.empty() && (inputStr.find("$GPRMC,", 0) != std::string::npos || - inputStr.find("$GPRMA,", 0) != std::string::npos); + inputStr.find("$GPGGA,", 0) != std::string::npos); } } // namespace common diff --git a/gnss/common/utils/default/NmeaFixInfo.cpp b/gnss/common/utils/default/NmeaFixInfo.cpp index c7ee13488b..22aef90204 100644 --- a/gnss/common/utils/default/NmeaFixInfo.cpp +++ b/gnss/common/utils/default/NmeaFixInfo.cpp @@ -34,6 +34,9 @@ namespace hardware { namespace gnss { namespace common { +using aidl::android::hardware::gnss::ElapsedRealtime; +using aidl::android::hardware::gnss::GnssLocation; + NmeaFixInfo::NmeaFixInfo() : hasGMCRecord(false), hasGGARecord(false) {} float NmeaFixInfo::getAltitudeMeters() const { @@ -236,6 +239,40 @@ std::unique_ptr NmeaFixInfo::getLocationFromInputStr( return nmeaFixInfo.toGnssLocation(); } +/** + * Convert V2_0::GnssLocation to aidl::GnssLocation. + */ +std::unique_ptr NmeaFixInfo::getAidlLocationFromInputStr( + const std::string& inputStr) { + std::unique_ptr locationV2 = getLocationFromInputStr(inputStr); + if (locationV2 == nullptr) { + return nullptr; + } + + ElapsedRealtime elapsedRealtime = { + .flags = ElapsedRealtime::HAS_TIMESTAMP_NS | ElapsedRealtime::HAS_TIME_UNCERTAINTY_NS, + .timestampNs = ::android::elapsedRealtimeNano(), + // This is an hardcoded value indicating a 1ms of uncertainty between the two clocks. + // In an actual implementation provide an estimate of the synchronization uncertainty + // or don't set the field. + .timeUncertaintyNs = 1020400}; + + GnssLocation location = { + .gnssLocationFlags = locationV2->v1_0.gnssLocationFlags, + .latitudeDegrees = locationV2->v1_0.latitudeDegrees, + .longitudeDegrees = locationV2->v1_0.longitudeDegrees, + .altitudeMeters = locationV2->v1_0.altitudeMeters, + .speedMetersPerSec = locationV2->v1_0.speedMetersPerSec, + .bearingDegrees = locationV2->v1_0.bearingDegrees, + .horizontalAccuracyMeters = locationV2->v1_0.horizontalAccuracyMeters, + .verticalAccuracyMeters = locationV2->v1_0.verticalAccuracyMeters, + .speedAccuracyMetersPerSecond = locationV2->v1_0.speedAccuracyMetersPerSecond, + .bearingAccuracyDegrees = locationV2->v1_0.bearingAccuracyDegrees, + .timestampMillis = locationV2->v1_0.timestamp, + .elapsedRealtime = elapsedRealtime}; + return std::make_unique(location); +} + /** * Parses the input string in NMEA format and convert to GnssLocation. */ diff --git a/gnss/common/utils/default/include/NmeaFixInfo.h b/gnss/common/utils/default/include/NmeaFixInfo.h index 5c27045316..407336121d 100644 --- a/gnss/common/utils/default/include/NmeaFixInfo.h +++ b/gnss/common/utils/default/include/NmeaFixInfo.h @@ -22,6 +22,7 @@ #include #include #include +#include "aidl/android/hardware/gnss/IGnss.h" namespace android { namespace hardware { namespace gnss { @@ -45,6 +46,8 @@ class NmeaFixInfo { public: static std::unique_ptr getLocationFromInputStr(const std::string& inputStr); + static std::unique_ptr getAidlLocationFromInputStr( + const std::string& inputStr); private: static void splitStr(const std::string& line, const char& delimiter,