Commit 0169cde1 authored by Jie Jiang's avatar Jie Jiang Committed by Commit Bot

arc: bluetooth: Send cached devices to Android

This change implements SendCachedDevices(), which should be called
after Bluetooth service in Android starts, to make device cache synced
between Chrome and Android. Here "cache devices" means devices that
have been discovered (not necessarily paired or connected) but not yet
expired. Some Android apps depend on this device cache, e.g., get info
of paired devices.

BUG=b:147401863
BUG=chromium:949918
TEST=Manually test with nRF: paired device can be seen in "BONDED" tab
after reboot or restart Bluetooth.

Change-Id: I80a813706770e9505b6b1db7a502739723e71f69
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2000398
Commit-Queue: Jie Jiang <jiejiang@chromium.org>
Reviewed-by: default avatarMiao-chen Chou <mcchou@chromium.org>
Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736233}
parent 502e1ab7
......@@ -1172,6 +1172,11 @@ void ArcBluetoothBridge::OnPoweredOn(
SetPrimaryUserBluetoothPowerSetting(true);
std::move(callback).Run(mojom::BluetoothAdapterState::ON);
// Sends cached devices to Android after its Bluetooth stack is ready. We
// should do this after the above callback since Android will clear its
// device cache after receiving the "ON" state of adapter.
SendCachedDevices();
}
void ArcBluetoothBridge::OnPoweredOff(
......@@ -2442,6 +2447,22 @@ void ArcBluetoothBridge::DequeueRemotePowerChange(
remote_power_changes_.pop();
}
void ArcBluetoothBridge::SendCachedDevices() const {
auto* bluetooth_instance = ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service_->bluetooth(), OnDevicePropertiesChanged);
if (!bluetooth_instance)
return;
for (const auto* device : bluetooth_adapter_->GetDevices()) {
// Since a cached device may not be a currently available device, we use
// OnDevicePropertiesChanged() instead of OnDeviceFound() to avoid trigger
// the logic of device found in Android.
bluetooth_instance->OnDevicePropertiesChanged(
mojom::BluetoothAddress::From(device->GetAddress()),
GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device));
}
}
std::vector<mojom::BluetoothPropertyPtr>
ArcBluetoothBridge::GetDeviceProperties(mojom::BluetoothPropertyType type,
const BluetoothDevice* device) const {
......
......@@ -400,6 +400,12 @@ class ArcBluetoothBridge
AdapterStateCallback callback);
void DequeueRemotePowerChange(AdapterPowerState powered);
// Sends properties of cached devices to Android. The list of cached devices
// is got by BluetoothAdapter::GetDevices(), which includes all devices have
// been discovered (not necessarily paired or connected) but not yet expired.
// This function should be called when Bluetooth service in Android is ready.
void SendCachedDevices() const;
std::vector<mojom::BluetoothPropertyPtr> GetDeviceProperties(
mojom::BluetoothPropertyType type,
const device::BluetoothDevice* device) const;
......
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