1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef GNSS_HAL_TEST_H_ 18 #define GNSS_HAL_TEST_H_ 19 20 #include <android/hardware/gnss/2.1/IGnss.h> 21 #include "GnssCallbackEventQueue.h" 22 23 #include <gtest/gtest.h> 24 25 using android::hardware::hidl_vec; 26 using android::hardware::Return; 27 using android::hardware::Void; 28 29 using android::hardware::gnss::common::GnssCallbackEventQueue; 30 using android::hardware::gnss::measurement_corrections::V1_0::IMeasurementCorrectionsCallback; 31 using android::hardware::gnss::V1_0::GnssLocationFlags; 32 using android::hardware::gnss::V2_0::GnssConstellationType; 33 using android::hardware::gnss::V2_1::IGnss; 34 using android::hardware::gnss::V2_1::IGnssAntennaInfo; 35 using android::hardware::gnss::V2_1::IGnssAntennaInfoCallback; 36 37 using GnssLocation_1_0 = android::hardware::gnss::V1_0::GnssLocation; 38 using GnssLocation_2_0 = android::hardware::gnss::V2_0::GnssLocation; 39 40 using IGnssCallback_1_0 = android::hardware::gnss::V1_0::IGnssCallback; 41 using IGnssCallback_2_0 = android::hardware::gnss::V2_0::IGnssCallback; 42 using IGnssCallback_2_1 = android::hardware::gnss::V2_1::IGnssCallback; 43 44 using IGnssMeasurementCallback_1_0 = android::hardware::gnss::V1_0::IGnssMeasurementCallback; 45 using IGnssMeasurementCallback_1_1 = android::hardware::gnss::V1_1::IGnssMeasurementCallback; 46 using IGnssMeasurementCallback_2_0 = android::hardware::gnss::V2_0::IGnssMeasurementCallback; 47 using IGnssMeasurementCallback_2_1 = android::hardware::gnss::V2_1::IGnssMeasurementCallback; 48 49 using android::sp; 50 51 #define TIMEOUT_SEC 2 // for basic commands/responses 52 53 // The main test class for GNSS HAL. 54 class GnssHalTest : public testing::TestWithParam<std::string> { 55 public: 56 virtual void SetUp() override; 57 58 virtual void TearDown() override; 59 60 /* Callback class for data & Event. */ 61 class GnssCallback : public IGnssCallback_2_1 { 62 public: 63 IGnssCallback_1_0::GnssSystemInfo last_info_; 64 android::hardware::hidl_string last_name_; 65 uint32_t last_capabilities_; 66 GnssLocation_2_0 last_location_; 67 68 GnssCallbackEventQueue<IGnssCallback_1_0::GnssSystemInfo> info_cbq_; 69 GnssCallbackEventQueue<android::hardware::hidl_string> name_cbq_; 70 GnssCallbackEventQueue<uint32_t> capabilities_cbq_; 71 GnssCallbackEventQueue<GnssLocation_2_0> location_cbq_; 72 GnssCallbackEventQueue<hidl_vec<IGnssCallback_2_1::GnssSvInfo>> sv_info_list_cbq_; 73 74 GnssCallback(); 75 virtual ~GnssCallback() = default; 76 77 // Dummy callback handlers gnssStatusCb(const IGnssCallback_1_0::GnssStatusValue)78 Return<void> gnssStatusCb(const IGnssCallback_1_0::GnssStatusValue /* status */) override { 79 return Void(); 80 } gnssNmeaCb(int64_t,const android::hardware::hidl_string &)81 Return<void> gnssNmeaCb(int64_t /* timestamp */, 82 const android::hardware::hidl_string& /* nmea */) override { 83 return Void(); 84 } gnssAcquireWakelockCb()85 Return<void> gnssAcquireWakelockCb() override { return Void(); } gnssReleaseWakelockCb()86 Return<void> gnssReleaseWakelockCb() override { return Void(); } gnssRequestLocationCb(bool)87 Return<void> gnssRequestLocationCb(bool /* independentFromGnss */) override { 88 return Void(); 89 } gnssRequestTimeCb()90 Return<void> gnssRequestTimeCb() override { return Void(); } 91 // Actual (test) callback handlers 92 Return<void> gnssNameCb(const android::hardware::hidl_string& name) override; 93 Return<void> gnssLocationCb(const GnssLocation_1_0& location) override; 94 Return<void> gnssSetCapabilitesCb(uint32_t capabilities) override; 95 Return<void> gnssSetSystemInfoCb(const IGnssCallback_1_0::GnssSystemInfo& info) override; 96 Return<void> gnssSvStatusCb(const IGnssCallback_1_0::GnssSvStatus& svStatus) override; 97 98 // New in v2.0 99 Return<void> gnssLocationCb_2_0(const GnssLocation_2_0& location) override; gnssRequestLocationCb_2_0(bool,bool)100 Return<void> gnssRequestLocationCb_2_0(bool /* independentFromGnss */, 101 bool /* isUserEmergency */) override { 102 return Void(); 103 } 104 Return<void> gnssSetCapabilitiesCb_2_0(uint32_t capabilities) override; gnssSvStatusCb_2_0(const hidl_vec<IGnssCallback_2_0::GnssSvInfo> &)105 Return<void> gnssSvStatusCb_2_0(const hidl_vec<IGnssCallback_2_0::GnssSvInfo>&) override { 106 return Void(); 107 } 108 109 // New in v2.1 110 Return<void> gnssSvStatusCb_2_1( 111 const hidl_vec<IGnssCallback_2_1::GnssSvInfo>& svInfoList) override; 112 Return<void> gnssSetCapabilitiesCb_2_1(uint32_t capabilities) override; 113 114 private: 115 Return<void> gnssLocationCbImpl(const GnssLocation_2_0& location); 116 }; 117 118 /* Callback class for GnssMeasurement. */ 119 class GnssMeasurementCallback : public IGnssMeasurementCallback_2_1 { 120 public: 121 GnssCallbackEventQueue<IGnssMeasurementCallback_2_1::GnssData> measurement_cbq_; 122 GnssMeasurementCallback()123 GnssMeasurementCallback() : measurement_cbq_("measurement"){}; 124 virtual ~GnssMeasurementCallback() = default; 125 126 // Methods from V1_0::IGnssMeasurementCallback follow. GnssMeasurementCb(const IGnssMeasurementCallback_1_0::GnssData &)127 Return<void> GnssMeasurementCb(const IGnssMeasurementCallback_1_0::GnssData&) override { 128 return Void(); 129 } 130 131 // Methods from V1_1::IGnssMeasurementCallback follow. gnssMeasurementCb(const IGnssMeasurementCallback_1_1::GnssData &)132 Return<void> gnssMeasurementCb(const IGnssMeasurementCallback_1_1::GnssData&) override { 133 return Void(); 134 } 135 136 // Methods from V2_0::IGnssMeasurementCallback follow. gnssMeasurementCb_2_0(const IGnssMeasurementCallback_2_0::GnssData &)137 Return<void> gnssMeasurementCb_2_0(const IGnssMeasurementCallback_2_0::GnssData&) override { 138 return Void(); 139 } 140 141 // Methods from V2_1::IGnssMeasurementCallback follow. 142 Return<void> gnssMeasurementCb_2_1(const IGnssMeasurementCallback_2_1::GnssData&) override; 143 }; 144 145 /* Callback class for GnssMeasurementCorrections. */ 146 class GnssMeasurementCorrectionsCallback : public IMeasurementCorrectionsCallback { 147 public: 148 uint32_t last_capabilities_; 149 GnssCallbackEventQueue<uint32_t> capabilities_cbq_; 150 GnssMeasurementCorrectionsCallback()151 GnssMeasurementCorrectionsCallback() : capabilities_cbq_("capabilities"){}; 152 virtual ~GnssMeasurementCorrectionsCallback() = default; 153 154 // Methods from V1_0::IMeasurementCorrectionsCallback follow. 155 Return<void> setCapabilitiesCb(uint32_t capabilities) override; 156 }; 157 158 /* Callback class for GnssAntennaInfo. */ 159 class GnssAntennaInfoCallback : public IGnssAntennaInfoCallback { 160 public: 161 GnssCallbackEventQueue<hidl_vec<IGnssAntennaInfoCallback::GnssAntennaInfo>> 162 antenna_info_cbq_; 163 GnssAntennaInfoCallback()164 GnssAntennaInfoCallback() : antenna_info_cbq_("info"){}; 165 virtual ~GnssAntennaInfoCallback() = default; 166 167 // Methods from V2_1::GnssAntennaInfoCallback follow. 168 Return<void> gnssAntennaInfoCb( 169 const hidl_vec<IGnssAntennaInfoCallback::GnssAntennaInfo>& gnssAntennaInfos); 170 }; 171 172 /* 173 * SetUpGnssCallback: 174 * Set GnssCallback and verify the result. 175 */ 176 void SetUpGnssCallback(); 177 178 /* 179 * StartAndCheckFirstLocation: 180 * Helper function to start location, and check the first one. 181 * 182 * <p> Note this leaves the Location request active, to enable Stop call vs. other call 183 * reordering tests. 184 * 185 * returns true if a location was successfully generated 186 */ 187 bool StartAndCheckFirstLocation(); 188 189 /* 190 * CheckLocation: 191 * Helper function to vet Location fields 192 * 193 * check_speed: true if speed related fields are also verified. 194 */ 195 void CheckLocation(const GnssLocation_2_0& location, const bool check_speed); 196 197 /* 198 * StartAndCheckLocations: 199 * Helper function to collect, and check a number of 200 * normal ~1Hz locations. 201 * 202 * Note this leaves the Location request active, to enable Stop call vs. other call 203 * reordering tests. 204 */ 205 void StartAndCheckLocations(int count); 206 207 /* 208 * StopAndClearLocations: 209 * Helper function to stop locations, and clear any remaining notifications 210 */ 211 void StopAndClearLocations(); 212 213 /* 214 * SetPositionMode: 215 * Helper function to set positioning mode and verify output 216 */ 217 void SetPositionMode(const int min_interval_msec, const bool low_power_mode); 218 219 /* 220 * startLocationAndGetNonGpsConstellation: 221 * 1. Start location 222 * 2. Find and return first non-GPS constellation 223 * 224 * Note that location is not stopped in this method. The client should call 225 * StopAndClearLocations() after the call. 226 */ 227 GnssConstellationType startLocationAndGetNonGpsConstellation( 228 const int locations_to_await, const int gnss_sv_info_list_timeout); 229 230 sp<IGnss> gnss_hal_; // GNSS HAL to call into 231 sp<GnssCallback> gnss_cb_; // Primary callback interface 232 }; 233 234 #endif // GNSS_HAL_TEST_H_ 235