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

Commit 0f6bacea authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Supported synchronized fixed location and measurement from device files"

parents 809d7cf6 090f16c0
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include "AGnss.h"
#include "AGnssRil.h"
#include "DeviceFileReader.h"
#include "FixLocationParser.h"
#include "GnssAntennaInfo.h"
#include "GnssBatching.h"
#include "GnssConfiguration.h"
@@ -32,11 +33,9 @@
#include "GnssPsds.h"
#include "GnssVisibilityControl.h"
#include "MeasurementCorrectionsInterface.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;
@@ -70,9 +69,12 @@ ScopedAStatus Gnss::setCallback(const std::shared_ptr<IGnssCallback>& callback)
}

std::unique_ptr<GnssLocation> Gnss::getLocationFromHW() {
    if (!::android::hardware::gnss::common::ReplayUtils::hasFixedLocationDeviceFile()) {
        return nullptr;
    }
    std::string inputStr =
            ::android::hardware::gnss::common::DeviceFileReader::Instance().getLocationData();
    return ::android::hardware::gnss::common::NmeaFixInfo::getAidlLocationFromInputStr(inputStr);
    return ::android::hardware::gnss::common::FixLocationParser::getLocationFromInputStr(inputStr);
}

ScopedAStatus Gnss::start() {
+17 −5
Original line number Diff line number Diff line
@@ -22,8 +22,17 @@ namespace common {

void DeviceFileReader::getDataFromDeviceFile(const std::string& command, int mMinIntervalMs) {
    char inputBuffer[INPUT_BUFFER_SIZE];
    int mGnssFd = open(ReplayUtils::getGnssPath().c_str(),
                       O_RDWR | O_NONBLOCK);
    std::string deviceFilePath = "";
    if (command == CMD_GET_LOCATION) {
        deviceFilePath = ReplayUtils::getFixedLocationPath();
    } else if (command == CMD_GET_RAWMEASUREMENT) {
        deviceFilePath = ReplayUtils::getGnssPath();
    } else {
        // Invalid command
        return;
    }

    int mGnssFd = open(deviceFilePath.c_str(), O_RDWR | O_NONBLOCK);

    if (mGnssFd == -1) {
        return;
@@ -68,10 +77,13 @@ void DeviceFileReader::getDataFromDeviceFile(const std::string& command, int mMi
    }

    // Cache the injected data.
    if (command == CMD_GET_LOCATION) {
        // TODO validate data
        data_[CMD_GET_LOCATION] = inputStr;
    } else if (command == CMD_GET_RAWMEASUREMENT) {
        if (ReplayUtils::isGnssRawMeasurement(inputStr)) {
            data_[CMD_GET_RAWMEASUREMENT] = inputStr;
    } else if (ReplayUtils::isNMEA(inputStr)) {
        data_[CMD_GET_LOCATION] = inputStr;
        }
    }
}

+13 −0
Original line number Diff line number Diff line
@@ -29,11 +29,24 @@ std::string ReplayUtils::getGnssPath() {
    return GNSS_PATH;
}

std::string ReplayUtils::getFixedLocationPath() {
    char devname_value[PROPERTY_VALUE_MAX] = "";
    if (property_get("debug.location.fixedlocation.devname", devname_value, NULL) > 0) {
        return devname_value;
    }
    return FIXED_LOCATION_PATH;
}

bool ReplayUtils::hasGnssDeviceFile() {
    struct stat sb;
    return stat(getGnssPath().c_str(), &sb) != -1;
}

bool ReplayUtils::hasFixedLocationDeviceFile() {
    struct stat sb;
    return stat(getFixedLocationPath().c_str(), &sb) != -1;
}

bool ReplayUtils::isGnssRawMeasurement(const std::string& inputStr) {
    // TODO: add more logic check to by pass invalid data.
    return !inputStr.empty() && (inputStr.find("Raw") != std::string::npos);
+1 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ const float kIrnssL5FreqHz = 1176.45 * 1e6;

// Location replay constants
constexpr char GNSS_PATH[] = "/dev/gnss0";
constexpr char FIXED_LOCATION_PATH[] = "/dev/gnss1";
constexpr int INPUT_BUFFER_SIZE = 256;
constexpr char CMD_GET_LOCATION[] = "CMD_GET_LOCATION";
constexpr char CMD_GET_RAWMEASUREMENT[] = "CMD_GET_RAWMEASUREMENT";
+4 −0
Original line number Diff line number Diff line
@@ -37,10 +37,14 @@ namespace common {
struct ReplayUtils {
    static std::string getGnssPath();

    static std::string getFixedLocationPath();

    static std::string getDataFromDeviceFile(const std::string& command, int mMinIntervalMs);

    static bool hasGnssDeviceFile();

    static bool hasFixedLocationDeviceFile();

    static bool isGnssRawMeasurement(const std::string& inputStr);

    static bool isNMEA(const std::string& inputStr);