Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2ef9ab38 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Do not blocklist BDS on CN builds" into main

parents 3082048d ac8419a6
Loading
Loading
Loading
Loading
+22 −10
Original line number Diff line number Diff line
@@ -276,29 +276,35 @@ std::list<std::vector<IGnssCallback::GnssSvInfo>> 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<hidl_vec<IGnssCallback_2_1::GnssSvInfo>> 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<std::vector<IGnssCallback::GnssSvInfo>> sv_info_list,
        const int min_observations) {
    std::map<ComparableBlocklistedSource, SignalCounts> 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<GnssConstellationType>(
@@ -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<IGnssCallback::GnssSvInfo> 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;
}

+3 −3
Original line number Diff line number Diff line
@@ -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<std::vector<android::hardware::gnss::IGnssCallback::GnssSvInfo>> convertToAidl(
            const std::list<hidl_vec<android::hardware::gnss::V2_1::IGnssCallback::GnssSvInfo>>&
                    sv_info_list);
    android::hardware::gnss::BlocklistedSource FindStrongFrequentNonGpsSource(
    android::hardware::gnss::BlocklistedSource FindStrongFrequentBlockableSource(
            const std::list<hidl_vec<android::hardware::gnss::V2_1::IGnssCallback::GnssSvInfo>>
                    sv_info_list,
            const int min_observations);
    android::hardware::gnss::BlocklistedSource FindStrongFrequentNonGpsSource(
    android::hardware::gnss::BlocklistedSource FindStrongFrequentBlockableSource(
            const std::list<std::vector<android::hardware::gnss::IGnssCallback::GnssSvInfo>>
                    sv_info_list,
            const int min_observations);
+12 −12
Original line number Diff line number Diff line
@@ -657,19 +657,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<std::vector<IGnssCallback::GnssSvInfo>> 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;
    }

@@ -816,8 +816,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.
@@ -833,9 +833,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<GnssConstellationType>(
            startLocationAndGetNonGpsConstellation(kLocationsToAwait, kGnssSvInfoListTimeout));
            startLocationAndGetBlockableConstellation(kLocationsToAwait, kGnssSvInfoListTimeout));

    // Turns off location
    StopAndClearLocations();
@@ -919,8 +919,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.
@@ -936,9 +936,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<GnssConstellationType>(
            startLocationAndGetNonGpsConstellation(kLocationsToAwait, kGnssSvInfoListTimeout));
            startLocationAndGetBlockableConstellation(kLocationsToAwait, kGnssSvInfoListTimeout));

    BlocklistedSource source_to_blocklist_1;
    source_to_blocklist_1.constellation = constellation_to_blocklist;
+18 −0
Original line number Diff line number Diff line
@@ -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
+5 −0
Original line number Diff line number Diff line
@@ -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 <class T>
    static int64_t getLocationTimestampMillis(const T&);