mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 16:50:18 +00:00
Report mock locations in 2.0 default implementation
- Create android.hardware.gnss@common-default-lib for sharing common default implementation code. - Create android.hardware.gnss@common-vts-lib for sharing common VTS code. Bug: 121217686 Change-Id: I35c127c23d97ab9a5c6ee13b36fbfe9c3708e3f3 Fixes: 121217686 Test: tested on cuttlefish
This commit is contained in:
@@ -18,4 +18,7 @@ cc_binary {
|
||||
"android.hardware.gnss@1.1",
|
||||
"android.hardware.gnss@1.0",
|
||||
],
|
||||
static_libs: [
|
||||
"android.hardware.gnss@common-default-lib",
|
||||
],
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
#include <log/log.h>
|
||||
|
||||
#include "Gnss.h"
|
||||
#include "GnssConstants.h"
|
||||
#include "GnssDebug.h"
|
||||
#include "GnssMeasurement.h"
|
||||
#include "Utils.h"
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
@@ -14,6 +14,7 @@ namespace gnss {
|
||||
namespace V1_1 {
|
||||
namespace implementation {
|
||||
|
||||
using ::android::hardware::gnss::common::Utils;
|
||||
using GnssSvFlags = IGnssCallback::GnssSvFlags;
|
||||
|
||||
const uint32_t MIN_INTERVAL_MILLIS = 100;
|
||||
@@ -43,7 +44,7 @@ Return<bool> Gnss::start() {
|
||||
auto svStatus = this->getMockSvStatus();
|
||||
this->reportSvStatus(svStatus);
|
||||
|
||||
auto location = this->getMockLocation();
|
||||
auto location = Utils::getMockLocation();
|
||||
this->reportLocation(location);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMs));
|
||||
@@ -193,44 +194,17 @@ Return<bool> Gnss::injectBestLocation(const GnssLocation&) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Return<GnssLocation> Gnss::getMockLocation() const {
|
||||
GnssLocation location = {.gnssLocationFlags = 0xFF,
|
||||
.latitudeDegrees = kMockLatitudeDegrees,
|
||||
.longitudeDegrees = kMockLongitudeDegrees,
|
||||
.altitudeMeters = kMockAltitudeMeters,
|
||||
.speedMetersPerSec = kMockSpeedMetersPerSec,
|
||||
.bearingDegrees = kMockBearingDegrees,
|
||||
.horizontalAccuracyMeters = kMockHorizontalAccuracyMeters,
|
||||
.verticalAccuracyMeters = kMockVerticalAccuracyMeters,
|
||||
.speedAccuracyMetersPerSecond = kMockSpeedAccuracyMetersPerSecond,
|
||||
.bearingAccuracyDegrees = kMockBearingAccuracyDegrees,
|
||||
.timestamp = kMockTimestamp};
|
||||
return location;
|
||||
}
|
||||
|
||||
Return<GnssSvInfo> Gnss::getSvInfo(int16_t svid, GnssConstellationType type, float cN0DbHz,
|
||||
float elevationDegrees, float azimuthDegrees) const {
|
||||
GnssSvInfo svInfo = {.svid = svid,
|
||||
.constellation = type,
|
||||
.cN0Dbhz = cN0DbHz,
|
||||
.elevationDegrees = elevationDegrees,
|
||||
.azimuthDegrees = azimuthDegrees,
|
||||
.svFlag = GnssSvFlags::USED_IN_FIX | GnssSvFlags::HAS_EPHEMERIS_DATA |
|
||||
GnssSvFlags::HAS_ALMANAC_DATA};
|
||||
return svInfo;
|
||||
}
|
||||
|
||||
Return<GnssSvStatus> Gnss::getMockSvStatus() const {
|
||||
std::unique_lock<std::recursive_mutex> lock(mGnssConfiguration->getMutex());
|
||||
GnssSvInfo mockGnssSvInfoList[] = {
|
||||
getSvInfo(3, GnssConstellationType::GPS, 32.5, 59.1, 166.5),
|
||||
getSvInfo(5, GnssConstellationType::GPS, 27.0, 29.0, 56.5),
|
||||
getSvInfo(17, GnssConstellationType::GPS, 30.5, 71.0, 77.0),
|
||||
getSvInfo(26, GnssConstellationType::GPS, 24.1, 28.0, 253.0),
|
||||
getSvInfo(5, GnssConstellationType::GLONASS, 20.5, 11.5, 116.0),
|
||||
getSvInfo(17, GnssConstellationType::GLONASS, 21.5, 28.5, 186.0),
|
||||
getSvInfo(18, GnssConstellationType::GLONASS, 28.3, 38.8, 69.0),
|
||||
getSvInfo(10, GnssConstellationType::GLONASS, 25.0, 66.0, 247.0)};
|
||||
Utils::getSvInfo(3, GnssConstellationType::GPS, 32.5, 59.1, 166.5),
|
||||
Utils::getSvInfo(5, GnssConstellationType::GPS, 27.0, 29.0, 56.5),
|
||||
Utils::getSvInfo(17, GnssConstellationType::GPS, 30.5, 71.0, 77.0),
|
||||
Utils::getSvInfo(26, GnssConstellationType::GPS, 24.1, 28.0, 253.0),
|
||||
Utils::getSvInfo(5, GnssConstellationType::GLONASS, 20.5, 11.5, 116.0),
|
||||
Utils::getSvInfo(17, GnssConstellationType::GLONASS, 21.5, 28.5, 186.0),
|
||||
Utils::getSvInfo(18, GnssConstellationType::GLONASS, 28.3, 38.8, 69.0),
|
||||
Utils::getSvInfo(10, GnssConstellationType::GLONASS, 25.0, 66.0, 247.0)};
|
||||
|
||||
GnssSvStatus svStatus = {.numSvs = sizeof(mockGnssSvInfoList) / sizeof(GnssSvInfo)};
|
||||
for (uint32_t i = 0; i < svStatus.numSvs; i++) {
|
||||
|
||||
@@ -84,10 +84,7 @@ struct Gnss : public IGnss {
|
||||
|
||||
// Methods from ::android::hidl::base::V1_0::IBase follow.
|
||||
private:
|
||||
Return<GnssLocation> getMockLocation() const;
|
||||
Return<GnssSvStatus> getMockSvStatus() const;
|
||||
Return<GnssSvInfo> getSvInfo(int16_t svid, GnssConstellationType type, float cN0DbHz,
|
||||
float elevationDegress, float azimuthDegress) const;
|
||||
Return<void> reportLocation(const GnssLocation&) const;
|
||||
Return<void> reportSvStatus(const GnssSvStatus&) const;
|
||||
|
||||
|
||||
@@ -18,9 +18,11 @@
|
||||
|
||||
#include <log/log.h>
|
||||
|
||||
#include "GnssConstants.h"
|
||||
#include "Constants.h"
|
||||
#include "GnssDebug.h"
|
||||
|
||||
using namespace ::android::hardware::gnss::common;
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace gnss {
|
||||
|
||||
@@ -25,6 +25,7 @@ cc_test {
|
||||
static_libs: [
|
||||
"android.hardware.gnss@1.0",
|
||||
"android.hardware.gnss@1.1",
|
||||
"android.hardware.gnss@common-vts-lib",
|
||||
],
|
||||
test_suites: ["general-tests"],
|
||||
}
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
#define LOG_TAG "GnssHalTest"
|
||||
|
||||
#include <gnss_hal_test.h>
|
||||
|
||||
#include <chrono>
|
||||
#include "Utils.h"
|
||||
|
||||
using ::android::hardware::gnss::common::Utils;
|
||||
|
||||
// Implementations for the main test class for GNSS HAL
|
||||
GnssHalTest::GnssHalTest()
|
||||
@@ -124,69 +126,7 @@ bool GnssHalTest::StartAndCheckFirstLocation() {
|
||||
void GnssHalTest::CheckLocation(GnssLocation& location, bool check_speed) {
|
||||
bool check_more_accuracies = (info_called_count_ > 0 && last_info_.yearOfHw >= 2017);
|
||||
|
||||
EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_LAT_LONG);
|
||||
EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_ALTITUDE);
|
||||
if (check_speed) {
|
||||
EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED);
|
||||
}
|
||||
EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_HORIZONTAL_ACCURACY);
|
||||
// New uncertainties available in O must be provided,
|
||||
// at least when paired with modern hardware (2017+)
|
||||
if (check_more_accuracies) {
|
||||
EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY);
|
||||
if (check_speed) {
|
||||
EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY);
|
||||
if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) {
|
||||
EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY);
|
||||
}
|
||||
}
|
||||
}
|
||||
EXPECT_GE(location.latitudeDegrees, -90.0);
|
||||
EXPECT_LE(location.latitudeDegrees, 90.0);
|
||||
EXPECT_GE(location.longitudeDegrees, -180.0);
|
||||
EXPECT_LE(location.longitudeDegrees, 180.0);
|
||||
EXPECT_GE(location.altitudeMeters, -1000.0);
|
||||
EXPECT_LE(location.altitudeMeters, 30000.0);
|
||||
if (check_speed) {
|
||||
EXPECT_GE(location.speedMetersPerSec, 0.0);
|
||||
EXPECT_LE(location.speedMetersPerSec, 5.0); // VTS tests are stationary.
|
||||
|
||||
// Non-zero speeds must be reported with an associated bearing
|
||||
if (location.speedMetersPerSec > 0.0) {
|
||||
EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tolerating some especially high values for accuracy estimate, in case of
|
||||
* first fix with especially poor geometry (happens occasionally)
|
||||
*/
|
||||
EXPECT_GT(location.horizontalAccuracyMeters, 0.0);
|
||||
EXPECT_LE(location.horizontalAccuracyMeters, 250.0);
|
||||
|
||||
/*
|
||||
* Some devices may define bearing as -180 to +180, others as 0 to 360.
|
||||
* Both are okay & understandable.
|
||||
*/
|
||||
if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) {
|
||||
EXPECT_GE(location.bearingDegrees, -180.0);
|
||||
EXPECT_LE(location.bearingDegrees, 360.0);
|
||||
}
|
||||
if (location.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY) {
|
||||
EXPECT_GT(location.verticalAccuracyMeters, 0.0);
|
||||
EXPECT_LE(location.verticalAccuracyMeters, 500.0);
|
||||
}
|
||||
if (location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY) {
|
||||
EXPECT_GT(location.speedAccuracyMetersPerSecond, 0.0);
|
||||
EXPECT_LE(location.speedAccuracyMetersPerSecond, 50.0);
|
||||
}
|
||||
if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY) {
|
||||
EXPECT_GT(location.bearingAccuracyDegrees, 0.0);
|
||||
EXPECT_LE(location.bearingAccuracyDegrees, 360.0);
|
||||
}
|
||||
|
||||
// Check timestamp > 1.48e12 (47 years in msec - 1970->2017+)
|
||||
EXPECT_GT(location.timestamp, 1.48e12);
|
||||
Utils::checkLocation(location, check_speed, check_more_accuracies);
|
||||
}
|
||||
|
||||
void GnssHalTest::StartAndCheckLocations(int count) {
|
||||
|
||||
@@ -40,4 +40,7 @@ cc_binary {
|
||||
"android.hardware.gnss@1.0",
|
||||
"android.hardware.gnss@1.1",
|
||||
],
|
||||
static_libs: [
|
||||
"android.hardware.gnss@common-default-lib",
|
||||
],
|
||||
}
|
||||
|
||||
@@ -23,8 +23,10 @@
|
||||
#include "GnssConfiguration.h"
|
||||
#include "GnssMeasurement.h"
|
||||
#include "GnssVisibilityControl.h"
|
||||
#include "Utils.h"
|
||||
|
||||
using ::android::hardware::Status;
|
||||
using ::android::hardware::gnss::common::Utils;
|
||||
using ::android::hardware::gnss::visibility_control::V1_0::implementation::GnssVisibilityControl;
|
||||
|
||||
namespace android {
|
||||
@@ -33,9 +35,17 @@ namespace gnss {
|
||||
namespace V2_0 {
|
||||
namespace implementation {
|
||||
|
||||
using GnssSvFlags = IGnssCallback::GnssSvFlags;
|
||||
|
||||
sp<V2_0::IGnssCallback> Gnss::sGnssCallback_2_0 = nullptr;
|
||||
sp<V1_1::IGnssCallback> Gnss::sGnssCallback_1_1 = nullptr;
|
||||
|
||||
Gnss::Gnss() : mMinIntervalMs(1000) {}
|
||||
|
||||
Gnss::~Gnss() {
|
||||
stop();
|
||||
}
|
||||
|
||||
// Methods from V1_0::IGnss follow.
|
||||
Return<bool> Gnss::setCallback(const sp<V1_0::IGnssCallback>&) {
|
||||
// TODO implement
|
||||
@@ -43,13 +53,29 @@ Return<bool> Gnss::setCallback(const sp<V1_0::IGnssCallback>&) {
|
||||
}
|
||||
|
||||
Return<bool> Gnss::start() {
|
||||
// TODO implement
|
||||
return bool{};
|
||||
if (mIsActive) {
|
||||
ALOGW("Gnss has started. Restarting...");
|
||||
stop();
|
||||
}
|
||||
|
||||
mIsActive = true;
|
||||
mThread = std::thread([this]() {
|
||||
while (mIsActive == true) {
|
||||
const auto location = Utils::getMockLocation();
|
||||
this->reportLocation(location);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMs));
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
Return<bool> Gnss::stop() {
|
||||
// TODO implement
|
||||
return bool{};
|
||||
mIsActive = false;
|
||||
if (mThread.joinable()) {
|
||||
mThread.join();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Return<void> Gnss::cleanup() {
|
||||
@@ -164,8 +190,7 @@ Return<bool> Gnss::setCallback_1_1(const sp<V1_1::IGnssCallback>& callback) {
|
||||
Return<bool> Gnss::setPositionMode_1_1(V1_0::IGnss::GnssPositionMode,
|
||||
V1_0::IGnss::GnssPositionRecurrence, uint32_t, uint32_t,
|
||||
uint32_t, bool) {
|
||||
// TODO implement
|
||||
return bool{};
|
||||
return true;
|
||||
}
|
||||
|
||||
Return<sp<V1_1::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration_1_1() {
|
||||
@@ -243,6 +268,16 @@ Return<bool> Gnss::setCallback_2_0(const sp<V2_0::IGnssCallback>& callback) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Return<void> Gnss::reportLocation(const GnssLocation& location) const {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
if (sGnssCallback_1_1 == nullptr) {
|
||||
ALOGE("%s: sGnssCallback is null.", __func__);
|
||||
return Void();
|
||||
}
|
||||
sGnssCallback_1_1->gnssLocationCb(location);
|
||||
return Void();
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V2_0
|
||||
} // namespace gnss
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
#include <android/hardware/gnss/2.0/IGnss.h>
|
||||
#include <hidl/MQDescriptor.h>
|
||||
#include <hidl/Status.h>
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
@@ -35,7 +38,14 @@ using ::android::hardware::hidl_vec;
|
||||
using ::android::hardware::Return;
|
||||
using ::android::hardware::Void;
|
||||
|
||||
using GnssConstellationType = V1_0::GnssConstellationType;
|
||||
using GnssLocation = V1_0::GnssLocation;
|
||||
using GnssSvInfo = V1_0::IGnssCallback::GnssSvInfo;
|
||||
using GnssSvStatus = V1_0::IGnssCallback::GnssSvStatus;
|
||||
|
||||
struct Gnss : public IGnss {
|
||||
Gnss();
|
||||
~Gnss();
|
||||
// Methods from V1_0::IGnss follow.
|
||||
Return<bool> setCallback(const sp<V1_0::IGnssCallback>& callback) override;
|
||||
Return<bool> start() override;
|
||||
@@ -69,7 +79,7 @@ struct Gnss : public IGnss {
|
||||
uint32_t preferredTimeMs, bool lowPowerMode) override;
|
||||
Return<sp<V1_1::IGnssConfiguration>> getExtensionGnssConfiguration_1_1() override;
|
||||
Return<sp<V1_1::IGnssMeasurement>> getExtensionGnssMeasurement_1_1() override;
|
||||
Return<bool> injectBestLocation(const V1_0::GnssLocation& location) override;
|
||||
Return<bool> injectBestLocation(const GnssLocation& location) override;
|
||||
|
||||
// Methods from V2_0::IGnss follow.
|
||||
Return<sp<V2_0::IGnssConfiguration>> getExtensionGnssConfiguration_2_0() override;
|
||||
@@ -83,8 +93,13 @@ struct Gnss : public IGnss {
|
||||
override;
|
||||
|
||||
private:
|
||||
static sp<V2_0::IGnssCallback> sGnssCallback_2_0;
|
||||
static sp<V1_1::IGnssCallback> sGnssCallback_1_1;
|
||||
Return<void> reportLocation(const GnssLocation&) const;
|
||||
static sp<V2_0::IGnssCallback> sGnssCallback_2_0;
|
||||
static sp<V1_1::IGnssCallback> sGnssCallback_1_1;
|
||||
std::atomic<long> mMinIntervalMs;
|
||||
std::atomic<bool> mIsActive;
|
||||
std::thread mThread;
|
||||
mutable std::mutex mMutex;
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
|
||||
@@ -28,5 +28,6 @@ cc_test {
|
||||
"android.hardware.gnss@1.0",
|
||||
"android.hardware.gnss@1.1",
|
||||
"android.hardware.gnss@2.0",
|
||||
"android.hardware.gnss@common-vts-lib",
|
||||
],
|
||||
}
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
#define LOG_TAG "GnssHalTest"
|
||||
|
||||
#include <gnss_hal_test.h>
|
||||
|
||||
#include <chrono>
|
||||
#include "Utils.h"
|
||||
|
||||
using ::android::hardware::gnss::common::Utils;
|
||||
|
||||
// Implementations for the main test class for GNSS HAL
|
||||
GnssHalTest::GnssHalTest()
|
||||
@@ -77,9 +79,88 @@ void GnssHalTest::SetUpGnssCallback() {
|
||||
EXPECT_EQ(name_called_count_, 1);
|
||||
}
|
||||
|
||||
void GnssHalTest::StopAndClearLocations() {
|
||||
const auto result = gnss_hal_->stop();
|
||||
|
||||
EXPECT_TRUE(result.isOk());
|
||||
EXPECT_TRUE(result);
|
||||
|
||||
/*
|
||||
* Clear notify/waiting counter, allowing up till the timeout after
|
||||
* the last reply for final startup messages to arrive (esp. system
|
||||
* info.)
|
||||
*/
|
||||
while (wait(TIMEOUT_SEC) == std::cv_status::no_timeout) {
|
||||
}
|
||||
location_called_count_ = 0;
|
||||
}
|
||||
|
||||
void GnssHalTest::SetPositionMode(const int min_interval_msec, const bool low_power_mode) {
|
||||
const int kPreferredAccuracy = 0; // Ideally perfect (matches GnssLocationProvider)
|
||||
const int kPreferredTimeMsec = 0; // Ideally immediate
|
||||
|
||||
const auto result = gnss_hal_->setPositionMode_1_1(
|
||||
IGnss::GnssPositionMode::MS_BASED, IGnss::GnssPositionRecurrence::RECURRENCE_PERIODIC,
|
||||
min_interval_msec, kPreferredAccuracy, kPreferredTimeMsec, low_power_mode);
|
||||
|
||||
ASSERT_TRUE(result.isOk());
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
|
||||
bool GnssHalTest::StartAndCheckFirstLocation() {
|
||||
const auto result = gnss_hal_->start();
|
||||
|
||||
EXPECT_TRUE(result.isOk());
|
||||
EXPECT_TRUE(result);
|
||||
|
||||
/*
|
||||
* GnssLocationProvider support of AGPS SUPL & XtraDownloader is not available in VTS,
|
||||
* so allow time to demodulate ephemeris over the air.
|
||||
*/
|
||||
const int kFirstGnssLocationTimeoutSeconds = 75;
|
||||
|
||||
wait(kFirstGnssLocationTimeoutSeconds);
|
||||
EXPECT_EQ(location_called_count_, 1);
|
||||
|
||||
if (location_called_count_ > 0) {
|
||||
// don't require speed on first fix
|
||||
CheckLocation(last_location_, false);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void GnssHalTest::CheckLocation(const GnssLocation& location, bool check_speed) {
|
||||
const bool check_more_accuracies = (info_called_count_ > 0 && last_info_.yearOfHw >= 2017);
|
||||
|
||||
Utils::checkLocation(location, check_speed, check_more_accuracies);
|
||||
}
|
||||
|
||||
void GnssHalTest::StartAndCheckLocations(int count) {
|
||||
const int kMinIntervalMsec = 500;
|
||||
const int kLocationTimeoutSubsequentSec = 2;
|
||||
const bool kLowPowerMode = false;
|
||||
|
||||
SetPositionMode(kMinIntervalMsec, kLowPowerMode);
|
||||
|
||||
EXPECT_TRUE(StartAndCheckFirstLocation());
|
||||
|
||||
for (int i = 1; i < count; i++) {
|
||||
EXPECT_EQ(std::cv_status::no_timeout, wait(kLocationTimeoutSubsequentSec));
|
||||
EXPECT_EQ(location_called_count_, i + 1);
|
||||
// Don't cause confusion by checking details if no location yet
|
||||
if (location_called_count_ > 0) {
|
||||
// Should be more than 1 location by now, but if not, still don't check first fix speed
|
||||
CheckLocation(last_location_, location_called_count_ > 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GnssHalTest::notify() {
|
||||
std::unique_lock<std::mutex> lock(mtx_);
|
||||
notify_count_++;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mtx_);
|
||||
notify_count_++;
|
||||
}
|
||||
cv_.notify_one();
|
||||
}
|
||||
|
||||
|
||||
@@ -130,9 +130,51 @@ class GnssHalTest : public ::testing::VtsHalHidlTargetTestBase {
|
||||
*/
|
||||
void SetUpGnssCallback();
|
||||
|
||||
/*
|
||||
* StartAndCheckFirstLocation:
|
||||
* Helper function to start location, and check the first one.
|
||||
*
|
||||
* <p> Note this leaves the Location request active, to enable Stop call vs. other call
|
||||
* reordering tests.
|
||||
*
|
||||
* returns true if a location was successfully generated
|
||||
*/
|
||||
bool StartAndCheckFirstLocation();
|
||||
|
||||
/*
|
||||
* CheckLocation:
|
||||
* Helper function to vet Location fields
|
||||
*
|
||||
* check_speed: true if speed related fields are also verified.
|
||||
*/
|
||||
void CheckLocation(const GnssLocation& location, const bool check_speed);
|
||||
|
||||
/*
|
||||
* StartAndCheckLocations:
|
||||
* Helper function to collect, and check a number of
|
||||
* normal ~1Hz locations.
|
||||
*
|
||||
* Note this leaves the Location request active, to enable Stop call vs. other call
|
||||
* reordering tests.
|
||||
*/
|
||||
void StartAndCheckLocations(int count);
|
||||
|
||||
/*
|
||||
* StopAndClearLocations:
|
||||
* Helper function to stop locations, and clear any remaining notifications
|
||||
*/
|
||||
void StopAndClearLocations();
|
||||
|
||||
/*
|
||||
* SetPositionMode:
|
||||
* Helper function to set positioning mode and verify output
|
||||
*/
|
||||
void SetPositionMode(const int min_interval_msec, const bool low_power_mode);
|
||||
|
||||
sp<IGnss> gnss_hal_; // GNSS HAL to call into
|
||||
sp<IGnssCallback> gnss_cb_; // Primary callback interface
|
||||
|
||||
// TODO: make these variables thread-safe.
|
||||
/* Count of calls to set the following items, and the latest item (used by
|
||||
* test.)
|
||||
*/
|
||||
|
||||
7
gnss/common/OWNERS
Normal file
7
gnss/common/OWNERS
Normal file
@@ -0,0 +1,7 @@
|
||||
wyattriley@google.com
|
||||
gomo@google.com
|
||||
smalkos@google.com
|
||||
yuhany@google.com
|
||||
|
||||
# VTS team
|
||||
yim@google.com
|
||||
33
gnss/common/utils/default/Android.bp
Normal file
33
gnss/common/utils/default/Android.bp
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// Copyright (C) 2019 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.
|
||||
//
|
||||
|
||||
cc_library_static {
|
||||
name: "android.hardware.gnss@common-default-lib",
|
||||
vendor_available: true,
|
||||
relative_install_path: "hw",
|
||||
cflags: [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
],
|
||||
srcs: [
|
||||
"Utils.cpp",
|
||||
],
|
||||
export_include_dirs: ["include"],
|
||||
shared_libs: [
|
||||
"android.hardware.gnss@1.0",
|
||||
],
|
||||
}
|
||||
57
gnss/common/utils/default/Utils.cpp
Normal file
57
gnss/common/utils/default/Utils.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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 <Constants.h>
|
||||
#include <Utils.h>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace gnss {
|
||||
namespace common {
|
||||
|
||||
using GnssSvFlags = V1_0::IGnssCallback::GnssSvFlags;
|
||||
|
||||
GnssLocation Utils::getMockLocation() {
|
||||
GnssLocation location = {.gnssLocationFlags = 0xFF,
|
||||
.latitudeDegrees = kMockLatitudeDegrees,
|
||||
.longitudeDegrees = kMockLongitudeDegrees,
|
||||
.altitudeMeters = kMockAltitudeMeters,
|
||||
.speedMetersPerSec = kMockSpeedMetersPerSec,
|
||||
.bearingDegrees = kMockBearingDegrees,
|
||||
.horizontalAccuracyMeters = kMockHorizontalAccuracyMeters,
|
||||
.verticalAccuracyMeters = kMockVerticalAccuracyMeters,
|
||||
.speedAccuracyMetersPerSecond = kMockSpeedAccuracyMetersPerSecond,
|
||||
.bearingAccuracyDegrees = kMockBearingAccuracyDegrees,
|
||||
.timestamp = kMockTimestamp};
|
||||
return location;
|
||||
}
|
||||
|
||||
GnssSvInfo Utils::getSvInfo(int16_t svid, GnssConstellationType type, float cN0DbHz,
|
||||
float elevationDegrees, float azimuthDegrees) {
|
||||
GnssSvInfo svInfo = {.svid = svid,
|
||||
.constellation = type,
|
||||
.cN0Dbhz = cN0DbHz,
|
||||
.elevationDegrees = elevationDegrees,
|
||||
.azimuthDegrees = azimuthDegrees,
|
||||
.svFlag = GnssSvFlags::USED_IN_FIX | GnssSvFlags::HAS_EPHEMERIS_DATA |
|
||||
GnssSvFlags::HAS_ALMANAC_DATA};
|
||||
return svInfo;
|
||||
}
|
||||
|
||||
} // namespace common
|
||||
} // namespace gnss
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
* Copyright (C) 2019 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.
|
||||
@@ -14,14 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef android_hardware_gnss_V1_1_GnssConstants_H_
|
||||
#define android_hardware_gnss_V1_1_GnssConstants_H_
|
||||
#ifndef android_hardware_gnss_common_Constants_H_
|
||||
#define android_hardware_gnss_common_Constants_H_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace gnss {
|
||||
namespace V1_1 {
|
||||
namespace implementation {
|
||||
namespace common {
|
||||
|
||||
const float kMockLatitudeDegrees = 37.4219999;
|
||||
const float kMockLongitudeDegrees = -122.0840575;
|
||||
@@ -34,10 +35,9 @@ const float kMockSpeedAccuracyMetersPerSecond = 1;
|
||||
const float kMockBearingAccuracyDegrees = 90;
|
||||
const int64_t kMockTimestamp = 1519930775453L;
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_1
|
||||
} // namespace common
|
||||
} // namespace gnss
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
||||
#endif // android_hardware_gnss_V1_1_GnssConstants_H_
|
||||
#endif // android_hardware_gnss_common_Constants_H_
|
||||
42
gnss/common/utils/default/include/Utils.h
Normal file
42
gnss/common/utils/default/include/Utils.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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_default_Utils_H_
|
||||
#define android_hardware_gnss_common_default_Utils_H_
|
||||
|
||||
#include <android/hardware/gnss/1.0/IGnss.h>
|
||||
|
||||
using GnssConstellationType = ::android::hardware::gnss::V1_0::GnssConstellationType;
|
||||
using GnssLocation = ::android::hardware::gnss::V1_0::GnssLocation;
|
||||
using GnssSvInfo = ::android::hardware::gnss::V1_0::IGnssCallback::GnssSvInfo;
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace gnss {
|
||||
namespace common {
|
||||
|
||||
struct Utils {
|
||||
static GnssLocation getMockLocation();
|
||||
static GnssSvInfo getSvInfo(int16_t svid, GnssConstellationType type, float cN0DbHz,
|
||||
float elevationDegrees, float azimuthDegrees);
|
||||
};
|
||||
|
||||
} // namespace common
|
||||
} // namespace gnss
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
||||
#endif // android_hardware_gnss_common_default_Utils_H_
|
||||
36
gnss/common/utils/vts/Android.bp
Normal file
36
gnss/common/utils/vts/Android.bp
Normal file
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// Copyright (C) 2019 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.
|
||||
//
|
||||
|
||||
cc_library_static {
|
||||
name: "android.hardware.gnss@common-vts-lib",
|
||||
vendor_available: true,
|
||||
relative_install_path: "hw",
|
||||
cflags: [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
],
|
||||
srcs: [
|
||||
"Utils.cpp",
|
||||
],
|
||||
export_include_dirs: ["include"],
|
||||
shared_libs: [
|
||||
"android.hardware.gnss@1.0",
|
||||
],
|
||||
static_libs: [
|
||||
"libgtest",
|
||||
],
|
||||
}
|
||||
97
gnss/common/utils/vts/Utils.cpp
Normal file
97
gnss/common/utils/vts/Utils.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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 <Utils.h>
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace gnss {
|
||||
namespace common {
|
||||
|
||||
using V1_0::GnssLocationFlags;
|
||||
|
||||
void Utils::checkLocation(const GnssLocation& location, bool check_speed,
|
||||
bool check_more_accuracies) {
|
||||
EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_LAT_LONG);
|
||||
EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_ALTITUDE);
|
||||
if (check_speed) {
|
||||
EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED);
|
||||
}
|
||||
EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_HORIZONTAL_ACCURACY);
|
||||
// New uncertainties available in O must be provided,
|
||||
// at least when paired with modern hardware (2017+)
|
||||
if (check_more_accuracies) {
|
||||
EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY);
|
||||
if (check_speed) {
|
||||
EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY);
|
||||
if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) {
|
||||
EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY);
|
||||
}
|
||||
}
|
||||
}
|
||||
EXPECT_GE(location.latitudeDegrees, -90.0);
|
||||
EXPECT_LE(location.latitudeDegrees, 90.0);
|
||||
EXPECT_GE(location.longitudeDegrees, -180.0);
|
||||
EXPECT_LE(location.longitudeDegrees, 180.0);
|
||||
EXPECT_GE(location.altitudeMeters, -1000.0);
|
||||
EXPECT_LE(location.altitudeMeters, 30000.0);
|
||||
if (check_speed) {
|
||||
EXPECT_GE(location.speedMetersPerSec, 0.0);
|
||||
EXPECT_LE(location.speedMetersPerSec, 5.0); // VTS tests are stationary.
|
||||
|
||||
// Non-zero speeds must be reported with an associated bearing
|
||||
if (location.speedMetersPerSec > 0.0) {
|
||||
EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tolerating some especially high values for accuracy estimate, in case of
|
||||
* first fix with especially poor geometry (happens occasionally)
|
||||
*/
|
||||
EXPECT_GT(location.horizontalAccuracyMeters, 0.0);
|
||||
EXPECT_LE(location.horizontalAccuracyMeters, 250.0);
|
||||
|
||||
/*
|
||||
* Some devices may define bearing as -180 to +180, others as 0 to 360.
|
||||
* Both are okay & understandable.
|
||||
*/
|
||||
if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) {
|
||||
EXPECT_GE(location.bearingDegrees, -180.0);
|
||||
EXPECT_LE(location.bearingDegrees, 360.0);
|
||||
}
|
||||
if (location.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY) {
|
||||
EXPECT_GT(location.verticalAccuracyMeters, 0.0);
|
||||
EXPECT_LE(location.verticalAccuracyMeters, 500.0);
|
||||
}
|
||||
if (location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY) {
|
||||
EXPECT_GT(location.speedAccuracyMetersPerSecond, 0.0);
|
||||
EXPECT_LE(location.speedAccuracyMetersPerSecond, 50.0);
|
||||
}
|
||||
if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY) {
|
||||
EXPECT_GT(location.bearingAccuracyDegrees, 0.0);
|
||||
EXPECT_LE(location.bearingAccuracyDegrees, 360.0);
|
||||
}
|
||||
|
||||
// Check timestamp > 1.48e12 (47 years in msec - 1970->2017+)
|
||||
EXPECT_GT(location.timestamp, 1.48e12);
|
||||
}
|
||||
|
||||
} // namespace common
|
||||
} // namespace gnss
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
39
gnss/common/utils/vts/include/Utils.h
Normal file
39
gnss/common/utils/vts/include/Utils.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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_vts_Utils_H_
|
||||
#define android_hardware_gnss_common_vts_Utils_H_
|
||||
|
||||
#include <android/hardware/gnss/1.0/IGnss.h>
|
||||
|
||||
using GnssLocation = ::android::hardware::gnss::V1_0::GnssLocation;
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace gnss {
|
||||
namespace common {
|
||||
|
||||
struct Utils {
|
||||
static void checkLocation(const GnssLocation& location, bool check_speed,
|
||||
bool check_more_accuracies);
|
||||
};
|
||||
|
||||
} // namespace common
|
||||
} // namespace gnss
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
||||
#endif // android_hardware_gnss_common_vts_Utils_H_
|
||||
Reference in New Issue
Block a user