diff --git a/android/GnssConfiguration.cpp b/android/GnssConfiguration.cpp index cee928ab..f52ae4bd 100644 --- a/android/GnssConfiguration.cpp +++ b/android/GnssConfiguration.cpp @@ -233,6 +233,11 @@ Return GnssConfiguration::setBlacklist( return false; } + // blValid is true if blacklist is empty, i.e. clearing the BL; + // if blacklist is not empty, blValid is initialied to false, and later + // updated in the for loop to become true only if there is at least + // one {constellation, svid} in the list that is valid. + bool blValid = (0 == blacklist.size()); GnssConfig config; memset(&config, 0, sizeof(GnssConfig)); config.size = sizeof(GnssConfig); @@ -241,25 +246,33 @@ Return GnssConfiguration::setBlacklist( GnssSvIdSource source = {}; for (int idx = 0; idx < (int)blacklist.size(); idx++) { - setBlacklistedSource(source, blacklist[idx]); + // Set blValid true if any one source is valid + blValid = setBlacklistedSource(source, blacklist[idx]) || blValid; config.blacklistedSvIds.push_back(source); } - return mGnss->updateConfiguration(config); + // Update configuration only if blValid is true + // i.e. only if atleast one source is valid for blacklisting + return (blValid && mGnss->updateConfiguration(config)); } -void GnssConfiguration::setBlacklistedSource( +bool GnssConfiguration::setBlacklistedSource( GnssSvIdSource& copyToSource, const GnssConfiguration::BlacklistedSource& copyFromSource) { + bool retVal = true; copyToSource.size = sizeof(GnssSvIdSource); switch(copyFromSource.constellation) { case GnssConstellationType::GPS: copyToSource.constellation = GNSS_SV_TYPE_GPS; + LOC_LOGe("GPS SVs can't be blacklisted."); + retVal = false; break; case GnssConstellationType::SBAS: copyToSource.constellation = GNSS_SV_TYPE_SBAS; + LOC_LOGe("SBAS SVs can't be blacklisted."); + retVal = false; break; case GnssConstellationType::GLONASS: copyToSource.constellation = GNSS_SV_TYPE_GLONASS; @@ -275,10 +288,13 @@ void GnssConfiguration::setBlacklistedSource( break; default: copyToSource.constellation = GNSS_SV_TYPE_UNKNOWN; + LOC_LOGe("Invalid constellation %d", copyFromSource.constellation); + retVal = false; break; } copyToSource.svId = copyFromSource.svid; + return retVal; } } // namespace implementation diff --git a/android/GnssConfiguration.h b/android/GnssConfiguration.h index 15ee2906..96681b61 100644 --- a/android/GnssConfiguration.h +++ b/android/GnssConfiguration.h @@ -64,7 +64,7 @@ struct GnssConfiguration : public IGnssConfiguration { private: Gnss* mGnss = nullptr; - void setBlacklistedSource( + bool setBlacklistedSource( GnssSvIdSource& copyToSource, const GnssConfiguration::BlacklistedSource& copyFromSource); }; diff --git a/gnss/GnssAdapter.cpp b/gnss/GnssAdapter.cpp index f3c7d5e2..90e1a50f 100644 --- a/gnss/GnssAdapter.cpp +++ b/gnss/GnssAdapter.cpp @@ -1101,10 +1101,14 @@ GnssAdapter::gnssSvIdConfigUpdate(const std::vector& blacklisted memset(&mGnssSvIdConfig, 0, sizeof(GnssSvIdConfig)); // Convert the sv id lists to masks - convertToGnssSvIdConfig(blacklistedSvIds, mGnssSvIdConfig); + bool convertSuccess = convertToGnssSvIdConfig(blacklistedSvIds, mGnssSvIdConfig); - // Now send to Modem - gnssSvIdConfigUpdate(); + // Now send to Modem if conversion successful + if (convertSuccess) { + gnssSvIdConfigUpdate(); + } else { + LOC_LOGe("convertToGnssSvIdConfig failed"); + } } void @@ -1288,10 +1292,11 @@ GnssAdapter::gnssGetConfigCommand(GnssConfigFlagsMask configMask) { return ids; } -void +bool GnssAdapter::convertToGnssSvIdConfig( const std::vector& blacklistedSvIds, GnssSvIdConfig& config) { + bool retVal = false; config.size = sizeof(GnssSvIdConfig); // Empty vector => Clear any previous blacklisted SVs @@ -1300,6 +1305,7 @@ GnssAdapter::convertToGnssSvIdConfig( config.bdsBlacklistSvMask = 0; config.qzssBlacklistSvMask = 0; config.galBlacklistSvMask = 0; + retVal = true; } else { // Parse the vector and convert SV IDs to mask values for (GnssSvIdSource source : blacklistedSvIds) { @@ -1340,7 +1346,17 @@ GnssAdapter::convertToGnssSvIdConfig( } } } + + // Return true if any one source is valid + if (0 != config.gloBlacklistSvMask || + 0 != config.bdsBlacklistSvMask || + 0 != config.galBlacklistSvMask || + 0 != config.qzssBlacklistSvMask) { + retVal = true; + } } + + return retVal; } void GnssAdapter::convertFromGnssSvIdConfig( diff --git a/gnss/GnssAdapter.h b/gnss/GnssAdapter.h index 7fbaf9cc..ad556877 100644 --- a/gnss/GnssAdapter.h +++ b/gnss/GnssAdapter.h @@ -327,7 +327,7 @@ public: static void convertSatelliteInfo(std::vector& out, const GnssSvType& in_constellation, const SystemStatusReports& in); - static void convertToGnssSvIdConfig( + static bool convertToGnssSvIdConfig( const std::vector& blacklistedSvIds, GnssSvIdConfig& config); static void convertFromGnssSvIdConfig( const GnssSvIdConfig& svConfig, GnssConfig& config);