Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(642)

Unified Diff: components/arc/bluetooth/arc_bluetooth_bridge.cc

Issue 2354933003: arc: bluetooth: Clean up arc_bluetooth_bridge (Closed)
Patch Set: fix #2 nit Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/arc/bluetooth/arc_bluetooth_bridge.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/arc/bluetooth/arc_bluetooth_bridge.cc
diff --git a/components/arc/bluetooth/arc_bluetooth_bridge.cc b/components/arc/bluetooth/arc_bluetooth_bridge.cc
index e9385438299f23f6110b048e441f2e5b65c4f43d..e370b6c16844fad32711035053d11324c3a4abc4 100644
--- a/components/arc/bluetooth/arc_bluetooth_bridge.cc
+++ b/components/arc/bluetooth/arc_bluetooth_bridge.cc
@@ -81,6 +81,11 @@ constexpr uint16_t kAndroidMBluetoothVersionNumber = 95;
constexpr uint16_t kMaxAdvertisement = 5;
// Bluetooth SDP Service Class ID List Attribute identifier
constexpr uint16_t kServiceClassIDListAttributeID = 0x0001;
+// Timeout for Bluetooth Discovery (scan)
+constexpr base::TimeDelta kDiscoveryTimeout = base::TimeDelta::FromSeconds(120);
Rahul Chaturvedi 2016/09/21 22:40:26 Mention in comment why 2 minutes.
puthik_chromium 2016/09/22 00:26:55 Done.
+// From https://www.bluetooth.com/specifications/assigned-numbers/baseband
+// The Class of Device for generic computer.
+constexpr uint32_t kBluetoothComputerClass = 0x100;
using GattStatusCallback =
base::Callback<void(arc::mojom::BluetoothGattStatus)>;
@@ -310,12 +315,6 @@ void ArcBluetoothBridge::OnInstanceClosed() {
bluetooth_adapter_->RemoveObserver(this);
}
-void ArcBluetoothBridge::AdapterPoweredChanged(BluetoothAdapter* adapter,
- bool powered) {
- // TODO(smbarber): Invoke EnableAdapter or DisableAdapter via ARC bridge
- // service.
-}
-
void ArcBluetoothBridge::DeviceAdded(BluetoothAdapter* adapter,
BluetoothDevice* device) {
auto* bluetooth_instance =
@@ -808,9 +807,10 @@ void ArcBluetoothBridge::SetRemoteDeviceProperty(
if (!bluetooth_instance)
return;
- // TODO(smbarber): Implement SetRemoteDeviceProperty
+ // Unsupported. Only used by Android hidden API, BluetoothDevice.SetAlias().
+ // And only Android Settings App / Android TV / NFC used that.
bluetooth_instance->OnRemoteDeviceProperties(
- mojom::BluetoothStatus::FAIL, std::move(remote_addr),
+ mojom::BluetoothStatus::UNSUPPORTED, std::move(remote_addr),
mojo::Array<mojom::BluetoothPropertyPtr>::New(0));
}
@@ -827,9 +827,13 @@ void ArcBluetoothBridge::GetRemoteServices(
void ArcBluetoothBridge::StartDiscovery() {
DCHECK(bluetooth_adapter_);
- // TODO(smbarber): Add timeout
+ DCHECK(CalledOnValidThread());
+
if (discovery_session_) {
- LOG(ERROR) << "Discovery session already running; leaving alone";
+ LOG(ERROR) << "Discovery session already running; Reset timeout.";
+ discovery_off_timer_.Start(FROM_HERE, kDiscoveryTimeout,
+ base::Bind(&ArcBluetoothBridge::CancelDiscovery,
+ weak_factory_.GetWeakPtr()));
SendCachedDevicesFound();
return;
}
@@ -874,6 +878,8 @@ void ArcBluetoothBridge::OnPoweredError(
void ArcBluetoothBridge::OnDiscoveryStarted(
std::unique_ptr<BluetoothDiscoverySession> session) {
+ DCHECK(CalledOnValidThread());
+
auto* bluetooth_instance =
arc_bridge_service()->bluetooth()->GetInstanceForMethod(
"OnDiscoveryStateChanged");
@@ -882,6 +888,10 @@ void ArcBluetoothBridge::OnDiscoveryStarted(
discovery_session_ = std::move(session);
+ discovery_off_timer_.Start(FROM_HERE, kDiscoveryTimeout,
+ base::Bind(&ArcBluetoothBridge::CancelDiscovery,
+ weak_factory_.GetWeakPtr()));
+
bluetooth_instance->OnDiscoveryStateChanged(
mojom::BluetoothDiscoveryState::STARTED);
@@ -896,6 +906,7 @@ void ArcBluetoothBridge::OnDiscoveryStopped() {
return;
discovery_session_.reset();
+ discovery_off_timer_.Stop();
bluetooth_instance->OnDiscoveryStateChanged(
mojom::BluetoothDiscoveryState::STOPPED);
@@ -1761,18 +1772,20 @@ ArcBluetoothBridge::GetAdapterProperties(
}
if (type == mojom::BluetoothPropertyType::ALL ||
type == mojom::BluetoothPropertyType::UUIDS) {
- // TODO(smbarber): Fill in once GetUUIDs is available for the adapter.
+ mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New();
+ btp->set_uuids(
+ mojo::Array<BluetoothUUID>::From(bluetooth_adapter_->GetUUIDs()));
+ properties.push_back(std::move(btp));
}
if (type == mojom::BluetoothPropertyType::ALL ||
type == mojom::BluetoothPropertyType::CLASS_OF_DEVICE) {
- // TODO(smbarber): Populate with the actual adapter class
mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New();
- btp->set_device_class(0);
+ btp->set_device_class(kBluetoothComputerClass);
properties.push_back(std::move(btp));
}
if (type == mojom::BluetoothPropertyType::ALL ||
type == mojom::BluetoothPropertyType::TYPE_OF_DEVICE) {
- // TODO(smbarber): Populate with the actual adapter type
+ // Assume that all ChromeOS devices are dual mode Bluetooth device.
mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New();
btp->set_device_type(device::BLUETOOTH_TRANSPORT_DUAL);
properties.push_back(std::move(btp));
« no previous file with comments | « components/arc/bluetooth/arc_bluetooth_bridge.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698