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

Commit 29f0a4ff authored by Yipeng Cao's avatar Yipeng Cao
Browse files

Fix for Gnss Hal for replay

In the old logic, if /dev/gnss0 doesn't report location, it will fail back
to the default mock location. Now we change to only report default location if /dev/gnss0 is
not present.

Test: launch_cvd --start_gnss_proxy
Change-Id: Ie1026d5b4dd3e3c2ed1e2107232bcb94c3ba5079

Change-Id: I787b71d80be7875fc594d17b4296e7d28d9c2f5a
parent 4dd2b6d8
Loading
Loading
Loading
Loading
+12 −13
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#pragma once

#include <android/hardware/gnss/2.1/IGnss.h>
#include <errno.h>
#include <fcntl.h>
#include <hidl/MQDescriptor.h>
#include <hidl/Status.h>
@@ -158,14 +159,16 @@ GnssTemplate<T_IGnss>::~GnssTemplate() {
template <class T_IGnss>
std::unique_ptr<V2_0::GnssLocation> GnssTemplate<T_IGnss>::getLocationFromHW() {
    char inputBuffer[INPUT_BUFFER_SIZE];
    mHardwareModeOn = false;
    if (mGnssFd == -1) {
        mGnssFd = open(GNSS_PATH, O_RDWR | O_NONBLOCK);
    }

    if (mGnssFd == -1) {
        ALOGW("Failed to open /dev/gnss0 errno: %d", errno);
        return nullptr;
    }
    // Send control message to device
    // Indicates it is a hardwareMode, don't report the default location.
    mHardwareModeOn = true;
    int bytes_write = write(mGnssFd, CMD_GET_LOCATION, strlen(CMD_GET_LOCATION));
    if (bytes_write <= 0) {
        return nullptr;
@@ -179,8 +182,7 @@ std::unique_ptr<V2_0::GnssLocation> GnssTemplate<T_IGnss>::getLocationFromHW() {
    int bytes_read = -1;
    std::string inputStr = "";
    int epoll_ret = epoll_wait(epoll_fd, events, 1, mMinIntervalMs);
    // Indicates it is a hardwareMode, don't need to wait outside.
    mHardwareModeOn = true;

    if (epoll_ret == -1) {
        return nullptr;
    }
@@ -206,10 +208,12 @@ Return<bool> GnssTemplate<T_IGnss>::start() {
        while (mIsActive == true) {
            auto svStatus = filterBlacklistedSatellitesV2_1(Utils::getMockSvInfoListV2_1());
            this->reportSvStatus(svStatus);

            auto currentLocation = getLocationFromHW();
            if (mHardwareModeOn) {
                if (currentLocation != nullptr) {
                    // Only report location if the return from hardware is valid
                    this->reportLocation(*currentLocation);
                }
            } else {
                if (sGnssCallback_2_1 != nullptr || sGnssCallback_2_0 != nullptr) {
                    const auto location = Utils::getMockLocationV2_0();
@@ -218,13 +222,8 @@ Return<bool> GnssTemplate<T_IGnss>::start() {
                    const auto location = Utils::getMockLocationV1_0();
                    this->reportLocation(location);
                }

                // Only need do the sleep in the static location mode, which mocks the "wait
                // for" hardware behavior.
                if (!mHardwareModeOn) {
                    std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMs));
                }
            }
            std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMs));
        }
    });
    return true;