Commit e602d3a8 authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS Tether] Do not perform host scans while the device is locked.

EasyUnlock tries to create Bluetooth connections at the lock screen, and
when both Instant Tethering and EasyUnlock try to create a Bluetooth
connection to the same device at the same time, they can cause
instability. By eliminating the possibility of this conflict, we work
around this issue.

Note that a full-fledged fix for this problem is in the works; see
https://crbug.com/752273.

Bug: 839522
Change-Id: I468515579ca46cabf279e11531ca489a71eb3255
Reviewed-on: https://chromium-review.googlesource.com/1045254
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarJames Hawkins <jhawkins@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556282}
parent e40dd636
......@@ -86,7 +86,7 @@ HostScanSchedulerImpl::~HostScanSchedulerImpl() {
}
void HostScanSchedulerImpl::ScheduleScan() {
EnsureScan();
AttemptScan();
}
void HostScanSchedulerImpl::DefaultNetworkChanged(const NetworkState* network) {
......@@ -102,12 +102,12 @@ void HostScanSchedulerImpl::DefaultNetworkChanged(const NetworkState* network) {
// NetworkStateHandlerObservers are finished running. Processing the
// network change immediately can cause crashes; see https://crbug.com/800370.
task_runner_->PostTask(FROM_HERE,
base::BindOnce(&HostScanSchedulerImpl::EnsureScan,
base::BindOnce(&HostScanSchedulerImpl::AttemptScan,
weak_ptr_factory_.GetWeakPtr()));
}
void HostScanSchedulerImpl::ScanRequested() {
EnsureScan();
AttemptScan();
}
void HostScanSchedulerImpl::ScanFinished() {
......@@ -142,7 +142,7 @@ void HostScanSchedulerImpl::OnSessionStateChanged() {
delay_scan_after_unlock_timer_->Start(
FROM_HERE,
base::TimeDelta::FromSeconds(kNumSecondsToDelayScanAfterUnlock),
base::Bind(&HostScanSchedulerImpl::EnsureScan,
base::Bind(&HostScanSchedulerImpl::AttemptScan,
weak_ptr_factory_.GetWeakPtr()));
}
......@@ -158,10 +158,18 @@ void HostScanSchedulerImpl::SetTestDoubles(
task_runner_ = test_task_runner;
}
void HostScanSchedulerImpl::EnsureScan() {
void HostScanSchedulerImpl::AttemptScan() {
// If already scanning, there is nothing to do.
if (host_scanner_->IsScanActive())
return;
// If the screen is locked, a host scan should not occur. A scan during the
// lock screen could cause bad interactions with EasyUnlock. See
// https://crbug.com/763604.
// Note: Once the SecureChannel API is available, this check can be removed.
if (session_manager_->IsScreenLocked())
return;
// If the timer is running, this new scan is part of the same batch as the
// previous scan, so the timer should be stopped (it will be restarted after
// the new scan finishes). If the timer is not running, the new scan is part
......
......@@ -63,7 +63,7 @@ class HostScanSchedulerImpl : public HostScanScheduler,
private:
friend class HostScanSchedulerImplTest;
void EnsureScan();
void AttemptScan();
bool IsTetherNetworkConnectingOrConnected();
void LogHostScanBatchMetric();
......
......@@ -191,12 +191,18 @@ TEST_F(HostScanSchedulerImplTest, ScheduleScan) {
VerifyScanDuration(5u /* expected_num_sections */);
}
TEST_F(HostScanSchedulerImplTest, ScansWhenDeviceUnlocked) {
TEST_F(HostScanSchedulerImplTest, TestDeviceLockAndUnlock) {
// Lock the screen. This should not trigger a scan.
SetScreenLockedState(true /* is_locked */);
EXPECT_EQ(0u, fake_host_scanner_->num_scans_started());
EXPECT_FALSE(mock_delay_scan_after_unlock_timer_->IsRunning());
// Try to start a scan. Because the screen is locked, this should not actually
// cause a scan to be started.
host_scan_scheduler_->ScheduleScan();
EXPECT_EQ(0u, fake_host_scanner_->num_scans_started());
EXPECT_FALSE(mock_delay_scan_after_unlock_timer_->IsRunning());
// Unlock the screen. A scan should not yet have been started, but the timer
// should have.
SetScreenLockedState(false /* is_locked */);
......
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