Commit 8bf6c6ed authored by Ryan Hansberry's avatar Ryan Hansberry Committed by Commit Bot

[Bluetooth] Restrict running HID detection logic at OOBE.

crrev.com/c/1758837 intended to restrict OOBE HID detection logic to
only run on devices that it should (e.g., Chromeboxes), but overlooked
the instantiation of HidDetectionScreen, which once created, goes ahead
and tries to connect to all HID devices even when the actual screen is
not shown. This CL corrects that oversight and only creates
HidDetectionScreen when it is known to be needed.

This CL also adds a WizardController::HasScreen() method to
facilitate testing. Using WizardController::GetScreen() to test
the absence of the HIDDetectionScreen does not work because it
triggers a DCHECK in SCreenManager [1].

1) https://cs.chromium.org/chromium/src/chrome/browser/chromeos/login/screen_manager.cc?l=25

Bug: 1007500, 1024479
Change-Id: I362a05bad73a2876d4b3a937b99823a90fa3e3a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1915080
Commit-Queue: Ryan Hansberry <hansberry@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715490}
parent 35be5bd6
......@@ -5,6 +5,7 @@
#include "base/bind.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/system/sys_info.h"
#include "chrome/browser/chromeos/login/login_wizard.h"
#include "chrome/browser/chromeos/login/screens/base_screen.h"
#include "chrome/browser/chromeos/login/screens/hid_detection_screen.h"
......@@ -24,6 +25,11 @@ namespace chromeos {
class HIDDetectionScreenTest : public InProcessBrowserTest {
public:
HIDDetectionScreenTest() {
// HID detection screen only appears for Chromebases, Chromebits, and
// Chromeboxes.
base::SysInfo::SetChromeOSVersionInfoForTest("DEVICETYPE=CHROMEBOX",
base::Time::Now());
fake_input_service_manager_ =
std::make_unique<device::FakeInputServiceLinux>();
......@@ -93,6 +99,18 @@ class HIDDetectionScreenTest : public InProcessBrowserTest {
DISALLOW_COPY_AND_ASSIGN(HIDDetectionScreenTest);
};
IN_PROC_BROWSER_TEST_F(HIDDetectionScreenTest, HIDDetectionScreenNotAllowed) {
// Set device type to one that should not invoke HIDDetectionScreen logic.
base::SysInfo::SetChromeOSVersionInfoForTest("DEVICETYPE=CHROMEBOOK",
base::Time::Now());
ShowLoginWizard(WelcomeView::kScreenId);
ASSERT_TRUE(WizardController::default_controller());
EXPECT_FALSE(WizardController::default_controller()->HasScreen(
HIDDetectionView::kScreenId));
}
IN_PROC_BROWSER_TEST_F(HIDDetectionScreenTest, MouseKeyboardStates) {
// NOTE: State strings match those in hid_detection_screen.cc.
// No devices added yet
......
......@@ -424,6 +424,10 @@ ErrorScreen* WizardController::GetErrorScreen() {
return GetOobeUI()->GetErrorScreen();
}
bool WizardController::HasScreen(OobeScreenId screen) {
return screen_manager_->HasScreen(screen);
}
BaseScreen* WizardController::GetScreen(OobeScreenId screen) {
if (screen == ErrorScreenView::kScreenId)
return GetErrorScreen();
......@@ -524,10 +528,14 @@ std::vector<std::unique_ptr<BaseScreen>> WizardController::CreateScreens() {
oobe_ui->GetView<WrongHWIDScreenHandler>(),
base::BindRepeating(&WizardController::OnWrongHWIDScreenExit,
weak_factory_.GetWeakPtr())));
append(std::make_unique<chromeos::HIDDetectionScreen>(
oobe_ui->GetView<HIDDetectionScreenHandler>(),
base::BindRepeating(&WizardController::OnHidDetectionScreenExit,
weak_factory_.GetWeakPtr())));
if (CanShowHIDDetectionScreen()) {
append(std::make_unique<chromeos::HIDDetectionScreen>(
oobe_ui->GetView<HIDDetectionScreenHandler>(),
base::BindRepeating(&WizardController::OnHidDetectionScreenExit,
weak_factory_.GetWeakPtr())));
}
append(std::make_unique<AutoEnrollmentCheckScreen>(
oobe_ui->GetView<AutoEnrollmentCheckScreenHandler>(),
oobe_ui->GetErrorScreen(),
......
......@@ -134,6 +134,9 @@ class WizardController {
// Returns true if the current wizard instance has reached the login screen.
bool login_screen_started() const { return login_screen_started_; }
// Returns true if a given screen exists.
bool HasScreen(OobeScreenId screen);
// Returns a given screen. Creates it lazily.
BaseScreen* GetScreen(OobeScreenId screen);
......
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