Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 42b2d0a6 authored by Yuchen He's avatar Yuchen He
Browse files

Support the location injection in AIDL HAL

Bug: 213225295
Test: atest VtsHalGnssTargetTest
Change-Id: Iff9fca55722af9bad6cc50f0170e4e1a069d05d6
parent 4f1aaa91
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <inttypes.h>
#include <log/log.h>
#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<IGnssCallback>& callback)
    return ScopedAStatus::ok();
}

std::unique_ptr<GnssLocation> 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();
            if (currentLocation != nullptr) {
                this->reportLocation(*currentLocation);
            } else {
                const auto location = Utils::getMockLocation();
                this->reportLocation(location);
            }
            std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMs));
        }
    });
+1 −0
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ class Gnss : public BnGnss {
    std::vector<IGnssCallback::GnssSvInfo> filterBlocklistedSatellites(
            std::vector<IGnssCallback::GnssSvInfo> gnssSvInfoList);
    void reportGnssStatusValue(const IGnssCallback::GnssStatusValue gnssStatusValue) const;
    std::unique_ptr<GnssLocation> getLocationFromHW();

    static std::shared_ptr<IGnssCallback> sGnssCallback;

+1 −1
Original line number Diff line number Diff line
@@ -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
+37 −0
Original line number Diff line number Diff line
@@ -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<V2_0::GnssLocation> NmeaFixInfo::getLocationFromInputStr(
    return nmeaFixInfo.toGnssLocation();
}

/**
 * Convert V2_0::GnssLocation to aidl::GnssLocation.
 */
std::unique_ptr<GnssLocation> NmeaFixInfo::getAidlLocationFromInputStr(
        const std::string& inputStr) {
    std::unique_ptr<V2_0::GnssLocation> 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<GnssLocation>(location);
}

/**
 * Parses the input string in NMEA format and convert to GnssLocation.
 */
+3 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <hidl/Status.h>
#include <ctime>
#include <string>
#include "aidl/android/hardware/gnss/IGnss.h"
namespace android {
namespace hardware {
namespace gnss {
@@ -45,6 +46,8 @@ class NmeaFixInfo {

  public:
    static std::unique_ptr<V2_0::GnssLocation> getLocationFromInputStr(const std::string& inputStr);
    static std::unique_ptr<aidl::android::hardware::gnss::GnssLocation> getAidlLocationFromInputStr(
            const std::string& inputStr);

  private:
    static void splitStr(const std::string& line, const char& delimiter,