Skip to content

Commit 8a2f3aa

Browse files
felixeCommit Bot
authored andcommitted
Revert of Remove confusing keyboard test & focus on input device (patchset #9 id:160001 of https://codereview.chromium.org/2964823002/ )
Reason for revert: A follow up fix for a race condition on cold boot was reverted in https://chromium-review.googlesource.com/c/574731/. With only this patch the functionality is broken in the user facing scenario. The code state without either this cl or the follow up is better than with only this cl. Original issue's description: > Remove confusing keyboard test & inspect input device > > In order to make the decision for when to trigger the OOBE display > chooser less confusing for end users I'm removing the keyboard check. > Instead an explicit remora requisition check is used to limit the > effects. > > BUG=738885 > > Review-Url: https://codereview.chromium.org/2964823002 > Cr-Commit-Position: refs/heads/master@{#485019} > Committed: https://chromium.googlesource.com/chromium/src/+/c923b817665a649b4e18243116c31c68404af7dd [email protected],[email protected] # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=738885 Review-Url: https://codereview.chromium.org/2977293002 Cr-Commit-Position: refs/heads/master@{#487262}
1 parent 14329d0 commit 8a2f3aa

File tree

3 files changed

+60
-99
lines changed

3 files changed

+60
-99
lines changed

chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.cc

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44

55
#include "chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.h"
66

7-
#include <stdint.h>
8-
97
#include "ash/display/window_tree_host_manager.h"
108
#include "ash/shell.h"
11-
#include "base/stl_util.h"
129
#include "content/public/browser/browser_thread.h"
1310
#include "ui/display/display.h"
11+
#include "ui/display/display_layout.h"
1412
#include "ui/display/manager/display_manager.h"
1513
#include "ui/display/screen.h"
16-
#include "ui/events/devices/device_data_manager.h"
17-
#include "ui/events/devices/touchscreen_device.h"
1814

1915
using content::BrowserThread;
2016

@@ -27,9 +23,6 @@ bool TouchSupportAvailable(const display::Display& display) {
2723
display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE;
2824
}
2925

30-
// TODO(felixe): More context at crbug.com/738885
31-
const uint16_t kDeviceIds[] = {0x0457, 0x266e};
32-
3326
} // namespace
3427

3528
OobeDisplayChooser::OobeDisplayChooser() : weak_ptr_factory_(this) {}
@@ -58,21 +51,18 @@ void OobeDisplayChooser::TryToPlaceUiOnTouchDisplay() {
5851
void OobeDisplayChooser::MoveToTouchDisplay() {
5952
DCHECK_CURRENTLY_ON(BrowserThread::UI);
6053

61-
const ui::DeviceDataManager* device_manager =
62-
ui::DeviceDataManager::GetInstance();
63-
for (const ui::TouchscreenDevice& device :
64-
device_manager->GetTouchscreenDevices()) {
65-
if (!base::ContainsValue(kDeviceIds, device.vendor_id))
66-
continue;
67-
68-
int64_t display_id =
69-
device_manager->GetTargetDisplayForTouchDevice(device.id);
70-
if (display_id == display::kInvalidDisplayId)
71-
continue;
72-
73-
ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(
74-
display_id);
75-
break;
54+
const display::Displays& displays =
55+
ash::Shell::Get()->display_manager()->active_only_display_list();
56+
57+
if (displays.size() <= 1)
58+
return;
59+
60+
for (const display::Display& display : displays) {
61+
if (TouchSupportAvailable(display)) {
62+
ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(
63+
display.id());
64+
break;
65+
}
7666
}
7767
}
7868

chrome/browser/ui/webui/chromeos/login/oobe_display_chooser_unittest.cc

Lines changed: 35 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.h"
66

77
#include <memory>
8-
#include <vector>
98

109
#include "ash/display/display_configuration_controller.h"
1110
#include "ash/shell.h"
@@ -14,12 +13,9 @@
1413
#include "testing/gtest/include/gtest/gtest.h"
1514
#include "ui/display/display.h"
1615
#include "ui/display/display_observer.h"
17-
#include "ui/display/manager/chromeos/touchscreen_util.h"
1816
#include "ui/display/manager/display_manager.h"
1917
#include "ui/display/screen.h"
2018
#include "ui/display/test/display_manager_test_api.h"
21-
#include "ui/events/devices/device_data_manager.h"
22-
#include "ui/events/devices/touchscreen_device.h"
2319

2420
namespace chromeos {
2521

@@ -29,93 +25,63 @@ class OobeDisplayChooserTest : public ash::test::AshTestBase {
2925
public:
3026
OobeDisplayChooserTest() : ash::test::AshTestBase() {}
3127

32-
int64_t GetPrimaryDisplay() {
33-
return display::Screen::GetScreen()->GetPrimaryDisplay().id();
28+
void SetUp() override {
29+
ash::test::AshTestBase::SetUp();
30+
display_manager_test_api_.reset(
31+
new display::test::DisplayManagerTestApi(display_manager()));
3432
}
3533

36-
void UpdateTouchscreenDevices(const ui::TouchscreenDevice& touchscreen) {
37-
std::vector<ui::TouchscreenDevice> devices{touchscreen};
34+
void EnableTouch(int64_t id) {
35+
display_manager_test_api_->SetTouchSupport(
36+
id, display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE);
37+
}
3838

39-
ui::DeviceHotplugEventObserver* manager =
40-
ui::DeviceDataManager::GetInstance();
41-
manager->OnTouchscreenDevicesUpdated(devices);
39+
void DisableTouch(int64_t id) {
40+
display_manager_test_api_->SetTouchSupport(
41+
id, display::Display::TouchSupport::TOUCH_SUPPORT_UNAVAILABLE);
42+
}
43+
44+
int64_t GetPrimaryDisplay() {
45+
return display::Screen::GetScreen()->GetPrimaryDisplay().id();
4246
}
4347

4448
private:
49+
std::unique_ptr<display::test::DisplayManagerTestApi>
50+
display_manager_test_api_;
51+
4552
DISALLOW_COPY_AND_ASSIGN(OobeDisplayChooserTest);
4653
};
4754

48-
const uint16_t kWhitelistedId = 0x266e;
49-
5055
} // namespace
5156

5257
TEST_F(OobeDisplayChooserTest, PreferTouchAsPrimary) {
53-
// Setup 2 displays, second one is intended to be a touch display
54-
std::vector<display::ManagedDisplayInfo> display_info;
55-
display_info.push_back(
56-
display::ManagedDisplayInfo::CreateFromSpecWithID("0+0-3000x2000", 1));
57-
display_info.push_back(
58-
display::ManagedDisplayInfo::CreateFromSpecWithID("3000+0-800x600", 2));
59-
display_manager()->OnNativeDisplaysChanged(display_info);
60-
base::RunLoop().RunUntilIdle();
61-
62-
// Make sure the non-touch display is primary
63-
ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(1);
64-
65-
// Setup corresponding TouchscreenDevice object
66-
ui::TouchscreenDevice touchscreen =
67-
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL,
68-
"Touchscreen", gfx::Size(800, 600), 1);
69-
touchscreen.vendor_id = kWhitelistedId;
70-
UpdateTouchscreenDevices(touchscreen);
71-
base::RunLoop().RunUntilIdle();
58+
OobeDisplayChooser display_chooser;
7259

73-
// Associate touchscreen device with display
74-
display_info[1].AddInputDevice(touchscreen.id);
75-
display_info[1].set_touch_support(display::Display::TOUCH_SUPPORT_AVAILABLE);
76-
display_manager()->OnNativeDisplaysChanged(display_info);
77-
base::RunLoop().RunUntilIdle();
60+
UpdateDisplay("3000x2000,800x600");
61+
display::DisplayIdList ids = display_manager()->GetCurrentDisplayIdList();
62+
DisableTouch(ids[0]);
63+
EnableTouch(ids[1]);
7864

79-
OobeDisplayChooser display_chooser;
80-
EXPECT_EQ(1, GetPrimaryDisplay());
65+
EXPECT_EQ(ids[0], GetPrimaryDisplay());
8166
display_chooser.TryToPlaceUiOnTouchDisplay();
8267
base::RunLoop().RunUntilIdle();
83-
EXPECT_EQ(2, GetPrimaryDisplay());
84-
}
85-
86-
TEST_F(OobeDisplayChooserTest, DontSwitchFromTouch) {
87-
// Setup 2 displays, second one is intended to be a touch display
88-
std::vector<display::ManagedDisplayInfo> display_info;
89-
display_info.push_back(
90-
display::ManagedDisplayInfo::CreateFromSpecWithID("0+0-3000x2000", 1));
91-
display_info.push_back(
92-
display::ManagedDisplayInfo::CreateFromSpecWithID("3000+0-800x600", 2));
93-
display_info[0].set_touch_support(display::Display::TOUCH_SUPPORT_AVAILABLE);
94-
display_manager()->OnNativeDisplaysChanged(display_info);
95-
base::RunLoop().RunUntilIdle();
9668

97-
// Make sure the non-touch display is primary
98-
ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(1);
69+
EXPECT_EQ(ids[1], GetPrimaryDisplay());
70+
}
9971

100-
// Setup corresponding TouchscreenDevice object
101-
ui::TouchscreenDevice touchscreen =
102-
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL,
103-
"Touchscreen", gfx::Size(800, 600), 1);
104-
touchscreen.vendor_id = kWhitelistedId;
105-
UpdateTouchscreenDevices(touchscreen);
106-
base::RunLoop().RunUntilIdle();
72+
TEST_F(OobeDisplayChooserTest, AddingSecondTouchDisplayShouldbeNOP) {
73+
OobeDisplayChooser display_chooser;
10774

108-
// Associate touchscreen device with display
109-
display_info[1].AddInputDevice(touchscreen.id);
110-
display_info[1].set_touch_support(display::Display::TOUCH_SUPPORT_AVAILABLE);
111-
display_manager()->OnNativeDisplaysChanged(display_info);
112-
base::RunLoop().RunUntilIdle();
75+
UpdateDisplay("3000x2000,800x600");
76+
display::DisplayIdList ids = display_manager()->GetCurrentDisplayIdList();
77+
EnableTouch(ids[0]);
78+
EnableTouch(ids[1]);
11379

114-
OobeDisplayChooser display_chooser;
115-
EXPECT_EQ(1, GetPrimaryDisplay());
80+
EXPECT_EQ(ids[0], GetPrimaryDisplay());
11681
display_chooser.TryToPlaceUiOnTouchDisplay();
11782
base::RunLoop().RunUntilIdle();
118-
EXPECT_EQ(1, GetPrimaryDisplay());
83+
84+
EXPECT_EQ(ids[0], GetPrimaryDisplay());
11985
}
12086

12187
} // namespace chromeos

chrome/browser/ui/webui/chromeos/login/oobe_ui.cc

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,17 @@ std::string GetDisplayType(const GURL& url) {
226226
return path;
227227
}
228228

229-
bool IsRemoraRequisitioned() {
230-
policy::DeviceCloudPolicyManagerChromeOS* policy_manager =
231-
g_browser_process->platform_part()
232-
->browser_policy_connector_chromeos()
233-
->GetDeviceCloudPolicyManager();
234-
return policy_manager && policy_manager->IsRemoraRequisition();
229+
bool IsKeyboardConnected() {
230+
const std::vector<ui::InputDevice>& keyboards =
231+
ui::InputDeviceManager::GetInstance()->GetKeyboardDevices();
232+
for (const ui::InputDevice& keyboard : keyboards) {
233+
if (keyboard.type == ui::INPUT_DEVICE_INTERNAL ||
234+
keyboard.type == ui::INPUT_DEVICE_EXTERNAL) {
235+
return true;
236+
}
237+
}
238+
239+
return false;
235240
}
236241

237242
} // namespace
@@ -371,7 +376,7 @@ OobeUI::OobeUI(content::WebUI* web_ui, const GURL& url)
371376

372377
// TODO(felixe): Display iteration and primary display selection not supported
373378
// in Mash. See http://crbug.com/720917.
374-
if (!ash_util::IsRunningInMash() && IsRemoraRequisitioned())
379+
if (!ash_util::IsRunningInMash() && !IsKeyboardConnected())
375380
oobe_display_chooser_ = base::MakeUnique<OobeDisplayChooser>();
376381
}
377382

0 commit comments

Comments
 (0)