Michael Bestas | 3a0209e | 2023-05-04 01:15:47 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. |
| 3 | * Not a Contribution |
| 4 | */ |
| 5 | /* |
| 6 | * Copyright (C) 2016 The Android Open Source Project |
| 7 | * |
| 8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | * you may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | * See the License for the specific language governing permissions and |
| 18 | * limitations under the License. |
| 19 | */ |
| 20 | |
| 21 | #define LOG_TAG "LocSvc_GnssConfigurationInterface" |
| 22 | |
| 23 | #include <log_util.h> |
| 24 | #include "Gnss.h" |
| 25 | #include "GnssConfiguration.h" |
| 26 | #include "ContextBase.h" |
| 27 | #include <android/hardware/gnss/1.0/types.h> |
| 28 | |
| 29 | namespace android { |
| 30 | namespace hardware { |
| 31 | namespace gnss { |
| 32 | namespace V2_0 { |
| 33 | namespace implementation { |
| 34 | |
| 35 | using ::android::hardware::gnss::V1_0::GnssConstellationType; |
| 36 | using namespace loc_core; |
| 37 | |
| 38 | GnssConfiguration::GnssConfiguration(Gnss* gnss) : mGnss(gnss) { |
| 39 | } |
| 40 | |
| 41 | // Methods from ::android::hardware::gps::V1_0::IGnssConfiguration follow. |
| 42 | Return<bool> GnssConfiguration::setSuplEs(bool enabled) { |
| 43 | // deprecated function. Must return false to pass VTS |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | Return<bool> GnssConfiguration::setSuplVersion(uint32_t version) { |
| 48 | if (mGnss == nullptr) { |
| 49 | LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | GnssConfig config; |
| 54 | memset(&config, 0, sizeof(GnssConfig)); |
| 55 | config.size = sizeof(GnssConfig); |
| 56 | config.flags = GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT; |
| 57 | switch (version) { |
| 58 | case 0x00020004: |
| 59 | config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_4; |
| 60 | break; |
| 61 | case 0x00020002: |
| 62 | config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_2; |
| 63 | break; |
| 64 | case 0x00020000: |
| 65 | config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_0; |
| 66 | break; |
| 67 | case 0x00010000: |
| 68 | config.suplVersion = GNSS_CONFIG_SUPL_VERSION_1_0_0; |
| 69 | break; |
| 70 | default: |
| 71 | LOC_LOGE("%s]: invalid version: 0x%x.", __FUNCTION__, version); |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | return mGnss->updateConfiguration(config); |
| 76 | } |
| 77 | |
| 78 | Return<bool> GnssConfiguration::setSuplMode(uint8_t mode) { |
| 79 | if (mGnss == nullptr) { |
| 80 | LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | GnssConfig config; |
| 85 | memset(&config, 0, sizeof(GnssConfig)); |
| 86 | config.size = sizeof(GnssConfig); |
| 87 | config.flags = GNSS_CONFIG_FLAGS_SUPL_MODE_BIT; |
| 88 | switch (mode) { |
| 89 | case 0: |
| 90 | config.suplModeMask = 0; // STANDALONE ONLY |
| 91 | break; |
| 92 | case 1: |
| 93 | config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSB_BIT; |
| 94 | break; |
| 95 | case 2: |
| 96 | config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSA_BIT; |
| 97 | break; |
| 98 | case 3: |
| 99 | config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSB_BIT | GNSS_CONFIG_SUPL_MODE_MSA_BIT; |
| 100 | break; |
| 101 | default: |
| 102 | LOC_LOGE("%s]: invalid mode: %d.", __FUNCTION__, mode); |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | return mGnss->updateConfiguration(config); |
| 107 | } |
| 108 | |
| 109 | Return<bool> GnssConfiguration::setLppProfile(uint8_t lppProfileMask) { |
| 110 | if (mGnss == nullptr) { |
| 111 | LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); |
| 112 | return false; |
| 113 | } |
| 114 | |
| 115 | GnssConfig config = {}; |
| 116 | config.size = sizeof(GnssConfig); |
| 117 | config.flags = GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT; |
| 118 | config.lppProfileMask = GNSS_CONFIG_LPP_PROFILE_RRLP_ON_LTE; //default |
| 119 | |
| 120 | if (lppProfileMask & (1<<0)) { |
| 121 | config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_USER_PLANE_BIT; |
| 122 | } |
| 123 | if (lppProfileMask & (1<<1)) { |
| 124 | config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE_BIT; |
| 125 | } |
| 126 | if (lppProfileMask & (1<<2)) { |
| 127 | config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_USER_PLANE_OVER_NR5G_SA_BIT; |
| 128 | } |
| 129 | if (lppProfileMask & (1<<3)) { |
| 130 | config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE_OVER_NR5G_SA_BIT; |
| 131 | } |
| 132 | |
| 133 | return mGnss->updateConfiguration(config); |
| 134 | } |
| 135 | |
| 136 | Return<bool> GnssConfiguration::setGlonassPositioningProtocol(uint8_t protocol) { |
| 137 | if (mGnss == nullptr) { |
| 138 | LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); |
| 139 | return false; |
| 140 | } |
| 141 | |
| 142 | GnssConfig config; |
| 143 | memset(&config, 0, sizeof(GnssConfig)); |
| 144 | config.size = sizeof(GnssConfig); |
| 145 | |
| 146 | config.flags = GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT; |
| 147 | if (protocol & (1<<0)) { |
| 148 | config.aGlonassPositionProtocolMask |= GNSS_CONFIG_RRC_CONTROL_PLANE_BIT; |
| 149 | } |
| 150 | if (protocol & (1<<1)) { |
| 151 | config.aGlonassPositionProtocolMask |= GNSS_CONFIG_RRLP_USER_PLANE_BIT; |
| 152 | } |
| 153 | if (protocol & (1<<2)) { |
| 154 | config.aGlonassPositionProtocolMask |= GNSS_CONFIG_LLP_USER_PLANE_BIT; |
| 155 | } |
| 156 | if (protocol & (1<<3)) { |
| 157 | config.aGlonassPositionProtocolMask |= GNSS_CONFIG_LLP_CONTROL_PLANE_BIT; |
| 158 | } |
| 159 | |
| 160 | return mGnss->updateConfiguration(config); |
| 161 | } |
| 162 | |
| 163 | Return<bool> GnssConfiguration::setGpsLock(uint8_t lock) { |
| 164 | |
| 165 | if (mGnss == nullptr) { |
| 166 | LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); |
| 167 | return false; |
| 168 | } |
| 169 | |
| 170 | GnssConfig config = {}; |
| 171 | config.size = sizeof(GnssConfig); |
| 172 | config.flags = GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT; |
| 173 | switch (lock) { |
| 174 | case 0: |
| 175 | config.gpsLock = GNSS_CONFIG_GPS_LOCK_NONE; |
| 176 | break; |
| 177 | case 1: |
| 178 | config.gpsLock = GNSS_CONFIG_GPS_LOCK_MO; |
| 179 | break; |
| 180 | case 2: |
| 181 | config.gpsLock = GNSS_CONFIG_GPS_LOCK_NI; |
| 182 | break; |
| 183 | case 3: |
| 184 | config.gpsLock = GNSS_CONFIG_GPS_LOCK_MO_AND_NI; |
| 185 | break; |
| 186 | default: |
| 187 | LOC_LOGE("%s]: invalid lock: %d.", __FUNCTION__, lock); |
| 188 | return false; |
| 189 | } |
| 190 | |
| 191 | mGnss->updateConfiguration(config); |
| 192 | // Must return false to pass VTS |
| 193 | return false; |
| 194 | } |
| 195 | |
| 196 | Return<bool> GnssConfiguration::setEmergencySuplPdn(bool enabled) { |
| 197 | if (mGnss == nullptr) { |
| 198 | LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); |
| 199 | return false; |
| 200 | } |
| 201 | |
| 202 | GnssConfig config; |
| 203 | memset(&config, 0, sizeof(GnssConfig)); |
| 204 | config.size = sizeof(GnssConfig); |
| 205 | config.flags = GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT; |
| 206 | config.emergencyPdnForEmergencySupl = (enabled ? |
| 207 | GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_YES : |
| 208 | GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_NO); |
| 209 | |
| 210 | return mGnss->updateConfiguration(config); |
| 211 | } |
| 212 | |
| 213 | // Methods from ::android::hardware::gnss::V1_1::IGnssConfiguration follow. |
| 214 | Return<bool> GnssConfiguration::setBlacklist( |
| 215 | const hidl_vec<GnssConfiguration::BlacklistedSource>& blacklist) { |
| 216 | |
| 217 | ENTRY_LOG_CALLFLOW(); |
| 218 | if (nullptr == mGnss) { |
| 219 | LOC_LOGe("mGnss is null"); |
| 220 | return false; |
| 221 | } |
| 222 | |
| 223 | // blValid is true if blacklist is empty, i.e. clearing the BL; |
| 224 | // if blacklist is not empty, blValid is initialied to false, and later |
| 225 | // updated in the for loop to become true only if there is at least |
| 226 | // one {constellation, svid} in the list that is valid. |
| 227 | bool blValid = (0 == blacklist.size()); |
| 228 | GnssConfig config; |
| 229 | memset(&config, 0, sizeof(GnssConfig)); |
| 230 | config.size = sizeof(GnssConfig); |
| 231 | config.flags = GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT; |
| 232 | config.blacklistedSvIds.clear(); |
| 233 | |
| 234 | GnssSvIdSource source = {}; |
| 235 | for (int idx = 0; idx < (int)blacklist.size(); idx++) { |
| 236 | // Set blValid true if any one source is valid |
| 237 | blValid = setBlacklistedSource(source, blacklist[idx]) || blValid; |
| 238 | config.blacklistedSvIds.push_back(source); |
| 239 | } |
| 240 | |
| 241 | // Update configuration only if blValid is true |
| 242 | // i.e. only if atleast one source is valid for blacklisting |
| 243 | return (blValid && mGnss->updateConfiguration(config)); |
| 244 | } |
| 245 | |
| 246 | bool GnssConfiguration::setBlacklistedSource( |
| 247 | GnssSvIdSource& copyToSource, |
| 248 | const GnssConfiguration::BlacklistedSource& copyFromSource) { |
| 249 | |
| 250 | bool retVal = true; |
| 251 | uint16_t svIdOffset = 0; |
| 252 | copyToSource.size = sizeof(GnssSvIdSource); |
| 253 | copyToSource.svId = copyFromSource.svid; |
| 254 | |
| 255 | switch(copyFromSource.constellation) { |
| 256 | case GnssConstellationType::GPS: |
| 257 | copyToSource.constellation = GNSS_SV_TYPE_GPS; |
| 258 | LOC_LOGe("GPS SVs can't be blacklisted."); |
| 259 | retVal = false; |
| 260 | break; |
| 261 | case GnssConstellationType::SBAS: |
| 262 | copyToSource.constellation = GNSS_SV_TYPE_SBAS; |
| 263 | LOC_LOGe("SBAS SVs can't be blacklisted."); |
| 264 | retVal = false; |
| 265 | break; |
| 266 | case GnssConstellationType::GLONASS: |
| 267 | copyToSource.constellation = GNSS_SV_TYPE_GLONASS; |
| 268 | svIdOffset = GNSS_SV_CONFIG_GLO_INITIAL_SV_ID - 1; |
| 269 | break; |
| 270 | case GnssConstellationType::QZSS: |
| 271 | copyToSource.constellation = GNSS_SV_TYPE_QZSS; |
| 272 | svIdOffset = 0; |
| 273 | break; |
| 274 | case GnssConstellationType::BEIDOU: |
| 275 | copyToSource.constellation = GNSS_SV_TYPE_BEIDOU; |
| 276 | svIdOffset = GNSS_SV_CONFIG_BDS_INITIAL_SV_ID - 1; |
| 277 | break; |
| 278 | case GnssConstellationType::GALILEO: |
| 279 | copyToSource.constellation = GNSS_SV_TYPE_GALILEO; |
| 280 | svIdOffset = GNSS_SV_CONFIG_GAL_INITIAL_SV_ID - 1; |
| 281 | break; |
| 282 | default: |
| 283 | copyToSource.constellation = GNSS_SV_TYPE_UNKNOWN; |
| 284 | LOC_LOGe("Invalid constellation %hhu", copyFromSource.constellation); |
| 285 | retVal = false; |
| 286 | break; |
| 287 | } |
| 288 | |
| 289 | if (copyToSource.svId > 0 && svIdOffset > 0) { |
| 290 | copyToSource.svId += svIdOffset; |
| 291 | } |
| 292 | |
| 293 | return retVal; |
| 294 | } |
| 295 | |
| 296 | // Methods from ::android::hardware::gnss::V2_0::IGnssConfiguration follow. |
| 297 | Return<bool> GnssConfiguration::setEsExtensionSec(uint32_t emergencyExtensionSeconds) { |
| 298 | ENTRY_LOG_CALLFLOW(); |
| 299 | if (mGnss == nullptr) { |
| 300 | LOC_LOGe("mGnss is nullptr"); |
| 301 | return false; |
| 302 | } |
| 303 | |
| 304 | GnssConfig config; |
| 305 | memset(&config, 0, sizeof(GnssConfig)); |
| 306 | config.size = sizeof(GnssConfig); |
| 307 | config.flags = GNSS_CONFIG_FLAGS_EMERGENCY_EXTENSION_SECONDS_BIT; |
| 308 | config.emergencyExtensionSeconds = emergencyExtensionSeconds; |
| 309 | |
| 310 | return mGnss->updateConfiguration(config); |
| 311 | } |
| 312 | |
| 313 | } // namespace implementation |
| 314 | } // namespace V2_0 |
| 315 | } // namespace gnss |
| 316 | } // namespace hardware |
| 317 | } // namespace android |