Complete 2.1 gnss default implementation to pass all VTS tests
Test: atest VtsHalGnssV2_1TargetTest && atest VtsHalGnssV2_0TargetTest && atest VtsHalGnssV1_1TargetTest && atest VtsHalGnssV1_0TargetTest
Bug: 146216289
Change-Id: Idfd80f70b67359dcbf1dc033b9b4218aff0c869c
diff --git a/gnss/2.1/default/Gnss.cpp b/gnss/2.1/default/Gnss.cpp
index 6b61a82..7db8689 100644
--- a/gnss/2.1/default/Gnss.cpp
+++ b/gnss/2.1/default/Gnss.cpp
@@ -17,6 +17,7 @@
#define LOG_TAG "Gnss"
#include "Gnss.h"
+#include "GnssDebug.h"
#include "GnssMeasurement.h"
#include "GnssMeasurementCorrections.h"
#include "Utils.h"
@@ -35,6 +36,8 @@
sp<V2_1::IGnssCallback> Gnss::sGnssCallback_2_1 = nullptr;
sp<V2_0::IGnssCallback> Gnss::sGnssCallback_2_0 = nullptr;
+sp<V1_1::IGnssCallback> Gnss::sGnssCallback_1_1 = nullptr;
+sp<V1_0::IGnssCallback> Gnss::sGnssCallback_1_0 = nullptr;
Gnss::Gnss() : mMinIntervalMs(1000), mGnssConfiguration{new GnssConfiguration()} {}
@@ -55,8 +58,13 @@
auto svStatus = filterBlacklistedSatellitesV2_1(Utils::getMockSvInfoListV2_1());
this->reportSvStatus(svStatus);
- const auto location = Utils::getMockLocationV2_0();
- this->reportLocation(location);
+ if (sGnssCallback_2_1 != nullptr || sGnssCallback_2_0 != nullptr) {
+ const auto location = Utils::getMockLocationV2_0();
+ this->reportLocation(location);
+ } else {
+ const auto location = Utils::getMockLocationV1_0();
+ this->reportLocation(location);
+ }
std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMs));
}
@@ -84,9 +92,29 @@
}
// Methods from V1_0::IGnss follow.
-Return<bool> Gnss::setCallback(const sp<V1_0::IGnssCallback>&) {
- // TODO implement
- return bool{};
+Return<bool> Gnss::setCallback(const sp<V1_0::IGnssCallback>& callback) {
+ if (callback == nullptr) {
+ ALOGE("%s: Null callback ignored", __func__);
+ return false;
+ }
+
+ sGnssCallback_1_0 = callback;
+
+ uint32_t capabilities = 0x0 | V1_0::IGnssCallback::Capabilities::MEASUREMENTS |
+ V1_0::IGnssCallback::Capabilities::SCHEDULING;
+ auto ret = sGnssCallback_1_0->gnssSetCapabilitesCb(capabilities);
+ if (!ret.isOk()) {
+ ALOGE("%s: Unable to invoke callback", __func__);
+ }
+
+ IGnssCallback::GnssSystemInfo gnssInfo = {.yearOfHw = 2018};
+
+ ret = sGnssCallback_1_0->gnssSetSystemInfoCb(gnssInfo);
+ if (!ret.isOk()) {
+ ALOGE("%s: Unable to invoke callback", __func__);
+ }
+
+ return true;
}
Return<void> Gnss::cleanup() {
@@ -96,13 +124,11 @@
}
Return<bool> Gnss::injectTime(int64_t, int64_t, int32_t) {
- // TODO implement
- return bool{};
+ return true;
}
Return<bool> Gnss::injectLocation(double, double, float) {
- // TODO implement
- return bool{};
+ return true;
}
Return<void> Gnss::deleteAidingData(V1_0::IGnss::GnssAidingData) {
@@ -111,10 +137,10 @@
}
Return<bool> Gnss::setPositionMode(V1_0::IGnss::GnssPositionMode,
- V1_0::IGnss::GnssPositionRecurrence, uint32_t, uint32_t,
- uint32_t) {
- // TODO implement
- return bool{};
+ V1_0::IGnss::GnssPositionRecurrence, uint32_t minIntervalMs,
+ uint32_t, uint32_t) {
+ mMinIntervalMs = minIntervalMs;
+ return true;
}
Return<sp<V1_0::IAGnssRil>> Gnss::getExtensionAGnssRil() {
@@ -138,8 +164,8 @@
}
Return<sp<V1_0::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement() {
- // TODO implement
- return ::android::sp<V1_0::IGnssMeasurement>{};
+ ALOGD("Gnss::getExtensionGnssMeasurement");
+ return new GnssMeasurement();
}
Return<sp<V1_0::IGnssNavigationMessage>> Gnss::getExtensionGnssNavigationMessage() {
@@ -158,8 +184,7 @@
}
Return<sp<V1_0::IGnssDebug>> Gnss::getExtensionGnssDebug() {
- // TODO implement
- return ::android::sp<V1_0::IGnssDebug>{};
+ return new V1_1::implementation::GnssDebug();
}
Return<sp<V1_0::IGnssBatching>> Gnss::getExtensionGnssBatching() {
@@ -168,9 +193,34 @@
}
// Methods from V1_1::IGnss follow.
-Return<bool> Gnss::setCallback_1_1(const sp<V1_1::IGnssCallback>&) {
- // TODO implement
- return bool{};
+Return<bool> Gnss::setCallback_1_1(const sp<V1_1::IGnssCallback>& callback) {
+ if (callback == nullptr) {
+ ALOGE("%s: Null callback ignored", __func__);
+ return false;
+ }
+
+ sGnssCallback_1_1 = callback;
+
+ uint32_t capabilities = 0x0;
+ auto ret = sGnssCallback_1_1->gnssSetCapabilitesCb(capabilities);
+ if (!ret.isOk()) {
+ ALOGE("%s: Unable to invoke callback", __func__);
+ }
+
+ IGnssCallback::GnssSystemInfo gnssInfo = {.yearOfHw = 2018};
+
+ ret = sGnssCallback_1_1->gnssSetSystemInfoCb(gnssInfo);
+ if (!ret.isOk()) {
+ ALOGE("%s: Unable to invoke callback", __func__);
+ }
+
+ auto gnssName = "Google Mock GNSS Implementation v2.1";
+ ret = sGnssCallback_1_1->gnssNameCb(gnssName);
+ if (!ret.isOk()) {
+ ALOGE("%s: Unable to invoke callback", __func__);
+ }
+
+ return true;
}
Return<bool> Gnss::setPositionMode_1_1(V1_0::IGnss::GnssPositionMode,
@@ -191,8 +241,7 @@
}
Return<bool> Gnss::injectBestLocation(const V1_0::GnssLocation&) {
- // TODO implement
- return bool{};
+ return true;
}
// Methods from V2_0::IGnss follow.
@@ -332,6 +381,25 @@
}
}
+void Gnss::reportLocation(const V1_0::GnssLocation& location) const {
+ std::unique_lock<std::mutex> lock(mMutex);
+ if (sGnssCallback_1_1 != nullptr) {
+ auto ret = sGnssCallback_1_1->gnssLocationCb(location);
+ if (!ret.isOk()) {
+ ALOGE("%s: Unable to invoke callback v1.1", __func__);
+ }
+ return;
+ }
+ if (sGnssCallback_1_0 == nullptr) {
+ ALOGE("%s: No non-null callback", __func__);
+ return;
+ }
+ auto ret = sGnssCallback_1_0->gnssLocationCb(location);
+ if (!ret.isOk()) {
+ ALOGE("%s: Unable to invoke callback v1.0", __func__);
+ }
+}
+
void Gnss::reportLocation(const V2_0::GnssLocation& location) const {
std::unique_lock<std::mutex> lock(mMutex);
if (sGnssCallback_2_1 != nullptr) {