From d93bf85e1e8cc55588e37093a33f723ce897bf46 Mon Sep 17 00:00:00 2001 From: Yu-Han Yang Date: Fri, 1 Nov 2024 01:26:10 +0000 Subject: [PATCH] Do not blocklist BDS on CN builds Bug: 354865513 Test: atest VtsHalGnssTargetTest (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:ac8419a655af4066e5a667636acd5115a69440c0) Merged-In: Idb2addc4200c99f3cf8944982ad7e5b50930a786 Change-Id: Idb2addc4200c99f3cf8944982ad7e5b50930a786 --- gnss/aidl/vts/gnss_hal_test.cpp | 32 ++++++++++++++++++--------- gnss/aidl/vts/gnss_hal_test.h | 6 ++--- gnss/aidl/vts/gnss_hal_test_cases.cpp | 24 ++++++++++---------- gnss/common/utils/vts/Utils.cpp | 18 +++++++++++++++ gnss/common/utils/vts/include/Utils.h | 5 +++++ 5 files changed, 60 insertions(+), 25 deletions(-) diff --git a/gnss/aidl/vts/gnss_hal_test.cpp b/gnss/aidl/vts/gnss_hal_test.cpp index 31e6536801..0dd8b32cf1 100644 --- a/gnss/aidl/vts/gnss_hal_test.cpp +++ b/gnss/aidl/vts/gnss_hal_test.cpp @@ -276,29 +276,35 @@ std::list> GnssHalTest::convertToAidl( } /* - * FindStrongFrequentNonGpsSource: + * FindStrongFrequentBlockableSource: * - * Search through a GnssSvStatus list for the strongest non-GPS satellite observed enough times + * Search through a GnssSvStatus list for the strongest blockable satellite observed enough times * * returns the strongest source, * or a source with constellation == UNKNOWN if none are found sufficient times */ -BlocklistedSource GnssHalTest::FindStrongFrequentNonGpsSource( +BlocklistedSource GnssHalTest::FindStrongFrequentBlockableSource( const std::list> sv_info_list, const int min_observations) { - return FindStrongFrequentNonGpsSource(convertToAidl(sv_info_list), min_observations); + return FindStrongFrequentBlockableSource(convertToAidl(sv_info_list), min_observations); } -BlocklistedSource GnssHalTest::FindStrongFrequentNonGpsSource( +BlocklistedSource GnssHalTest::FindStrongFrequentBlockableSource( const std::list> sv_info_list, const int min_observations) { std::map mapSignals; + bool isCnBuild = Utils::isCnBuild(); + ALOGD("isCnBuild: %s", isCnBuild ? "true" : "false"); for (const auto& sv_info_vec : sv_info_list) { for (uint32_t iSv = 0; iSv < sv_info_vec.size(); iSv++) { const auto& gnss_sv = sv_info_vec[iSv]; if ((gnss_sv.svFlag & (int)IGnssCallback::GnssSvFlags::USED_IN_FIX) && (gnss_sv.constellation != GnssConstellationType::GPS)) { + if (isCnBuild && (gnss_sv.constellation == GnssConstellationType::BEIDOU)) { + // Do not blocklist BDS on CN builds + continue; + } ComparableBlocklistedSource source; source.id.svid = gnss_sv.svid; source.id.constellation = gnss_sv.constellation; @@ -343,7 +349,7 @@ BlocklistedSource GnssHalTest::FindStrongFrequentNonGpsSource( return source_to_blocklist.id; } -GnssConstellationType GnssHalTest::startLocationAndGetNonGpsConstellation( +GnssConstellationType GnssHalTest::startLocationAndGetBlockableConstellation( const int locations_to_await, const int gnss_sv_info_list_timeout) { if (aidl_gnss_hal_->getInterfaceVersion() <= 1) { return static_cast( @@ -360,7 +366,9 @@ GnssConstellationType GnssHalTest::startLocationAndGetNonGpsConstellation( ALOGD("Observed %d GnssSvInfo, while awaiting %d Locations (%d received)", sv_info_list_cbq_size, locations_to_await, location_called_count); - // Find first non-GPS constellation to blocklist + bool isCnBuild = Utils::isCnBuild(); + ALOGD("isCnBuild: %s", isCnBuild ? "true" : "false"); + // Find first blockable constellation to blocklist GnssConstellationType constellation_to_blocklist = GnssConstellationType::UNKNOWN; for (int i = 0; i < sv_info_list_cbq_size; ++i) { std::vector sv_info_vec; @@ -370,7 +378,11 @@ GnssConstellationType GnssHalTest::startLocationAndGetNonGpsConstellation( if ((gnss_sv.svFlag & (uint32_t)IGnssCallback::GnssSvFlags::USED_IN_FIX) && (gnss_sv.constellation != GnssConstellationType::UNKNOWN) && (gnss_sv.constellation != GnssConstellationType::GPS)) { - // found a non-GPS constellation + if (isCnBuild && (gnss_sv.constellation == GnssConstellationType::BEIDOU)) { + // Do not blocklist BDS on CN builds + continue; + } + // found a blockable constellation constellation_to_blocklist = gnss_sv.constellation; break; } @@ -381,11 +393,11 @@ GnssConstellationType GnssHalTest::startLocationAndGetNonGpsConstellation( } if (constellation_to_blocklist == GnssConstellationType::UNKNOWN) { - ALOGI("No non-GPS constellations found, constellation blocklist test less effective."); + ALOGI("No blockable constellations found, constellation blocklist test less effective."); // Proceed functionally to blocklist something. constellation_to_blocklist = GnssConstellationType::GLONASS; } - + ALOGD("Constellation to blocklist: %d", constellation_to_blocklist); return constellation_to_blocklist; } diff --git a/gnss/aidl/vts/gnss_hal_test.h b/gnss/aidl/vts/gnss_hal_test.h index 88d01c1769..dec58560fc 100644 --- a/gnss/aidl/vts/gnss_hal_test.h +++ b/gnss/aidl/vts/gnss_hal_test.h @@ -76,16 +76,16 @@ class GnssHalTest : public android::hardware::gnss::common::GnssHalTestTemplate< void StartAndCheckLocations(const int count); void StartAndCheckLocations(const int count, const bool start_sv_status, const bool start_nmea); - android::hardware::gnss::GnssConstellationType startLocationAndGetNonGpsConstellation( + android::hardware::gnss::GnssConstellationType startLocationAndGetBlockableConstellation( const int locations_to_await, const int gnss_sv_info_list_timeout); std::list> convertToAidl( const std::list>& sv_info_list); - android::hardware::gnss::BlocklistedSource FindStrongFrequentNonGpsSource( + android::hardware::gnss::BlocklistedSource FindStrongFrequentBlockableSource( const std::list> sv_info_list, const int min_observations); - android::hardware::gnss::BlocklistedSource FindStrongFrequentNonGpsSource( + android::hardware::gnss::BlocklistedSource FindStrongFrequentBlockableSource( const std::list> sv_info_list, const int min_observations); diff --git a/gnss/aidl/vts/gnss_hal_test_cases.cpp b/gnss/aidl/vts/gnss_hal_test_cases.cpp index 8abf7ab8ef..e4890a778e 100644 --- a/gnss/aidl/vts/gnss_hal_test_cases.cpp +++ b/gnss/aidl/vts/gnss_hal_test_cases.cpp @@ -665,19 +665,19 @@ TEST_P(GnssHalTest, BlocklistIndividualSatellites) { kGnssSvInfoListTimeout); ASSERT_EQ(count, sv_info_list_cbq_size); source_to_blocklist = - FindStrongFrequentNonGpsSource(sv_info_vec_list, kLocationsToAwait - 1); + FindStrongFrequentBlockableSource(sv_info_vec_list, kLocationsToAwait - 1); } else { std::list> sv_info_vec_list; int count = aidl_gnss_cb_->sv_info_list_cbq_.retrieve( sv_info_vec_list, sv_info_list_cbq_size, kGnssSvInfoListTimeout); ASSERT_EQ(count, sv_info_list_cbq_size); source_to_blocklist = - FindStrongFrequentNonGpsSource(sv_info_vec_list, kLocationsToAwait - 1); + FindStrongFrequentBlockableSource(sv_info_vec_list, kLocationsToAwait - 1); } if (source_to_blocklist.constellation == GnssConstellationType::UNKNOWN) { - // Cannot find a non-GPS satellite. Let the test pass. - ALOGD("Cannot find a non-GPS satellite. Letting the test pass."); + // Cannot find a blockable satellite. Let the test pass. + ALOGD("Cannot find a blockable satellite. Letting the test pass."); return; } @@ -824,8 +824,8 @@ TEST_P(GnssHalTest, BlocklistIndividualSatellites) { * BlocklistConstellationLocationOff: * * 1) Turns on location, waits for 3 locations, ensuring they are valid, and checks corresponding - * GnssStatus for any non-GPS constellations. - * 2a & b) Turns off location, and blocklist first non-GPS constellations. + * GnssStatus for any blockable constellations. + * 2a & b) Turns off location, and blocklist first blockable constellations. * 3) Restart location, wait for 3 locations, ensuring they are valid, and checks corresponding * GnssStatus does not use any constellation but GPS. * 4a & b) Clean up by turning off location, and send in empty blocklist. @@ -841,9 +841,9 @@ TEST_P(GnssHalTest, BlocklistConstellationLocationOff) { const int kLocationsToAwait = 3; const int kGnssSvInfoListTimeout = 2; - // Find first non-GPS constellation to blocklist + // Find first blockable constellation to blocklist GnssConstellationType constellation_to_blocklist = static_cast( - startLocationAndGetNonGpsConstellation(kLocationsToAwait, kGnssSvInfoListTimeout)); + startLocationAndGetBlockableConstellation(kLocationsToAwait, kGnssSvInfoListTimeout)); // Turns off location StopAndClearLocations(); @@ -927,8 +927,8 @@ TEST_P(GnssHalTest, BlocklistConstellationLocationOff) { * BlocklistConstellationLocationOn: * * 1) Turns on location, waits for 3 locations, ensuring they are valid, and checks corresponding - * GnssStatus for any non-GPS constellations. - * 2a & b) Blocklist first non-GPS constellation, and turn off location. + * GnssStatus for any blockable constellations. + * 2a & b) Blocklist first blockable constellation, and turn off location. * 3) Restart location, wait for 3 locations, ensuring they are valid, and checks corresponding * GnssStatus does not use any constellation but GPS. * 4a & b) Clean up by turning off location, and send in empty blocklist. @@ -944,9 +944,9 @@ TEST_P(GnssHalTest, BlocklistConstellationLocationOn) { const int kLocationsToAwait = 3; const int kGnssSvInfoListTimeout = 2; - // Find first non-GPS constellation to blocklist + // Find first blockable constellation to blocklist GnssConstellationType constellation_to_blocklist = static_cast( - startLocationAndGetNonGpsConstellation(kLocationsToAwait, kGnssSvInfoListTimeout)); + startLocationAndGetBlockableConstellation(kLocationsToAwait, kGnssSvInfoListTimeout)); BlocklistedSource source_to_blocklist_1; source_to_blocklist_1.constellation = constellation_to_blocklist; diff --git a/gnss/common/utils/vts/Utils.cpp b/gnss/common/utils/vts/Utils.cpp index e3ff0f3d24..38afaf3791 100644 --- a/gnss/common/utils/vts/Utils.cpp +++ b/gnss/common/utils/vts/Utils.cpp @@ -319,6 +319,24 @@ double Utils::distanceMeters(double lat1, double lon1, double lat2, double lon2) return d * 1000; // meters } +// Returns true iff the device has the specified feature. +bool Utils::deviceSupportsFeature(const char* feature) { + bool device_supports_feature = false; + FILE* p = popen("/system/bin/pm list features", "re"); + if (p) { + char* line = NULL; + size_t len = 0; + while (getline(&line, &len, p) > 0) { + if (strstr(line, feature)) { + device_supports_feature = true; + break; + } + } + pclose(p); + } + return device_supports_feature; +} + } // namespace common } // namespace gnss } // namespace hardware diff --git a/gnss/common/utils/vts/include/Utils.h b/gnss/common/utils/vts/include/Utils.h index 62d409ac66..09b99c444a 100644 --- a/gnss/common/utils/vts/include/Utils.h +++ b/gnss/common/utils/vts/include/Utils.h @@ -60,6 +60,11 @@ struct Utils { static bool isAutomotiveDevice(); static double distanceMeters(double lat1, double lon1, double lat2, double lon2); + // Returns true iff the device has the specified feature. + static bool deviceSupportsFeature(const char* feature); + + static bool isCnBuild() { return deviceSupportsFeature("cn.google.services"); } + private: template static int64_t getLocationTimestampMillis(const T&);