diff --git a/gnss/common/utils/default/GnssReplayUtils.cpp b/gnss/common/utils/default/GnssReplayUtils.cpp index 6dcf6ea252..fc4c477ae8 100644 --- a/gnss/common/utils/default/GnssReplayUtils.cpp +++ b/gnss/common/utils/default/GnssReplayUtils.cpp @@ -21,18 +21,17 @@ namespace hardware { namespace gnss { namespace common { -const char* ReplayUtils::getGnssPath() { - const char* gnss_dev_path = GNSS_PATH; +std::string ReplayUtils::getGnssPath() { char devname_value[PROPERTY_VALUE_MAX] = ""; if (property_get("debug.location.gnss.devname", devname_value, NULL) > 0) { - gnss_dev_path = devname_value; + return devname_value; } - return gnss_dev_path; + return GNSS_PATH; } bool ReplayUtils::hasGnssDeviceFile() { struct stat sb; - return stat(getGnssPath(), &sb) != -1; + return stat(getGnssPath().c_str(), &sb) != -1; } bool ReplayUtils::isGnssRawMeasurement(const std::string& inputStr) { @@ -47,7 +46,7 @@ bool ReplayUtils::isNMEA(const std::string& inputStr) { std::string ReplayUtils::getDataFromDeviceFile(const std::string& command, int mMinIntervalMs) { char inputBuffer[INPUT_BUFFER_SIZE]; - int mGnssFd = open(getGnssPath(), O_RDWR | O_NONBLOCK); + int mGnssFd = open(getGnssPath().c_str(), O_RDWR | O_NONBLOCK); if (mGnssFd == -1) { return ""; diff --git a/gnss/common/utils/default/include/GnssReplayUtils.h b/gnss/common/utils/default/include/GnssReplayUtils.h index d7530f741a..32c0e58c0c 100644 --- a/gnss/common/utils/default/include/GnssReplayUtils.h +++ b/gnss/common/utils/default/include/GnssReplayUtils.h @@ -35,7 +35,7 @@ namespace gnss { namespace common { struct ReplayUtils { - static const char* getGnssPath(); + static std::string getGnssPath(); static std::string getDataFromDeviceFile(const std::string& command, int mMinIntervalMs); diff --git a/gnss/common/utils/default/include/v2_1/GnssTemplate.h b/gnss/common/utils/default/include/v2_1/GnssTemplate.h index 66c23d4719..4e07af9853 100644 --- a/gnss/common/utils/default/include/v2_1/GnssTemplate.h +++ b/gnss/common/utils/default/include/v2_1/GnssTemplate.h @@ -162,11 +162,11 @@ template std::unique_ptr GnssTemplate::getLocationFromHW() { if (!mHardwareModeChecked) { // default using /dev/gnss0 - const char* gnss_dev_path = ReplayUtils::getGnssPath(); + std::string gnss_dev_path = ReplayUtils::getGnssPath(); - mGnssFd = open(gnss_dev_path, O_RDWR | O_NONBLOCK); + mGnssFd = open(gnss_dev_path.c_str(), O_RDWR | O_NONBLOCK); if (mGnssFd == -1) { - ALOGW("Failed to open %s errno: %d", gnss_dev_path, errno); + ALOGW("Failed to open %s errno: %d", gnss_dev_path.c_str(), errno); } mHardwareModeChecked = true; }