diff --git a/gnss/1.1/vts/functional/gnss_hal_test.cpp b/gnss/1.1/vts/functional/gnss_hal_test.cpp index 24de37d0e2..88fbff8164 100644 --- a/gnss/1.1/vts/functional/gnss_hal_test.cpp +++ b/gnss/1.1/vts/functional/gnss_hal_test.cpp @@ -172,7 +172,14 @@ bool GnssHalTest::IsGnssHalVersion_1_1() const { hasGnssHalVersion_2_0 = registered.size() != 0; }); - return hasGnssHalVersion_1_1 && !hasGnssHalVersion_2_0; + bool hasGnssHalVersion_2_1 = false; + manager->listManifestByInterface( + "android.hardware.gnss@2.1::IGnss", + [&hasGnssHalVersion_2_1](const hidl_vec& registered) { + hasGnssHalVersion_2_1 = registered.size() != 0; + }); + + return hasGnssHalVersion_1_1 && !hasGnssHalVersion_2_0 && !hasGnssHalVersion_2_1; } GnssConstellationType GnssHalTest::startLocationAndGetNonGpsConstellation( diff --git a/gnss/2.0/vts/functional/gnss_hal_test.cpp b/gnss/2.0/vts/functional/gnss_hal_test.cpp index 8ca3f684a3..b3a3203214 100644 --- a/gnss/2.0/vts/functional/gnss_hal_test.cpp +++ b/gnss/2.0/vts/functional/gnss_hal_test.cpp @@ -16,11 +16,14 @@ #define LOG_TAG "GnssHalTest" +#include #include +#include +#include #include #include "Utils.h" -#include +using ::android::hardware::hidl_string; using ::android::hardware::gnss::common::Utils; @@ -99,7 +102,6 @@ bool GnssHalTest::StartAndCheckFirstLocation() { 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. @@ -148,6 +150,27 @@ void GnssHalTest::StartAndCheckLocations(int count) { } } +bool GnssHalTest::IsGnssHalVersion_2_0() const { + using ::android::hidl::manager::V1_2::IServiceManager; + sp manager = ::android::hardware::defaultServiceManager1_2(); + + bool hasGnssHalVersion_2_0 = false; + manager->listManifestByInterface( + "android.hardware.gnss@2.0::IGnss", + [&hasGnssHalVersion_2_0](const hidl_vec& registered) { + hasGnssHalVersion_2_0 = registered.size() != 0; + }); + + bool hasGnssHalVersion_2_1 = false; + manager->listManifestByInterface( + "android.hardware.gnss@2.1::IGnss", + [&hasGnssHalVersion_2_1](const hidl_vec& registered) { + hasGnssHalVersion_2_1 = registered.size() != 0; + }); + + return hasGnssHalVersion_2_0 && !hasGnssHalVersion_2_1; +} + GnssHalTest::GnssCallback::GnssCallback() : info_cbq_("system_info"), name_cbq_("name"), diff --git a/gnss/2.0/vts/functional/gnss_hal_test.h b/gnss/2.0/vts/functional/gnss_hal_test.h index 4f7b87a485..55dc1bc4f6 100644 --- a/gnss/2.0/vts/functional/gnss_hal_test.h +++ b/gnss/2.0/vts/functional/gnss_hal_test.h @@ -180,6 +180,12 @@ class GnssHalTest : public testing::TestWithParam { */ void StopAndClearLocations(); + /* + * IsGnssHalVersion_2_0: + * returns true if the GNSS HAL version is exactly 2.0. + */ + bool IsGnssHalVersion_2_0() const; + /* * SetPositionMode: * Helper function to set positioning mode and verify output 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 c442cc6bf8..0fa08b903e 100644 --- a/gnss/2.0/vts/functional/gnss_hal_test_cases.cpp +++ b/gnss/2.0/vts/functional/gnss_hal_test_cases.cpp @@ -182,6 +182,10 @@ TEST_P(GnssHalTest, TestAGnssRil_UpdateNetworkState_2_0) { * 3. state is valid. */ TEST_P(GnssHalTest, TestGnssMeasurementFields) { + if (!IsGnssHalVersion_2_0()) { + ALOGI("Test GnssMeasurementFields skipped. GNSS HAL version is greater than 2.0."); + return; + } const int kFirstGnssMeasurementTimeoutSeconds = 10; auto gnssMeasurement = gnss_hal_->getExtensionGnssMeasurement_2_0(); @@ -464,7 +468,7 @@ TEST_P(GnssHalTest, GetLocationLowPower) { } EXPECT_LE(location_called_count, i); if (location_called_count != i) { - ALOGW("GetLocationLowPower test - not enough locations received. %d vs. %d expected ", + ALOGW("GetLocationLowPower test - too many locations received. %d vs. %d expected ", location_called_count, i); } @@ -601,6 +605,11 @@ IGnssConfiguration_1_1::BlacklistedSource FindStrongFrequentNonGpsSource( * formerly strongest satellite */ TEST_P(GnssHalTest, BlacklistIndividualSatellites) { + if (!IsGnssHalVersion_2_0()) { + ALOGI("Test BlacklistIndividualSatellites skipped. GNSS HAL version is greater than 2.0."); + return; + } + if (!(gnss_cb_->last_capabilities_ & IGnssCallback::Capabilities::SATELLITE_BLACKLIST)) { ALOGI("Test BlacklistIndividualSatellites skipped. SATELLITE_BLACKLIST capability" " not supported."); @@ -746,6 +755,11 @@ TEST_P(GnssHalTest, BlacklistIndividualSatellites) { * 4a & b) Clean up by turning off location, and send in empty blacklist. */ TEST_P(GnssHalTest, BlacklistConstellation) { + if (!IsGnssHalVersion_2_0()) { + ALOGI("Test BlacklistConstellation skipped. GNSS HAL version is greater than 2.0."); + return; + } + if (!(gnss_cb_->last_capabilities_ & IGnssCallback::Capabilities::SATELLITE_BLACKLIST)) { ALOGI("Test BlacklistConstellation skipped. SATELLITE_BLACKLIST capability not supported."); return; diff --git a/gnss/2.1/default/Android.bp b/gnss/2.1/default/Android.bp index 57233aa6cb..7ef999081e 100644 --- a/gnss/2.1/default/Android.bp +++ b/gnss/2.1/default/Android.bp @@ -23,8 +23,9 @@ cc_binary { srcs: [ "Gnss.cpp", "GnssMeasurement.cpp", + "GnssMeasurementCorrections.cpp", "GnssConfiguration.cpp", - "service.cpp" + "service.cpp", ], shared_libs: [ "libhidlbase", diff --git a/gnss/2.1/default/Gnss.cpp b/gnss/2.1/default/Gnss.cpp index fd7a9dfd0d..6b61a827d0 100644 --- a/gnss/2.1/default/Gnss.cpp +++ b/gnss/2.1/default/Gnss.cpp @@ -18,11 +18,14 @@ #include "Gnss.h" #include "GnssMeasurement.h" +#include "GnssMeasurementCorrections.h" #include "Utils.h" #include using ::android::hardware::gnss::common::Utils; +using ::android::hardware::gnss::measurement_corrections::V1_0::implementation:: + GnssMeasurementCorrections; namespace android { namespace hardware { @@ -87,7 +90,8 @@ Return Gnss::setCallback(const sp&) { } Return Gnss::cleanup() { - // TODO implement + sGnssCallback_2_1 = nullptr; + sGnssCallback_2_0 = nullptr; return Void(); } @@ -170,8 +174,9 @@ Return Gnss::setCallback_1_1(const sp&) { } Return Gnss::setPositionMode_1_1(V1_0::IGnss::GnssPositionMode, - V1_0::IGnss::GnssPositionRecurrence, uint32_t, uint32_t, - uint32_t, bool) { + V1_0::IGnss::GnssPositionRecurrence, uint32_t minIntervalMs, + uint32_t, uint32_t, bool) { + mMinIntervalMs = minIntervalMs; return true; } @@ -215,7 +220,7 @@ Return Gnss::setCallback_2_0(const sp& callback) { ALOGE("%s: Unable to invoke callback", __func__); } - auto gnssName = "Google Mock GNSS Implementation v2.0"; + auto gnssName = "Google Mock GNSS Implementation v2.1"; ret = sGnssCallback_2_0->gnssNameCb(gnssName); if (!ret.isOk()) { ALOGE("%s: Unable to invoke callback", __func__); @@ -251,8 +256,8 @@ Return> Gnss::getExtensionGnssMeasurement_2_0() { Return> Gnss::getExtensionMeasurementCorrections() { - // TODO implement - return ::android::sp{}; + ALOGD("Gnss::getExtensionMeasurementCorrections()"); + return new GnssMeasurementCorrections(); } Return> Gnss::getExtensionVisibilityControl() { @@ -266,7 +271,7 @@ Return> Gnss::getExtensionGnssBatching_2_0() { } Return Gnss::injectBestLocation_2_0(const V2_0::GnssLocation&) { - // TODO implement + // TODO(b/124012850): Implement function. return bool{}; } @@ -316,6 +321,7 @@ Return> Gnss::getExtensionGnssConfiguration_2_1() { void Gnss::reportSvStatus(const hidl_vec& svInfoList) const { std::unique_lock lock(mMutex); + // TODO(skz): update this to call 2_0 callback if non-null if (sGnssCallback_2_1 == nullptr) { ALOGE("%s: sGnssCallback v2.1 is null.", __func__); return; @@ -328,13 +334,20 @@ void Gnss::reportSvStatus(const hidl_vec& svInfoList) const { void Gnss::reportLocation(const V2_0::GnssLocation& location) const { std::unique_lock lock(mMutex); - if (sGnssCallback_2_1 == nullptr) { - ALOGE("%s: sGnssCallback v2.1 is null.", __func__); + if (sGnssCallback_2_1 != nullptr) { + auto ret = sGnssCallback_2_1->gnssLocationCb_2_0(location); + if (!ret.isOk()) { + ALOGE("%s: Unable to invoke callback v2.1", __func__); + } return; } - auto ret = sGnssCallback_2_1->gnssLocationCb_2_0(location); + if (sGnssCallback_2_0 == nullptr) { + ALOGE("%s: No non-null callback", __func__); + return; + } + auto ret = sGnssCallback_2_0->gnssLocationCb_2_0(location); if (!ret.isOk()) { - ALOGE("%s: Unable to invoke callback", __func__); + ALOGE("%s: Unable to invoke callback v2.0", __func__); } } diff --git a/gnss/2.1/default/GnssMeasurement.cpp b/gnss/2.1/default/GnssMeasurement.cpp index ebfa7ddf1d..34e20e5790 100644 --- a/gnss/2.1/default/GnssMeasurement.cpp +++ b/gnss/2.1/default/GnssMeasurement.cpp @@ -29,7 +29,8 @@ using common::Utils; namespace V2_1 { namespace implementation { -sp GnssMeasurement::sCallback = nullptr; +sp GnssMeasurement::sCallback_2_1 = nullptr; +sp GnssMeasurement::sCallback_2_0 = nullptr; GnssMeasurement::GnssMeasurement() : mMinIntervalMillis(1000) {} @@ -48,7 +49,8 @@ Return GnssMeasurement::close() { ALOGD("close"); std::unique_lock lock(mMutex); stop(); - sCallback = nullptr; + sCallback_2_1 = nullptr; + sCallback_2_0 = nullptr; return Void(); } @@ -61,9 +63,18 @@ Return GnssMeasurement::setCallba // Methods from V2_0::IGnssMeasurement follow. Return GnssMeasurement::setCallback_2_0( - const sp&, bool) { - // TODO implement - return V1_0::IGnssMeasurement::GnssMeasurementStatus{}; + const sp& callback, bool) { + ALOGD("setCallback_2_0"); + std::unique_lock lock(mMutex); + sCallback_2_0 = callback; + + if (mIsActive) { + ALOGW("GnssMeasurement callback already set. Resetting the callback..."); + stop(); + } + start(); + + return V1_0::IGnssMeasurement::GnssMeasurementStatus::SUCCESS; } // Methods from V2_1::IGnssMeasurement follow. @@ -71,7 +82,7 @@ Return GnssMeasurement::setCallba const sp& callback, bool) { ALOGD("setCallback_2_1"); std::unique_lock lock(mMutex); - sCallback = callback; + sCallback_2_1 = callback; if (mIsActive) { ALOGW("GnssMeasurement callback already set. Resetting the callback..."); @@ -87,8 +98,13 @@ void GnssMeasurement::start() { mIsActive = true; mThread = std::thread([this]() { while (mIsActive == true) { - auto measurement = Utils::getMockMeasurementV2_1(); - this->reportMeasurement(measurement); + if (sCallback_2_1 != nullptr) { + auto measurement = Utils::getMockMeasurementV2_1(); + this->reportMeasurement(measurement); + } else { + auto measurement = Utils::getMockMeasurementV2_0(); + this->reportMeasurement(measurement); + } std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMillis)); } @@ -103,14 +119,27 @@ void GnssMeasurement::stop() { } } +void GnssMeasurement::reportMeasurement(const GnssDataV2_0& data) { + ALOGD("reportMeasurement()"); + std::unique_lock lock(mMutex); + if (sCallback_2_0 == nullptr) { + ALOGE("%s: GnssMeasurement::sCallback_2_0 is null.", __func__); + return; + } + auto ret = sCallback_2_0->gnssMeasurementCb_2_0(data); + if (!ret.isOk()) { + ALOGE("%s: Unable to invoke callback", __func__); + } +} + void GnssMeasurement::reportMeasurement(const GnssDataV2_1& data) { ALOGD("reportMeasurement()"); std::unique_lock lock(mMutex); - if (sCallback == nullptr) { - ALOGE("%s: GnssMeasurement::sCallback is null.", __func__); + if (sCallback_2_1 == nullptr) { + ALOGE("%s: GnssMeasurement::sCallback_2_1 is null.", __func__); return; } - auto ret = sCallback->gnssMeasurementCb_2_1(data); + auto ret = sCallback_2_1->gnssMeasurementCb_2_1(data); if (!ret.isOk()) { ALOGE("%s: Unable to invoke callback", __func__); } diff --git a/gnss/2.1/default/GnssMeasurement.h b/gnss/2.1/default/GnssMeasurement.h index ee329039d9..3ed7bc597d 100644 --- a/gnss/2.1/default/GnssMeasurement.h +++ b/gnss/2.1/default/GnssMeasurement.h @@ -30,6 +30,7 @@ namespace V2_1 { namespace implementation { using GnssDataV2_1 = V2_1::IGnssMeasurementCallback::GnssData; +using GnssDataV2_0 = V2_0::IGnssMeasurementCallback::GnssData; using ::android::sp; using ::android::hardware::hidl_array; @@ -62,9 +63,11 @@ struct GnssMeasurement : public IGnssMeasurement { private: void start(); void stop(); + void reportMeasurement(const GnssDataV2_0&); void reportMeasurement(const GnssDataV2_1&); - static sp sCallback; + static sp sCallback_2_1; + static sp sCallback_2_0; std::atomic mMinIntervalMillis; std::atomic mIsActive; std::thread mThread; diff --git a/gnss/2.1/default/GnssMeasurementCorrections.cpp b/gnss/2.1/default/GnssMeasurementCorrections.cpp new file mode 100644 index 0000000000..2bf5601820 --- /dev/null +++ b/gnss/2.1/default/GnssMeasurementCorrections.cpp @@ -0,0 +1,75 @@ +/* + * 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. + */ + +#define LOG_TAG "GnssMeasurementCorrections" + +#include "GnssMeasurementCorrections.h" +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace measurement_corrections { +namespace V1_0 { +namespace implementation { + +// Methods from V1_0::IMeasurementCorrections follow. +Return GnssMeasurementCorrections::setCorrections(const MeasurementCorrections& corrections) { + ALOGD("setCorrections"); + ALOGD("corrections = lat: %f, lng: %f, alt: %f, hUnc: %f, vUnc: %f, toa: %llu, " + "satCorrections.size: %d", + corrections.latitudeDegrees, corrections.longitudeDegrees, corrections.altitudeMeters, + corrections.horizontalPositionUncertaintyMeters, + corrections.verticalPositionUncertaintyMeters, + static_cast(corrections.toaGpsNanosecondsOfWeek), + static_cast(corrections.satCorrections.size())); + for (auto singleSatCorrection : corrections.satCorrections) { + ALOGD("singleSatCorrection = flags: %d, constellation: %d, svid: %d, cfHz: %f, probLos: %f," + " epl: %f, eplUnc: %f", + static_cast(singleSatCorrection.singleSatCorrectionFlags), + static_cast(singleSatCorrection.constellation), + static_cast(singleSatCorrection.svid), singleSatCorrection.carrierFrequencyHz, + singleSatCorrection.probSatIsLos, singleSatCorrection.excessPathLengthMeters, + singleSatCorrection.excessPathLengthUncertaintyMeters); + ALOGD("reflecting plane = lat: %f, lng: %f, alt: %f, azm: %f", + singleSatCorrection.reflectingPlane.latitudeDegrees, + singleSatCorrection.reflectingPlane.longitudeDegrees, + singleSatCorrection.reflectingPlane.altitudeMeters, + singleSatCorrection.reflectingPlane.azimuthDegrees); + } + + return true; +} + +Return GnssMeasurementCorrections::setCallback( + const sp& callback) { + using Capabilities = V1_0::IMeasurementCorrectionsCallback::Capabilities; + auto ret = + callback->setCapabilitiesCb(Capabilities::LOS_SATS | Capabilities::EXCESS_PATH_LENGTH | + Capabilities::REFLECTING_PLANE); + if (!ret.isOk()) { + ALOGE("%s: Unable to invoke callback", __func__); + return false; + } + return true; +} + +} // namespace implementation +} // namespace V1_0 +} // namespace measurement_corrections +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gnss/2.1/default/GnssMeasurementCorrections.h b/gnss/2.1/default/GnssMeasurementCorrections.h new file mode 100644 index 0000000000..4339bed55d --- /dev/null +++ b/gnss/2.1/default/GnssMeasurementCorrections.h @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#pragma once + +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace measurement_corrections { +namespace V1_0 { +namespace implementation { + +using ::android::sp; +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; + +struct GnssMeasurementCorrections : public IMeasurementCorrections { + // Methods from V1_0::IMeasurementCorrections follow. + Return setCorrections(const MeasurementCorrections& corrections) override; + Return setCallback(const sp& callback) override; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace measurement_corrections +} // namespace gnss +} // namespace hardware +} // namespace android