Allow changing the mock location returned by GNSS HAL

This CL introduces a new lshal debug command for GNSS HAL
  location [lat=..] [lon=..] [ele=..] that allows changing
the mock location provided by GNSS HAL to clients

This can be used manually to configure a single mock location,
or in a scripted scenario to, e.g., supply a set of locations
from a GPX file to simulate a moving device

Bug: None
Test: set different locations via command line to Cuttlefish device, e.g.
$ adb shell lshal debug android.hardware.gnss@2.1::IGnss/default location lat=46.6317 lon=-114.0789
Change-Id: I7217c59f66f1ee7f5a9bd3f3dd3af7be4b43c024
This commit is contained in:
Enrico Granata
2020-10-21 17:20:00 -06:00
parent c146f8615b
commit 3ba5d228ba
8 changed files with 143 additions and 20 deletions

View File

@@ -20,6 +20,7 @@
#include "Constants.h"
#include "GnssDebug.h"
#include "MockLocation.h"
using namespace ::android::hardware::gnss::common;
@@ -32,17 +33,17 @@ namespace implementation {
// Methods from ::android::hardware::gnss::V1_0::IGnssDebug follow.
Return<void> GnssDebug::getDebugData(V1_0::IGnssDebug::getDebugData_cb _hidl_cb) {
PositionDebug positionDebug = {
.valid = true,
.latitudeDegrees = kMockLatitudeDegrees,
.longitudeDegrees = kMockLongitudeDegrees,
.altitudeMeters = kMockAltitudeMeters,
.speedMetersPerSec = kMockSpeedMetersPerSec,
.bearingDegrees = kMockBearingDegrees,
.horizontalAccuracyMeters = kMockHorizontalAccuracyMeters,
.verticalAccuracyMeters = kMockVerticalAccuracyMeters,
.speedAccuracyMetersPerSecond = kMockSpeedAccuracyMetersPerSecond,
.bearingAccuracyDegrees = kMockBearingAccuracyDegrees,
.ageSeconds = 0.99};
.valid = true,
.latitudeDegrees = gMockLatitudeDegrees,
.longitudeDegrees = gMockLongitudeDegrees,
.altitudeMeters = gMockAltitudeMeters,
.speedMetersPerSec = kMockSpeedMetersPerSec,
.bearingDegrees = kMockBearingDegrees,
.horizontalAccuracyMeters = kMockHorizontalAccuracyMeters,
.verticalAccuracyMeters = kMockVerticalAccuracyMeters,
.speedAccuracyMetersPerSecond = kMockSpeedAccuracyMetersPerSecond,
.bearingAccuracyDegrees = kMockBearingAccuracyDegrees,
.ageSeconds = 0.99};
TimeDebug timeDebug = {.timeEstimate = kMockTimestamp,
.timeUncertaintyNs = 1000,

View File

@@ -29,6 +29,7 @@ cc_library_static {
"v2_1/GnssDebug.cpp",
"v2_1/GnssMeasurement.cpp",
"v2_1/GnssMeasurementCorrections.cpp",
"MockLocation.cpp",
"Utils.cpp",
"NmeaFixInfo.cpp",
],

View File

@@ -0,0 +1,25 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "MockLocation.h"
namespace android::hardware::gnss::common {
float gMockLatitudeDegrees{37.4219999};
float gMockLongitudeDegrees{-122.0840575};
float gMockAltitudeMeters{1.60062531};
} // namespace android::hardware::gnss::common

View File

@@ -15,6 +15,7 @@
*/
#include <Constants.h>
#include <MockLocation.h>
#include <Utils.h>
#include <utils/SystemClock.h>
@@ -141,9 +142,9 @@ V2_0::GnssLocation Utils::getMockLocationV2_0() {
V1_0::GnssLocation Utils::getMockLocationV1_0() {
V1_0::GnssLocation location = {
.gnssLocationFlags = 0xFF,
.latitudeDegrees = kMockLatitudeDegrees,
.longitudeDegrees = kMockLongitudeDegrees,
.altitudeMeters = kMockAltitudeMeters,
.latitudeDegrees = gMockLatitudeDegrees,
.longitudeDegrees = gMockLongitudeDegrees,
.altitudeMeters = gMockAltitudeMeters,
.speedMetersPerSec = kMockSpeedMetersPerSec,
.bearingDegrees = kMockBearingDegrees,
.horizontalAccuracyMeters = kMockHorizontalAccuracyMeters,

View File

@@ -24,9 +24,6 @@ namespace hardware {
namespace gnss {
namespace common {
const float kMockLatitudeDegrees = 37.4219999;
const float kMockLongitudeDegrees = -122.0840575;
const float kMockAltitudeMeters = 1.60062531;
const float kMockSpeedMetersPerSec = 0;
const float kMockBearingDegrees = 0;
const float kMockHorizontalAccuracyMeters = 5;

View File

@@ -0,0 +1,36 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef android_hardware_gnss_common_MockLocation_H_
#define android_hardware_gnss_common_MockLocation_H_
#include <cstdint>
namespace android {
namespace hardware {
namespace gnss {
namespace common {
extern float gMockLatitudeDegrees;
extern float gMockLongitudeDegrees;
extern float gMockAltitudeMeters;
} // namespace common
} // namespace gnss
} // namespace hardware
} // namespace android
#endif // android_hardware_gnss_common_MockLocation_H_

View File

@@ -33,6 +33,7 @@
#include "GnssDebug.h"
#include "GnssMeasurement.h"
#include "GnssMeasurementCorrections.h"
#include "MockLocation.h"
#include "NmeaFixInfo.h"
#include "Utils.h"
@@ -113,12 +114,17 @@ struct GnssTemplate : public T_IGnss {
getExtensionMeasurementCorrections_1_1() override;
Return<sp<V2_1::IGnssAntennaInfo>> getExtensionGnssAntennaInfo() override;
Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override;
private:
std::unique_ptr<V2_0::GnssLocation> getLocationFromHW();
void reportLocation(const V2_0::GnssLocation&) const;
void reportLocation(const V1_0::GnssLocation&) const;
void reportSvStatus(const hidl_vec<GnssSvInfo>&) const;
Return<void> help(const hidl_handle& fd);
Return<void> setLocation(const hidl_handle& fd, const hidl_vec<hidl_string>& options);
static sp<V2_1::IGnssCallback> sGnssCallback_2_1;
static sp<V2_0::IGnssCallback> sGnssCallback_2_0;
static sp<V1_1::IGnssCallback> sGnssCallback_1_1;
@@ -639,4 +645,59 @@ void GnssTemplate<T_IGnss>::reportLocation(const V2_0::GnssLocation& location) c
}
}
template <class T_IGnss>
Return<void> GnssTemplate<T_IGnss>::setLocation(const hidl_handle& fd,
const hidl_vec<hidl_string>& options) {
auto lat = gMockLatitudeDegrees;
auto lon = gMockLongitudeDegrees;
auto ele = gMockAltitudeMeters;
for (size_t i = 1; i < options.size(); ++i) {
std::string option = options[i];
if (option.rfind("lat=", 0) == 0) {
option = option.substr(4);
lat = stof(option);
} else if (option.rfind("lon=", 0) == 0) {
option = option.substr(4);
lon = stof(option);
} else if (option.rfind("ele=", 0) == 0) {
option = option.substr(4);
ele = stof(option);
} else {
dprintf(fd->data[0], "unsupported location argument: %s\n", option.c_str());
}
}
gMockLatitudeDegrees = lat;
gMockLongitudeDegrees = lon;
gMockAltitudeMeters = ele;
dprintf(fd->data[0], "mock location updated to lat=%f lon=%f ele=%f\n", gMockLatitudeDegrees,
gMockLongitudeDegrees, gMockAltitudeMeters);
return Void();
}
template <class T_IGnss>
Return<void> GnssTemplate<T_IGnss>::help(const hidl_handle& fd) {
dprintf(fd->data[0],
"invalid option for Gnss HAL; valid options are:\n"
"location lat=.. lon=.. ele=..\n");
return Void();
}
template <class T_IGnss>
Return<void> GnssTemplate<T_IGnss>::debug(const hidl_handle& fd,
const hidl_vec<hidl_string>& options) {
if (options.size() == 0) {
return help(fd);
} else if (options[0] == "location") {
return setLocation(fd, options);
} else {
return help(fd);
}
return Void();
}
} // namespace android::hardware::gnss::common::implementation

View File

@@ -19,6 +19,7 @@
#include <log/log.h>
#include "Constants.h"
#include "MockLocation.h"
#include "v2_1/GnssDebug.h"
using namespace ::android::hardware::gnss::common;
@@ -29,9 +30,9 @@ namespace android::hardware::gnss::V1_1::implementation {
Return<void> GnssDebug::getDebugData(V1_0::IGnssDebug::getDebugData_cb _hidl_cb) {
PositionDebug positionDebug = {
.valid = true,
.latitudeDegrees = kMockLatitudeDegrees,
.longitudeDegrees = kMockLongitudeDegrees,
.altitudeMeters = kMockAltitudeMeters,
.latitudeDegrees = gMockLatitudeDegrees,
.longitudeDegrees = gMockLongitudeDegrees,
.altitudeMeters = gMockAltitudeMeters,
.speedMetersPerSec = kMockSpeedMetersPerSec,
.bearingDegrees = kMockBearingDegrees,
.horizontalAccuracyMeters = kMockHorizontalAccuracyMeters,