diff options
author | Pierre Fite-Georgel <pfg@google.com> | 2019-01-17 16:56:17 -0800 |
---|---|---|
committer | Pierre Fite-Georgel <pfg@google.com> | 2019-02-22 21:18:35 -0800 |
commit | 12ac2b5d0f3da834c0a410a4f4fcbadc4f558dc8 (patch) | |
tree | 50c7dbfa160eefc66e1402e4f166df03b0a2b438 /gnss/2.0 | |
parent | 8eb6c4ed30a71a1b20fcb3f80c1eadabc2d66705 (diff) | |
download | platform_hardware_interfaces-12ac2b5d0f3da834c0a410a4f4fcbadc4f558dc8.tar.gz platform_hardware_interfaces-12ac2b5d0f3da834c0a410a4f4fcbadc4f558dc8.tar.bz2 platform_hardware_interfaces-12ac2b5d0f3da834c0a410a4f4fcbadc4f558dc8.zip |
Adding Elapsed Time since boot field to GnssData [HAL].
Test: Added VTS and did a build check.
Bug: 121353225
Change-Id: I3cb329c16b0bfbff68c45033bcfdc85d53914f18
Diffstat (limited to 'gnss/2.0')
-rw-r--r-- | gnss/2.0/Android.bp | 3 | ||||
-rw-r--r-- | gnss/2.0/IGnss.hal | 13 | ||||
-rw-r--r-- | gnss/2.0/IGnssCallback.hal | 8 | ||||
-rw-r--r-- | gnss/2.0/IGnssMeasurementCallback.hal | 7 | ||||
-rw-r--r-- | gnss/2.0/default/Gnss.cpp | 70 | ||||
-rw-r--r-- | gnss/2.0/default/Gnss.h | 17 | ||||
-rw-r--r-- | gnss/2.0/default/GnssMeasurement.cpp | 15 | ||||
-rw-r--r-- | gnss/2.0/types.hal | 55 | ||||
-rw-r--r-- | gnss/2.0/vts/functional/gnss_hal_test.cpp | 25 | ||||
-rw-r--r-- | gnss/2.0/vts/functional/gnss_hal_test.h | 20 | ||||
-rw-r--r-- | gnss/2.0/vts/functional/gnss_hal_test_cases.cpp | 63 |
11 files changed, 255 insertions, 41 deletions
diff --git a/gnss/2.0/Android.bp b/gnss/2.0/Android.bp index 9b04be0053..230dd907dd 100644 --- a/gnss/2.0/Android.bp +++ b/gnss/2.0/Android.bp @@ -25,6 +25,9 @@ hidl_interface { "android.hidl.base@1.0", ], types: [ + "ElapsedRealtime", + "ElapsedRealtimeFlags", + "GnssLocation", ], gen_java: true, gen_java_constants: true, diff --git a/gnss/2.0/IGnss.hal b/gnss/2.0/IGnss.hal index 1f1858e940..2c149b7a7b 100644 --- a/gnss/2.0/IGnss.hal +++ b/gnss/2.0/IGnss.hal @@ -20,6 +20,7 @@ import android.hardware.gnss.measurement_corrections@1.0::IMeasurementCorrection import android.hardware.gnss.visibility_control@1.0::IGnssVisibilityControl; import @1.1::IGnss; +import GnssLocation; import IGnssCallback; import IGnssConfiguration; import IGnssMeasurement; @@ -94,4 +95,16 @@ interface IGnss extends @1.1::IGnss { * @return visibilityControlIface Handle to the IGnssVisibilityControl interface. */ getExtensionVisibilityControl() generates (IGnssVisibilityControl visibilityControlIface); + + /** + * Injects current location from the best available location provider. + * + * Unlike injectLocation, this method may inject a recent GNSS location from the HAL + * implementation, if that is the best available location known to the framework. + * + * @param location Location information from the best available location provider. + * + * @return success Returns true if successful. + */ + injectBestLocation_2_0(GnssLocation location) generates (bool success); };
\ No newline at end of file diff --git a/gnss/2.0/IGnssCallback.hal b/gnss/2.0/IGnssCallback.hal index 6baff91a55..e2ac02ac03 100644 --- a/gnss/2.0/IGnssCallback.hal +++ b/gnss/2.0/IGnssCallback.hal @@ -18,6 +18,7 @@ package android.hardware.gnss@2.0; import @1.0::IGnssCallback; import @1.1::IGnssCallback; +import GnssLocation; /** * The interface is required for the HAL to communicate certain information @@ -44,4 +45,11 @@ interface IGnssCallback extends @1.1::IGnssCallback { */ gnssSetCapabilitiesCb_2_0(bitfield<Capabilities> capabilities); + /** + * Called when a GNSS location is available. + * + * @param location Location information from HAL. + */ + gnssLocationCb_2_0(GnssLocation location); + };
\ No newline at end of file diff --git a/gnss/2.0/IGnssMeasurementCallback.hal b/gnss/2.0/IGnssMeasurementCallback.hal index fc4446571e..d5dc038b82 100644 --- a/gnss/2.0/IGnssMeasurementCallback.hal +++ b/gnss/2.0/IGnssMeasurementCallback.hal @@ -18,6 +18,7 @@ package android.hardware.gnss@2.0; import @1.0::IGnssMeasurementCallback; import @1.1::IGnssMeasurementCallback; +import ElapsedRealtime; /** The callback interface to report measurements from the HAL. */ interface IGnssMeasurementCallback extends @1.1::IGnssMeasurementCallback { @@ -492,6 +493,12 @@ interface IGnssMeasurementCallback extends @1.1::IGnssMeasurementCallback { /** The GNSS clock time reading. */ GnssClock clock; + + /** + * Timing information of the GNSS data synchronized with SystemClock.elapsedRealtimeNanos() + * clock. + */ + ElapsedRealtime elapsedRealtime; }; /** diff --git a/gnss/2.0/default/Gnss.cpp b/gnss/2.0/default/Gnss.cpp index 1efc9f5b48..599681bf38 100644 --- a/gnss/2.0/default/Gnss.cpp +++ b/gnss/2.0/default/Gnss.cpp @@ -17,7 +17,10 @@ #define LOG_TAG "Gnss" #include "Gnss.h" + #include <log/log.h> +#include <utils/SystemClock.h> + #include "AGnss.h" #include "AGnssRil.h" #include "GnssConfiguration.h" @@ -40,6 +43,24 @@ using GnssSvFlags = IGnssCallback::GnssSvFlags; sp<V2_0::IGnssCallback> Gnss::sGnssCallback_2_0 = nullptr; sp<V1_1::IGnssCallback> Gnss::sGnssCallback_1_1 = nullptr; +namespace { + +V2_0::GnssLocation getMockLocationV2_0() { + const ElapsedRealtime timestamp = { + .flags = ElapsedRealtimeFlags::HAS_TIMESTAMP_NS | + ElapsedRealtimeFlags::HAS_TIME_UNCERTAINTY_NS, + .timestampNs = static_cast<uint64_t>(::android::elapsedRealtimeNano()), + // This is an hardcoded value indicating a 1ms of uncertainty between the two clocks. + // In an actual implementation provide an estimate of the synchronization uncertainty + // or don't set the field. + .timeUncertaintyNs = 1000000}; + + V2_0::GnssLocation location = {.v1_0 = Utils::getMockLocation(), .elapsedRealtime = timestamp}; + return location; +} + +} // namespace + Gnss::Gnss() : mMinIntervalMs(1000) {} Gnss::~Gnss() { @@ -48,7 +69,7 @@ Gnss::~Gnss() { // Methods from V1_0::IGnss follow. Return<bool> Gnss::setCallback(const sp<V1_0::IGnssCallback>&) { - // TODO implement + // TODO(b/124012850): Implement function. return bool{}; } @@ -61,7 +82,7 @@ Return<bool> Gnss::start() { mIsActive = true; mThread = std::thread([this]() { while (mIsActive == true) { - const auto location = Utils::getMockLocation(); + const auto location = getMockLocationV2_0(); this->reportLocation(location); std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMs)); @@ -79,44 +100,44 @@ Return<bool> Gnss::stop() { } Return<void> Gnss::cleanup() { - // TODO implement + // TODO(b/124012850): Implement function. return Void(); } Return<bool> Gnss::injectTime(int64_t, int64_t, int32_t) { - // TODO implement + // TODO(b/124012850): Implement function. return bool{}; } Return<bool> Gnss::injectLocation(double, double, float) { - // TODO implement + // TODO(b/124012850): Implement function. return bool{}; } Return<void> Gnss::deleteAidingData(V1_0::IGnss::GnssAidingData) { - // TODO implement + // TODO(b/124012850): Implement function. return Void(); } Return<bool> Gnss::setPositionMode(V1_0::IGnss::GnssPositionMode, V1_0::IGnss::GnssPositionRecurrence, uint32_t, uint32_t, uint32_t) { - // TODO implement + // TODO(b/124012850): Implement function. return bool{}; } Return<sp<V1_0::IAGnssRil>> Gnss::getExtensionAGnssRil() { - // TODO implement + // TODO(b/124012850): Implement function. return sp<V1_0::IAGnssRil>{}; } Return<sp<V1_0::IGnssGeofencing>> Gnss::getExtensionGnssGeofencing() { - // TODO implement + // TODO(b/124012850): Implement function. return sp<V1_0::IGnssGeofencing>{}; } Return<sp<V1_0::IAGnss>> Gnss::getExtensionAGnss() { - // TODO implement + // TODO(b/124012850): Implement function. return sp<V1_0::IAGnss>{}; } @@ -131,27 +152,27 @@ Return<sp<V1_0::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement() { } Return<sp<V1_0::IGnssNavigationMessage>> Gnss::getExtensionGnssNavigationMessage() { - // TODO implement + // TODO(b/124012850): Implement function. return sp<V1_0::IGnssNavigationMessage>{}; } Return<sp<V1_0::IGnssXtra>> Gnss::getExtensionXtra() { - // TODO implement + // TODO(b/124012850): Implement function. return sp<V1_0::IGnssXtra>{}; } Return<sp<V1_0::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration() { - // TODO implement + // TODO(b/124012850): Implement function. return sp<V1_0::IGnssConfiguration>{}; } Return<sp<V1_0::IGnssDebug>> Gnss::getExtensionGnssDebug() { - // TODO implement + // TODO(b/124012850): Implement function. return sp<V1_0::IGnssDebug>{}; } Return<sp<V1_0::IGnssBatching>> Gnss::getExtensionGnssBatching() { - // TODO implement + // TODO(b/124012850): Implement function. return sp<V1_0::IGnssBatching>{}; } @@ -194,7 +215,7 @@ Return<bool> Gnss::setPositionMode_1_1(V1_0::IGnss::GnssPositionMode, } Return<sp<V1_1::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration_1_1() { - // TODO implement + // TODO(b/124012850): Implement function. return sp<V1_1::IGnssConfiguration>{}; } @@ -204,7 +225,7 @@ Return<sp<V1_1::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement_1_1() { } Return<bool> Gnss::injectBestLocation(const V1_0::GnssLocation&) { - // TODO implement + // TODO(b/124012850): Implement function. return bool{}; } @@ -228,7 +249,7 @@ Return<sp<V2_0::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement_2_0() { Return<sp<measurement_corrections::V1_0::IMeasurementCorrections>> Gnss::getExtensionMeasurementCorrections() { - // TODO implement + // TODO(b/124012850): Implement function. return sp<measurement_corrections::V1_0::IMeasurementCorrections>{}; } @@ -268,16 +289,21 @@ Return<bool> Gnss::setCallback_2_0(const sp<V2_0::IGnssCallback>& callback) { return true; } -Return<void> Gnss::reportLocation(const GnssLocation& location) const { +Return<void> Gnss::reportLocation(const V2_0::GnssLocation& location) const { std::unique_lock<std::mutex> lock(mMutex); - if (sGnssCallback_1_1 == nullptr) { - ALOGE("%s: sGnssCallback is null.", __func__); + if (sGnssCallback_2_0 == nullptr) { + ALOGE("%s: sGnssCallback 2.0 is null.", __func__); return Void(); } - sGnssCallback_1_1->gnssLocationCb(location); + sGnssCallback_2_0->gnssLocationCb_2_0(location); return Void(); } +Return<bool> Gnss::injectBestLocation_2_0(const V2_0::GnssLocation&) { + // TODO(b/124012850): Implement function. + return bool{}; +} + } // namespace implementation } // namespace V2_0 } // namespace gnss diff --git a/gnss/2.0/default/Gnss.h b/gnss/2.0/default/Gnss.h index 7d9e7831cd..f02ab0a21e 100644 --- a/gnss/2.0/default/Gnss.h +++ b/gnss/2.0/default/Gnss.h @@ -91,15 +91,16 @@ struct Gnss : public IGnss { getExtensionMeasurementCorrections() override; Return<sp<visibility_control::V1_0::IGnssVisibilityControl>> getExtensionVisibilityControl() override; + Return<bool> injectBestLocation_2_0(const V2_0::GnssLocation& location) override; - private: - 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; + private: + Return<void> reportLocation(const V2_0::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 diff --git a/gnss/2.0/default/GnssMeasurement.cpp b/gnss/2.0/default/GnssMeasurement.cpp index 0f707b4d4a..702c9e2362 100644 --- a/gnss/2.0/default/GnssMeasurement.cpp +++ b/gnss/2.0/default/GnssMeasurement.cpp @@ -16,7 +16,9 @@ #define LOG_TAG "GnssMeasurement" #include "GnssMeasurement.h" + #include <log/log.h> +#include <utils/SystemClock.h> namespace android { namespace hardware { @@ -129,7 +131,18 @@ GnssData GnssMeasurement::getMockMeasurement() { .driftNsps = -51.757811607455452, .driftUncertaintyNsps = 310.64968328491528, .hwClockDiscontinuityCount = 1}; - GnssData gnssData = {.measurements = measurements, .clock = clock}; + + ElapsedRealtime timestamp = { + .flags = ElapsedRealtimeFlags::HAS_TIMESTAMP_NS | + ElapsedRealtimeFlags::HAS_TIME_UNCERTAINTY_NS, + .timestampNs = static_cast<uint64_t>(::android::elapsedRealtimeNano()), + // This is an hardcoded value indicating a 1ms of uncertainty between the two clocks. + // In an actual implementation provide an estimate of the synchronization uncertainty + // or don't set the field. + .timeUncertaintyNs = 1000000}; + + GnssData gnssData = { + .measurements = measurements, .clock = clock, .elapsedRealtime = timestamp}; return gnssData; } diff --git a/gnss/2.0/types.hal b/gnss/2.0/types.hal index 97c178ff32..4abb6048c9 100644 --- a/gnss/2.0/types.hal +++ b/gnss/2.0/types.hal @@ -16,5 +16,60 @@ package android.hardware.gnss@2.0; +import @1.0::GnssLocation; + /** Network handle type. */ typedef uint64_t net_handle_t; + +/** + * Flags indicating the validity of the fields in ElapsedRealtime. + */ +@export(name="", value_prefix="ELAPSED_REALTIME_") +enum ElapsedRealtimeFlags : uint16_t { + /** A valid timestampNs is stored in the data structure. */ + HAS_TIMESTAMP_NS = 1 << 0, + /** A valid timeUncertaintyNs is stored in the data structure. */ + HAS_TIME_UNCERTAINTY_NS = 1 << 1, +}; + +/** + * Represents an estimate of elapsed time since boot of Android for a given event. + * + * This timestamp MUST represent the time the event happened and MUST be synchronized + * with the SystemClock.elapsedRealtimeNanos() clock. + */ +struct ElapsedRealtime { + /** + * A set of flags indicating the validity of each field in this data structure. + * + * Fields may have invalid information in them, if not marked as valid by the + * corresponding bit in flags. + */ + bitfield<ElapsedRealtimeFlags> flags; + + /** + * Estimate of the elapsed time since boot value for the corresponding event in nanoseconds. + */ + uint64_t timestampNs; + + /** + * Estimate of the relative precision of the alignment of this SystemClock + * timestamp, with the reported measurements in nanoseconds (68% confidence). + */ + uint64_t timeUncertaintyNs; +}; + +/** Represents a location. */ +struct GnssLocation { + @1.0::GnssLocation v1_0; + + /** + * Timing information of the GNSS location synchronized with SystemClock.elapsedRealtimeNanos() + * clock. + * + * This clock information can be obtained from SystemClock.elapsedRealtimeNanos(), when the GNSS + * is attached straight to the AP/SOC. When it is attached to a separate module the timestamp + * needs to be estimatedd by syncing the notion of time via PTP or some other mechanism. + */ + ElapsedRealtime elapsedRealtime; +};
\ No newline at end of file diff --git a/gnss/2.0/vts/functional/gnss_hal_test.cpp b/gnss/2.0/vts/functional/gnss_hal_test.cpp index 1580c28841..c564f41a03 100644 --- a/gnss/2.0/vts/functional/gnss_hal_test.cpp +++ b/gnss/2.0/vts/functional/gnss_hal_test.cpp @@ -130,10 +130,10 @@ bool GnssHalTest::StartAndCheckFirstLocation() { return false; } -void GnssHalTest::CheckLocation(const GnssLocation& location, bool check_speed) { +void GnssHalTest::CheckLocation(const GnssLocation_2_0& 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); + Utils::checkLocation(location.v1_0, check_speed, check_more_accuracies); } void GnssHalTest::StartAndCheckLocations(int count) { @@ -193,6 +193,14 @@ Return<void> GnssHalTest::GnssCallback::gnssSetCapabilitesCb(uint32_t capabiliti return Void(); } +Return<void> GnssHalTest::GnssCallback::gnssSetCapabilitiesCb_2_0(uint32_t capabilities) { + ALOGI("Capabilities (v2.0) received %d", capabilities); + parent_.capabilities_called_count_++; + parent_.last_capabilities_ = capabilities; + parent_.notify(); + return Void(); +} + Return<void> GnssHalTest::GnssCallback::gnssNameCb(const android::hardware::hidl_string& name) { ALOGI("Name received: %s", name.c_str()); parent_.name_called_count_++; @@ -201,8 +209,19 @@ Return<void> GnssHalTest::GnssCallback::gnssNameCb(const android::hardware::hidl return Void(); } -Return<void> GnssHalTest::GnssCallback::gnssLocationCb(const GnssLocation& location) { +Return<void> GnssHalTest::GnssCallback::gnssLocationCb(const GnssLocation_1_0& location) { ALOGI("Location received"); + GnssLocation_2_0 location_v2_0; + location_v2_0.v1_0 = location; + return gnssLocationCbImpl(location_v2_0); +} + +Return<void> GnssHalTest::GnssCallback::gnssLocationCb_2_0(const GnssLocation_2_0& location) { + ALOGI("Location (v2.0) received"); + return gnssLocationCbImpl(location); +} + +Return<void> GnssHalTest::GnssCallback::gnssLocationCbImpl(const GnssLocation_2_0& location) { parent_.location_called_count_++; parent_.last_location_ = location; parent_.notify(); diff --git a/gnss/2.0/vts/functional/gnss_hal_test.h b/gnss/2.0/vts/functional/gnss_hal_test.h index 2c16651d8d..7793eb75cb 100644 --- a/gnss/2.0/vts/functional/gnss_hal_test.h +++ b/gnss/2.0/vts/functional/gnss_hal_test.h @@ -18,7 +18,6 @@ #define GNSS_HAL_TEST_H_ #include <android/hardware/gnss/2.0/IGnss.h> - #include <VtsHalHidlTargetTestBase.h> #include <VtsHalHidlTargetTestEnvBase.h> @@ -29,11 +28,13 @@ using android::hardware::Return; using android::hardware::Void; -using android::hardware::gnss::V1_0::GnssLocation; - using android::hardware::gnss::V1_0::GnssLocationFlags; -using android::hardware::gnss::V1_1::IGnssCallback; using android::hardware::gnss::V2_0::IGnss; +using android::hardware::gnss::V2_0::IGnssCallback; + +using GnssLocation_1_0 = android::hardware::gnss::V1_0::GnssLocation; +using GnssLocation_2_0 = android::hardware::gnss::V2_0::GnssLocation; + using IGnssMeasurementCallback_1_0 = android::hardware::gnss::V1_0::IGnssMeasurementCallback; using IGnssMeasurementCallback_1_1 = android::hardware::gnss::V1_1::IGnssMeasurementCallback; using IGnssMeasurementCallback_2_0 = android::hardware::gnss::V2_0::IGnssMeasurementCallback; @@ -97,10 +98,15 @@ class GnssHalTest : public ::testing::VtsHalHidlTargetTestBase { Return<void> gnssRequestTimeCb() override { return Void(); } // Actual (test) callback handlers Return<void> gnssNameCb(const android::hardware::hidl_string& name) override; - Return<void> gnssLocationCb(const GnssLocation& location) override; + Return<void> gnssLocationCb(const GnssLocation_1_0& location) override; + Return<void> gnssLocationCb_2_0(const GnssLocation_2_0& location) override; Return<void> gnssSetCapabilitesCb(uint32_t capabilities) override; + Return<void> gnssSetCapabilitiesCb_2_0(uint32_t capabilities) override; Return<void> gnssSetSystemInfoCb(const IGnssCallback::GnssSystemInfo& info) override; Return<void> gnssSvStatusCb(const IGnssCallback::GnssSvStatus& svStatus) override; + + private: + Return<void> gnssLocationCbImpl(const GnssLocation_2_0& location); }; /* Callback class for GnssMeasurement. */ @@ -147,7 +153,7 @@ class GnssHalTest : public ::testing::VtsHalHidlTargetTestBase { * * check_speed: true if speed related fields are also verified. */ - void CheckLocation(const GnssLocation& location, const bool check_speed); + void CheckLocation(const GnssLocation_2_0& location, const bool check_speed); /* * StartAndCheckLocations: @@ -186,7 +192,7 @@ class GnssHalTest : public ::testing::VtsHalHidlTargetTestBase { IGnssCallback::GnssSystemInfo last_info_; uint32_t last_capabilities_; - GnssLocation last_location_; + GnssLocation_2_0 last_location_; IGnssMeasurementCallback_2_0::GnssData last_measurement_; android::hardware::hidl_string last_name_; diff --git a/gnss/2.0/vts/functional/gnss_hal_test_cases.cpp b/gnss/2.0/vts/functional/gnss_hal_test_cases.cpp index 48f2be8802..b135dba2c1 100644 --- a/gnss/2.0/vts/functional/gnss_hal_test_cases.cpp +++ b/gnss/2.0/vts/functional/gnss_hal_test_cases.cpp @@ -31,7 +31,9 @@ using IAGnssRil_2_0 = android::hardware::gnss::V2_0::IAGnssRil; using IAGnss_2_0 = android::hardware::gnss::V2_0::IAGnss; using IAGnss_1_0 = android::hardware::gnss::V1_0::IAGnss; using IAGnssCallback_2_0 = android::hardware::gnss::V2_0::IAGnssCallback; + using android::hardware::gnss::V1_0::IGnssNi; +using android::hardware::gnss::V2_0::ElapsedRealtimeFlags; using android::hardware::gnss::visibility_control::V1_0::IGnssVisibilityControl; /* @@ -269,3 +271,64 @@ TEST_F(GnssHalTest, TestGnssVisibilityControlExtension) { ASSERT_TRUE(result.isOk()); EXPECT_TRUE(result); } + +/* + * TestGnssDataElapsedRealtimeFlags: + * Sets a GnssMeasurementCallback, waits for a GnssData object, and verifies the flags in member + * elapsedRealitme are valid. + */ +TEST_F(GnssHalTest, TestGnssDataElapsedRealtimeFlags) { + const int kFirstGnssMeasurementTimeoutSeconds = 10; + + auto gnssMeasurement = gnss_hal_->getExtensionGnssMeasurement_2_0(); + if (!gnssMeasurement.isOk()) { + return; + } + + sp<IGnssMeasurement_2_0> iGnssMeasurement = gnssMeasurement; + if (iGnssMeasurement == nullptr) { + return; + } + + sp<IGnssMeasurementCallback_2_0> callback = new GnssMeasurementCallback(*this); + + auto result = iGnssMeasurement->setCallback_2_0(callback, /* enableFullTracking= */ true); + ASSERT_TRUE(result.isOk()); + EXPECT_EQ(result, IGnssMeasurement_1_0::GnssMeasurementStatus::SUCCESS); + + wait(kFirstGnssMeasurementTimeoutSeconds); + EXPECT_EQ(measurement_called_count_, 1); + + ASSERT_TRUE((int)last_measurement_.elapsedRealtime.flags >= 0 && + (int)last_measurement_.elapsedRealtime.flags <= + (int)ElapsedRealtimeFlags::HAS_TIME_UNCERTAINTY_NS); + + // We expect a non-zero timestamp when set. + if (last_measurement_.elapsedRealtime.flags & ElapsedRealtimeFlags::HAS_TIMESTAMP_NS) { + ASSERT_TRUE(last_measurement_.elapsedRealtime.timestampNs != 0); + } + + iGnssMeasurement->close(); +} + +TEST_F(GnssHalTest, TestGnssLocationElapsedRealtime) { + StartAndCheckFirstLocation(); + + ASSERT_TRUE((int)last_location_.elapsedRealtime.flags >= 0 && + (int)last_location_.elapsedRealtime.flags <= + (int)ElapsedRealtimeFlags::HAS_TIME_UNCERTAINTY_NS); + + // We expect a non-zero timestamp when set. + if (last_location_.elapsedRealtime.flags & ElapsedRealtimeFlags::HAS_TIMESTAMP_NS) { + ASSERT_TRUE(last_location_.elapsedRealtime.timestampNs != 0); + } + + StopAndClearLocations(); +} + +// This test only verify that injectBestLocation_2_0 does not crash. +TEST_F(GnssHalTest, TestInjectBestLocation_2_0) { + StartAndCheckFirstLocation(); + gnss_hal_->injectBestLocation_2_0(last_location_); + StopAndClearLocations(); +} |