Commit 80a1b16c authored by Sarah Hu's avatar Sarah Hu Committed by Commit Bot

Fix bluetooth pairing regression

Instead of using ArcBluetoothBridge as the pairing delegate and forward
pairing request to the UI dialog, use BluetoothPairingDialog directly,
which will automatically pair and handling incoming requests.

This would also fix the general bluetooth pairing regression which
incorrectly send the pairing request to ArcBluetoothBridge, so default
handling in BluetoothNotificationController is skipped unexpectedly.

Tested two device pairing flow[A] and ble signin flow[B].

A:
1. Get two chromebooks A and B, with B as your DUT.
2. After login on B, start a terminal, type in "bluetoothctl" and then
   "discoverable on".
3. On A, scan for B and then pair with B.
4. Confirm the passcode on A.
5. Confirm the passcode on B.

1. In settings, navigate to manage Android preferences.
2. Click Accounts to add a google account with a ble security key registered
as the second factor authenticator.
3. Follow the steps and observe a UI dialog show up and ask for passcode.
4. Enter the passcode and the pairing is successful (a notification is shown).

B: 
Change-Id: I48ce5d1968f4d532b72af7df5e5b6e7be586d7d8
Reviewed-on: https://chromium-review.googlesource.com/1109377Reviewed-by: default avatarLuis Hector Chavez <lhchavez@chromium.org>
Commit-Queue: Xiaoyin Hu <xiaoyinh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569308}
parent 255c6d0f
...@@ -482,10 +482,8 @@ ArcBluetoothBridge::ArcBluetoothBridge(content::BrowserContext* context, ...@@ -482,10 +482,8 @@ ArcBluetoothBridge::ArcBluetoothBridge(content::BrowserContext* context,
ArcBluetoothBridge::~ArcBluetoothBridge() { ArcBluetoothBridge::~ArcBluetoothBridge() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
if (bluetooth_adapter_) { if (bluetooth_adapter_)
bluetooth_adapter_->RemovePairingDelegate(this);
bluetooth_adapter_->RemoveObserver(this); bluetooth_adapter_->RemoveObserver(this);
}
arc_bridge_service_->bluetooth()->RemoveObserver(this); arc_bridge_service_->bluetooth()->RemoveObserver(this);
arc_bridge_service_->bluetooth()->SetHost(nullptr); arc_bridge_service_->bluetooth()->SetHost(nullptr);
...@@ -503,8 +501,6 @@ void ArcBluetoothBridge::OnAdapterInitialized( ...@@ -503,8 +501,6 @@ void ArcBluetoothBridge::OnAdapterInitialized(
if (!bluetooth_adapter_->HasObserver(this)) if (!bluetooth_adapter_->HasObserver(this))
bluetooth_adapter_->AddObserver(this); bluetooth_adapter_->AddObserver(this);
bluetooth_adapter_->AddPairingDelegate(
this, device::BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
} }
void ArcBluetoothBridge::OnConnectionReady() { void ArcBluetoothBridge::OnConnectionReady() {
...@@ -553,22 +549,6 @@ void ArcBluetoothBridge::SendDevice(const BluetoothDevice* device, ...@@ -553,22 +549,6 @@ void ArcBluetoothBridge::SendDevice(const BluetoothDevice* device,
std::move(adv_data)); std::move(adv_data));
} }
device::BluetoothDevice::PairingDelegate* ArcBluetoothBridge::ShowPairingDialog(
device::BluetoothDevice* device) {
chromeos::BluetoothPairingDialog::ShowDialog(
device::BluetoothDevice::CanonicalizeAddress(device->GetAddress()),
device->GetNameForDisplay(), device->IsPaired(), device->IsConnected());
BluetoothDevice::PairingDelegate* delegate =
bluetooth_adapter_->DefaultPairingDelegate();
if (!delegate || delegate == this) {
OnPairedError(mojom::BluetoothAddress::From(device->GetAddress()),
BluetoothDevice::ERROR_FAILED);
return nullptr;
}
return delegate;
}
void ArcBluetoothBridge::AdapterPoweredChanged(BluetoothAdapter* adapter, void ArcBluetoothBridge::AdapterPoweredChanged(BluetoothAdapter* adapter,
bool powered) { bool powered) {
AdapterPowerState power_change = AdapterPowerState power_change =
...@@ -1236,12 +1216,11 @@ void ArcBluetoothBridge::CreateBond(mojom::BluetoothAddressPtr addr, ...@@ -1236,12 +1216,11 @@ void ArcBluetoothBridge::CreateBond(mojom::BluetoothAddressPtr addr,
return; return;
} }
// Use this object as the pairing delegate to handle pairing requests. // BluetoothPairingDialog will automatically pair the device and handle all
// If pairing finished successfully, DevicePairedChanged will notify Android // the incoming pairing requests.
// on paired state change event, so DoNothing is passed as a success callback. chromeos::BluetoothPairingDialog::ShowDialog(
device->Pair(this, base::DoNothing(), device::BluetoothDevice::CanonicalizeAddress(device->GetAddress()),
base::Bind(&ArcBluetoothBridge::OnPairedError, device->GetNameForDisplay(), device->IsPaired(), device->IsConnected());
weak_factory_.GetWeakPtr(), base::Passed(&addr)));
} }
void ArcBluetoothBridge::RemoveBond(mojom::BluetoothAddressPtr addr) { void ArcBluetoothBridge::RemoveBond(mojom::BluetoothAddressPtr addr) {
...@@ -2094,73 +2073,6 @@ void ArcBluetoothBridge::RemoveSdpRecord(uint32_t service_handle, ...@@ -2094,73 +2073,6 @@ void ArcBluetoothBridge::RemoveSdpRecord(uint32_t service_handle,
base::Bind(&OnRemoveServiceRecordError, repeating_callback)); base::Bind(&OnRemoveServiceRecordError, repeating_callback));
} }
void ArcBluetoothBridge::RequestPinCode(device::BluetoothDevice* device) {
BluetoothDevice::PairingDelegate* delegate = ShowPairingDialog(device);
// Forward RequestPinCode to extension's pairing delegate to update the UI
// dialog properly.
if (delegate)
delegate->RequestPinCode(device);
}
void ArcBluetoothBridge::RequestPasskey(device::BluetoothDevice* device) {
BluetoothDevice::PairingDelegate* delegate = ShowPairingDialog(device);
// Forward RequestPasskey to extension's pairing delegate to update the UI
// dialog properly.
if (delegate)
delegate->RequestPasskey(device);
}
void ArcBluetoothBridge::DisplayPinCode(device::BluetoothDevice* device,
const std::string& pincode) {
BluetoothDevice::PairingDelegate* delegate = ShowPairingDialog(device);
// Forward DisplayPinCode to extension's pairing delegate to update the UI
// dialog properly.
if (delegate)
delegate->DisplayPinCode(device, pincode);
}
void ArcBluetoothBridge::DisplayPasskey(device::BluetoothDevice* device,
uint32_t passkey) {
BluetoothDevice::PairingDelegate* delegate = ShowPairingDialog(device);
// Forward DisplayPasskey to extension's pairing delegate to update the UI
// dialog properly.
if (delegate)
delegate->DisplayPasskey(device, passkey);
}
void ArcBluetoothBridge::KeysEntered(device::BluetoothDevice* device,
uint32_t entered) {
BluetoothDevice::PairingDelegate* delegate = ShowPairingDialog(device);
// Forward KeysEntered to extension's pairing delegate to update the UI
// dialog properly.
if (delegate)
delegate->KeysEntered(device, entered);
}
void ArcBluetoothBridge::ConfirmPasskey(device::BluetoothDevice* device,
uint32_t passkey) {
BluetoothDevice::PairingDelegate* delegate = ShowPairingDialog(device);
// Forward ConfirmPasskey to extension's pairing delegate to update the UI
// dialog properly.
if (delegate)
delegate->ConfirmPasskey(device, passkey);
}
void ArcBluetoothBridge::AuthorizePairing(device::BluetoothDevice* device) {
BluetoothDevice::PairingDelegate* delegate = ShowPairingDialog(device);
// Forward AuthorizePairing to extension's pairing delegate to update the UI
// dialog properly.
if (delegate)
delegate->AuthorizePairing(device);
}
template <typename... Args> template <typename... Args>
void ArcBluetoothBridge::AddAdvertisementTask( void ArcBluetoothBridge::AddAdvertisementTask(
base::OnceCallback<void(base::OnceCallback<void(Args...)>)> task, base::OnceCallback<void(base::OnceCallback<void(Args...)>)> task,
......
...@@ -54,8 +54,7 @@ class ArcBluetoothBridge ...@@ -54,8 +54,7 @@ class ArcBluetoothBridge
public device::BluetoothAdapter::Observer, public device::BluetoothAdapter::Observer,
public device::BluetoothAdapterFactory::AdapterCallback, public device::BluetoothAdapterFactory::AdapterCallback,
public device::BluetoothLocalGattService::Delegate, public device::BluetoothLocalGattService::Delegate,
public mojom::BluetoothHost, public mojom::BluetoothHost {
public device::BluetoothDevice::PairingDelegate {
public: public:
using GattStatusCallback = using GattStatusCallback =
base::OnceCallback<void(mojom::BluetoothGattStatus)>; base::OnceCallback<void(mojom::BluetoothGattStatus)>;
...@@ -307,18 +306,6 @@ class ArcBluetoothBridge ...@@ -307,18 +306,6 @@ class ArcBluetoothBridge
void RemoveSdpRecord(uint32_t service_handle, void RemoveSdpRecord(uint32_t service_handle,
RemoveSdpRecordCallback callback) override; RemoveSdpRecordCallback callback) override;
// device::BluetoothDevice::PairingDelegate:
void RequestPinCode(device::BluetoothDevice* device) override;
void RequestPasskey(device::BluetoothDevice* device) override;
void DisplayPinCode(device::BluetoothDevice* device,
const std::string& pincode) override;
void DisplayPasskey(device::BluetoothDevice* device,
uint32_t passkey) override;
void KeysEntered(device::BluetoothDevice* device, uint32_t entered) override;
void ConfirmPasskey(device::BluetoothDevice* device,
uint32_t passkey) override;
void AuthorizePairing(device::BluetoothDevice* device) override;
// Set up or disable multiple advertising. // Set up or disable multiple advertising.
void ReserveAdvertisementHandle( void ReserveAdvertisementHandle(
ReserveAdvertisementHandleCallback callback) override; ReserveAdvertisementHandleCallback callback) override;
...@@ -533,11 +520,6 @@ class ArcBluetoothBridge ...@@ -533,11 +520,6 @@ class ArcBluetoothBridge
void SendDevice(const device::BluetoothDevice* device, void SendDevice(const device::BluetoothDevice* device,
bool include_cached_device) const; bool include_cached_device) const;
// Shows a pairing dialog to handle incoming pairing requests.
// Returns the pairing delegate of the dialog UI.
device::BluetoothDevice::PairingDelegate* ShowPairingDialog(
device::BluetoothDevice* device);
ArcBridgeService* const arc_bridge_service_; // Owned by ArcServiceManager. ArcBridgeService* const arc_bridge_service_; // Owned by ArcServiceManager.
scoped_refptr<bluez::BluetoothAdapterBlueZ> bluetooth_adapter_; scoped_refptr<bluez::BluetoothAdapterBlueZ> bluetooth_adapter_;
......
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