BT adapter is switched to initial state after HID screen if no BT devices connected.

BUG=401501

Review URL: https://codereview.chromium.org/448153002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288079 0039d316-1c4b-4281-b951-d872f2087c98
parent e322b6ee
......@@ -73,12 +73,15 @@ HIDDetectionScreenHandler::HIDDetectionScreenHandler(
core_oobe_actor_(core_oobe_actor),
show_on_init_(false),
mouse_is_pairing_(false),
pointing_device_connect_type_(InputDeviceInfo::TYPE_UNKNOWN),
keyboard_is_pairing_(false),
keyboard_device_connect_type_(InputDeviceInfo::TYPE_UNKNOWN),
switch_on_adapter_when_ready_(false),
weak_ptr_factory_(this) {
}
HIDDetectionScreenHandler::~HIDDetectionScreenHandler() {
adapter_initially_powered_.reset();
if (adapter_.get())
adapter_->RemoveObserver(this);
input_service_proxy_.RemoveObserver(this);
......@@ -97,6 +100,10 @@ void HIDDetectionScreenHandler::SetPoweredError() {
LOG(ERROR) << "Failed to power BT adapter";
}
void HIDDetectionScreenHandler::SetPoweredOffError() {
LOG(ERROR) << "Failed to power off BT adapter";
}
void HIDDetectionScreenHandler::FindDevicesError() {
VLOG(1) << "Failed to start Bluetooth discovery.";
}
......@@ -196,6 +203,20 @@ void HIDDetectionScreenHandler::HandleOnContinue() {
scenario_type,
CONTINUE_SCENARIO_TYPE_SIZE);
// Switch off BT adapter if it was off before the screen and no BT device
// connected.
if (adapter_ && adapter_->IsPresent() && adapter_->IsPowered() &&
!(pointing_device_connect_type_ == InputDeviceInfo::TYPE_BLUETOOTH ||
keyboard_device_connect_type_ == InputDeviceInfo::TYPE_BLUETOOTH) &&
adapter_initially_powered_ && !(*adapter_initially_powered_)) {
VLOG(1) << "Switching off BT adapter after HID OOBE screen as unused.";
adapter_->SetPowered(
false,
base::Bind(&base::DoNothing),
base::Bind(&HIDDetectionScreenHandler::SetPoweredOffError,
weak_ptr_factory_.GetWeakPtr()));
}
core_oobe_actor_->StopDemoModeDetection();
if (delegate_)
delegate_->OnExit();
......@@ -286,6 +307,8 @@ void HIDDetectionScreenHandler::AuthorizePairing(
void HIDDetectionScreenHandler::AdapterPresentChanged(
device::BluetoothAdapter* adapter, bool present) {
if (present && switch_on_adapter_when_ready_) {
VLOG(1) << "Switching on BT adapter on HID OOBE screen.";
adapter_initially_powered_.reset(new bool(adapter_->IsPowered()));
adapter_->SetPowered(
true,
base::Bind(&HIDDetectionScreenHandler::StartBTDiscoverySession,
......@@ -430,6 +453,8 @@ void HIDDetectionScreenHandler::TryInitiateBTDevicesUpdate() {
// Switch on BT adapter later when it's available.
switch_on_adapter_when_ready_ = true;
} else if (!adapter_->IsPowered()) {
VLOG(1) << "Switching on BT adapter on HID OOBE screen.";
adapter_initially_powered_.reset(new bool(false));
adapter_->SetPowered(
true,
base::Bind(&HIDDetectionScreenHandler::StartBTDiscoverySession,
......
......@@ -168,6 +168,10 @@ class HIDDetectionScreenHandler
// power BT adapter.
void SetPoweredError();
// Called by device::BluetoothAdapter in response to a failure to
// power off BT adapter.
void SetPoweredOffError();
// Called for revision of active devices. If current-placement is available
// for mouse or keyboard device, sets one of active devices as current or
// tries to connect some BT device if no appropriate devices are connected.
......@@ -210,6 +214,9 @@ class HIDDetectionScreenHandler
bool switch_on_adapter_when_ready_;
// State of BT adapter before screen-initiated changes.
scoped_ptr<bool> adapter_initially_powered_;
base::WeakPtrFactory<HIDDetectionScreenHandler> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(HIDDetectionScreenHandler);
......
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