Commit 64b3ce15 authored by Jordy Greenblatt's avatar Jordy Greenblatt Committed by Commit Bot

[CrOS Tether] Allow tests to ignore ethernet during tether host scan

As we try to add new e2e tethering tests, we need a way to make the
host scan occur normally even when there is an ethernet connection
because there's always an ethernet connection to deploy the test.

This CL creates the infrastructure necessary to create a flag to
override the prohibition against searching for a tethering host with an
ethernet connection by gating it on booleans called
ignore_wired_networks_

-----

Testing:

I manually tested that this change causes the tethering notification to
appear when the user logs in with an ethernet connection but no wifi
connection. For comparison, I also tested that logging in with a wifi
network does not cause the notification to appear.

Bug: 904609
Change-Id: I7406274cd159ae2b18ad6a22ca90cba76b98dbad
Reviewed-on: https://chromium-review.googlesource.com/c/1332693
Commit-Queue: Jordy Greenblatt <jordynass@chromium.org>
Reviewed-by: default avatarJeremy Klein <jlklein@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607461}
parent 7bee38bd
......@@ -62,6 +62,7 @@ HostScanSchedulerImpl::HostScanSchedulerImpl(
delay_scan_after_unlock_timer_(std::make_unique<base::OneShotTimer>()),
clock_(base::DefaultClock::GetInstance()),
task_runner_(base::ThreadTaskRunnerHandle::Get()),
ignore_wired_networks_(false),
is_screen_locked_(session_manager_->IsScreenLocked()),
weak_ptr_factory_(this) {
network_state_handler_->AddObserver(this, FROM_HERE);
......@@ -90,9 +91,11 @@ HostScanSchedulerImpl::~HostScanSchedulerImpl() {
}
void HostScanSchedulerImpl::AttemptScanIfOffline() {
const chromeos::NetworkTypePattern network_type_pattern =
ignore_wired_networks_ ? chromeos::NetworkTypePattern::Wireless()
: chromeos::NetworkTypePattern::Default();
const chromeos::NetworkState* first_network =
network_state_handler_->FirstNetworkByType(
chromeos::NetworkTypePattern::Default());
network_state_handler_->FirstNetworkByType(network_type_pattern);
if (IsOnlineOrHasActiveTetherConnection(first_network)) {
PA_LOG(VERBOSE) << "Skipping scan attempt because the device is already "
"connected to a network.";
......@@ -103,8 +106,8 @@ void HostScanSchedulerImpl::AttemptScanIfOffline() {
}
void HostScanSchedulerImpl::DefaultNetworkChanged(const NetworkState* network) {
// If there is an active (i.e., connecting or connected) network, there is no
// need to schedule a scan.
// If there is an active (i.e., connecting or connected) network, there is
// no need to schedule a scan.
if (IsOnlineOrHasActiveTetherConnection(network)) {
return;
}
......@@ -112,7 +115,8 @@ void HostScanSchedulerImpl::DefaultNetworkChanged(const NetworkState* network) {
// Schedule a scan as part of a new task. Posting a task here ensures that
// processing the default network change is done after other
// NetworkStateHandlerObservers are finished running. Processing the
// network change immediately can cause crashes; see https://crbug.com/800370.
// network change immediately can cause crashes; see
// https://crbug.com/800370.
task_runner_->PostTask(FROM_HERE,
base::BindOnce(&HostScanSchedulerImpl::AttemptScan,
weak_ptr_factory_.GetWeakPtr()));
......@@ -148,8 +152,8 @@ void HostScanSchedulerImpl::OnSessionStateChanged() {
if (!was_screen_locked)
return;
// If the device was just unlocked, start a scan if not already connected to a
// network.
// If the device was just unlocked, start a scan if not already connected to
// a network.
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
AttemptScanIfOffline();
} else {
......
......@@ -87,6 +87,10 @@ class HostScanSchedulerImpl : public HostScanScheduler,
base::Time last_scan_batch_start_timestamp_;
base::Time last_scan_end_timestamp_;
// TODO(crbug.com/904609): Read ignore_wired_networks_ from flag defaulting to
// false. Scan for tethering hosts even if there is a wired connection to
// allow end-to-end tests to be deployed and run without unplugging ethernet.
bool ignore_wired_networks_;
bool is_screen_locked_;
base::WeakPtrFactory<HostScanSchedulerImpl> weak_ptr_factory_;
......
......@@ -268,12 +268,14 @@ bool HostScannerImpl::IsPotentialHotspotNotificationShowing() {
}
bool HostScannerImpl::CanAvailableHostNotificationBeShown() {
const chromeos::NetworkTypePattern network_type_pattern =
ignore_wired_networks_ ? chromeos::NetworkTypePattern::Wireless()
: chromeos::NetworkTypePattern::Default();
// Note: If a network is active (i.e., connecting or connected), it will be
// returned at the front of the list, so using FirstNetworkByType() guarantees
// that we will find an active network if there is one.
const chromeos::NetworkState* first_network =
network_state_handler_->FirstNetworkByType(
chromeos::NetworkTypePattern::Default());
network_state_handler_->FirstNetworkByType(network_type_pattern);
if (first_network && first_network->IsConnectingOrConnected()) {
// If a network is connecting or connected, the notification should not be
// shown.
......
......@@ -132,6 +132,10 @@ class HostScannerImpl : public HostScanner,
ConnectionPreserver* connection_preserver_;
base::Clock* clock_;
// TODO(crbug.com/904609): Read ignore_wired_networks_ from flag defaulting to
// false. Scan for tethering hosts even if there is a wired connection to
// allow end-to-end tests to be deployed and run without unplugging ethernet.
bool ignore_wired_networks_ = false;
bool is_fetching_hosts_ = false;
bool was_notification_showing_when_current_scan_started_ = false;
bool was_notification_shown_in_current_scan_ = false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment