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

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

Issue 2324463004: arc: bluetooth: Implement set discoverable state (Closed)
Patch Set: 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 964f1986f31971bd6144b5708049f9f2f68fef93..50963c920acb590c87964d8ff3cc9fbea4a1d6d3 100644
--- a/components/arc/bluetooth/arc_bluetooth_bridge.cc
+++ b/components/arc/bluetooth/arc_bluetooth_bridge.cc
@@ -184,6 +184,16 @@ uint16_t GetUUID16(const BluetoothUUID& uuid) {
return std::stoi(uuid.canonical_value().substr(4, 4), nullptr, 16);
}
+mojo::Array<arc::mojom::BluetoothPropertyPtr> GetDiscoveryTimeoutProperty(
+ uint32_t timeout) {
+ arc::mojom::BluetoothPropertyPtr property =
+ arc::mojom::BluetoothProperty::New();
+ property->set_discovery_timeout(timeout);
+ mojo::Array<arc::mojom::BluetoothPropertyPtr> properties;
+ properties.push_back(std::move(property));
+ return properties;
+}
+
} // namespace
namespace arc {
@@ -618,16 +628,86 @@ void ArcBluetoothBridge::GetAdapterProperty(mojom::BluetoothPropertyType type) {
mojom::BluetoothStatus::SUCCESS, std::move(properties));
}
+void ArcBluetoothBridge::OnSetDiscoverable(bool discoverable,
+ bool success,
+ uint32_t timeout) {
+ DCHECK(CalledOnValidThread());
+
+ if (success && discoverable && timeout > 0) {
+ discoverable_off_timer_.Start(
+ FROM_HERE, base::TimeDelta::FromSeconds(timeout),
+ base::Bind(&ArcBluetoothBridge::SetDiscoverable,
+ weak_factory_.GetWeakPtr(), false, 0));
+ }
+
+ if (!HasBluetoothInstance())
+ return;
+
+ if (success) {
+ arc_bridge_service()->bluetooth()->instance()->OnAdapterProperties(
+ mojom::BluetoothStatus::SUCCESS, GetDiscoveryTimeoutProperty(timeout));
+ } else {
+ arc_bridge_service()->bluetooth()->instance()->OnAdapterProperties(
+ mojom::BluetoothStatus::FAIL,
+ mojo::Array<arc::mojom::BluetoothPropertyPtr>::New(0));
+ }
+}
+
+// Set discoverable state to on / off.
+// In case of turning on, start timer to turn it back off in |timeout| seconds.
+void ArcBluetoothBridge::SetDiscoverable(bool discoverable, uint32_t timeout) {
+ DCHECK(bluetooth_adapter_);
+ DCHECK(CalledOnValidThread());
+ DCHECK(!discoverable || timeout == 0);
+
+ bool currently_discoverable = bluetooth_adapter_->IsDiscoverable();
+
+ if (!discoverable && !currently_discoverable)
+ return;
+
+ if (discoverable && currently_discoverable) {
+ if (base::TimeDelta::FromSeconds(timeout) >
+ discoverable_off_timer_.GetCurrentDelay()) {
+ // Restart discoverable_off_timer_ if new timeout is greater
+ OnSetDiscoverable(true, true, timeout);
+ } else if (HasBluetoothInstance()) {
+ // Just send message to Android if new timeout is lower.
+ arc_bridge_service()->bluetooth()->instance()->OnAdapterProperties(
+ mojom::BluetoothStatus::SUCCESS,
+ GetDiscoveryTimeoutProperty(timeout));
+ }
+ return;
+ }
+
+ bluetooth_adapter_->SetDiscoverable(
+ discoverable,
+ base::Bind(&ArcBluetoothBridge::OnSetDiscoverable,
+ weak_factory_.GetWeakPtr(), discoverable, true, timeout),
+ base::Bind(&ArcBluetoothBridge::OnSetDiscoverable,
+ weak_factory_.GetWeakPtr(), discoverable, false, timeout));
+}
+
void ArcBluetoothBridge::SetAdapterProperty(
mojom::BluetoothPropertyPtr property) {
DCHECK(bluetooth_adapter_);
if (!HasBluetoothInstance())
return;
- // TODO(smbarber): Implement SetAdapterProperty
- arc_bridge_service()->bluetooth()->instance()->OnAdapterProperties(
- mojom::BluetoothStatus::FAIL,
- mojo::Array<mojom::BluetoothPropertyPtr>::New(0));
+ if (property->is_discovery_timeout()) {
+ uint32_t discovery_timeout = property->get_discovery_timeout();
+ if (discovery_timeout > 0) {
+ SetDiscoverable(true, discovery_timeout);
+ } else {
+ arc_bridge_service()->bluetooth()->instance()->OnAdapterProperties(
+ mojom::BluetoothStatus::PARM_INVALID,
+ mojo::Array<arc::mojom::BluetoothPropertyPtr>::New(0));
+ }
+ } else {
+ // TODO(puthik) Implement other case.
+ arc_bridge_service()->bluetooth()->instance()->OnAdapterProperties(
+ mojom::BluetoothStatus::UNSUPPORTED,
+ mojo::Array<arc::mojom::BluetoothPropertyPtr>::New(0));
+ }
}
void ArcBluetoothBridge::GetRemoteDeviceProperty(
« 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