Yu-Han Yang | a509861 | 2019-02-08 16:22:07 -0800 | [diff] [blame] | 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 android_hardware_gnss_common_vts_Utils_H_ |
| 18 | #define android_hardware_gnss_common_vts_Utils_H_ |
| 19 | |
| 20 | #include <android/hardware/gnss/1.0/IGnss.h> |
Yu-Han Yang | 4e5ffc2 | 2020-04-17 15:44:59 -0700 | [diff] [blame] | 21 | #include <android/hardware/gnss/2.0/IGnss.h> |
Yu-Han Yang | 4165ed1 | 2022-02-09 14:47:50 -0800 | [diff] [blame] | 22 | #include <android/hardware/gnss/IGnss.h> |
Yu-Han Yang | 08642f9 | 2019-03-02 14:22:14 -0800 | [diff] [blame] | 23 | #include <android/hardware/gnss/measurement_corrections/1.0/IMeasurementCorrections.h> |
Sasha Kuznetsov | 31eea85 | 2020-01-03 13:06:38 -0800 | [diff] [blame] | 24 | #include <android/hardware/gnss/measurement_corrections/1.1/IMeasurementCorrections.h> |
Edwin Tung | bbf7fb9 | 2021-12-27 12:13:02 +0800 | [diff] [blame] | 25 | #include <android/hardware/gnss/measurement_corrections/BnMeasurementCorrectionsInterface.h> |
| 26 | |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 27 | #include <gtest/gtest.h> |
Yu-Han Yang | 4165ed1 | 2022-02-09 14:47:50 -0800 | [diff] [blame] | 28 | #include <type_traits> |
Yu-Han Yang | a509861 | 2019-02-08 16:22:07 -0800 | [diff] [blame] | 29 | |
Yu-Han Yang | a509861 | 2019-02-08 16:22:07 -0800 | [diff] [blame] | 30 | namespace android { |
| 31 | namespace hardware { |
| 32 | namespace gnss { |
| 33 | namespace common { |
| 34 | |
| 35 | struct Utils { |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 36 | public: |
Yu-Han Yang | 4165ed1 | 2022-02-09 14:47:50 -0800 | [diff] [blame] | 37 | static const int64_t kMockTimestamp = 1519930775453L; |
| 38 | |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 39 | template <class T> |
| 40 | static void checkLocation(const T& location, bool check_speed, bool check_more_accuracies); |
Yu-Han Yang | 4165ed1 | 2022-02-09 14:47:50 -0800 | [diff] [blame] | 41 | template <class T> |
| 42 | static void checkLocationElapsedRealtime(const T& location); |
| 43 | |
| 44 | static void checkElapsedRealtime( |
| 45 | const android::hardware::gnss::ElapsedRealtime& elapsedRealtime); |
Yu-Han Yang | 72a431e | 2024-02-22 23:34:42 +0000 | [diff] [blame] | 46 | static void checkPositionDebug(android::hardware::gnss::IGnssDebug::DebugData data); |
Yu-Han Yang | 4165ed1 | 2022-02-09 14:47:50 -0800 | [diff] [blame] | 47 | |
| 48 | static const android::hardware::gnss::GnssLocation getMockLocation( |
| 49 | double latitudeDegrees, double longitudeDegrees, double horizontalAccuracyMeters); |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 50 | static const measurement_corrections::V1_0::MeasurementCorrections |
| 51 | getMockMeasurementCorrections(); |
| 52 | static const measurement_corrections::V1_1::MeasurementCorrections |
| 53 | getMockMeasurementCorrections_1_1(); |
Edwin Tung | bbf7fb9 | 2021-12-27 12:13:02 +0800 | [diff] [blame] | 54 | static const android::hardware::gnss::measurement_corrections::MeasurementCorrections |
| 55 | getMockMeasurementCorrections_aidl(); |
Yu-Han Yang | 4e5ffc2 | 2020-04-17 15:44:59 -0700 | [diff] [blame] | 56 | |
Yu-Han Yang | 3a75dc0 | 2021-09-27 01:01:06 -0700 | [diff] [blame] | 57 | static V1_0::GnssConstellationType mapConstellationType( |
| 58 | V2_0::GnssConstellationType constellation); |
Tyler Trephan | 0d9206a | 2020-09-28 22:03:18 -0700 | [diff] [blame] | 59 | |
| 60 | static bool isAutomotiveDevice(); |
Yu-Han Yang | 72a431e | 2024-02-22 23:34:42 +0000 | [diff] [blame] | 61 | static double distanceMeters(double lat1, double lon1, double lat2, double lon2); |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 62 | |
Yu-Han Yang | ac8419a | 2024-08-27 22:28:47 +0000 | [diff] [blame] | 63 | // Returns true iff the device has the specified feature. |
| 64 | static bool deviceSupportsFeature(const char* feature); |
| 65 | |
| 66 | static bool isCnBuild() { return deviceSupportsFeature("cn.google.services"); } |
| 67 | |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 68 | private: |
| 69 | template <class T> |
| 70 | static int64_t getLocationTimestampMillis(const T&); |
Yu-Han Yang | a509861 | 2019-02-08 16:22:07 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 73 | template <class T> |
| 74 | void Utils::checkLocation(const T& location, bool check_speed, bool check_more_accuracies) { |
| 75 | EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_LAT_LONG); |
| 76 | EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_ALTITUDE); |
| 77 | if (check_speed) { |
| 78 | EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_SPEED); |
| 79 | } |
| 80 | EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_HORIZONTAL_ACCURACY); |
| 81 | // New uncertainties available in O must be provided, |
| 82 | // at least when paired with modern hardware (2017+) |
| 83 | if (check_more_accuracies) { |
| 84 | EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_VERTICAL_ACCURACY); |
| 85 | if (check_speed) { |
| 86 | EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_SPEED_ACCURACY); |
| 87 | if (location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_BEARING) { |
| 88 | EXPECT_TRUE(location.gnssLocationFlags & |
| 89 | V1_0::GnssLocationFlags::HAS_BEARING_ACCURACY); |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | EXPECT_GE(location.latitudeDegrees, -90.0); |
| 94 | EXPECT_LE(location.latitudeDegrees, 90.0); |
| 95 | EXPECT_GE(location.longitudeDegrees, -180.0); |
| 96 | EXPECT_LE(location.longitudeDegrees, 180.0); |
| 97 | EXPECT_GE(location.altitudeMeters, -1000.0); |
| 98 | EXPECT_LE(location.altitudeMeters, 30000.0); |
| 99 | if (check_speed) { |
| 100 | EXPECT_GE(location.speedMetersPerSec, 0.0); |
| 101 | EXPECT_LE(location.speedMetersPerSec, 5.0); // VTS tests are stationary. |
| 102 | |
| 103 | // Non-zero speeds must be reported with an associated bearing |
| 104 | if (location.speedMetersPerSec > 0.0) { |
| 105 | EXPECT_TRUE(location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_BEARING); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | /* |
| 110 | * Tolerating some especially high values for accuracy estimate, in case of |
| 111 | * first fix with especially poor geometry (happens occasionally) |
| 112 | */ |
| 113 | EXPECT_GT(location.horizontalAccuracyMeters, 0.0); |
| 114 | EXPECT_LE(location.horizontalAccuracyMeters, 250.0); |
| 115 | |
| 116 | /* |
| 117 | * Some devices may define bearing as -180 to +180, others as 0 to 360. |
| 118 | * Both are okay & understandable. |
| 119 | */ |
| 120 | if (location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_BEARING) { |
| 121 | EXPECT_GE(location.bearingDegrees, -180.0); |
| 122 | EXPECT_LE(location.bearingDegrees, 360.0); |
| 123 | } |
| 124 | if (location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_VERTICAL_ACCURACY) { |
| 125 | EXPECT_GT(location.verticalAccuracyMeters, 0.0); |
| 126 | EXPECT_LE(location.verticalAccuracyMeters, 500.0); |
| 127 | } |
| 128 | if (location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_SPEED_ACCURACY) { |
| 129 | EXPECT_GT(location.speedAccuracyMetersPerSecond, 0.0); |
| 130 | EXPECT_LE(location.speedAccuracyMetersPerSecond, 50.0); |
| 131 | } |
| 132 | if (location.gnssLocationFlags & V1_0::GnssLocationFlags::HAS_BEARING_ACCURACY) { |
| 133 | EXPECT_GT(location.bearingAccuracyDegrees, 0.0); |
| 134 | EXPECT_LE(location.bearingAccuracyDegrees, 360.0); |
| 135 | } |
| 136 | |
| 137 | // Check timestamp > 1.48e12 (47 years in msec - 1970->2017+) |
| 138 | EXPECT_GT(getLocationTimestampMillis(location), 1.48e12); |
Yu-Han Yang | 4165ed1 | 2022-02-09 14:47:50 -0800 | [diff] [blame] | 139 | |
| 140 | checkLocationElapsedRealtime(location); |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 141 | } |
| 142 | |
Yu-Han Yang | a509861 | 2019-02-08 16:22:07 -0800 | [diff] [blame] | 143 | } // namespace common |
| 144 | } // namespace gnss |
| 145 | } // namespace hardware |
| 146 | } // namespace android |
| 147 | |
| 148 | #endif // android_hardware_gnss_common_vts_Utils_H_ |