/* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef GNSS_HAL_TEST_H_ #define GNSS_HAL_TEST_H_ #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 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_