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

Commit 4423533c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add test to setBlacklist with location on"

parents 82bf9e83 9c451cfb
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -148,6 +148,47 @@ void GnssHalTest::StartAndCheckLocations(int count) {
    }
}

GnssConstellationType GnssHalTest::startLocationAndGetNonGpsConstellation(
        const int locations_to_await, const int gnss_sv_info_list_timeout) {
    gnss_cb_->location_cbq_.reset();
    StartAndCheckLocations(locations_to_await);
    const int location_called_count = gnss_cb_->location_cbq_.calledCount();

    // Tolerate 1 less sv status to handle edge cases in reporting.
    int sv_info_list_cbq_size = gnss_cb_->sv_info_list_cbq_.size();
    EXPECT_GE(sv_info_list_cbq_size + 1, locations_to_await);
    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 blacklist
    GnssConstellationType constellation_to_blacklist = GnssConstellationType::UNKNOWN;
    for (int i = 0; i < sv_info_list_cbq_size; ++i) {
        hidl_vec<IGnssCallback_2_1::GnssSvInfo> sv_info_vec;
        gnss_cb_->sv_info_list_cbq_.retrieve(sv_info_vec, gnss_sv_info_list_timeout);
        for (uint32_t iSv = 0; iSv < sv_info_vec.size(); iSv++) {
            const auto& gnss_sv = sv_info_vec[iSv];
            if ((gnss_sv.v2_0.v1_0.svFlag & IGnssCallback_1_0::GnssSvFlags::USED_IN_FIX) &&
                (gnss_sv.v2_0.constellation != GnssConstellationType::UNKNOWN) &&
                (gnss_sv.v2_0.constellation != GnssConstellationType::GPS)) {
                // found a non-GPS constellation
                constellation_to_blacklist = gnss_sv.v2_0.constellation;
                break;
            }
        }
        if (constellation_to_blacklist != GnssConstellationType::UNKNOWN) {
            break;
        }
    }

    if (constellation_to_blacklist == GnssConstellationType::UNKNOWN) {
        ALOGI("No non-GPS constellations found, constellation blacklist test less effective.");
        // Proceed functionally to blacklist something.
        constellation_to_blacklist = GnssConstellationType::GLONASS;
    }

    return constellation_to_blacklist;
}

GnssHalTest::GnssCallback::GnssCallback()
    : info_cbq_("system_info"),
      name_cbq_("name"),
+12 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ using android::hardware::Void;

using android::hardware::gnss::common::GnssCallbackEventQueue;
using android::hardware::gnss::V1_0::GnssLocationFlags;
using android::hardware::gnss::V2_0::GnssConstellationType;
using android::hardware::gnss::V2_1::IGnss;

using GnssLocation_1_0 = android::hardware::gnss::V1_0::GnssLocation;
@@ -184,6 +185,17 @@ class GnssHalTest : public testing::TestWithParam<std::string> {
     */
    void SetPositionMode(const int min_interval_msec, const bool low_power_mode);

    /*
     * startLocationAndGetNonGpsConstellation:
     * 1. Start location
     * 2. Find and return first non-GPS constellation
     *
     * Note that location is not stopped in this method. The client should call
     * StopAndClearLocations() after the call.
     */
    GnssConstellationType startLocationAndGetNonGpsConstellation(
            const int locations_to_await, const int gnss_sv_info_list_timeout);

    sp<IGnss> gnss_hal_;        // GNSS HAL to call into
    sp<GnssCallback> gnss_cb_;  // Primary callback interface
};
+71 −26
Original line number Diff line number Diff line
@@ -384,7 +384,7 @@ TEST_P(GnssHalTest, BlacklistIndividualSatellites) {
}

/*
 * BlacklistConstellation:
 * BlacklistConstellationLocationOff:
 *
 * 1) Turns on location, waits for 3 locations, ensuring they are valid, and checks corresponding
 * GnssStatus for any non-GPS constellations.
@@ -393,48 +393,90 @@ TEST_P(GnssHalTest, BlacklistIndividualSatellites) {
 * GnssStatus does not use any constellation but GPS.
 * 4a & b) Clean up by turning off location, and send in empty blacklist.
 */
TEST_P(GnssHalTest, BlacklistConstellation) {
TEST_P(GnssHalTest, BlacklistConstellationLocationOff) {
    const int kLocationsToAwait = 3;
    const int kGnssSvInfoListTimeout = 2;

    // Find first non-GPS constellation to blacklist
    GnssConstellationType constellation_to_blacklist =
            startLocationAndGetNonGpsConstellation(kLocationsToAwait, kGnssSvInfoListTimeout);

    // Turns off location
    StopAndClearLocations();

    IGnssConfiguration::BlacklistedSource source_to_blacklist_1;
    source_to_blacklist_1.constellation = constellation_to_blacklist;
    source_to_blacklist_1.svid = 0;  // documented wildcard for all satellites in this constellation

    // IRNSS was added in 2.0. Always attempt to blacklist IRNSS to verify that the new enum is
    // supported.
    IGnssConfiguration::BlacklistedSource source_to_blacklist_2;
    source_to_blacklist_2.constellation = GnssConstellationType::IRNSS;
    source_to_blacklist_2.svid = 0;  // documented wildcard for all satellites in this constellation

    auto gnss_configuration_hal_return = gnss_hal_->getExtensionGnssConfiguration_2_1();
    ASSERT_TRUE(gnss_configuration_hal_return.isOk());
    sp<IGnssConfiguration> gnss_configuration_hal = gnss_configuration_hal_return;
    ASSERT_NE(gnss_configuration_hal, nullptr);

    hidl_vec<IGnssConfiguration::BlacklistedSource> sources;
    sources.resize(2);
    sources[0] = source_to_blacklist_1;
    sources[1] = source_to_blacklist_2;

    auto result = gnss_configuration_hal->setBlacklist_2_1(sources);
    ASSERT_TRUE(result.isOk());
    EXPECT_TRUE(result);

    // retry and ensure constellation not used
    gnss_cb_->sv_info_list_cbq_.reset();

    gnss_cb_->location_cbq_.reset();
    StartAndCheckLocations(kLocationsToAwait);
    const int location_called_count = gnss_cb_->location_cbq_.calledCount();

    // Tolerate 1 less sv status to handle edge cases in reporting.
    int sv_info_list_cbq_size = gnss_cb_->sv_info_list_cbq_.size();
    EXPECT_GE(sv_info_list_cbq_size + 1, kLocationsToAwait);
    ALOGD("Observed %d GnssSvInfo, while awaiting %d Locations (%d received)",
          sv_info_list_cbq_size, kLocationsToAwait, location_called_count);

    // Find first non-GPS constellation to blacklist
    const int kGnssSvInfoListTimeout = 2;
    GnssConstellationType constellation_to_blacklist = GnssConstellationType::UNKNOWN;
    ALOGD("Observed %d GnssSvInfo, while awaiting %d Locations", sv_info_list_cbq_size,
          kLocationsToAwait);
    for (int i = 0; i < sv_info_list_cbq_size; ++i) {
        hidl_vec<IGnssCallback_2_1::GnssSvInfo> sv_info_vec;
        gnss_cb_->sv_info_list_cbq_.retrieve(sv_info_vec, kGnssSvInfoListTimeout);
        for (uint32_t iSv = 0; iSv < sv_info_vec.size(); iSv++) {
            const auto& gnss_sv = sv_info_vec[iSv];
            if ((gnss_sv.v2_0.v1_0.svFlag & IGnssCallback_1_0::GnssSvFlags::USED_IN_FIX) &&
                (gnss_sv.v2_0.constellation != GnssConstellationType::UNKNOWN) &&
                (gnss_sv.v2_0.constellation != GnssConstellationType::GPS)) {
                // found a non-GPS constellation
                constellation_to_blacklist = gnss_sv.v2_0.constellation;
                break;
            }
        }
        if (constellation_to_blacklist != GnssConstellationType::UNKNOWN) {
            break;
            EXPECT_FALSE((gnss_sv.v2_0.constellation == source_to_blacklist_1.constellation) &&
                         (gnss_sv.v2_0.v1_0.svFlag & IGnssCallback_1_0::GnssSvFlags::USED_IN_FIX));
            EXPECT_FALSE((gnss_sv.v2_0.constellation == source_to_blacklist_2.constellation) &&
                         (gnss_sv.v2_0.v1_0.svFlag & IGnssCallback_1_0::GnssSvFlags::USED_IN_FIX));
        }
    }

    // Turns off location
    // clean up
    StopAndClearLocations();

    if (constellation_to_blacklist == GnssConstellationType::UNKNOWN) {
        ALOGI("No non-GPS constellations found, constellation blacklist test less effective.");
        // Proceed functionally to blacklist something.
        constellation_to_blacklist = GnssConstellationType::GLONASS;
    sources.resize(0);
    result = gnss_configuration_hal->setBlacklist_2_1(sources);
    ASSERT_TRUE(result.isOk());
    EXPECT_TRUE(result);
}

/*
 * BlacklistConstellationLocationOn:
 *
 * 1) Turns on location, waits for 3 locations, ensuring they are valid, and checks corresponding
 * GnssStatus for any non-GPS constellations.
 * 2a & b) Blacklist first non-GPS 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 blacklist.
 */
TEST_P(GnssHalTest, BlacklistConstellationLocationOn) {
    const int kLocationsToAwait = 3;
    const int kGnssSvInfoListTimeout = 2;

    // Find first non-GPS constellation to blacklist
    GnssConstellationType constellation_to_blacklist =
            startLocationAndGetNonGpsConstellation(kLocationsToAwait, kGnssSvInfoListTimeout);

    IGnssConfiguration::BlacklistedSource source_to_blacklist_1;
    source_to_blacklist_1.constellation = constellation_to_blacklist;
    source_to_blacklist_1.svid = 0;  // documented wildcard for all satellites in this constellation
@@ -459,6 +501,9 @@ TEST_P(GnssHalTest, BlacklistConstellation) {
    ASSERT_TRUE(result.isOk());
    EXPECT_TRUE(result);

    // Turns off location
    StopAndClearLocations();

    // retry and ensure constellation not used
    gnss_cb_->sv_info_list_cbq_.reset();

@@ -466,7 +511,7 @@ TEST_P(GnssHalTest, BlacklistConstellation) {
    StartAndCheckLocations(kLocationsToAwait);

    // Tolerate 1 less sv status to handle edge cases in reporting.
    sv_info_list_cbq_size = gnss_cb_->sv_info_list_cbq_.size();
    int sv_info_list_cbq_size = gnss_cb_->sv_info_list_cbq_.size();
    EXPECT_GE(sv_info_list_cbq_size + 1, kLocationsToAwait);
    ALOGD("Observed %d GnssSvInfo, while awaiting %d Locations", sv_info_list_cbq_size,
          kLocationsToAwait);