From 3fcb7bf3fe8af8ac40b0685e16a5b8c1f5dd4ccc Mon Sep 17 00:00:00 2001 From: Yu-Han Yang Date: Wed, 10 Jun 2020 14:59:50 -0700 Subject: [PATCH] Add GNSS HAL v3.0 (hardware/interfaces) Bug: 158518085 Test: atest VtsHalGnssV3_0TargetTest atest VtsHalGnssV2_1TargetTest atest VtsHalGnssV2_0TargetTest atest VtsHalGnssV1_1TargetTest atest VtsHalGnssV1_0TargetTest Change-Id: Id4ac1e31207da7cfff3f1885c84748785bec19ba --- .../compatibility_matrix.current.xml | 1 + gnss/2.1/Android.bp | 5 +- gnss/2.1/default/Android.bp | 6 - gnss/2.1/default/Gnss.h | 128 ------ gnss/2.1/default/service.cpp | 6 +- gnss/2.1/vts/functional/Android.bp | 1 - gnss/2.1/vts/functional/gnss_hal_test.cpp | 278 ------------- gnss/2.1/vts/functional/gnss_hal_test.h | 217 +--------- gnss/3.0/Android.bp | 25 ++ gnss/3.0/IGnss.hal | 32 ++ gnss/3.0/IGnssPsds.hal | 48 +++ gnss/3.0/IGnssPsdsCallback.hal | 41 ++ gnss/3.0/default/Android.bp | 43 ++ gnss/3.0/default/Gnss.cpp | 32 ++ gnss/3.0/default/Gnss.h | 42 ++ gnss/3.0/default/GnssPsds.cpp | 50 +++ gnss/3.0/default/GnssPsds.h | 50 +++ gnss/3.0/default/OWNERS | 4 + .../android.hardware.gnss@3.0-service.rc | 4 + .../android.hardware.gnss@3.0-service.xml | 13 + gnss/3.0/default/service.cpp | 41 ++ gnss/3.0/vts/OWNERS | 4 + gnss/3.0/vts/functional/Android.bp | 39 ++ .../functional/VtsHalGnssV3_0TargetTest.cpp | 29 ++ gnss/3.0/vts/functional/gnss_hal_test.h | 25 ++ .../vts/functional/gnss_hal_test_cases.cpp | 49 +++ gnss/common/utils/default/Android.bp | 7 + .../default/include/v2_1}/GnssAntennaInfo.h | 19 +- .../default/include/v2_1}/GnssConfiguration.h | 17 +- .../utils/default/include/v2_1}/GnssDebug.h | 17 +- .../default/include/v2_1}/GnssMeasurement.h | 12 +- .../v2_1}/GnssMeasurementCorrections.h | 22 +- .../default/include/v2_1/GnssTemplate.h} | 287 +++++++++---- .../utils/default/v2_1}/GnssAntennaInfo.cpp | 14 +- .../utils/default/v2_1}/GnssConfiguration.cpp | 14 +- .../utils/default/v2_1}/GnssDebug.cpp | 14 +- .../utils/default/v2_1}/GnssMeasurement.cpp | 15 +- .../v2_1}/GnssMeasurementCorrections.cpp | 20 +- gnss/common/utils/vts/Android.bp | 3 + .../utils/vts/include/v2_1/GnssCallback.h | 107 +++++ .../vts/include/v2_1/gnss_hal_test_template.h | 381 ++++++++++++++++++ gnss/common/utils/vts/v2_1/GnssCallback.cpp | 95 +++++ gnss/measurement_corrections/1.1/Android.bp | 2 +- 43 files changed, 1430 insertions(+), 829 deletions(-) delete mode 100644 gnss/2.1/default/Gnss.h delete mode 100644 gnss/2.1/vts/functional/gnss_hal_test.cpp create mode 100644 gnss/3.0/Android.bp create mode 100644 gnss/3.0/IGnss.hal create mode 100644 gnss/3.0/IGnssPsds.hal create mode 100644 gnss/3.0/IGnssPsdsCallback.hal create mode 100644 gnss/3.0/default/Android.bp create mode 100644 gnss/3.0/default/Gnss.cpp create mode 100644 gnss/3.0/default/Gnss.h create mode 100644 gnss/3.0/default/GnssPsds.cpp create mode 100644 gnss/3.0/default/GnssPsds.h create mode 100644 gnss/3.0/default/OWNERS create mode 100644 gnss/3.0/default/android.hardware.gnss@3.0-service.rc create mode 100644 gnss/3.0/default/android.hardware.gnss@3.0-service.xml create mode 100644 gnss/3.0/default/service.cpp create mode 100644 gnss/3.0/vts/OWNERS create mode 100644 gnss/3.0/vts/functional/Android.bp create mode 100644 gnss/3.0/vts/functional/VtsHalGnssV3_0TargetTest.cpp create mode 100644 gnss/3.0/vts/functional/gnss_hal_test.h create mode 100644 gnss/3.0/vts/functional/gnss_hal_test_cases.cpp rename gnss/{2.1/default => common/utils/default/include/v2_1}/GnssAntennaInfo.h (80%) rename gnss/{2.1/default => common/utils/default/include/v2_1}/GnssConfiguration.h (89%) rename gnss/{2.1/default => common/utils/default/include/v2_1}/GnssDebug.h (76%) rename gnss/{2.1/default => common/utils/default/include/v2_1}/GnssMeasurement.h (92%) rename gnss/{2.1/default => common/utils/default/include/v2_1}/GnssMeasurementCorrections.h (72%) rename gnss/{2.1/default/Gnss.cpp => common/utils/default/include/v2_1/GnssTemplate.h} (50%) rename gnss/{2.1/default => common/utils/default/v2_1}/GnssAntennaInfo.cpp (91%) rename gnss/{2.1/default => common/utils/default/v2_1}/GnssConfiguration.cpp (93%) rename gnss/{2.1/default => common/utils/default/v2_1}/GnssDebug.cpp (88%) rename gnss/{2.1/default => common/utils/default/v2_1}/GnssMeasurement.cpp (94%) rename gnss/{2.1/default => common/utils/default/v2_1}/GnssMeasurementCorrections.cpp (93%) create mode 100644 gnss/common/utils/vts/include/v2_1/GnssCallback.h create mode 100644 gnss/common/utils/vts/include/v2_1/gnss_hal_test_template.h create mode 100644 gnss/common/utils/vts/v2_1/GnssCallback.cpp diff --git a/compatibility_matrices/compatibility_matrix.current.xml b/compatibility_matrices/compatibility_matrix.current.xml index 41a7d0bb76..cfee298c6d 100644 --- a/compatibility_matrices/compatibility_matrix.current.xml +++ b/compatibility_matrices/compatibility_matrix.current.xml @@ -203,6 +203,7 @@ android.hardware.gnss 2.0-1 + 3.0 IGnss default diff --git a/gnss/2.1/Android.bp b/gnss/2.1/Android.bp index 21223997b3..1a6b4140c1 100644 --- a/gnss/2.1/Android.bp +++ b/gnss/2.1/Android.bp @@ -12,13 +12,13 @@ hidl_interface { "IGnssAntennaInfo.hal", "IGnssAntennaInfoCallback.hal", "IGnssCallback.hal", + "IGnssConfiguration.hal", "IGnssMeasurement.hal", "IGnssMeasurementCallback.hal", - "IGnssConfiguration.hal", ], interfaces: [ - "android.hardware.gnss.measurement_corrections@1.1", "android.hardware.gnss.measurement_corrections@1.0", + "android.hardware.gnss.measurement_corrections@1.1", "android.hardware.gnss.visibility_control@1.0", "android.hardware.gnss@1.0", "android.hardware.gnss@1.1", @@ -26,4 +26,5 @@ hidl_interface { "android.hidl.base@1.0", ], gen_java: true, + gen_java_constants: true, } diff --git a/gnss/2.1/default/Android.bp b/gnss/2.1/default/Android.bp index c4dc8fd55d..7739f908a7 100644 --- a/gnss/2.1/default/Android.bp +++ b/gnss/2.1/default/Android.bp @@ -21,12 +21,6 @@ cc_binary { vendor: true, vintf_fragments: ["android.hardware.gnss@2.1-service.xml"], srcs: [ - "Gnss.cpp", - "GnssAntennaInfo.cpp", - "GnssDebug.cpp", - "GnssMeasurement.cpp", - "GnssMeasurementCorrections.cpp", - "GnssConfiguration.cpp", "service.cpp", ], shared_libs: [ diff --git a/gnss/2.1/default/Gnss.h b/gnss/2.1/default/Gnss.h deleted file mode 100644 index 9af0d46e39..0000000000 --- a/gnss/2.1/default/Gnss.h +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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 -#include -#include -#include -#include "GnssAntennaInfo.h" -#include "GnssConfiguration.h" -#include "NmeaFixInfo.h" - -namespace android { -namespace hardware { -namespace gnss { -namespace V2_1 { - -using GnssSvInfo = IGnssCallback::GnssSvInfo; -using ::android::hardware::gnss::common::NmeaFixInfo; - -namespace implementation { - -constexpr int INPUT_BUFFER_SIZE = 128; -constexpr char CMD_GET_LOCATION[] = "CMD_GET_LOCATION"; -constexpr char GNSS_PATH[] = "/dev/gnss0"; - -struct Gnss : public IGnss { - Gnss(); - ~Gnss(); - // Methods from V1_0::IGnss follow. - Return setCallback(const sp& callback) override; - Return start() override; - Return stop() override; - Return cleanup() override; - Return injectTime(int64_t timeMs, int64_t timeReferenceMs, - int32_t uncertaintyMs) override; - Return injectLocation(double latitudeDegrees, double longitudeDegrees, - float accuracyMeters) override; - Return deleteAidingData(V1_0::IGnss::GnssAidingData aidingDataFlags) override; - Return setPositionMode(V1_0::IGnss::GnssPositionMode mode, - V1_0::IGnss::GnssPositionRecurrence recurrence, - uint32_t minIntervalMs, uint32_t preferredAccuracyMeters, - uint32_t preferredTimeMs) override; - Return> getExtensionAGnssRil() override; - Return> getExtensionGnssGeofencing() override; - Return> getExtensionAGnss() override; - Return> getExtensionGnssNi() override; - Return> getExtensionGnssMeasurement() override; - Return> getExtensionGnssNavigationMessage() override; - Return> getExtensionXtra() override; - Return> getExtensionGnssConfiguration() override; - Return> getExtensionGnssDebug() override; - Return> getExtensionGnssBatching() override; - - // Methods from V1_1::IGnss follow. - Return setCallback_1_1(const sp& callback) override; - Return setPositionMode_1_1(V1_0::IGnss::GnssPositionMode mode, - V1_0::IGnss::GnssPositionRecurrence recurrence, - uint32_t minIntervalMs, uint32_t preferredAccuracyMeters, - uint32_t preferredTimeMs, bool lowPowerMode) override; - Return> getExtensionGnssConfiguration_1_1() override; - Return> getExtensionGnssMeasurement_1_1() override; - Return injectBestLocation(const V1_0::GnssLocation& location) override; - - // Methods from V2_0::IGnss follow. - Return setCallback_2_0(const sp& callback) override; - Return> getExtensionGnssConfiguration_2_0() override; - Return> getExtensionGnssDebug_2_0() override; - Return> getExtensionAGnss_2_0() override; - Return> getExtensionAGnssRil_2_0() override; - Return> getExtensionGnssMeasurement_2_0() override; - Return> - getExtensionMeasurementCorrections() override; - Return> getExtensionVisibilityControl() - override; - Return> getExtensionGnssBatching_2_0() override; - Return injectBestLocation_2_0(const V2_0::GnssLocation& location) override; - - // Methods from V2_1::IGnss follow. - Return setCallback_2_1(const sp& callback) override; - Return> getExtensionGnssMeasurement_2_1() override; - Return> getExtensionGnssConfiguration_2_1() override; - Return> - getExtensionMeasurementCorrections_1_1() override; - Return> getExtensionGnssAntennaInfo() override; - - private: - std::unique_ptr getLocationFromHW(); - void reportLocation(const V2_0::GnssLocation&) const; - void reportLocation(const V1_0::GnssLocation&) const; - void reportSvStatus(const hidl_vec&) const; - - static sp sGnssCallback_2_1; - static sp sGnssCallback_2_0; - static sp sGnssCallback_1_1; - static sp sGnssCallback_1_0; - std::atomic mMinIntervalMs; - sp mGnssConfiguration; - std::atomic mIsActive; - std::atomic mHardwareModeOn; - std::atomic mGnssFd; - std::thread mThread; - - mutable std::mutex mMutex; - hidl_vec filterBlacklistedSatellitesV2_1(hidl_vec gnssSvInfoList); -}; - -} // namespace implementation -} // namespace V2_1 -} // namespace gnss -} // namespace hardware -} // namespace android diff --git a/gnss/2.1/default/service.cpp b/gnss/2.1/default/service.cpp index 5e004d5697..4f282cfdaf 100644 --- a/gnss/2.1/default/service.cpp +++ b/gnss/2.1/default/service.cpp @@ -18,17 +18,17 @@ #include #include -#include "Gnss.h" +#include "v2_1/GnssTemplate.h" using ::android::OK; using ::android::sp; using ::android::hardware::configureRpcThreadpool; using ::android::hardware::joinRpcThreadpool; +using ::android::hardware::gnss::common::implementation::GnssTemplate; using ::android::hardware::gnss::V2_1::IGnss; -using ::android::hardware::gnss::V2_1::implementation::Gnss; int main(int /* argc */, char* /* argv */[]) { - sp gnss = new Gnss(); + sp gnss = new GnssTemplate(); configureRpcThreadpool(1, true /* will join */); if (gnss->registerAsService() != OK) { ALOGE("Could not register gnss 2.1 service."); diff --git a/gnss/2.1/vts/functional/Android.bp b/gnss/2.1/vts/functional/Android.bp index b3051d4b48..175bc75481 100644 --- a/gnss/2.1/vts/functional/Android.bp +++ b/gnss/2.1/vts/functional/Android.bp @@ -18,7 +18,6 @@ cc_test { name: "VtsHalGnssV2_1TargetTest", defaults: ["VtsHalTargetTestDefaults"], srcs: [ - "gnss_hal_test.cpp", "gnss_hal_test_cases.cpp", "VtsHalGnssV2_1TargetTest.cpp", ], diff --git a/gnss/2.1/vts/functional/gnss_hal_test.cpp b/gnss/2.1/vts/functional/gnss_hal_test.cpp deleted file mode 100644 index da7a62b4bd..0000000000 --- a/gnss/2.1/vts/functional/gnss_hal_test.cpp +++ /dev/null @@ -1,278 +0,0 @@ -/* - * 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 "GnssHalTest" - -#include -#include -#include "Utils.h" - -#include - -using ::android::hardware::gnss::common::Utils; - -// Implementations for the main test class for GNSS HAL -void GnssHalTest::SetUp() { - gnss_hal_ = IGnss::getService(GetParam()); - ASSERT_NE(gnss_hal_, nullptr); - - SetUpGnssCallback(); -} - -void GnssHalTest::TearDown() { - if (gnss_hal_ != nullptr) { - gnss_hal_->cleanup(); - gnss_hal_ = nullptr; - } - - // Set to nullptr to destruct the callback event queues and warn of any unprocessed events. - gnss_cb_ = nullptr; -} - -void GnssHalTest::SetUpGnssCallback() { - gnss_cb_ = new GnssCallback(); - ASSERT_NE(gnss_cb_, nullptr); - - auto result = gnss_hal_->setCallback_2_1(gnss_cb_); - if (!result.isOk()) { - ALOGE("result of failed setCallback %s", result.description().c_str()); - } - - ASSERT_TRUE(result.isOk()); - ASSERT_TRUE(result); - - /* - * All capabilities, name and systemInfo callbacks should trigger - */ - EXPECT_TRUE(gnss_cb_->capabilities_cbq_.retrieve(gnss_cb_->last_capabilities_, TIMEOUT_SEC)); - EXPECT_TRUE(gnss_cb_->info_cbq_.retrieve(gnss_cb_->last_info_, TIMEOUT_SEC)); - EXPECT_TRUE(gnss_cb_->name_cbq_.retrieve(gnss_cb_->last_name_, TIMEOUT_SEC)); - - EXPECT_EQ(gnss_cb_->capabilities_cbq_.calledCount(), 1); - EXPECT_EQ(gnss_cb_->info_cbq_.calledCount(), 1); - EXPECT_EQ(gnss_cb_->name_cbq_.calledCount(), 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 (gnss_cb_->location_cbq_.retrieve(gnss_cb_->last_location_, TIMEOUT_SEC)) { - } - gnss_cb_->location_cbq_.reset(); -} - -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; - - EXPECT_TRUE(gnss_cb_->location_cbq_.retrieve(gnss_cb_->last_location_, - kFirstGnssLocationTimeoutSeconds)); - int locationCalledCount = gnss_cb_->location_cbq_.calledCount(); - EXPECT_EQ(locationCalledCount, 1); - - if (locationCalledCount > 0) { - // don't require speed on first fix - CheckLocation(gnss_cb_->last_location_, false); - return true; - } - return false; -} - -void GnssHalTest::CheckLocation(const GnssLocation_2_0& location, bool check_speed) { - const bool check_more_accuracies = - (gnss_cb_->info_cbq_.calledCount() > 0 && gnss_cb_->last_info_.yearOfHw >= 2017); - - Utils::checkLocation(location.v1_0, 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_TRUE(gnss_cb_->location_cbq_.retrieve(gnss_cb_->last_location_, - kLocationTimeoutSubsequentSec)); - int locationCalledCount = gnss_cb_->location_cbq_.calledCount(); - EXPECT_EQ(locationCalledCount, i + 1); - // Don't cause confusion by checking details if no location yet - if (locationCalledCount > 0) { - // Should be more than 1 location by now, but if not, still don't check first fix speed - CheckLocation(gnss_cb_->last_location_, locationCalledCount > 1); - } - } -} - -GnssConstellationType GnssHalTest::startLocationAndGetNonGpsConstellation( - const int locations_to_await, const int gnss_sv_info_list_timeout) { - gnss_cb_->location_cbq_.reset(); - StartAndCheckLocations(locations_to_await); - const int location_called_count = gnss_cb_->location_cbq_.calledCount(); - - // Tolerate 1 less sv status to handle edge cases in reporting. - int sv_info_list_cbq_size = gnss_cb_->sv_info_list_cbq_.size(); - EXPECT_GE(sv_info_list_cbq_size + 1, locations_to_await); - ALOGD("Observed %d GnssSvInfo, while awaiting %d Locations (%d received)", - sv_info_list_cbq_size, locations_to_await, location_called_count); - - // Find first non-GPS constellation to blacklist - GnssConstellationType constellation_to_blacklist = GnssConstellationType::UNKNOWN; - for (int i = 0; i < sv_info_list_cbq_size; ++i) { - hidl_vec sv_info_vec; - gnss_cb_->sv_info_list_cbq_.retrieve(sv_info_vec, gnss_sv_info_list_timeout); - for (uint32_t iSv = 0; iSv < sv_info_vec.size(); iSv++) { - const auto& gnss_sv = sv_info_vec[iSv]; - if ((gnss_sv.v2_0.v1_0.svFlag & IGnssCallback_1_0::GnssSvFlags::USED_IN_FIX) && - (gnss_sv.v2_0.constellation != GnssConstellationType::UNKNOWN) && - (gnss_sv.v2_0.constellation != GnssConstellationType::GPS)) { - // found a non-GPS constellation - constellation_to_blacklist = gnss_sv.v2_0.constellation; - break; - } - } - if (constellation_to_blacklist != GnssConstellationType::UNKNOWN) { - break; - } - } - - if (constellation_to_blacklist == GnssConstellationType::UNKNOWN) { - ALOGI("No non-GPS constellations found, constellation blacklist test less effective."); - // Proceed functionally to blacklist something. - constellation_to_blacklist = GnssConstellationType::GLONASS; - } - - return constellation_to_blacklist; -} - -GnssHalTest::GnssCallback::GnssCallback() - : info_cbq_("system_info"), - name_cbq_("name"), - capabilities_cbq_("capabilities"), - location_cbq_("location"), - sv_info_list_cbq_("sv_info") {} - -Return GnssHalTest::GnssCallback::gnssSetSystemInfoCb( - const IGnssCallback_1_0::GnssSystemInfo& info) { - ALOGI("Info received, year %d", info.yearOfHw); - info_cbq_.store(info); - return Void(); -} - -Return GnssHalTest::GnssCallback::gnssSetCapabilitesCb(uint32_t capabilities) { - ALOGI("Capabilities received %d", capabilities); - capabilities_cbq_.store(capabilities); - return Void(); -} - -Return GnssHalTest::GnssCallback::gnssSetCapabilitiesCb_2_0(uint32_t capabilities) { - ALOGI("Capabilities (v2.0) received %d", capabilities); - capabilities_cbq_.store(capabilities); - return Void(); -} - -Return GnssHalTest::GnssCallback::gnssSetCapabilitiesCb_2_1(uint32_t capabilities) { - ALOGI("Capabilities (v2.1) received %d", capabilities); - capabilities_cbq_.store(capabilities); - return Void(); -} - -Return GnssHalTest::GnssCallback::gnssNameCb(const android::hardware::hidl_string& name) { - ALOGI("Name received: %s", name.c_str()); - name_cbq_.store(name); - return Void(); -} - -Return 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 GnssHalTest::GnssCallback::gnssLocationCb_2_0(const GnssLocation_2_0& location) { - ALOGI("Location (v2.0) received"); - return gnssLocationCbImpl(location); -} - -Return GnssHalTest::GnssCallback::gnssLocationCbImpl(const GnssLocation_2_0& location) { - location_cbq_.store(location); - return Void(); -} - -Return GnssHalTest::GnssCallback::gnssSvStatusCb(const IGnssCallback_1_0::GnssSvStatus&) { - ALOGI("gnssSvStatusCb"); - return Void(); -} - -Return GnssHalTest::GnssCallback::gnssSvStatusCb_2_1( - const hidl_vec& svInfoList) { - ALOGI("gnssSvStatusCb_2_1. Size = %d", (int)svInfoList.size()); - sv_info_list_cbq_.store(svInfoList); - return Void(); -} - -Return GnssHalTest::GnssMeasurementCallback::gnssMeasurementCb_2_1( - const IGnssMeasurementCallback_2_1::GnssData& data) { - ALOGD("GnssMeasurement v2.1 received. Size = %d", (int)data.measurements.size()); - measurement_cbq_.store(data); - return Void(); -} - -Return GnssHalTest::GnssMeasurementCorrectionsCallback::setCapabilitiesCb( - uint32_t capabilities) { - ALOGI("GnssMeasurementCorrectionsCallback capabilities received %d", capabilities); - capabilities_cbq_.store(capabilities); - return Void(); -} - -Return GnssHalTest::GnssAntennaInfoCallback::gnssAntennaInfoCb( - const hidl_vec& gnssAntennaInfos) { - ALOGD("GnssAntennaInfo v2.1 received. Size = %d", (int)gnssAntennaInfos.size()); - antenna_info_cbq_.store(gnssAntennaInfos); - return Void(); -} \ No newline at end of file diff --git a/gnss/2.1/vts/functional/gnss_hal_test.h b/gnss/2.1/vts/functional/gnss_hal_test.h index 9e6e162a13..c28e2480f7 100644 --- a/gnss/2.1/vts/functional/gnss_hal_test.h +++ b/gnss/2.1/vts/functional/gnss_hal_test.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 The Android Open Source Project + * 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. @@ -14,221 +14,12 @@ * limitations under the License. */ -#ifndef GNSS_HAL_TEST_H_ -#define GNSS_HAL_TEST_H_ +#pragma once #include -#include "GnssCallbackEventQueue.h" +#include "v2_1/gnss_hal_test_template.h" -#include - -using android::hardware::hidl_vec; -using android::hardware::Return; -using android::hardware::Void; - -using android::hardware::gnss::common::GnssCallbackEventQueue; -using android::hardware::gnss::measurement_corrections::V1_0::IMeasurementCorrectionsCallback; -using android::hardware::gnss::V1_0::GnssLocationFlags; -using android::hardware::gnss::V2_0::GnssConstellationType; using android::hardware::gnss::V2_1::IGnss; -using android::hardware::gnss::V2_1::IGnssAntennaInfo; -using android::hardware::gnss::V2_1::IGnssAntennaInfoCallback; - -using GnssLocation_1_0 = android::hardware::gnss::V1_0::GnssLocation; -using GnssLocation_2_0 = android::hardware::gnss::V2_0::GnssLocation; - -using IGnssCallback_1_0 = android::hardware::gnss::V1_0::IGnssCallback; -using IGnssCallback_2_0 = android::hardware::gnss::V2_0::IGnssCallback; -using IGnssCallback_2_1 = android::hardware::gnss::V2_1::IGnssCallback; - -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; -using IGnssMeasurementCallback_2_1 = android::hardware::gnss::V2_1::IGnssMeasurementCallback; - -using android::sp; - -#define TIMEOUT_SEC 2 // for basic commands/responses // The main test class for GNSS HAL. -class GnssHalTest : public testing::TestWithParam { - public: - virtual void SetUp() override; - - virtual void TearDown() override; - - /* Callback class for data & Event. */ - class GnssCallback : public IGnssCallback_2_1 { - public: - IGnssCallback_1_0::GnssSystemInfo last_info_; - android::hardware::hidl_string last_name_; - uint32_t last_capabilities_; - GnssLocation_2_0 last_location_; - - GnssCallbackEventQueue info_cbq_; - GnssCallbackEventQueue name_cbq_; - GnssCallbackEventQueue capabilities_cbq_; - GnssCallbackEventQueue location_cbq_; - GnssCallbackEventQueue> sv_info_list_cbq_; - - GnssCallback(); - virtual ~GnssCallback() = default; - - // Dummy callback handlers - Return gnssStatusCb(const IGnssCallback_1_0::GnssStatusValue /* status */) override { - return Void(); - } - Return gnssNmeaCb(int64_t /* timestamp */, - const android::hardware::hidl_string& /* nmea */) override { - return Void(); - } - Return gnssAcquireWakelockCb() override { return Void(); } - Return gnssReleaseWakelockCb() override { return Void(); } - Return gnssRequestLocationCb(bool /* independentFromGnss */) override { - return Void(); - } - Return gnssRequestTimeCb() override { return Void(); } - // Actual (test) callback handlers - Return gnssNameCb(const android::hardware::hidl_string& name) override; - Return gnssLocationCb(const GnssLocation_1_0& location) override; - Return gnssSetCapabilitesCb(uint32_t capabilities) override; - Return gnssSetSystemInfoCb(const IGnssCallback_1_0::GnssSystemInfo& info) override; - Return gnssSvStatusCb(const IGnssCallback_1_0::GnssSvStatus& svStatus) override; - - // New in v2.0 - Return gnssLocationCb_2_0(const GnssLocation_2_0& location) override; - Return gnssRequestLocationCb_2_0(bool /* independentFromGnss */, - bool /* isUserEmergency */) override { - return Void(); - } - Return gnssSetCapabilitiesCb_2_0(uint32_t capabilities) override; - Return gnssSvStatusCb_2_0(const hidl_vec&) override { - return Void(); - } - - // New in v2.1 - Return gnssSvStatusCb_2_1( - const hidl_vec& svInfoList) override; - Return gnssSetCapabilitiesCb_2_1(uint32_t capabilities) override; - - private: - Return gnssLocationCbImpl(const GnssLocation_2_0& location); - }; - - /* Callback class for GnssMeasurement. */ - class GnssMeasurementCallback : public IGnssMeasurementCallback_2_1 { - public: - GnssCallbackEventQueue measurement_cbq_; - - GnssMeasurementCallback() : measurement_cbq_("measurement"){}; - virtual ~GnssMeasurementCallback() = default; - - // Methods from V1_0::IGnssMeasurementCallback follow. - Return GnssMeasurementCb(const IGnssMeasurementCallback_1_0::GnssData&) override { - return Void(); - } - - // Methods from V1_1::IGnssMeasurementCallback follow. - Return gnssMeasurementCb(const IGnssMeasurementCallback_1_1::GnssData&) override { - return Void(); - } - - // Methods from V2_0::IGnssMeasurementCallback follow. - Return gnssMeasurementCb_2_0(const IGnssMeasurementCallback_2_0::GnssData&) override { - return Void(); - } - - // Methods from V2_1::IGnssMeasurementCallback follow. - Return gnssMeasurementCb_2_1(const IGnssMeasurementCallback_2_1::GnssData&) override; - }; - - /* Callback class for GnssMeasurementCorrections. */ - class GnssMeasurementCorrectionsCallback : public IMeasurementCorrectionsCallback { - public: - uint32_t last_capabilities_; - GnssCallbackEventQueue capabilities_cbq_; - - GnssMeasurementCorrectionsCallback() : capabilities_cbq_("capabilities"){}; - virtual ~GnssMeasurementCorrectionsCallback() = default; - - // Methods from V1_0::IMeasurementCorrectionsCallback follow. - Return setCapabilitiesCb(uint32_t capabilities) override; - }; - - /* Callback class for GnssAntennaInfo. */ - class GnssAntennaInfoCallback : public IGnssAntennaInfoCallback { - public: - GnssCallbackEventQueue> - antenna_info_cbq_; - - GnssAntennaInfoCallback() : antenna_info_cbq_("info"){}; - virtual ~GnssAntennaInfoCallback() = default; - - // Methods from V2_1::GnssAntennaInfoCallback follow. - Return gnssAntennaInfoCb( - const hidl_vec& gnssAntennaInfos); - }; - - /* - * SetUpGnssCallback: - * Set GnssCallback and verify the result. - */ - void SetUpGnssCallback(); - - /* - * StartAndCheckFirstLocation: - * Helper function to start location, and check the first one. - * - *

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_2_0& 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); - - /* - * startLocationAndGetNonGpsConstellation: - * 1. Start location - * 2. Find and return first non-GPS constellation - * - * Note that location is not stopped in this method. The client should call - * StopAndClearLocations() after the call. - */ - GnssConstellationType startLocationAndGetNonGpsConstellation( - const int locations_to_await, const int gnss_sv_info_list_timeout); - - sp gnss_hal_; // GNSS HAL to call into - sp gnss_cb_; // Primary callback interface -}; - -#endif // GNSS_HAL_TEST_H_ +class GnssHalTest : public GnssHalTestTemplate {}; diff --git a/gnss/3.0/Android.bp b/gnss/3.0/Android.bp new file mode 100644 index 0000000000..603c0db589 --- /dev/null +++ b/gnss/3.0/Android.bp @@ -0,0 +1,25 @@ +// This file is autogenerated by hidl-gen -Landroidbp. + +hidl_interface { + name: "android.hardware.gnss@3.0", + root: "android.hardware", + vndk: { + enabled: true, + }, + srcs: [ + "IGnss.hal", + "IGnssPsds.hal", + "IGnssPsdsCallback.hal", + ], + interfaces: [ + "android.hardware.gnss.measurement_corrections@1.0", + "android.hardware.gnss.measurement_corrections@1.1", + "android.hardware.gnss.visibility_control@1.0", + "android.hardware.gnss@1.0", + "android.hardware.gnss@1.1", + "android.hardware.gnss@2.0", + "android.hardware.gnss@2.1", + "android.hidl.base@1.0", + ], + gen_java: true, +} diff --git a/gnss/3.0/IGnss.hal b/gnss/3.0/IGnss.hal new file mode 100644 index 0000000000..18e5a9dee3 --- /dev/null +++ b/gnss/3.0/IGnss.hal @@ -0,0 +1,32 @@ +/* + * 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. + */ + +package android.hardware.gnss@3.0; + +import @2.1::IGnss; +import IGnssPsds; + +/** + * Represents the standard GNSS (Global Navigation Satellite System) interface. + */ +interface IGnss extends @2.1::IGnss { + /** + * This method returns the IGnssPsds interface. + * + * @return psdsIface Handle to the IGnssPsds interface. + */ + getExtensionPsds() generates (IGnssPsds psdsIface); +}; diff --git a/gnss/3.0/IGnssPsds.hal b/gnss/3.0/IGnssPsds.hal new file mode 100644 index 0000000000..5004570574 --- /dev/null +++ b/gnss/3.0/IGnssPsds.hal @@ -0,0 +1,48 @@ +/* + * 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. + */ + +package android.hardware.gnss@3.0; + +import @1.0::IGnssXtra; +import IGnssPsdsCallback; + +/** + * This interface is used by the GNSS HAL to request the framework to download Predicted Satellite + * Data Service data. + */ +interface IGnssPsds extends @1.0::IGnssXtra { + /** + * Opens the PSDS interface and provides the callback routines to the implementation of this + * interface. + * + * @param callback Handle to the IGnssPsdsCallback interface. + * + * @return success True if the operation is successful. + */ + setCallback_3_0(IGnssPsdsCallback callback) generates (bool success); + + /** + * Inject the downloaded PSDS data into the GNSS receiver. + * + * @param psdsType Type of PSDS as defined in IGnssPsdsCallback.hal + * @param psdsData GNSS PSDS data. Framework must not parse the data since the data format is + * opaque to framework. + * + * @return success True if the operation is successful. + */ + injectPsdsData_3_0(int32_t psdsType, string psdsData) generates (bool success); +}; + diff --git a/gnss/3.0/IGnssPsdsCallback.hal b/gnss/3.0/IGnssPsdsCallback.hal new file mode 100644 index 0000000000..d91385f814 --- /dev/null +++ b/gnss/3.0/IGnssPsdsCallback.hal @@ -0,0 +1,41 @@ +/* + * 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. + */ + +package android.hardware.gnss@3.0; + +import @1.0::IGnssXtraCallback; + +/** + * This interface is used by the GNSS HAL to request download data from Predicted Satellite Data + * Service (PSDS). + */ +interface IGnssPsdsCallback extends @1.0::IGnssXtraCallback { + /** + * Callback to request the client to download PSDS data. The client should + * download PSDS data and inject it by calling injectPsdsData(). + * + * psdsType represents the type of PSDS data requested. + * - Value 1 represents the Long-Term type PSDS data, which lasts for many hours to several days + * and often provides satellite orbit and clock accuracy of 2 - 20 meters. + * - Value 2 represents the Normal type PSDS data, which is similar to broadcast ephemeris in + * longevity - lasting for hours and providings satellite orbit and clock accuracy of 1 - 2 + * meters. + * - Value 3 represents the Real-Time type PSDS data, which lasts for minutes and provides brief + * satellite status information such as temporary malfunction, but does not include satellite + * orbit or clock information. + */ + downloadRequestCb_3_0(int32_t psdsType); +}; diff --git a/gnss/3.0/default/Android.bp b/gnss/3.0/default/Android.bp new file mode 100644 index 0000000000..2b33b32058 --- /dev/null +++ b/gnss/3.0/default/Android.bp @@ -0,0 +1,43 @@ +/* + * 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. + */ + +cc_binary { + name: "android.hardware.gnss@3.0-service", + init_rc: ["android.hardware.gnss@3.0-service.rc"], + relative_install_path: "hw", + vendor: true, + vintf_fragments: ["android.hardware.gnss@3.0-service.xml"], + srcs: [ + "Gnss.cpp", + "GnssPsds.cpp", + "service.cpp", + ], + shared_libs: [ + "libhidlbase", + "libutils", + "liblog", + "android.hardware.gnss@1.0", + "android.hardware.gnss@1.1", + "android.hardware.gnss@2.0", + "android.hardware.gnss@2.1", + "android.hardware.gnss@3.0", + "android.hardware.gnss.measurement_corrections@1.1", + "android.hardware.gnss.measurement_corrections@1.0", + ], + static_libs: [ + "android.hardware.gnss@common-default-lib", + ], +} diff --git a/gnss/3.0/default/Gnss.cpp b/gnss/3.0/default/Gnss.cpp new file mode 100644 index 0000000000..5f2ca4f522 --- /dev/null +++ b/gnss/3.0/default/Gnss.cpp @@ -0,0 +1,32 @@ +/* + * 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. + */ + +#define LOG_TAG "Gnss" + +#include "Gnss.h" +#include +#include "GnssPsds.h" +#include "Utils.h" + +namespace android::hardware::gnss::V3_0::implementation { + +// Methods from V3_0::IGnss follow. +Return> Gnss::getExtensionPsds() { + ALOGD("Gnss::getExtensionPsds"); + return new GnssPsds(); +} + +} // namespace android::hardware::gnss::V3_0::implementation diff --git a/gnss/3.0/default/Gnss.h b/gnss/3.0/default/Gnss.h new file mode 100644 index 0000000000..7ae562ade3 --- /dev/null +++ b/gnss/3.0/default/Gnss.h @@ -0,0 +1,42 @@ +/* + * 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. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include "v2_1/GnssTemplate.h" + +namespace android::hardware::gnss::V3_0::implementation { + +using ::android::sp; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::gnss::common::implementation::GnssTemplate; + +struct Gnss : public GnssTemplate { + Gnss(){}; + ~Gnss(){}; + + // Methods from V3_0::IGnss follow. + Return> getExtensionPsds() override; +}; + +} // namespace android::hardware::gnss::V3_0::implementation diff --git a/gnss/3.0/default/GnssPsds.cpp b/gnss/3.0/default/GnssPsds.cpp new file mode 100644 index 0000000000..44e096ebd3 --- /dev/null +++ b/gnss/3.0/default/GnssPsds.cpp @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#define LOG_TAG "GnssPsds" + +#include "GnssPsds.h" + +#include + +namespace android::hardware::gnss::V3_0::implementation { + +sp GnssPsds::sCallback_3_0 = nullptr; + +// Methods from V1_0::IGnssXtra follow. +Return GnssPsds::setCallback(const sp&) { + // TODO implement + return bool{}; +} + +Return GnssPsds::injectXtraData(const hidl_string&) { + // TODO implement + return bool{}; +} + +// Methods from V3_0::IGnssPsds follow. +Return GnssPsds::setCallback_3_0(const sp& callback) { + ALOGD("setCallback_3_0"); + std::unique_lock lock(mMutex); + sCallback_3_0 = callback; + return true; +} + +Return GnssPsds::injectPsdsData_3_0(int32_t psdsType, const hidl_string& psdsData) { + ALOGD("injectPsdsData_3_0. psdsType: %d, psdsData: %s", psdsType, psdsData.c_str()); + return true; +} +} // namespace android::hardware::gnss::V3_0::implementation diff --git a/gnss/3.0/default/GnssPsds.h b/gnss/3.0/default/GnssPsds.h new file mode 100644 index 0000000000..4053bf17c8 --- /dev/null +++ b/gnss/3.0/default/GnssPsds.h @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#pragma once + +#include +#include +#include + +namespace android::hardware::gnss::V3_0::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 GnssPsds : public V3_0::IGnssPsds { + // Methods from V1_0::IGnssXtra follow. + Return setCallback(const sp& callback) override; + Return injectXtraData(const hidl_string& xtraData) override; + + // Methods from V3_0::IGnssPsds follow. + Return setCallback_3_0(const sp& callback) override; + Return injectPsdsData_3_0(int32_t psdsType, const hidl_string& psdsData) override; + + private: + // Guarded by mMutex + static sp sCallback_3_0; + + // Synchronization lock for sCallback_3_0 + mutable std::mutex mMutex; +}; + +} // namespace android::hardware::gnss::V3_0::implementation diff --git a/gnss/3.0/default/OWNERS b/gnss/3.0/default/OWNERS new file mode 100644 index 0000000000..b7b4a2e902 --- /dev/null +++ b/gnss/3.0/default/OWNERS @@ -0,0 +1,4 @@ +gomo@google.com +smalkos@google.com +wyattriley@google.com +yuhany@google.com diff --git a/gnss/3.0/default/android.hardware.gnss@3.0-service.rc b/gnss/3.0/default/android.hardware.gnss@3.0-service.rc new file mode 100644 index 0000000000..c2bfb91e22 --- /dev/null +++ b/gnss/3.0/default/android.hardware.gnss@3.0-service.rc @@ -0,0 +1,4 @@ +service vendor.gnss-3-0 /vendor/bin/hw/android.hardware.gnss@3.0-service + class hal + user system + group system diff --git a/gnss/3.0/default/android.hardware.gnss@3.0-service.xml b/gnss/3.0/default/android.hardware.gnss@3.0-service.xml new file mode 100644 index 0000000000..6709e0c3b5 --- /dev/null +++ b/gnss/3.0/default/android.hardware.gnss@3.0-service.xml @@ -0,0 +1,13 @@ + + + android.hardware.gnss + hwbinder + 3.0 + 2.1 + 1.1 + + IGnss + default + + + diff --git a/gnss/3.0/default/service.cpp b/gnss/3.0/default/service.cpp new file mode 100644 index 0000000000..87b458070b --- /dev/null +++ b/gnss/3.0/default/service.cpp @@ -0,0 +1,41 @@ +/* + * 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. + */ + +#define LOG_TAG "android.hardware.gnss@3.0-service" + +#include +#include +#include "Gnss.h" + +using ::android::OK; +using ::android::sp; +using ::android::hardware::configureRpcThreadpool; +using ::android::hardware::joinRpcThreadpool; +using ::android::hardware::gnss::V3_0::IGnss; +using ::android::hardware::gnss::V3_0::implementation::Gnss; + +int main(int /* argc */, char* /* argv */[]) { + sp gnss = new Gnss(); + configureRpcThreadpool(1, true /* will join */); + if (gnss->registerAsService() != OK) { + ALOGE("Could not register gnss 3.0 service."); + return 1; + } + joinRpcThreadpool(); + + ALOGE("Service exited!"); + return 1; +} \ No newline at end of file diff --git a/gnss/3.0/vts/OWNERS b/gnss/3.0/vts/OWNERS new file mode 100644 index 0000000000..b7b4a2e902 --- /dev/null +++ b/gnss/3.0/vts/OWNERS @@ -0,0 +1,4 @@ +gomo@google.com +smalkos@google.com +wyattriley@google.com +yuhany@google.com diff --git a/gnss/3.0/vts/functional/Android.bp b/gnss/3.0/vts/functional/Android.bp new file mode 100644 index 0000000000..584424ccc4 --- /dev/null +++ b/gnss/3.0/vts/functional/Android.bp @@ -0,0 +1,39 @@ +// +// 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. +// + +cc_test { + name: "VtsHalGnssV3_0TargetTest", + defaults: ["VtsHalTargetTestDefaults"], + srcs: [ + "gnss_hal_test_cases.cpp", + "VtsHalGnssV3_0TargetTest.cpp", + ], + static_libs: [ + "android.hardware.gnss.measurement_corrections@1.0", + "android.hardware.gnss.measurement_corrections@1.1", + "android.hardware.gnss.visibility_control@1.0", + "android.hardware.gnss@1.0", + "android.hardware.gnss@1.1", + "android.hardware.gnss@2.0", + "android.hardware.gnss@2.1", + "android.hardware.gnss@3.0", + "android.hardware.gnss@common-vts-lib", + ], + test_suites: [ + "general-tests", + "vts", + ], +} diff --git a/gnss/3.0/vts/functional/VtsHalGnssV3_0TargetTest.cpp b/gnss/3.0/vts/functional/VtsHalGnssV3_0TargetTest.cpp new file mode 100644 index 0000000000..9eca7b0620 --- /dev/null +++ b/gnss/3.0/vts/functional/VtsHalGnssV3_0TargetTest.cpp @@ -0,0 +1,29 @@ +/* + * 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. + */ +#define LOG_TAG "VtsHalGnssV3_0TargetTest" + +#include +#include +#include + +#include "gnss_hal_test.h" + +using android::hardware::gnss::V3_0::IGnss; + +INSTANTIATE_TEST_SUITE_P( + PerInstance, GnssHalTest, + testing::ValuesIn(android::hardware::getAllHalInstanceNames(IGnss::descriptor)), + android::hardware::PrintInstanceNameToString); \ No newline at end of file diff --git a/gnss/3.0/vts/functional/gnss_hal_test.h b/gnss/3.0/vts/functional/gnss_hal_test.h new file mode 100644 index 0000000000..387214eba2 --- /dev/null +++ b/gnss/3.0/vts/functional/gnss_hal_test.h @@ -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. + */ + +#pragma once + +#include +#include "v2_1/gnss_hal_test_template.h" + +using android::hardware::gnss::V3_0::IGnss; + +// The main test class for GNSS HAL. +class GnssHalTest : public GnssHalTestTemplate {}; \ No newline at end of file diff --git a/gnss/3.0/vts/functional/gnss_hal_test_cases.cpp b/gnss/3.0/vts/functional/gnss_hal_test_cases.cpp new file mode 100644 index 0000000000..cc5341c181 --- /dev/null +++ b/gnss/3.0/vts/functional/gnss_hal_test_cases.cpp @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#define LOG_TAG "GnssHalTestCases" + +#include +#include +#include "Utils.h" + +#include + +using android::hardware::hidl_string; +using android::hardware::hidl_vec; + +using android::hardware::gnss::common::Utils; + +using android::hardware::gnss::V3_0::IGnssPsds; + +/* + * SetupTeardownCreateCleanup: + * Requests the gnss HAL then calls cleanup + * + * Empty test fixture to verify basic Setup & Teardown + */ +TEST_P(GnssHalTest, SetupTeardownCreateCleanup) {} + +/* + * TestPsdsExtension: + * Gets the PsdsExtension and verifies that it returns a non-null extension. + */ +TEST_P(GnssHalTest, TestPsdsExtension) { + auto psds = gnss_hal_->getExtensionPsds(); + ASSERT_TRUE(psds.isOk()); + sp iPsds = psds; + ASSERT_TRUE(iPsds != nullptr); +} diff --git a/gnss/common/utils/default/Android.bp b/gnss/common/utils/default/Android.bp index 2712e7776c..8d9d4d46aa 100644 --- a/gnss/common/utils/default/Android.bp +++ b/gnss/common/utils/default/Android.bp @@ -24,6 +24,11 @@ cc_library_static { "-Werror", ], srcs: [ + "v2_1/GnssAntennaInfo.cpp", + "v2_1/GnssConfiguration.cpp", + "v2_1/GnssDebug.cpp", + "v2_1/GnssMeasurement.cpp", + "v2_1/GnssMeasurementCorrections.cpp", "Utils.cpp", "NmeaFixInfo.cpp", ], @@ -34,5 +39,7 @@ cc_library_static { "android.hardware.gnss@1.0", "android.hardware.gnss@2.0", "android.hardware.gnss@2.1", + "android.hardware.gnss.measurement_corrections@1.1", + "android.hardware.gnss.measurement_corrections@1.0", ], } diff --git a/gnss/2.1/default/GnssAntennaInfo.h b/gnss/common/utils/default/include/v2_1/GnssAntennaInfo.h similarity index 80% rename from gnss/2.1/default/GnssAntennaInfo.h rename to gnss/common/utils/default/include/v2_1/GnssAntennaInfo.h index f2ce9a8955..e74ff54839 100644 --- a/gnss/2.1/default/GnssAntennaInfo.h +++ b/gnss/common/utils/default/include/v2_1/GnssAntennaInfo.h @@ -14,23 +14,20 @@ * limitations under the License. */ -#ifndef ANDROID_HARDWARE_GNSS_V2_1_GNSSANTENNAINFO_H -#define ANDROID_HARDWARE_GNSS_V2_1_GNSSANTENNAINFO_H +#pragma once #include #include #include -namespace android { -namespace hardware { -namespace gnss { -namespace V2_1 { -namespace implementation { +namespace android::hardware::gnss::V2_1::implementation { using ::android::sp; using ::android::hardware::Return; using ::android::hardware::Void; +using IGnssAntennaInfo = ::android::hardware::gnss::V2_1::IGnssAntennaInfo; +using IGnssAntennaInfoCallback = ::android::hardware::gnss::V2_1::IGnssAntennaInfoCallback; struct GnssAntennaInfo : public IGnssAntennaInfo { GnssAntennaInfo(); @@ -58,10 +55,4 @@ struct GnssAntennaInfo : public IGnssAntennaInfo { mutable std::mutex mMutex; }; -} // namespace implementation -} // namespace V2_1 -} // namespace gnss -} // namespace hardware -} // namespace android - -#endif // ANDROID_HARDWARE_GNSS_V2_1_GNSSCONFIGURATION_H \ No newline at end of file +} // namespace android::hardware::gnss::V2_1::implementation diff --git a/gnss/2.1/default/GnssConfiguration.h b/gnss/common/utils/default/include/v2_1/GnssConfiguration.h similarity index 89% rename from gnss/2.1/default/GnssConfiguration.h rename to gnss/common/utils/default/include/v2_1/GnssConfiguration.h index 662d61d038..8463a5caa2 100644 --- a/gnss/2.1/default/GnssConfiguration.h +++ b/gnss/common/utils/default/include/v2_1/GnssConfiguration.h @@ -14,8 +14,7 @@ * limitations under the License. */ -#ifndef ANDROID_HARDWARE_GNSS_V2_1_GNSSCONFIGURATION_H -#define ANDROID_HARDWARE_GNSS_V2_1_GNSSCONFIGURATION_H +#pragma once #include #include @@ -24,11 +23,7 @@ #include #include -namespace android { -namespace hardware { -namespace gnss { -namespace V2_1 { -namespace implementation { +namespace android::hardware::gnss::V2_1::implementation { using ::android::sp; using ::android::hardware::hidl_array; @@ -92,10 +87,4 @@ struct GnssConfiguration : public IGnssConfiguration { BlacklistedConstellationSetV2_1 mBlacklistedConstellationSet; }; -} // namespace implementation -} // namespace V2_1 -} // namespace gnss -} // namespace hardware -} // namespace android - -#endif // ANDROID_HARDWARE_GNSS_V2_1_GNSSCONFIGURATION_H \ No newline at end of file +} // namespace android::hardware::gnss::V2_1::implementation diff --git a/gnss/2.1/default/GnssDebug.h b/gnss/common/utils/default/include/v2_1/GnssDebug.h similarity index 76% rename from gnss/2.1/default/GnssDebug.h rename to gnss/common/utils/default/include/v2_1/GnssDebug.h index 969d337524..8580989c6a 100644 --- a/gnss/2.1/default/GnssDebug.h +++ b/gnss/common/utils/default/include/v2_1/GnssDebug.h @@ -14,17 +14,12 @@ * limitations under the License. */ -#ifndef android_hardware_gnss_V1_1_GnssDebug_H_ -#define android_hardware_gnss_V1_1_GnssDebug_H_ +#pragma once #include #include -namespace android { -namespace hardware { -namespace gnss { -namespace V1_1 { -namespace implementation { +namespace android::hardware::gnss::V1_1::implementation { using ::android::sp; using ::android::hardware::hidl_string; @@ -42,10 +37,4 @@ struct GnssDebug : public IGnssDebug { Return getDebugData(V1_0::IGnssDebug::getDebugData_cb _hidl_cb) override; }; -} // namespace implementation -} // namespace V1_1 -} // namespace gnss -} // namespace hardware -} // namespace android - -#endif // android_hardware_gnss_V1_1_GnssDebug_H_ +} // namespace android::hardware::gnss::V1_1::implementation diff --git a/gnss/2.1/default/GnssMeasurement.h b/gnss/common/utils/default/include/v2_1/GnssMeasurement.h similarity index 92% rename from gnss/2.1/default/GnssMeasurement.h rename to gnss/common/utils/default/include/v2_1/GnssMeasurement.h index d44641978f..1d1fc9d712 100644 --- a/gnss/2.1/default/GnssMeasurement.h +++ b/gnss/common/utils/default/include/v2_1/GnssMeasurement.h @@ -23,11 +23,7 @@ #include #include -namespace android { -namespace hardware { -namespace gnss { -namespace V2_1 { -namespace implementation { +namespace android::hardware::gnss::V2_1::implementation { using GnssDataV2_1 = V2_1::IGnssMeasurementCallback::GnssData; using GnssDataV2_0 = V2_0::IGnssMeasurementCallback::GnssData; @@ -80,8 +76,4 @@ struct GnssMeasurement : public IGnssMeasurement { mutable std::mutex mMutex; }; -} // namespace implementation -} // namespace V2_1 -} // namespace gnss -} // namespace hardware -} // namespace android +} // namespace android::hardware::gnss::V2_1::implementation diff --git a/gnss/2.1/default/GnssMeasurementCorrections.h b/gnss/common/utils/default/include/v2_1/GnssMeasurementCorrections.h similarity index 72% rename from gnss/2.1/default/GnssMeasurementCorrections.h rename to gnss/common/utils/default/include/v2_1/GnssMeasurementCorrections.h index 036e855586..eaa7659c6b 100644 --- a/gnss/2.1/default/GnssMeasurementCorrections.h +++ b/gnss/common/utils/default/include/v2_1/GnssMeasurementCorrections.h @@ -20,22 +20,15 @@ #include #include -namespace android { -namespace hardware { -namespace gnss { -namespace measurement_corrections { -namespace V1_1 { -namespace implementation { +namespace android::hardware::gnss::measurement_corrections::V1_1::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 { + GnssMeasurementCorrections(); + ~GnssMeasurementCorrections(); + // Methods from V1_0::IMeasurementCorrections follow. Return setCorrections(const V1_0::MeasurementCorrections& corrections) override; Return setCallback(const sp& callback) override; @@ -44,9 +37,4 @@ struct GnssMeasurementCorrections : public IMeasurementCorrections { Return setCorrections_1_1(const V1_1::MeasurementCorrections& corrections) override; }; -} // namespace implementation -} // namespace V1_1 -} // namespace measurement_corrections -} // namespace gnss -} // namespace hardware -} // namespace android +} // namespace android::hardware::gnss::measurement_corrections::V1_1::implementation diff --git a/gnss/2.1/default/Gnss.cpp b/gnss/common/utils/default/include/v2_1/GnssTemplate.h similarity index 50% rename from gnss/2.1/default/Gnss.cpp rename to gnss/common/utils/default/include/v2_1/GnssTemplate.h index 16f2bf3cd0..d16a67bffe 100644 --- a/gnss/2.1/default/Gnss.cpp +++ b/gnss/common/utils/default/include/v2_1/GnssTemplate.h @@ -14,44 +14,149 @@ * limitations under the License. */ -#define LOG_TAG "Gnss" +#pragma once -#include "Gnss.h" +#include +#include +#include +#include #include #include +#include +#include #include +#include + #include "GnssAntennaInfo.h" +#include "GnssConfiguration.h" #include "GnssDebug.h" #include "GnssMeasurement.h" #include "GnssMeasurementCorrections.h" +#include "NmeaFixInfo.h" #include "Utils.h" -using ::android::hardware::gnss::common::Utils; -using ::android::hardware::gnss::measurement_corrections::V1_1::implementation:: - GnssMeasurementCorrections; +namespace android::hardware::gnss::common::implementation { -namespace android { -namespace hardware { -namespace gnss { -namespace V2_1 { -namespace implementation { +using GnssSvInfo = V2_1::IGnssCallback::GnssSvInfo; -sp Gnss::sGnssCallback_2_1 = nullptr; -sp Gnss::sGnssCallback_2_0 = nullptr; -sp Gnss::sGnssCallback_1_1 = nullptr; -sp Gnss::sGnssCallback_1_0 = nullptr; +using common::NmeaFixInfo; +using common::Utils; +using measurement_corrections::V1_1::implementation::GnssMeasurementCorrections; -Gnss::Gnss() +using V2_1::implementation::GnssAntennaInfo; +using V2_1::implementation::GnssConfiguration; +using V2_1::implementation::GnssMeasurement; + +constexpr int INPUT_BUFFER_SIZE = 128; +constexpr char CMD_GET_LOCATION[] = "CMD_GET_LOCATION"; +constexpr char GNSS_PATH[] = "/dev/gnss0"; + +template +struct GnssTemplate : public T_IGnss { + GnssTemplate(); + ~GnssTemplate(); + // Methods from V1_0::IGnss follow. + Return setCallback(const sp& callback) override; + Return start() override; + Return stop() override; + Return cleanup() override; + Return injectTime(int64_t timeMs, int64_t timeReferenceMs, + int32_t uncertaintyMs) override; + Return injectLocation(double latitudeDegrees, double longitudeDegrees, + float accuracyMeters) override; + Return deleteAidingData(V1_0::IGnss::GnssAidingData aidingDataFlags) override; + Return setPositionMode(V1_0::IGnss::GnssPositionMode mode, + V1_0::IGnss::GnssPositionRecurrence recurrence, + uint32_t minIntervalMs, uint32_t preferredAccuracyMeters, + uint32_t preferredTimeMs) override; + Return> getExtensionAGnssRil() override; + Return> getExtensionGnssGeofencing() override; + Return> getExtensionAGnss() override; + Return> getExtensionGnssNi() override; + Return> getExtensionGnssMeasurement() override; + Return> getExtensionGnssNavigationMessage() override; + Return> getExtensionXtra() override; + Return> getExtensionGnssConfiguration() override; + Return> getExtensionGnssDebug() override; + Return> getExtensionGnssBatching() override; + + // Methods from V1_1::IGnss follow. + Return setCallback_1_1(const sp& callback) override; + Return setPositionMode_1_1(V1_0::IGnss::GnssPositionMode mode, + V1_0::IGnss::GnssPositionRecurrence recurrence, + uint32_t minIntervalMs, uint32_t preferredAccuracyMeters, + uint32_t preferredTimeMs, bool lowPowerMode) override; + Return> getExtensionGnssConfiguration_1_1() override; + Return> getExtensionGnssMeasurement_1_1() override; + Return injectBestLocation(const V1_0::GnssLocation& location) override; + + // Methods from V2_0::IGnss follow. + Return setCallback_2_0(const sp& callback) override; + Return> getExtensionGnssConfiguration_2_0() override; + Return> getExtensionGnssDebug_2_0() override; + Return> getExtensionAGnss_2_0() override; + Return> getExtensionAGnssRil_2_0() override; + Return> getExtensionGnssMeasurement_2_0() override; + Return> + getExtensionMeasurementCorrections() override; + Return> getExtensionVisibilityControl() + override; + Return> getExtensionGnssBatching_2_0() override; + Return injectBestLocation_2_0(const V2_0::GnssLocation& location) override; + + // Methods from V2_1::IGnss follow. + Return setCallback_2_1(const sp& callback) override; + Return> getExtensionGnssMeasurement_2_1() override; + Return> getExtensionGnssConfiguration_2_1() override; + Return> + getExtensionMeasurementCorrections_1_1() override; + Return> getExtensionGnssAntennaInfo() override; + + private: + std::unique_ptr getLocationFromHW(); + void reportLocation(const V2_0::GnssLocation&) const; + void reportLocation(const V1_0::GnssLocation&) const; + void reportSvStatus(const hidl_vec&) const; + + static sp sGnssCallback_2_1; + static sp sGnssCallback_2_0; + static sp sGnssCallback_1_1; + static sp sGnssCallback_1_0; + + std::atomic mMinIntervalMs; + sp mGnssConfiguration; + std::atomic mIsActive; + std::atomic mHardwareModeOn; + std::atomic mGnssFd; + std::thread mThread; + + mutable std::mutex mMutex; + hidl_vec filterBlacklistedSatellitesV2_1(hidl_vec gnssSvInfoList); +}; + +template +sp GnssTemplate::sGnssCallback_2_1 = nullptr; +template +sp GnssTemplate::sGnssCallback_2_0 = nullptr; +template +sp GnssTemplate::sGnssCallback_1_1 = nullptr; +template +sp GnssTemplate::sGnssCallback_1_0 = nullptr; + +template +GnssTemplate::GnssTemplate() : mMinIntervalMs(1000), mGnssConfiguration{new GnssConfiguration()}, mHardwareModeOn(false), mGnssFd(-1) {} -Gnss::~Gnss() { +template +GnssTemplate::~GnssTemplate() { stop(); } -std::unique_ptr Gnss::getLocationFromHW() { +template +std::unique_ptr GnssTemplate::getLocationFromHW() { char inputBuffer[INPUT_BUFFER_SIZE]; mHardwareModeOn = false; if (mGnssFd == -1) { @@ -89,7 +194,8 @@ std::unique_ptr Gnss::getLocationFromHW() { return NmeaFixInfo::getLocationFromInputStr(inputStr); } -Return Gnss::start() { +template +Return GnssTemplate::start() { if (mIsActive) { ALOGW("Gnss has started. Restarting..."); stop(); @@ -124,7 +230,9 @@ Return Gnss::start() { return true; } -hidl_vec Gnss::filterBlacklistedSatellitesV2_1(hidl_vec gnssSvInfoList) { +template +hidl_vec GnssTemplate::filterBlacklistedSatellitesV2_1( + hidl_vec gnssSvInfoList) { for (uint32_t i = 0; i < gnssSvInfoList.size(); i++) { if (mGnssConfiguration->isBlacklistedV2_1(gnssSvInfoList[i])) { gnssSvInfoList[i].v2_0.v1_0.svFlag &= @@ -134,7 +242,8 @@ hidl_vec Gnss::filterBlacklistedSatellitesV2_1(hidl_vec return gnssSvInfoList; } -Return Gnss::stop() { +template +Return GnssTemplate::stop() { ALOGD("stop"); mIsActive = false; if (mThread.joinable()) { @@ -148,7 +257,8 @@ Return Gnss::stop() { } // Methods from V1_0::IGnss follow. -Return Gnss::setCallback(const sp& callback) { +template +Return GnssTemplate::setCallback(const sp& callback) { if (callback == nullptr) { ALOGE("%s: Null callback ignored", __func__); return false; @@ -163,7 +273,7 @@ Return Gnss::setCallback(const sp& callback) { ALOGE("%s: Unable to invoke callback", __func__); } - IGnssCallback::GnssSystemInfo gnssInfo = {.yearOfHw = 2018}; + V2_1::IGnssCallback::GnssSystemInfo gnssInfo = {.yearOfHw = 2018}; ret = sGnssCallback_1_0->gnssSetSystemInfoCb(gnssInfo); if (!ret.isOk()) { @@ -173,83 +283,100 @@ Return Gnss::setCallback(const sp& callback) { return true; } -Return Gnss::cleanup() { +template +Return GnssTemplate::cleanup() { sGnssCallback_2_1 = nullptr; sGnssCallback_2_0 = nullptr; return Void(); } -Return Gnss::injectTime(int64_t, int64_t, int32_t) { +template +Return GnssTemplate::injectTime(int64_t, int64_t, int32_t) { return true; } -Return Gnss::injectLocation(double, double, float) { +template +Return GnssTemplate::injectLocation(double, double, float) { return true; } -Return Gnss::deleteAidingData(V1_0::IGnss::GnssAidingData) { +template +Return GnssTemplate::deleteAidingData(V1_0::IGnss::GnssAidingData) { // TODO implement return Void(); } -Return Gnss::setPositionMode(V1_0::IGnss::GnssPositionMode, - V1_0::IGnss::GnssPositionRecurrence, uint32_t minIntervalMs, - uint32_t, uint32_t) { +template +Return GnssTemplate::setPositionMode(V1_0::IGnss::GnssPositionMode, + V1_0::IGnss::GnssPositionRecurrence, + uint32_t minIntervalMs, uint32_t, uint32_t) { mMinIntervalMs = minIntervalMs; return true; } -Return> Gnss::getExtensionAGnssRil() { +template +Return> GnssTemplate::getExtensionAGnssRil() { // TODO implement return ::android::sp{}; } -Return> Gnss::getExtensionGnssGeofencing() { +template +Return> GnssTemplate::getExtensionGnssGeofencing() { // TODO implement return ::android::sp{}; } -Return> Gnss::getExtensionAGnss() { +template +Return> GnssTemplate::getExtensionAGnss() { // TODO implement return ::android::sp{}; } -Return> Gnss::getExtensionGnssNi() { +template +Return> GnssTemplate::getExtensionGnssNi() { // TODO implement return ::android::sp{}; } -Return> Gnss::getExtensionGnssMeasurement() { +template +Return> GnssTemplate::getExtensionGnssMeasurement() { ALOGD("Gnss::getExtensionGnssMeasurement"); return new GnssMeasurement(); } -Return> Gnss::getExtensionGnssNavigationMessage() { +template +Return> +GnssTemplate::getExtensionGnssNavigationMessage() { // TODO implement return ::android::sp{}; } -Return> Gnss::getExtensionXtra() { +template +Return> GnssTemplate::getExtensionXtra() { // TODO implement return ::android::sp{}; } -Return> Gnss::getExtensionGnssConfiguration() { +template +Return> GnssTemplate::getExtensionGnssConfiguration() { // TODO implement return ::android::sp{}; } -Return> Gnss::getExtensionGnssDebug() { +template +Return> GnssTemplate::getExtensionGnssDebug() { return new V1_1::implementation::GnssDebug(); } -Return> Gnss::getExtensionGnssBatching() { +template +Return> GnssTemplate::getExtensionGnssBatching() { // TODO implement return ::android::sp{}; } // Methods from V1_1::IGnss follow. -Return Gnss::setCallback_1_1(const sp& callback) { +template +Return GnssTemplate::setCallback_1_1(const sp& callback) { if (callback == nullptr) { ALOGE("%s: Null callback ignored", __func__); return false; @@ -263,7 +390,7 @@ Return Gnss::setCallback_1_1(const sp& callback) { ALOGE("%s: Unable to invoke callback", __func__); } - IGnssCallback::GnssSystemInfo gnssInfo = {.yearOfHw = 2018}; + V2_1::IGnssCallback::GnssSystemInfo gnssInfo = {.yearOfHw = 2018}; ret = sGnssCallback_1_1->gnssSetSystemInfoCb(gnssInfo); if (!ret.isOk()) { @@ -279,29 +406,35 @@ Return Gnss::setCallback_1_1(const sp& callback) { return true; } -Return Gnss::setPositionMode_1_1(V1_0::IGnss::GnssPositionMode, - V1_0::IGnss::GnssPositionRecurrence, uint32_t minIntervalMs, - uint32_t, uint32_t, bool) { +template +Return GnssTemplate::setPositionMode_1_1(V1_0::IGnss::GnssPositionMode, + V1_0::IGnss::GnssPositionRecurrence, + uint32_t minIntervalMs, uint32_t, uint32_t, + bool) { mMinIntervalMs = minIntervalMs; return true; } -Return> Gnss::getExtensionGnssConfiguration_1_1() { +template +Return> GnssTemplate::getExtensionGnssConfiguration_1_1() { // TODO implement return ::android::sp{}; } -Return> Gnss::getExtensionGnssMeasurement_1_1() { +template +Return> GnssTemplate::getExtensionGnssMeasurement_1_1() { // TODO implement return ::android::sp{}; } -Return Gnss::injectBestLocation(const V1_0::GnssLocation&) { +template +Return GnssTemplate::injectBestLocation(const V1_0::GnssLocation&) { return true; } // Methods from V2_0::IGnss follow. -Return Gnss::setCallback_2_0(const sp& callback) { +template +Return GnssTemplate::setCallback_2_0(const sp& callback) { ALOGD("Gnss::setCallback_2_0"); if (callback == nullptr) { ALOGE("%s: Null callback ignored", __func__); @@ -334,54 +467,65 @@ Return Gnss::setCallback_2_0(const sp& callback) { return true; } -Return> Gnss::getExtensionGnssConfiguration_2_0() { +template +Return> GnssTemplate::getExtensionGnssConfiguration_2_0() { ALOGD("Gnss::getExtensionGnssConfiguration_2_0"); return mGnssConfiguration; } -Return> Gnss::getExtensionGnssDebug_2_0() { +template +Return> GnssTemplate::getExtensionGnssDebug_2_0() { // TODO implement return ::android::sp{}; } -Return> Gnss::getExtensionAGnss_2_0() { +template +Return> GnssTemplate::getExtensionAGnss_2_0() { // TODO implement return ::android::sp{}; } -Return> Gnss::getExtensionAGnssRil_2_0() { +template +Return> GnssTemplate::getExtensionAGnssRil_2_0() { // TODO implement return ::android::sp{}; } -Return> Gnss::getExtensionGnssMeasurement_2_0() { +template +Return> GnssTemplate::getExtensionGnssMeasurement_2_0() { ALOGD("Gnss::getExtensionGnssMeasurement_2_0"); return new GnssMeasurement(); } +template Return> -Gnss::getExtensionMeasurementCorrections() { +GnssTemplate::getExtensionMeasurementCorrections() { ALOGD("Gnss::getExtensionMeasurementCorrections()"); return new GnssMeasurementCorrections(); } -Return> Gnss::getExtensionVisibilityControl() { +template +Return> +GnssTemplate::getExtensionVisibilityControl() { // TODO implement return ::android::sp{}; } -Return> Gnss::getExtensionGnssBatching_2_0() { +template +Return> GnssTemplate::getExtensionGnssBatching_2_0() { // TODO implement return ::android::sp{}; } -Return Gnss::injectBestLocation_2_0(const V2_0::GnssLocation&) { +template +Return GnssTemplate::injectBestLocation_2_0(const V2_0::GnssLocation&) { // TODO(b/124012850): Implement function. return bool{}; } // Methods from V2_1::IGnss follow. -Return Gnss::setCallback_2_1(const sp& callback) { +template +Return GnssTemplate::setCallback_2_1(const sp& callback) { ALOGD("Gnss::setCallback_2_1"); if (callback == nullptr) { ALOGE("%s: Null callback ignored", __func__); @@ -415,28 +559,33 @@ Return Gnss::setCallback_2_1(const sp& callback) { return true; } -Return> Gnss::getExtensionGnssMeasurement_2_1() { +template +Return> GnssTemplate::getExtensionGnssMeasurement_2_1() { ALOGD("Gnss::getExtensionGnssMeasurement_2_1"); return new GnssMeasurement(); } -Return> Gnss::getExtensionGnssConfiguration_2_1() { +template +Return> GnssTemplate::getExtensionGnssConfiguration_2_1() { ALOGD("Gnss::getExtensionGnssConfiguration_2_1"); return mGnssConfiguration; } +template Return> -Gnss::getExtensionMeasurementCorrections_1_1() { +GnssTemplate::getExtensionMeasurementCorrections_1_1() { ALOGD("Gnss::getExtensionMeasurementCorrections_1_1()"); return new GnssMeasurementCorrections(); } -Return> Gnss::getExtensionGnssAntennaInfo() { +template +Return> GnssTemplate::getExtensionGnssAntennaInfo() { ALOGD("Gnss::getExtensionGnssAntennaInfo"); return new GnssAntennaInfo(); } -void Gnss::reportSvStatus(const hidl_vec& svInfoList) const { +template +void GnssTemplate::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) { @@ -449,7 +598,8 @@ void Gnss::reportSvStatus(const hidl_vec& svInfoList) const { } } -void Gnss::reportLocation(const V1_0::GnssLocation& location) const { +template +void GnssTemplate::reportLocation(const V1_0::GnssLocation& location) const { std::unique_lock lock(mMutex); if (sGnssCallback_1_1 != nullptr) { auto ret = sGnssCallback_1_1->gnssLocationCb(location); @@ -468,7 +618,8 @@ void Gnss::reportLocation(const V1_0::GnssLocation& location) const { } } -void Gnss::reportLocation(const V2_0::GnssLocation& location) const { +template +void GnssTemplate::reportLocation(const V2_0::GnssLocation& location) const { std::unique_lock lock(mMutex); if (sGnssCallback_2_1 != nullptr) { auto ret = sGnssCallback_2_1->gnssLocationCb_2_0(location); @@ -487,8 +638,4 @@ void Gnss::reportLocation(const V2_0::GnssLocation& location) const { } } -} // namespace implementation -} // namespace V2_1 -} // namespace gnss -} // namespace hardware -} // namespace android +} // namespace android::hardware::gnss::common::implementation diff --git a/gnss/2.1/default/GnssAntennaInfo.cpp b/gnss/common/utils/default/v2_1/GnssAntennaInfo.cpp similarity index 91% rename from gnss/2.1/default/GnssAntennaInfo.cpp rename to gnss/common/utils/default/v2_1/GnssAntennaInfo.cpp index ed183a9383..962451c0dd 100644 --- a/gnss/2.1/default/GnssAntennaInfo.cpp +++ b/gnss/common/utils/default/v2_1/GnssAntennaInfo.cpp @@ -16,18 +16,14 @@ #define LOG_TAG "GnssAntennaInfo" -#include "GnssAntennaInfo.h" +#include "v2_1/GnssAntennaInfo.h" #include "Utils.h" #include using ::android::hardware::gnss::common::Utils; -namespace android { -namespace hardware { -namespace gnss { -namespace V2_1 { -namespace implementation { +namespace android::hardware::gnss::V2_1::implementation { sp GnssAntennaInfo::sCallback = nullptr; @@ -102,8 +98,4 @@ void GnssAntennaInfo::reportAntennaInfo( } } -} // namespace implementation -} // namespace V2_1 -} // namespace gnss -} // namespace hardware -} // namespace android \ No newline at end of file +} // namespace android::hardware::gnss::V2_1::implementation diff --git a/gnss/2.1/default/GnssConfiguration.cpp b/gnss/common/utils/default/v2_1/GnssConfiguration.cpp similarity index 93% rename from gnss/2.1/default/GnssConfiguration.cpp rename to gnss/common/utils/default/v2_1/GnssConfiguration.cpp index cd8f07fcc4..8b30701ea1 100644 --- a/gnss/2.1/default/GnssConfiguration.cpp +++ b/gnss/common/utils/default/v2_1/GnssConfiguration.cpp @@ -16,14 +16,10 @@ #define LOG_TAG "GnssConfiguration" -#include "GnssConfiguration.h" +#include "v2_1/GnssConfiguration.h" #include -namespace android { -namespace hardware { -namespace gnss { -namespace V2_1 { -namespace implementation { +namespace android::hardware::gnss::V2_1::implementation { // Methods from ::android::hardware::gnss::V1_0::IGnssConfiguration follow. Return GnssConfiguration::setSuplEs(bool enable) { @@ -99,8 +95,4 @@ Return GnssConfiguration::isBlacklistedV2_1(const GnssSvInfoV2_1& gnssSvIn return (mBlacklistedSourceSet.find(source) != mBlacklistedSourceSet.end()); } -} // namespace implementation -} // namespace V2_1 -} // namespace gnss -} // namespace hardware -} // namespace android \ No newline at end of file +} // namespace android::hardware::gnss::V2_1::implementation diff --git a/gnss/2.1/default/GnssDebug.cpp b/gnss/common/utils/default/v2_1/GnssDebug.cpp similarity index 88% rename from gnss/2.1/default/GnssDebug.cpp rename to gnss/common/utils/default/v2_1/GnssDebug.cpp index a9f7ded2a7..492b970b59 100644 --- a/gnss/2.1/default/GnssDebug.cpp +++ b/gnss/common/utils/default/v2_1/GnssDebug.cpp @@ -19,15 +19,11 @@ #include #include "Constants.h" -#include "GnssDebug.h" +#include "v2_1/GnssDebug.h" using namespace ::android::hardware::gnss::common; -namespace android { -namespace hardware { -namespace gnss { -namespace V1_1 { -namespace implementation { +namespace android::hardware::gnss::V1_1::implementation { // Methods from ::android::hardware::gnss::V1_0::IGnssDebug follow. Return GnssDebug::getDebugData(V1_0::IGnssDebug::getDebugData_cb _hidl_cb) { @@ -55,8 +51,4 @@ Return GnssDebug::getDebugData(V1_0::IGnssDebug::getDebugData_cb _hidl_cb) return Void(); } -} // namespace implementation -} // namespace V1_1 -} // namespace gnss -} // namespace hardware -} // namespace android +} // namespace android::hardware::gnss::V1_1::implementation diff --git a/gnss/2.1/default/GnssMeasurement.cpp b/gnss/common/utils/default/v2_1/GnssMeasurement.cpp similarity index 94% rename from gnss/2.1/default/GnssMeasurement.cpp rename to gnss/common/utils/default/v2_1/GnssMeasurement.cpp index 63bbc0a399..7d3a002ea7 100644 --- a/gnss/2.1/default/GnssMeasurement.cpp +++ b/gnss/common/utils/default/v2_1/GnssMeasurement.cpp @@ -16,19 +16,14 @@ #define LOG_TAG "GnssMeasurement" -#include "GnssMeasurement.h" +#include "v2_1/GnssMeasurement.h" #include #include "Utils.h" -namespace android { -namespace hardware { -namespace gnss { +namespace android::hardware::gnss::V2_1::implementation { using common::Utils; -namespace V2_1 { -namespace implementation { - sp GnssMeasurement::sCallback_2_1 = nullptr; sp GnssMeasurement::sCallback_2_0 = nullptr; @@ -145,8 +140,4 @@ void GnssMeasurement::reportMeasurement(const GnssDataV2_1& data) { } } -} // namespace implementation -} // namespace V2_1 -} // namespace gnss -} // namespace hardware -} // namespace android +} // namespace android::hardware::gnss::V2_1::implementation diff --git a/gnss/2.1/default/GnssMeasurementCorrections.cpp b/gnss/common/utils/default/v2_1/GnssMeasurementCorrections.cpp similarity index 93% rename from gnss/2.1/default/GnssMeasurementCorrections.cpp rename to gnss/common/utils/default/v2_1/GnssMeasurementCorrections.cpp index accf62b733..9be7e2350f 100644 --- a/gnss/2.1/default/GnssMeasurementCorrections.cpp +++ b/gnss/common/utils/default/v2_1/GnssMeasurementCorrections.cpp @@ -16,15 +16,14 @@ #define LOG_TAG "GnssMeasurementCorrections" -#include "GnssMeasurementCorrections.h" +#include "v2_1/GnssMeasurementCorrections.h" #include -namespace android { -namespace hardware { -namespace gnss { -namespace measurement_corrections { -namespace V1_1 { -namespace implementation { +namespace android::hardware::gnss::measurement_corrections::V1_1::implementation { + +GnssMeasurementCorrections::GnssMeasurementCorrections() {} + +GnssMeasurementCorrections::~GnssMeasurementCorrections() {} // Methods from V1_0::IMeasurementCorrections follow. Return GnssMeasurementCorrections::setCorrections( @@ -101,9 +100,4 @@ Return GnssMeasurementCorrections::setCorrections_1_1( return true; } -} // namespace implementation -} // namespace V1_1 -} // namespace measurement_corrections -} // namespace gnss -} // namespace hardware -} // namespace android +} // namespace android::hardware::gnss::measurement_corrections::V1_1::implementation diff --git a/gnss/common/utils/vts/Android.bp b/gnss/common/utils/vts/Android.bp index 4c6d4439bc..e36b656171 100644 --- a/gnss/common/utils/vts/Android.bp +++ b/gnss/common/utils/vts/Android.bp @@ -25,11 +25,14 @@ cc_library_static { ], srcs: [ "Utils.cpp", + "v2_1/GnssCallback.cpp", ], export_include_dirs: ["include"], shared_libs: [ "android.hardware.gnss@1.0", + "android.hardware.gnss@1.1", "android.hardware.gnss@2.0", + "android.hardware.gnss@2.1", "android.hardware.gnss.measurement_corrections@1.0", "android.hardware.gnss.measurement_corrections@1.1", ], diff --git a/gnss/common/utils/vts/include/v2_1/GnssCallback.h b/gnss/common/utils/vts/include/v2_1/GnssCallback.h new file mode 100644 index 0000000000..ab1375d3a5 --- /dev/null +++ b/gnss/common/utils/vts/include/v2_1/GnssCallback.h @@ -0,0 +1,107 @@ +/* + * 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. + */ + +#pragma once + +#include +#include "GnssCallbackEventQueue.h" + +#include + +using android::hardware::hidl_vec; +using android::hardware::Return; +using android::hardware::Void; + +using android::hardware::gnss::common::GnssCallbackEventQueue; +using android::hardware::gnss::measurement_corrections::V1_0::IMeasurementCorrectionsCallback; +using android::hardware::gnss::V1_0::GnssLocationFlags; +using android::hardware::gnss::V2_0::GnssConstellationType; + +using GnssLocation_1_0 = android::hardware::gnss::V1_0::GnssLocation; +using GnssLocation_2_0 = android::hardware::gnss::V2_0::GnssLocation; + +using IGnssCallback_1_0 = android::hardware::gnss::V1_0::IGnssCallback; +using IGnssCallback_2_0 = android::hardware::gnss::V2_0::IGnssCallback; +using IGnssCallback_2_1 = android::hardware::gnss::V2_1::IGnssCallback; + +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; +using IGnssMeasurementCallback_2_1 = android::hardware::gnss::V2_1::IGnssMeasurementCallback; + +using android::sp; + +#define TIMEOUT_SEC 2 // for basic commands/responses + +namespace android::hardware::gnss::common { + +/* Callback class for data & Event. */ +class GnssCallback : public IGnssCallback_2_1 { + public: + IGnssCallback_1_0::GnssSystemInfo last_info_; + android::hardware::hidl_string last_name_; + uint32_t last_capabilities_; + GnssLocation_2_0 last_location_; + + GnssCallbackEventQueue info_cbq_; + GnssCallbackEventQueue name_cbq_; + GnssCallbackEventQueue capabilities_cbq_; + GnssCallbackEventQueue location_cbq_; + GnssCallbackEventQueue> sv_info_list_cbq_; + + GnssCallback(); + virtual ~GnssCallback() = default; + + // Dummy callback handlers + Return gnssStatusCb(const IGnssCallback_1_0::GnssStatusValue /* status */) override { + return Void(); + } + Return gnssNmeaCb(int64_t /* timestamp */, + const android::hardware::hidl_string& /* nmea */) override { + return Void(); + } + Return gnssAcquireWakelockCb() override { return Void(); } + Return gnssReleaseWakelockCb() override { return Void(); } + Return gnssRequestLocationCb(bool /* independentFromGnss */) override { return Void(); } + Return gnssRequestTimeCb() override { return Void(); } + // Actual (test) callback handlers + Return gnssNameCb(const android::hardware::hidl_string& name) override; + Return gnssLocationCb(const GnssLocation_1_0& location) override; + Return gnssSetCapabilitesCb(uint32_t capabilities) override; + Return gnssSetSystemInfoCb(const IGnssCallback_1_0::GnssSystemInfo& info) override; + Return gnssSvStatusCb(const IGnssCallback_1_0::GnssSvStatus& svStatus) override; + + // New in v2.0 + Return gnssLocationCb_2_0(const GnssLocation_2_0& location) override; + Return gnssRequestLocationCb_2_0(bool /* independentFromGnss */, + bool /* isUserEmergency */) override { + return Void(); + } + Return gnssSetCapabilitiesCb_2_0(uint32_t capabilities) override; + Return gnssSvStatusCb_2_0(const hidl_vec&) override { + return Void(); + } + + // New in v2.1 + Return gnssSvStatusCb_2_1( + const hidl_vec& svInfoList) override; + Return gnssSetCapabilitiesCb_2_1(uint32_t capabilities) override; + + private: + Return gnssLocationCbImpl(const GnssLocation_2_0& location); +}; + +} // namespace android::hardware::gnss::common diff --git a/gnss/common/utils/vts/include/v2_1/gnss_hal_test_template.h b/gnss/common/utils/vts/include/v2_1/gnss_hal_test_template.h new file mode 100644 index 0000000000..d057c617be --- /dev/null +++ b/gnss/common/utils/vts/include/v2_1/gnss_hal_test_template.h @@ -0,0 +1,381 @@ +/* + * 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 "GnssCallbackEventQueue.h" +#include "Utils.h" +#include "v2_1/GnssCallback.h" + +#include +#include + +using ::android::hardware::gnss::common::Utils; + +using android::hardware::hidl_vec; +using android::hardware::Return; +using android::hardware::Void; + +using android::hardware::gnss::common::GnssCallback; +using android::hardware::gnss::common::GnssCallbackEventQueue; +using android::hardware::gnss::measurement_corrections::V1_0::IMeasurementCorrectionsCallback; +using android::hardware::gnss::V1_0::GnssLocationFlags; +using android::hardware::gnss::V2_0::GnssConstellationType; +using android::hardware::gnss::V2_1::IGnssAntennaInfo; +using android::hardware::gnss::V2_1::IGnssAntennaInfoCallback; + +using GnssLocation_1_0 = android::hardware::gnss::V1_0::GnssLocation; +using GnssLocation_2_0 = android::hardware::gnss::V2_0::GnssLocation; + +using IGnssCallback_1_0 = android::hardware::gnss::V1_0::IGnssCallback; +using IGnssCallback_2_0 = android::hardware::gnss::V2_0::IGnssCallback; +using IGnssCallback_2_1 = android::hardware::gnss::V2_1::IGnssCallback; + +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; +using IGnssMeasurementCallback_2_1 = android::hardware::gnss::V2_1::IGnssMeasurementCallback; + +using android::sp; + +#define TIMEOUT_SEC 2 // for basic commands/responses + +// The main test class for GNSS HAL. +template +class GnssHalTestTemplate : public testing::TestWithParam { + public: + virtual void SetUp() override; + + virtual void TearDown() override; + + /* Callback class for GnssMeasurement. */ + class GnssMeasurementCallback : public IGnssMeasurementCallback_2_1 { + public: + GnssCallbackEventQueue measurement_cbq_; + + GnssMeasurementCallback() : measurement_cbq_("measurement"){}; + virtual ~GnssMeasurementCallback() = default; + + // Methods from V1_0::IGnssMeasurementCallback follow. + Return GnssMeasurementCb(const IGnssMeasurementCallback_1_0::GnssData&) override { + return Void(); + } + + // Methods from V1_1::IGnssMeasurementCallback follow. + Return gnssMeasurementCb(const IGnssMeasurementCallback_1_1::GnssData&) override { + return Void(); + } + + // Methods from V2_0::IGnssMeasurementCallback follow. + Return gnssMeasurementCb_2_0(const IGnssMeasurementCallback_2_0::GnssData&) override { + return Void(); + } + + // Methods from V2_1::IGnssMeasurementCallback follow. + Return gnssMeasurementCb_2_1(const IGnssMeasurementCallback_2_1::GnssData&) override; + }; + + /* Callback class for GnssMeasurementCorrections. */ + class GnssMeasurementCorrectionsCallback : public IMeasurementCorrectionsCallback { + public: + uint32_t last_capabilities_; + GnssCallbackEventQueue capabilities_cbq_; + + GnssMeasurementCorrectionsCallback() : capabilities_cbq_("capabilities"){}; + virtual ~GnssMeasurementCorrectionsCallback() = default; + + // Methods from V1_0::IMeasurementCorrectionsCallback follow. + Return setCapabilitiesCb(uint32_t capabilities) override; + }; + + /* Callback class for GnssAntennaInfo. */ + class GnssAntennaInfoCallback : public IGnssAntennaInfoCallback { + public: + GnssCallbackEventQueue> + antenna_info_cbq_; + + GnssAntennaInfoCallback() : antenna_info_cbq_("info"){}; + virtual ~GnssAntennaInfoCallback() = default; + + // Methods from V2_1::GnssAntennaInfoCallback follow. + Return gnssAntennaInfoCb( + const hidl_vec& gnssAntennaInfos); + }; + + /* + * SetUpGnssCallback: + * Set GnssCallback and verify the result. + */ + void SetUpGnssCallback(); + + /* + * StartAndCheckFirstLocation: + * Helper function to start location, and check the first one. + * + *

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_2_0& 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); + + /* + * startLocationAndGetNonGpsConstellation: + * 1. Start location + * 2. Find and return first non-GPS constellation + * + * Note that location is not stopped in this method. The client should call + * StopAndClearLocations() after the call. + */ + GnssConstellationType startLocationAndGetNonGpsConstellation( + const int locations_to_await, const int gnss_sv_info_list_timeout); + + sp gnss_hal_; // GNSS HAL to call into + sp gnss_cb_; // Primary callback interface +}; + +using ::android::hardware::gnss::common::Utils; + +// Implementations for the main test class for GNSS HAL +template +void GnssHalTestTemplate::SetUp() { + gnss_hal_ = T_IGnss::getService(GetParam()); + ASSERT_NE(gnss_hal_, nullptr); + + SetUpGnssCallback(); +} + +template +void GnssHalTestTemplate::TearDown() { + if (gnss_hal_ != nullptr) { + gnss_hal_->cleanup(); + gnss_hal_ = nullptr; + } + + // Set to nullptr to destruct the callback event queues and warn of any unprocessed events. + gnss_cb_ = nullptr; +} + +template +void GnssHalTestTemplate::SetUpGnssCallback() { + gnss_cb_ = new GnssCallback(); + ASSERT_NE(gnss_cb_, nullptr); + + auto result = gnss_hal_->setCallback_2_1(gnss_cb_); + if (!result.isOk()) { + ALOGE("result of failed setCallback %s", result.description().c_str()); + } + + ASSERT_TRUE(result.isOk()); + ASSERT_TRUE(result); + + /* + * All capabilities, name and systemInfo callbacks should trigger + */ + EXPECT_TRUE(gnss_cb_->capabilities_cbq_.retrieve(gnss_cb_->last_capabilities_, TIMEOUT_SEC)); + EXPECT_TRUE(gnss_cb_->info_cbq_.retrieve(gnss_cb_->last_info_, TIMEOUT_SEC)); + EXPECT_TRUE(gnss_cb_->name_cbq_.retrieve(gnss_cb_->last_name_, TIMEOUT_SEC)); + + EXPECT_EQ(gnss_cb_->capabilities_cbq_.calledCount(), 1); + EXPECT_EQ(gnss_cb_->info_cbq_.calledCount(), 1); + EXPECT_EQ(gnss_cb_->name_cbq_.calledCount(), 1); +} + +template +void GnssHalTestTemplate::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 (gnss_cb_->location_cbq_.retrieve(gnss_cb_->last_location_, TIMEOUT_SEC)) { + } + gnss_cb_->location_cbq_.reset(); +} + +template +void GnssHalTestTemplate::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( + T_IGnss::GnssPositionMode::MS_BASED, + T_IGnss::GnssPositionRecurrence::RECURRENCE_PERIODIC, min_interval_msec, + kPreferredAccuracy, kPreferredTimeMsec, low_power_mode); + + ASSERT_TRUE(result.isOk()); + EXPECT_TRUE(result); +} + +template +bool GnssHalTestTemplate::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; + + EXPECT_TRUE(gnss_cb_->location_cbq_.retrieve(gnss_cb_->last_location_, + kFirstGnssLocationTimeoutSeconds)); + int locationCalledCount = gnss_cb_->location_cbq_.calledCount(); + EXPECT_EQ(locationCalledCount, 1); + + if (locationCalledCount > 0) { + // don't require speed on first fix + CheckLocation(gnss_cb_->last_location_, false); + return true; + } + return false; +} + +template +void GnssHalTestTemplate::CheckLocation(const GnssLocation_2_0& location, + bool check_speed) { + const bool check_more_accuracies = + (gnss_cb_->info_cbq_.calledCount() > 0 && gnss_cb_->last_info_.yearOfHw >= 2017); + + Utils::checkLocation(location.v1_0, check_speed, check_more_accuracies); +} + +template +void GnssHalTestTemplate::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_TRUE(gnss_cb_->location_cbq_.retrieve(gnss_cb_->last_location_, + kLocationTimeoutSubsequentSec)); + int locationCalledCount = gnss_cb_->location_cbq_.calledCount(); + EXPECT_EQ(locationCalledCount, i + 1); + // Don't cause confusion by checking details if no location yet + if (locationCalledCount > 0) { + // Should be more than 1 location by now, but if not, still don't check first fix speed + CheckLocation(gnss_cb_->last_location_, locationCalledCount > 1); + } + } +} + +template +GnssConstellationType GnssHalTestTemplate::startLocationAndGetNonGpsConstellation( + const int locations_to_await, const int gnss_sv_info_list_timeout) { + gnss_cb_->location_cbq_.reset(); + StartAndCheckLocations(locations_to_await); + const int location_called_count = gnss_cb_->location_cbq_.calledCount(); + + // Tolerate 1 less sv status to handle edge cases in reporting. + int sv_info_list_cbq_size = gnss_cb_->sv_info_list_cbq_.size(); + EXPECT_GE(sv_info_list_cbq_size + 1, locations_to_await); + ALOGD("Observed %d GnssSvInfo, while awaiting %d Locations (%d received)", + sv_info_list_cbq_size, locations_to_await, location_called_count); + + // Find first non-GPS constellation to blacklist + GnssConstellationType constellation_to_blacklist = GnssConstellationType::UNKNOWN; + for (int i = 0; i < sv_info_list_cbq_size; ++i) { + hidl_vec sv_info_vec; + gnss_cb_->sv_info_list_cbq_.retrieve(sv_info_vec, gnss_sv_info_list_timeout); + for (uint32_t iSv = 0; iSv < sv_info_vec.size(); iSv++) { + const auto& gnss_sv = sv_info_vec[iSv]; + if ((gnss_sv.v2_0.v1_0.svFlag & IGnssCallback_1_0::GnssSvFlags::USED_IN_FIX) && + (gnss_sv.v2_0.constellation != GnssConstellationType::UNKNOWN) && + (gnss_sv.v2_0.constellation != GnssConstellationType::GPS)) { + // found a non-GPS constellation + constellation_to_blacklist = gnss_sv.v2_0.constellation; + break; + } + } + if (constellation_to_blacklist != GnssConstellationType::UNKNOWN) { + break; + } + } + + if (constellation_to_blacklist == GnssConstellationType::UNKNOWN) { + ALOGI("No non-GPS constellations found, constellation blacklist test less effective."); + // Proceed functionally to blacklist something. + constellation_to_blacklist = GnssConstellationType::GLONASS; + } + + return constellation_to_blacklist; +} + +template +Return GnssHalTestTemplate::GnssMeasurementCallback::gnssMeasurementCb_2_1( + const IGnssMeasurementCallback_2_1::GnssData& data) { + ALOGD("GnssMeasurement v2.1 received. Size = %d", (int)data.measurements.size()); + measurement_cbq_.store(data); + return Void(); +} + +template +Return GnssHalTestTemplate::GnssMeasurementCorrectionsCallback::setCapabilitiesCb( + uint32_t capabilities) { + ALOGI("GnssMeasurementCorrectionsCallback capabilities received %d", capabilities); + capabilities_cbq_.store(capabilities); + return Void(); +} + +template +Return GnssHalTestTemplate::GnssAntennaInfoCallback::gnssAntennaInfoCb( + const hidl_vec& gnssAntennaInfos) { + ALOGD("GnssAntennaInfo v2.1 received. Size = %d", (int)gnssAntennaInfos.size()); + antenna_info_cbq_.store(gnssAntennaInfos); + return Void(); +} diff --git a/gnss/common/utils/vts/v2_1/GnssCallback.cpp b/gnss/common/utils/vts/v2_1/GnssCallback.cpp new file mode 100644 index 0000000000..3b96fb834b --- /dev/null +++ b/gnss/common/utils/vts/v2_1/GnssCallback.cpp @@ -0,0 +1,95 @@ +/* + * 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. + */ + +#define LOG_TAG "GnssCallback" + +#include "v2_1/GnssCallback.h" +#include +#include "Utils.h" + +#include + +using ::android::hardware::gnss::common::Utils; + +namespace android::hardware::gnss::common { + +GnssCallback::GnssCallback() + : info_cbq_("system_info"), + name_cbq_("name"), + capabilities_cbq_("capabilities"), + location_cbq_("location"), + sv_info_list_cbq_("sv_info") {} + +Return GnssCallback::gnssSetSystemInfoCb(const IGnssCallback_1_0::GnssSystemInfo& info) { + ALOGI("Info received, year %d", info.yearOfHw); + info_cbq_.store(info); + return Void(); +} + +Return GnssCallback::gnssSetCapabilitesCb(uint32_t capabilities) { + ALOGI("Capabilities received %d", capabilities); + capabilities_cbq_.store(capabilities); + return Void(); +} + +Return GnssCallback::gnssSetCapabilitiesCb_2_0(uint32_t capabilities) { + ALOGI("Capabilities (v2.0) received %d", capabilities); + capabilities_cbq_.store(capabilities); + return Void(); +} + +Return GnssCallback::gnssSetCapabilitiesCb_2_1(uint32_t capabilities) { + ALOGI("Capabilities (v2.1) received %d", capabilities); + capabilities_cbq_.store(capabilities); + return Void(); +} + +Return GnssCallback::gnssNameCb(const android::hardware::hidl_string& name) { + ALOGI("Name received: %s", name.c_str()); + name_cbq_.store(name); + return Void(); +} + +Return 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 GnssCallback::gnssLocationCb_2_0(const GnssLocation_2_0& location) { + ALOGI("Location (v2.0) received"); + return gnssLocationCbImpl(location); +} + +Return GnssCallback::gnssLocationCbImpl(const GnssLocation_2_0& location) { + location_cbq_.store(location); + return Void(); +} + +Return GnssCallback::gnssSvStatusCb(const IGnssCallback_1_0::GnssSvStatus&) { + ALOGI("gnssSvStatusCb"); + return Void(); +} + +Return GnssCallback::gnssSvStatusCb_2_1( + const hidl_vec& svInfoList) { + ALOGI("gnssSvStatusCb_2_1. Size = %d", (int)svInfoList.size()); + sv_info_list_cbq_.store(svInfoList); + return Void(); +} + +} // namespace android::hardware::gnss::common diff --git a/gnss/measurement_corrections/1.1/Android.bp b/gnss/measurement_corrections/1.1/Android.bp index d279af6cd2..f7ac8b88fd 100644 --- a/gnss/measurement_corrections/1.1/Android.bp +++ b/gnss/measurement_corrections/1.1/Android.bp @@ -12,8 +12,8 @@ hidl_interface { ], interfaces: [ "android.hardware.gnss.measurement_corrections@1.0", - "android.hardware.gnss@2.0", "android.hardware.gnss@1.0", + "android.hardware.gnss@2.0", "android.hidl.base@1.0", ], gen_java: true,