| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/arc/bluetooth/arc_bluetooth_bridge.h" | 5 #include "components/arc/bluetooth/arc_bluetooth_bridge.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <iomanip> | 10 #include <iomanip> |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 bluetooth_adapter_->RemoveObserver(this); | 55 bluetooth_adapter_->RemoveObserver(this); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void ArcBluetoothBridge::OnAdapterInitialized( | 58 void ArcBluetoothBridge::OnAdapterInitialized( |
| 59 scoped_refptr<BluetoothAdapter> adapter) { | 59 scoped_refptr<BluetoothAdapter> adapter) { |
| 60 bluetooth_adapter_ = adapter; | 60 bluetooth_adapter_ = adapter; |
| 61 bluetooth_adapter_->AddObserver(this); | 61 bluetooth_adapter_->AddObserver(this); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void ArcBluetoothBridge::OnBluetoothInstanceReady() { | 64 void ArcBluetoothBridge::OnBluetoothInstanceReady() { |
| 65 BluetoothInstance* bluetooth_instance = | 65 mojom::BluetoothInstance* bluetooth_instance = |
| 66 arc_bridge_service()->bluetooth_instance(); | 66 arc_bridge_service()->bluetooth_instance(); |
| 67 if (!bluetooth_instance) { | 67 if (!bluetooth_instance) { |
| 68 LOG(ERROR) << "OnBluetoothInstanceReady called, " | 68 LOG(ERROR) << "OnBluetoothInstanceReady called, " |
| 69 << "but no bluetooth instance found"; | 69 << "but no bluetooth instance found"; |
| 70 return; | 70 return; |
| 71 } | 71 } |
| 72 | 72 |
| 73 arc_bridge_service()->bluetooth_instance()->Init( | 73 arc_bridge_service()->bluetooth_instance()->Init( |
| 74 binding_.CreateInterfacePtrAndBind()); | 74 binding_.CreateInterfacePtrAndBind()); |
| 75 } | 75 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 93 } | 93 } |
| 94 | 94 |
| 95 void ArcBluetoothBridge::DeviceAdded(BluetoothAdapter* adapter, | 95 void ArcBluetoothBridge::DeviceAdded(BluetoothAdapter* adapter, |
| 96 BluetoothDevice* device) { | 96 BluetoothDevice* device) { |
| 97 if (!HasBluetoothInstance()) | 97 if (!HasBluetoothInstance()) |
| 98 return; | 98 return; |
| 99 | 99 |
| 100 if (device->IsConnected()) | 100 if (device->IsConnected()) |
| 101 return; | 101 return; |
| 102 | 102 |
| 103 mojo::Array<BluetoothPropertyPtr> properties = | 103 mojo::Array<mojom::BluetoothPropertyPtr> properties = |
| 104 GetDeviceProperties(BluetoothPropertyType::ALL, device); | 104 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); |
| 105 | 105 |
| 106 arc_bridge_service()->bluetooth_instance()->OnDeviceFound( | 106 arc_bridge_service()->bluetooth_instance()->OnDeviceFound( |
| 107 std::move(properties)); | 107 std::move(properties)); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void ArcBluetoothBridge::DeviceChanged(BluetoothAdapter* adapter, | 110 void ArcBluetoothBridge::DeviceChanged(BluetoothAdapter* adapter, |
| 111 BluetoothDevice* device) { | 111 BluetoothDevice* device) { |
| 112 // TODO(smbarber): device properties changed; inform the container. | 112 // TODO(smbarber): device properties changed; inform the container. |
| 113 } | 113 } |
| 114 | 114 |
| 115 void ArcBluetoothBridge::DeviceAddressChanged(BluetoothAdapter* adapter, | 115 void ArcBluetoothBridge::DeviceAddressChanged(BluetoothAdapter* adapter, |
| 116 BluetoothDevice* device, | 116 BluetoothDevice* device, |
| 117 const std::string& old_address) { | 117 const std::string& old_address) { |
| 118 // Must be implemented for LE Privacy/GATT client. | 118 // Must be implemented for LE Privacy/GATT client. |
| 119 } | 119 } |
| 120 | 120 |
| 121 void ArcBluetoothBridge::DevicePairedChanged(BluetoothAdapter* adapter, | 121 void ArcBluetoothBridge::DevicePairedChanged(BluetoothAdapter* adapter, |
| 122 BluetoothDevice* device, | 122 BluetoothDevice* device, |
| 123 bool new_paired_status) { | 123 bool new_paired_status) { |
| 124 DCHECK(adapter); | 124 DCHECK(adapter); |
| 125 DCHECK(device); | 125 DCHECK(device); |
| 126 | 126 |
| 127 BluetoothAddressPtr addr = BluetoothAddress::From(device->GetAddress()); | 127 mojom::BluetoothAddressPtr addr = |
| 128 mojom::BluetoothAddress::From(device->GetAddress()); |
| 128 | 129 |
| 129 if (new_paired_status) { | 130 if (new_paired_status) { |
| 130 // OnBondStateChanged must be called with BluetoothBondState::BONDING to | 131 // OnBondStateChanged must be called with BluetoothBondState::BONDING to |
| 131 // make sure the bond state machine on Android is ready to take the | 132 // make sure the bond state machine on Android is ready to take the |
| 132 // pair-done event. Otherwise the pair-done event will be dropped as an | 133 // pair-done event. Otherwise the pair-done event will be dropped as an |
| 133 // invalid change of paired status. | 134 // invalid change of paired status. |
| 134 OnPairing(addr->Clone()); | 135 OnPairing(addr->Clone()); |
| 135 OnPairedDone(std::move(addr)); | 136 OnPairedDone(std::move(addr)); |
| 136 } else { | 137 } else { |
| 137 OnForgetDone(std::move(addr)); | 138 OnForgetDone(std::move(addr)); |
| 138 } | 139 } |
| 139 } | 140 } |
| 140 | 141 |
| 141 void ArcBluetoothBridge::DeviceRemoved(BluetoothAdapter* adapter, | 142 void ArcBluetoothBridge::DeviceRemoved(BluetoothAdapter* adapter, |
| 142 BluetoothDevice* device) { | 143 BluetoothDevice* device) { |
| 143 DCHECK(adapter); | 144 DCHECK(adapter); |
| 144 DCHECK(device); | 145 DCHECK(device); |
| 145 | 146 |
| 146 BluetoothAddressPtr addr = BluetoothAddress::From(device->GetAddress()); | 147 mojom::BluetoothAddressPtr addr = |
| 148 mojom::BluetoothAddress::From(device->GetAddress()); |
| 147 OnForgetDone(std::move(addr)); | 149 OnForgetDone(std::move(addr)); |
| 148 } | 150 } |
| 149 | 151 |
| 150 void ArcBluetoothBridge::GattServiceAdded(BluetoothAdapter* adapter, | 152 void ArcBluetoothBridge::GattServiceAdded(BluetoothAdapter* adapter, |
| 151 BluetoothDevice* device, | 153 BluetoothDevice* device, |
| 152 BluetoothGattService* service) { | 154 BluetoothGattService* service) { |
| 153 // Placeholder for GATT client functionality | 155 // Placeholder for GATT client functionality |
| 154 } | 156 } |
| 155 | 157 |
| 156 void ArcBluetoothBridge::GattServiceRemoved(BluetoothAdapter* adapter, | 158 void ArcBluetoothBridge::GattServiceRemoved(BluetoothAdapter* adapter, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 void ArcBluetoothBridge::DisableAdapter( | 232 void ArcBluetoothBridge::DisableAdapter( |
| 231 const DisableAdapterCallback& callback) { | 233 const DisableAdapterCallback& callback) { |
| 232 DCHECK(bluetooth_adapter_); | 234 DCHECK(bluetooth_adapter_); |
| 233 bluetooth_adapter_->SetPowered( | 235 bluetooth_adapter_->SetPowered( |
| 234 false, base::Bind(&ArcBluetoothBridge::OnPoweredOff, | 236 false, base::Bind(&ArcBluetoothBridge::OnPoweredOff, |
| 235 weak_factory_.GetWeakPtr(), callback), | 237 weak_factory_.GetWeakPtr(), callback), |
| 236 base::Bind(&ArcBluetoothBridge::OnPoweredError, | 238 base::Bind(&ArcBluetoothBridge::OnPoweredError, |
| 237 weak_factory_.GetWeakPtr(), callback)); | 239 weak_factory_.GetWeakPtr(), callback)); |
| 238 } | 240 } |
| 239 | 241 |
| 240 void ArcBluetoothBridge::GetAdapterProperty(BluetoothPropertyType type) { | 242 void ArcBluetoothBridge::GetAdapterProperty(mojom::BluetoothPropertyType type) { |
| 241 DCHECK(bluetooth_adapter_); | 243 DCHECK(bluetooth_adapter_); |
| 242 if (!HasBluetoothInstance()) | 244 if (!HasBluetoothInstance()) |
| 243 return; | 245 return; |
| 244 | 246 |
| 245 mojo::Array<BluetoothPropertyPtr> properties = GetAdapterProperties(type); | 247 mojo::Array<mojom::BluetoothPropertyPtr> properties = |
| 248 GetAdapterProperties(type); |
| 246 | 249 |
| 247 arc_bridge_service()->bluetooth_instance()->OnAdapterProperties( | 250 arc_bridge_service()->bluetooth_instance()->OnAdapterProperties( |
| 248 BluetoothStatus::SUCCESS, std::move(properties)); | 251 mojom::BluetoothStatus::SUCCESS, std::move(properties)); |
| 249 } | 252 } |
| 250 | 253 |
| 251 void ArcBluetoothBridge::SetAdapterProperty(BluetoothPropertyPtr property) { | 254 void ArcBluetoothBridge::SetAdapterProperty( |
| 255 mojom::BluetoothPropertyPtr property) { |
| 252 DCHECK(bluetooth_adapter_); | 256 DCHECK(bluetooth_adapter_); |
| 253 if (!HasBluetoothInstance()) | 257 if (!HasBluetoothInstance()) |
| 254 return; | 258 return; |
| 255 | 259 |
| 256 // TODO(smbarber): Implement SetAdapterProperty | 260 // TODO(smbarber): Implement SetAdapterProperty |
| 257 arc_bridge_service()->bluetooth_instance()->OnAdapterProperties( | 261 arc_bridge_service()->bluetooth_instance()->OnAdapterProperties( |
| 258 BluetoothStatus::FAIL, mojo::Array<BluetoothPropertyPtr>::New(0)); | 262 mojom::BluetoothStatus::FAIL, |
| 263 mojo::Array<mojom::BluetoothPropertyPtr>::New(0)); |
| 259 } | 264 } |
| 260 | 265 |
| 261 void ArcBluetoothBridge::GetRemoteDeviceProperty( | 266 void ArcBluetoothBridge::GetRemoteDeviceProperty( |
| 262 BluetoothAddressPtr remote_addr, | 267 mojom::BluetoothAddressPtr remote_addr, |
| 263 BluetoothPropertyType type) { | 268 mojom::BluetoothPropertyType type) { |
| 264 DCHECK(bluetooth_adapter_); | 269 DCHECK(bluetooth_adapter_); |
| 265 if (!HasBluetoothInstance()) | 270 if (!HasBluetoothInstance()) |
| 266 return; | 271 return; |
| 267 | 272 |
| 268 std::string addr_str = remote_addr->To<std::string>(); | 273 std::string addr_str = remote_addr->To<std::string>(); |
| 269 BluetoothDevice* device = bluetooth_adapter_->GetDevice(addr_str); | 274 BluetoothDevice* device = bluetooth_adapter_->GetDevice(addr_str); |
| 270 | 275 |
| 271 mojo::Array<BluetoothPropertyPtr> properties = | 276 mojo::Array<mojom::BluetoothPropertyPtr> properties = |
| 272 GetDeviceProperties(type, device); | 277 GetDeviceProperties(type, device); |
| 273 BluetoothStatus status = BluetoothStatus::SUCCESS; | 278 mojom::BluetoothStatus status = mojom::BluetoothStatus::SUCCESS; |
| 274 | 279 |
| 275 if (!device) { | 280 if (!device) { |
| 276 VLOG(1) << __func__ << ": device " << addr_str << " not available"; | 281 VLOG(1) << __func__ << ": device " << addr_str << " not available"; |
| 277 status = BluetoothStatus::FAIL; | 282 status = mojom::BluetoothStatus::FAIL; |
| 278 } | 283 } |
| 279 | 284 |
| 280 arc_bridge_service()->bluetooth_instance()->OnRemoteDeviceProperties( | 285 arc_bridge_service()->bluetooth_instance()->OnRemoteDeviceProperties( |
| 281 status, std::move(remote_addr), std::move(properties)); | 286 status, std::move(remote_addr), std::move(properties)); |
| 282 } | 287 } |
| 283 | 288 |
| 284 void ArcBluetoothBridge::SetRemoteDeviceProperty( | 289 void ArcBluetoothBridge::SetRemoteDeviceProperty( |
| 285 BluetoothAddressPtr remote_addr, | 290 mojom::BluetoothAddressPtr remote_addr, |
| 286 BluetoothPropertyPtr property) { | 291 mojom::BluetoothPropertyPtr property) { |
| 287 DCHECK(bluetooth_adapter_); | 292 DCHECK(bluetooth_adapter_); |
| 288 if (!HasBluetoothInstance()) | 293 if (!HasBluetoothInstance()) |
| 289 return; | 294 return; |
| 290 | 295 |
| 291 // TODO(smbarber): Implement SetRemoteDeviceProperty | 296 // TODO(smbarber): Implement SetRemoteDeviceProperty |
| 292 arc_bridge_service()->bluetooth_instance()->OnRemoteDeviceProperties( | 297 arc_bridge_service()->bluetooth_instance()->OnRemoteDeviceProperties( |
| 293 BluetoothStatus::FAIL, std::move(remote_addr), | 298 mojom::BluetoothStatus::FAIL, std::move(remote_addr), |
| 294 mojo::Array<BluetoothPropertyPtr>::New(0)); | 299 mojo::Array<mojom::BluetoothPropertyPtr>::New(0)); |
| 295 } | 300 } |
| 296 | 301 |
| 297 void ArcBluetoothBridge::GetRemoteServiceRecord(BluetoothAddressPtr remote_addr, | 302 void ArcBluetoothBridge::GetRemoteServiceRecord( |
| 298 BluetoothUUIDPtr uuid) { | 303 mojom::BluetoothAddressPtr remote_addr, |
| 304 mojom::BluetoothUUIDPtr uuid) { |
| 299 // TODO(smbarber): Implement GetRemoteServiceRecord | 305 // TODO(smbarber): Implement GetRemoteServiceRecord |
| 300 } | 306 } |
| 301 | 307 |
| 302 void ArcBluetoothBridge::GetRemoteServices(BluetoothAddressPtr remote_addr) { | 308 void ArcBluetoothBridge::GetRemoteServices( |
| 309 mojom::BluetoothAddressPtr remote_addr) { |
| 303 // TODO(smbarber): Implement GetRemoteServices | 310 // TODO(smbarber): Implement GetRemoteServices |
| 304 } | 311 } |
| 305 | 312 |
| 306 void ArcBluetoothBridge::StartDiscovery() { | 313 void ArcBluetoothBridge::StartDiscovery() { |
| 307 DCHECK(bluetooth_adapter_); | 314 DCHECK(bluetooth_adapter_); |
| 308 // TODO(smbarber): Add timeout | 315 // TODO(smbarber): Add timeout |
| 309 if (discovery_session_) { | 316 if (discovery_session_) { |
| 310 LOG(ERROR) << "Discovery session already running; leaving alone"; | 317 LOG(ERROR) << "Discovery session already running; leaving alone"; |
| 311 SendCachedDevicesFound(); | 318 SendCachedDevicesFound(); |
| 312 return; | 319 return; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 324 return; | 331 return; |
| 325 } | 332 } |
| 326 | 333 |
| 327 discovery_session_->Stop(base::Bind(&ArcBluetoothBridge::OnDiscoveryStopped, | 334 discovery_session_->Stop(base::Bind(&ArcBluetoothBridge::OnDiscoveryStopped, |
| 328 weak_factory_.GetWeakPtr()), | 335 weak_factory_.GetWeakPtr()), |
| 329 base::Bind(&ArcBluetoothBridge::OnDiscoveryError, | 336 base::Bind(&ArcBluetoothBridge::OnDiscoveryError, |
| 330 weak_factory_.GetWeakPtr())); | 337 weak_factory_.GetWeakPtr())); |
| 331 } | 338 } |
| 332 | 339 |
| 333 void ArcBluetoothBridge::OnPoweredOn( | 340 void ArcBluetoothBridge::OnPoweredOn( |
| 334 const mojo::Callback<void(BluetoothAdapterState)>& callback) const { | 341 const mojo::Callback<void(mojom::BluetoothAdapterState)>& callback) const { |
| 335 callback.Run(BluetoothAdapterState::ON); | 342 callback.Run(mojom::BluetoothAdapterState::ON); |
| 336 SendCachedPairedDevices(); | 343 SendCachedPairedDevices(); |
| 337 } | 344 } |
| 338 | 345 |
| 339 void ArcBluetoothBridge::OnPoweredOff( | 346 void ArcBluetoothBridge::OnPoweredOff( |
| 340 const mojo::Callback<void(BluetoothAdapterState)>& callback) const { | 347 const mojo::Callback<void(mojom::BluetoothAdapterState)>& callback) const { |
| 341 callback.Run(BluetoothAdapterState::OFF); | 348 callback.Run(mojom::BluetoothAdapterState::OFF); |
| 342 } | 349 } |
| 343 | 350 |
| 344 void ArcBluetoothBridge::OnPoweredError( | 351 void ArcBluetoothBridge::OnPoweredError( |
| 345 const mojo::Callback<void(BluetoothAdapterState)>& callback) const { | 352 const mojo::Callback<void(mojom::BluetoothAdapterState)>& callback) const { |
| 346 LOG(WARNING) << "failed to change power state"; | 353 LOG(WARNING) << "failed to change power state"; |
| 347 | 354 |
| 348 callback.Run(bluetooth_adapter_->IsPowered() ? BluetoothAdapterState::ON | 355 callback.Run(bluetooth_adapter_->IsPowered() |
| 349 : BluetoothAdapterState::OFF); | 356 ? mojom::BluetoothAdapterState::ON |
| 357 : mojom::BluetoothAdapterState::OFF); |
| 350 } | 358 } |
| 351 | 359 |
| 352 void ArcBluetoothBridge::OnDiscoveryStarted( | 360 void ArcBluetoothBridge::OnDiscoveryStarted( |
| 353 scoped_ptr<BluetoothDiscoverySession> session) { | 361 scoped_ptr<BluetoothDiscoverySession> session) { |
| 354 if (!HasBluetoothInstance()) | 362 if (!HasBluetoothInstance()) |
| 355 return; | 363 return; |
| 356 | 364 |
| 357 discovery_session_ = std::move(session); | 365 discovery_session_ = std::move(session); |
| 358 | 366 |
| 359 arc_bridge_service()->bluetooth_instance()->OnDiscoveryStateChanged( | 367 arc_bridge_service()->bluetooth_instance()->OnDiscoveryStateChanged( |
| 360 BluetoothDiscoveryState::STARTED); | 368 mojom::BluetoothDiscoveryState::STARTED); |
| 361 | 369 |
| 362 SendCachedDevicesFound(); | 370 SendCachedDevicesFound(); |
| 363 } | 371 } |
| 364 | 372 |
| 365 void ArcBluetoothBridge::OnDiscoveryStopped() { | 373 void ArcBluetoothBridge::OnDiscoveryStopped() { |
| 366 if (!HasBluetoothInstance()) | 374 if (!HasBluetoothInstance()) |
| 367 return; | 375 return; |
| 368 | 376 |
| 369 discovery_session_.reset(); | 377 discovery_session_.reset(); |
| 370 | 378 |
| 371 arc_bridge_service()->bluetooth_instance()->OnDiscoveryStateChanged( | 379 arc_bridge_service()->bluetooth_instance()->OnDiscoveryStateChanged( |
| 372 BluetoothDiscoveryState::STOPPED); | 380 mojom::BluetoothDiscoveryState::STOPPED); |
| 373 } | 381 } |
| 374 | 382 |
| 375 void ArcBluetoothBridge::CreateBond(BluetoothAddressPtr addr, | 383 void ArcBluetoothBridge::CreateBond(mojom::BluetoothAddressPtr addr, |
| 376 int32_t transport) { | 384 int32_t transport) { |
| 377 std::string addr_str = addr->To<std::string>(); | 385 std::string addr_str = addr->To<std::string>(); |
| 378 BluetoothDevice* device = bluetooth_adapter_->GetDevice(addr_str); | 386 BluetoothDevice* device = bluetooth_adapter_->GetDevice(addr_str); |
| 379 if (!device || !device->IsPairable()) { | 387 if (!device || !device->IsPairable()) { |
| 380 VLOG(1) << __func__ << ": device " << addr_str | 388 VLOG(1) << __func__ << ": device " << addr_str |
| 381 << " is no longer valid or pairable"; | 389 << " is no longer valid or pairable"; |
| 382 OnPairedError(std::move(addr), BluetoothDevice::ERROR_FAILED); | 390 OnPairedError(std::move(addr), BluetoothDevice::ERROR_FAILED); |
| 383 return; | 391 return; |
| 384 } | 392 } |
| 385 | 393 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 398 return; | 406 return; |
| 399 } | 407 } |
| 400 | 408 |
| 401 // If pairing finished successfully, DevicePairedChanged will notify Android | 409 // If pairing finished successfully, DevicePairedChanged will notify Android |
| 402 // on paired state change event, so DoNothing is passed as a success callback. | 410 // on paired state change event, so DoNothing is passed as a success callback. |
| 403 device->Pair(delegate, base::Bind(&base::DoNothing), | 411 device->Pair(delegate, base::Bind(&base::DoNothing), |
| 404 base::Bind(&ArcBluetoothBridge::OnPairedError, | 412 base::Bind(&ArcBluetoothBridge::OnPairedError, |
| 405 weak_factory_.GetWeakPtr(), base::Passed(&addr))); | 413 weak_factory_.GetWeakPtr(), base::Passed(&addr))); |
| 406 } | 414 } |
| 407 | 415 |
| 408 void ArcBluetoothBridge::RemoveBond(BluetoothAddressPtr addr) { | 416 void ArcBluetoothBridge::RemoveBond(mojom::BluetoothAddressPtr addr) { |
| 409 // Forget the device if it is no longer valid or not even paired. | 417 // Forget the device if it is no longer valid or not even paired. |
| 410 BluetoothDevice* device = | 418 BluetoothDevice* device = |
| 411 bluetooth_adapter_->GetDevice(addr->To<std::string>()); | 419 bluetooth_adapter_->GetDevice(addr->To<std::string>()); |
| 412 if (!device || !device->IsPaired()) { | 420 if (!device || !device->IsPaired()) { |
| 413 OnForgetDone(std::move(addr)); | 421 OnForgetDone(std::move(addr)); |
| 414 return; | 422 return; |
| 415 } | 423 } |
| 416 | 424 |
| 417 // If unpairing finished successfully, DevicePairedChanged will notify Android | 425 // If unpairing finished successfully, DevicePairedChanged will notify Android |
| 418 // on paired state change event, so DoNothing is passed as a success callback. | 426 // on paired state change event, so DoNothing is passed as a success callback. |
| 419 device->Forget(base::Bind(&base::DoNothing), | 427 device->Forget(base::Bind(&base::DoNothing), |
| 420 base::Bind(&ArcBluetoothBridge::OnForgetError, | 428 base::Bind(&ArcBluetoothBridge::OnForgetError, |
| 421 weak_factory_.GetWeakPtr(), base::Passed(&addr))); | 429 weak_factory_.GetWeakPtr(), base::Passed(&addr))); |
| 422 } | 430 } |
| 423 | 431 |
| 424 void ArcBluetoothBridge::CancelBond(BluetoothAddressPtr addr) { | 432 void ArcBluetoothBridge::CancelBond(mojom::BluetoothAddressPtr addr) { |
| 425 BluetoothDevice* device = | 433 BluetoothDevice* device = |
| 426 bluetooth_adapter_->GetDevice(addr->To<std::string>()); | 434 bluetooth_adapter_->GetDevice(addr->To<std::string>()); |
| 427 if (!device) { | 435 if (!device) { |
| 428 OnForgetDone(std::move(addr)); | 436 OnForgetDone(std::move(addr)); |
| 429 return; | 437 return; |
| 430 } | 438 } |
| 431 | 439 |
| 432 device->CancelPairing(); | 440 device->CancelPairing(); |
| 433 OnForgetDone(std::move(addr)); | 441 OnForgetDone(std::move(addr)); |
| 434 } | 442 } |
| 435 | 443 |
| 436 void ArcBluetoothBridge::GetConnectionState( | 444 void ArcBluetoothBridge::GetConnectionState( |
| 437 BluetoothAddressPtr addr, | 445 mojom::BluetoothAddressPtr addr, |
| 438 const GetConnectionStateCallback& callback) { | 446 const GetConnectionStateCallback& callback) { |
| 439 if (!bluetooth_adapter_) { | 447 if (!bluetooth_adapter_) { |
| 440 callback.Run(false); | 448 callback.Run(false); |
| 441 return; | 449 return; |
| 442 } | 450 } |
| 443 | 451 |
| 444 BluetoothDevice* device = | 452 BluetoothDevice* device = |
| 445 bluetooth_adapter_->GetDevice(addr->To<std::string>()); | 453 bluetooth_adapter_->GetDevice(addr->To<std::string>()); |
| 446 if (!device) { | 454 if (!device) { |
| 447 callback.Run(false); | 455 callback.Run(false); |
| 448 return; | 456 return; |
| 449 } | 457 } |
| 450 | 458 |
| 451 callback.Run(device->IsConnected()); | 459 callback.Run(device->IsConnected()); |
| 452 } | 460 } |
| 453 | 461 |
| 454 void ArcBluetoothBridge::OnDiscoveryError() { | 462 void ArcBluetoothBridge::OnDiscoveryError() { |
| 455 LOG(WARNING) << "failed to change discovery state"; | 463 LOG(WARNING) << "failed to change discovery state"; |
| 456 } | 464 } |
| 457 | 465 |
| 458 void ArcBluetoothBridge::OnPairing(BluetoothAddressPtr addr) const { | 466 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { |
| 459 if (!HasBluetoothInstance()) | 467 if (!HasBluetoothInstance()) |
| 460 return; | 468 return; |
| 461 | 469 |
| 462 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( | 470 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( |
| 463 BluetoothStatus::SUCCESS, std::move(addr), BluetoothBondState::BONDING); | 471 mojom::BluetoothStatus::SUCCESS, std::move(addr), |
| 472 mojom::BluetoothBondState::BONDING); |
| 464 } | 473 } |
| 465 | 474 |
| 466 void ArcBluetoothBridge::OnPairedDone(BluetoothAddressPtr addr) const { | 475 void ArcBluetoothBridge::OnPairedDone(mojom::BluetoothAddressPtr addr) const { |
| 467 if (!HasBluetoothInstance()) | 476 if (!HasBluetoothInstance()) |
| 468 return; | 477 return; |
| 469 | 478 |
| 470 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( | 479 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( |
| 471 BluetoothStatus::SUCCESS, std::move(addr), BluetoothBondState::BONDED); | 480 mojom::BluetoothStatus::SUCCESS, std::move(addr), |
| 481 mojom::BluetoothBondState::BONDED); |
| 472 } | 482 } |
| 473 | 483 |
| 474 void ArcBluetoothBridge::OnPairedError( | 484 void ArcBluetoothBridge::OnPairedError( |
| 475 BluetoothAddressPtr addr, | 485 mojom::BluetoothAddressPtr addr, |
| 476 BluetoothDevice::ConnectErrorCode error_code) const { | 486 BluetoothDevice::ConnectErrorCode error_code) const { |
| 477 if (!HasBluetoothInstance()) | 487 if (!HasBluetoothInstance()) |
| 478 return; | 488 return; |
| 479 | 489 |
| 480 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( | 490 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( |
| 481 BluetoothStatus::FAIL, std::move(addr), BluetoothBondState::NONE); | 491 mojom::BluetoothStatus::FAIL, std::move(addr), |
| 492 mojom::BluetoothBondState::NONE); |
| 482 } | 493 } |
| 483 | 494 |
| 484 void ArcBluetoothBridge::OnForgetDone(BluetoothAddressPtr addr) const { | 495 void ArcBluetoothBridge::OnForgetDone(mojom::BluetoothAddressPtr addr) const { |
| 485 if (!HasBluetoothInstance()) | 496 if (!HasBluetoothInstance()) |
| 486 return; | 497 return; |
| 487 | 498 |
| 488 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( | 499 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( |
| 489 BluetoothStatus::SUCCESS, std::move(addr), BluetoothBondState::NONE); | 500 mojom::BluetoothStatus::SUCCESS, std::move(addr), |
| 501 mojom::BluetoothBondState::NONE); |
| 490 } | 502 } |
| 491 | 503 |
| 492 void ArcBluetoothBridge::OnForgetError(BluetoothAddressPtr addr) const { | 504 void ArcBluetoothBridge::OnForgetError(mojom::BluetoothAddressPtr addr) const { |
| 493 if (!HasBluetoothInstance()) | 505 if (!HasBluetoothInstance()) |
| 494 return; | 506 return; |
| 495 | 507 |
| 496 BluetoothDevice* device = | 508 BluetoothDevice* device = |
| 497 bluetooth_adapter_->GetDevice(addr->To<std::string>()); | 509 bluetooth_adapter_->GetDevice(addr->To<std::string>()); |
| 498 BluetoothBondState bond_state = BluetoothBondState::NONE; | 510 mojom::BluetoothBondState bond_state = mojom::BluetoothBondState::NONE; |
| 499 if (device && device->IsPaired()) { | 511 if (device && device->IsPaired()) { |
| 500 bond_state = BluetoothBondState::BONDED; | 512 bond_state = mojom::BluetoothBondState::BONDED; |
| 501 } | 513 } |
| 502 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( | 514 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( |
| 503 BluetoothStatus::FAIL, std::move(addr), bond_state); | 515 mojom::BluetoothStatus::FAIL, std::move(addr), bond_state); |
| 504 } | 516 } |
| 505 | 517 |
| 506 mojo::Array<BluetoothPropertyPtr> ArcBluetoothBridge::GetDeviceProperties( | 518 mojo::Array<mojom::BluetoothPropertyPtr> |
| 507 BluetoothPropertyType type, | 519 ArcBluetoothBridge::GetDeviceProperties(mojom::BluetoothPropertyType type, |
| 508 BluetoothDevice* device) const { | 520 BluetoothDevice* device) const { |
| 509 mojo::Array<BluetoothPropertyPtr> properties; | 521 mojo::Array<mojom::BluetoothPropertyPtr> properties; |
| 510 | 522 |
| 511 if (!device) { | 523 if (!device) { |
| 512 return properties; | 524 return properties; |
| 513 } | 525 } |
| 514 | 526 |
| 515 if (type == BluetoothPropertyType::ALL || | 527 if (type == mojom::BluetoothPropertyType::ALL || |
| 516 type == BluetoothPropertyType::BDNAME) { | 528 type == mojom::BluetoothPropertyType::BDNAME) { |
| 517 BluetoothPropertyPtr btp = BluetoothProperty::New(); | 529 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 518 btp->set_bdname(mojo::String::From(base::UTF16ToUTF8(device->GetName()))); | 530 btp->set_bdname(mojo::String::From(base::UTF16ToUTF8(device->GetName()))); |
| 519 properties.push_back(std::move(btp)); | 531 properties.push_back(std::move(btp)); |
| 520 } | 532 } |
| 521 if (type == BluetoothPropertyType::ALL || | 533 if (type == mojom::BluetoothPropertyType::ALL || |
| 522 type == BluetoothPropertyType::BDADDR) { | 534 type == mojom::BluetoothPropertyType::BDADDR) { |
| 523 BluetoothPropertyPtr btp = BluetoothProperty::New(); | 535 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 524 btp->set_bdaddr(BluetoothAddress::From(device->GetAddress())); | 536 btp->set_bdaddr(mojom::BluetoothAddress::From(device->GetAddress())); |
| 525 properties.push_back(std::move(btp)); | 537 properties.push_back(std::move(btp)); |
| 526 } | 538 } |
| 527 if (type == BluetoothPropertyType::ALL || | 539 if (type == mojom::BluetoothPropertyType::ALL || |
| 528 type == BluetoothPropertyType::UUIDS) { | 540 type == mojom::BluetoothPropertyType::UUIDS) { |
| 529 BluetoothPropertyPtr btp = BluetoothProperty::New(); | 541 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 530 std::vector<device::BluetoothUUID> uuids = device->GetUUIDs(); | 542 std::vector<device::BluetoothUUID> uuids = device->GetUUIDs(); |
| 531 mojo::Array<BluetoothUUIDPtr> uuid_results = | 543 mojo::Array<mojom::BluetoothUUIDPtr> uuid_results = |
| 532 mojo::Array<BluetoothUUIDPtr>::New(0); | 544 mojo::Array<mojom::BluetoothUUIDPtr>::New(0); |
| 533 | 545 |
| 534 for (size_t i = 0; i < uuids.size(); i++) { | 546 for (size_t i = 0; i < uuids.size(); i++) { |
| 535 uuid_results.push_back(BluetoothUUID::From(uuids[i])); | 547 uuid_results.push_back(mojom::BluetoothUUID::From(uuids[i])); |
| 536 } | 548 } |
| 537 | 549 |
| 538 btp->set_uuids(std::move(uuid_results)); | 550 btp->set_uuids(std::move(uuid_results)); |
| 539 properties.push_back(std::move(btp)); | 551 properties.push_back(std::move(btp)); |
| 540 } | 552 } |
| 541 if (type == BluetoothPropertyType::ALL || | 553 if (type == mojom::BluetoothPropertyType::ALL || |
| 542 type == BluetoothPropertyType::CLASS_OF_DEVICE) { | 554 type == mojom::BluetoothPropertyType::CLASS_OF_DEVICE) { |
| 543 BluetoothPropertyPtr btp = BluetoothProperty::New(); | 555 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 544 btp->set_device_class(device->GetBluetoothClass()); | 556 btp->set_device_class(device->GetBluetoothClass()); |
| 545 properties.push_back(std::move(btp)); | 557 properties.push_back(std::move(btp)); |
| 546 } | 558 } |
| 547 if (type == BluetoothPropertyType::ALL || | 559 if (type == mojom::BluetoothPropertyType::ALL || |
| 548 type == BluetoothPropertyType::TYPE_OF_DEVICE) { | 560 type == mojom::BluetoothPropertyType::TYPE_OF_DEVICE) { |
| 549 // TODO(smbarber): This needs to be populated with the actual device type | 561 // TODO(smbarber): This needs to be populated with the actual device type |
| 550 BluetoothPropertyPtr btp = BluetoothProperty::New(); | 562 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 551 btp->set_device_type(BluetoothDeviceType::DUAL); | 563 btp->set_device_type(mojom::BluetoothDeviceType::DUAL); |
| 552 properties.push_back(std::move(btp)); | 564 properties.push_back(std::move(btp)); |
| 553 } | 565 } |
| 554 if (type == BluetoothPropertyType::ALL || | 566 if (type == mojom::BluetoothPropertyType::ALL || |
| 555 type == BluetoothPropertyType::REMOTE_FRIENDLY_NAME) { | 567 type == mojom::BluetoothPropertyType::REMOTE_FRIENDLY_NAME) { |
| 556 BluetoothPropertyPtr btp = BluetoothProperty::New(); | 568 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 557 btp->set_bdname(mojo::String::From(base::UTF16ToUTF8(device->GetName()))); | 569 btp->set_bdname(mojo::String::From(base::UTF16ToUTF8(device->GetName()))); |
| 558 properties.push_back(std::move(btp)); | 570 properties.push_back(std::move(btp)); |
| 559 } | 571 } |
| 560 if (type == BluetoothPropertyType::ALL || | 572 if (type == mojom::BluetoothPropertyType::ALL || |
| 561 type == BluetoothPropertyType::REMOTE_RSSI) { | 573 type == mojom::BluetoothPropertyType::REMOTE_RSSI) { |
| 562 BluetoothPropertyPtr btp = BluetoothProperty::New(); | 574 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 563 btp->set_remote_rssi(device->GetInquiryRSSI()); | 575 btp->set_remote_rssi(device->GetInquiryRSSI()); |
| 564 properties.push_back(std::move(btp)); | 576 properties.push_back(std::move(btp)); |
| 565 } | 577 } |
| 566 // TODO(smbarber): Add remote version info | 578 // TODO(smbarber): Add remote version info |
| 567 | 579 |
| 568 return properties; | 580 return properties; |
| 569 } | 581 } |
| 570 | 582 |
| 571 mojo::Array<BluetoothPropertyPtr> ArcBluetoothBridge::GetAdapterProperties( | 583 mojo::Array<mojom::BluetoothPropertyPtr> |
| 572 BluetoothPropertyType type) const { | 584 ArcBluetoothBridge::GetAdapterProperties( |
| 573 mojo::Array<BluetoothPropertyPtr> properties; | 585 mojom::BluetoothPropertyType type) const { |
| 586 mojo::Array<mojom::BluetoothPropertyPtr> properties; |
| 574 | 587 |
| 575 if (type == BluetoothPropertyType::ALL || | 588 if (type == mojom::BluetoothPropertyType::ALL || |
| 576 type == BluetoothPropertyType::BDNAME) { | 589 type == mojom::BluetoothPropertyType::BDNAME) { |
| 577 BluetoothPropertyPtr btp = BluetoothProperty::New(); | 590 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 578 std::string name = bluetooth_adapter_->GetName(); | 591 std::string name = bluetooth_adapter_->GetName(); |
| 579 btp->set_bdname(mojo::String(name)); | 592 btp->set_bdname(mojo::String(name)); |
| 580 properties.push_back(std::move(btp)); | 593 properties.push_back(std::move(btp)); |
| 581 } | 594 } |
| 582 if (type == BluetoothPropertyType::ALL || | 595 if (type == mojom::BluetoothPropertyType::ALL || |
| 583 type == BluetoothPropertyType::BDADDR) { | 596 type == mojom::BluetoothPropertyType::BDADDR) { |
| 584 BluetoothPropertyPtr btp = BluetoothProperty::New(); | 597 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 585 btp->set_bdaddr(BluetoothAddress::From(bluetooth_adapter_->GetAddress())); | 598 btp->set_bdaddr( |
| 599 mojom::BluetoothAddress::From(bluetooth_adapter_->GetAddress())); |
| 586 properties.push_back(std::move(btp)); | 600 properties.push_back(std::move(btp)); |
| 587 } | 601 } |
| 588 if (type == BluetoothPropertyType::ALL || | 602 if (type == mojom::BluetoothPropertyType::ALL || |
| 589 type == BluetoothPropertyType::UUIDS) { | 603 type == mojom::BluetoothPropertyType::UUIDS) { |
| 590 // TODO(smbarber): Fill in once GetUUIDs is available for the adapter. | 604 // TODO(smbarber): Fill in once GetUUIDs is available for the adapter. |
| 591 } | 605 } |
| 592 if (type == BluetoothPropertyType::ALL || | 606 if (type == mojom::BluetoothPropertyType::ALL || |
| 593 type == BluetoothPropertyType::CLASS_OF_DEVICE) { | 607 type == mojom::BluetoothPropertyType::CLASS_OF_DEVICE) { |
| 594 // TODO(smbarber): Populate with the actual adapter class | 608 // TODO(smbarber): Populate with the actual adapter class |
| 595 BluetoothPropertyPtr btp = BluetoothProperty::New(); | 609 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 596 btp->set_device_class(0); | 610 btp->set_device_class(0); |
| 597 properties.push_back(std::move(btp)); | 611 properties.push_back(std::move(btp)); |
| 598 } | 612 } |
| 599 if (type == BluetoothPropertyType::ALL || | 613 if (type == mojom::BluetoothPropertyType::ALL || |
| 600 type == BluetoothPropertyType::TYPE_OF_DEVICE) { | 614 type == mojom::BluetoothPropertyType::TYPE_OF_DEVICE) { |
| 601 // TODO(smbarber): Populate with the actual device type | 615 // TODO(smbarber): Populate with the actual device type |
| 602 BluetoothPropertyPtr btp = BluetoothProperty::New(); | 616 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 603 btp->set_device_type(BluetoothDeviceType::DUAL); | 617 btp->set_device_type(mojom::BluetoothDeviceType::DUAL); |
| 604 properties.push_back(std::move(btp)); | 618 properties.push_back(std::move(btp)); |
| 605 } | 619 } |
| 606 if (type == BluetoothPropertyType::ALL || | 620 if (type == mojom::BluetoothPropertyType::ALL || |
| 607 type == BluetoothPropertyType::ADAPTER_SCAN_MODE) { | 621 type == mojom::BluetoothPropertyType::ADAPTER_SCAN_MODE) { |
| 608 BluetoothPropertyPtr btp = BluetoothProperty::New(); | 622 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 609 BluetoothScanMode scan_mode = BluetoothScanMode::CONNECTABLE; | 623 mojom::BluetoothScanMode scan_mode = mojom::BluetoothScanMode::CONNECTABLE; |
| 610 | 624 |
| 611 if (bluetooth_adapter_->IsDiscoverable()) | 625 if (bluetooth_adapter_->IsDiscoverable()) |
| 612 scan_mode = BluetoothScanMode::CONNECTABLE_DISCOVERABLE; | 626 scan_mode = mojom::BluetoothScanMode::CONNECTABLE_DISCOVERABLE; |
| 613 | 627 |
| 614 btp->set_adapter_scan_mode(scan_mode); | 628 btp->set_adapter_scan_mode(scan_mode); |
| 615 properties.push_back(std::move(btp)); | 629 properties.push_back(std::move(btp)); |
| 616 } | 630 } |
| 617 if (type == BluetoothPropertyType::ALL || | 631 if (type == mojom::BluetoothPropertyType::ALL || |
| 618 type == BluetoothPropertyType::ADAPTER_BONDED_DEVICES) { | 632 type == mojom::BluetoothPropertyType::ADAPTER_BONDED_DEVICES) { |
| 619 BluetoothPropertyPtr btp = BluetoothProperty::New(); | 633 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 620 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); | 634 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); |
| 621 | 635 |
| 622 mojo::Array<BluetoothAddressPtr> bonded_devices = | 636 mojo::Array<mojom::BluetoothAddressPtr> bonded_devices = |
| 623 mojo::Array<BluetoothAddressPtr>::New(0); | 637 mojo::Array<mojom::BluetoothAddressPtr>::New(0); |
| 624 | 638 |
| 625 for (size_t i = 0; i < devices.size(); i++) { | 639 for (size_t i = 0; i < devices.size(); i++) { |
| 626 if (!devices[i]->IsPaired()) | 640 if (!devices[i]->IsPaired()) |
| 627 continue; | 641 continue; |
| 628 | 642 |
| 629 BluetoothAddressPtr addr = | 643 mojom::BluetoothAddressPtr addr = |
| 630 BluetoothAddress::From(devices[i]->GetAddress()); | 644 mojom::BluetoothAddress::From(devices[i]->GetAddress()); |
| 631 bonded_devices.push_back(std::move(addr)); | 645 bonded_devices.push_back(std::move(addr)); |
| 632 } | 646 } |
| 633 | 647 |
| 634 btp->set_bonded_devices(std::move(bonded_devices)); | 648 btp->set_bonded_devices(std::move(bonded_devices)); |
| 635 properties.push_back(std::move(btp)); | 649 properties.push_back(std::move(btp)); |
| 636 } | 650 } |
| 637 if (type == BluetoothPropertyType::ALL || | 651 if (type == mojom::BluetoothPropertyType::ALL || |
| 638 type == BluetoothPropertyType::ADAPTER_DISCOVERY_TIMEOUT) { | 652 type == mojom::BluetoothPropertyType::ADAPTER_DISCOVERY_TIMEOUT) { |
| 639 BluetoothPropertyPtr btp = BluetoothProperty::New(); | 653 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); |
| 640 btp->set_discovery_timeout(120); | 654 btp->set_discovery_timeout(120); |
| 641 properties.push_back(std::move(btp)); | 655 properties.push_back(std::move(btp)); |
| 642 } | 656 } |
| 643 | 657 |
| 644 return properties; | 658 return properties; |
| 645 } | 659 } |
| 646 | 660 |
| 647 void ArcBluetoothBridge::SendCachedDevicesFound() const { | 661 void ArcBluetoothBridge::SendCachedDevicesFound() const { |
| 648 // Send devices that have already been discovered, but aren't connected. | 662 // Send devices that have already been discovered, but aren't connected. |
| 649 if (!HasBluetoothInstance()) | 663 if (!HasBluetoothInstance()) |
| 650 return; | 664 return; |
| 651 | 665 |
| 652 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); | 666 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); |
| 653 for (size_t i = 0; i < devices.size(); i++) { | 667 for (size_t i = 0; i < devices.size(); i++) { |
| 654 if (devices[i]->IsPaired()) | 668 if (devices[i]->IsPaired()) |
| 655 continue; | 669 continue; |
| 656 | 670 |
| 657 mojo::Array<BluetoothPropertyPtr> properties = | 671 mojo::Array<mojom::BluetoothPropertyPtr> properties = |
| 658 GetDeviceProperties(BluetoothPropertyType::ALL, devices[i]); | 672 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, devices[i]); |
| 659 | 673 |
| 660 arc_bridge_service()->bluetooth_instance()->OnDeviceFound( | 674 arc_bridge_service()->bluetooth_instance()->OnDeviceFound( |
| 661 std::move(properties)); | 675 std::move(properties)); |
| 662 } | 676 } |
| 663 } | 677 } |
| 664 | 678 |
| 665 bool ArcBluetoothBridge::HasBluetoothInstance() const { | 679 bool ArcBluetoothBridge::HasBluetoothInstance() const { |
| 666 if (!arc_bridge_service()->bluetooth_instance()) { | 680 if (!arc_bridge_service()->bluetooth_instance()) { |
| 667 LOG(WARNING) << "no Bluetooth instance available"; | 681 LOG(WARNING) << "no Bluetooth instance available"; |
| 668 return false; | 682 return false; |
| 669 } | 683 } |
| 670 | 684 |
| 671 return true; | 685 return true; |
| 672 } | 686 } |
| 673 | 687 |
| 674 void ArcBluetoothBridge::SendCachedPairedDevices() const { | 688 void ArcBluetoothBridge::SendCachedPairedDevices() const { |
| 675 DCHECK(bluetooth_adapter_); | 689 DCHECK(bluetooth_adapter_); |
| 676 | 690 |
| 677 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); | 691 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); |
| 678 for (BluetoothDevice* device : devices) { | 692 for (BluetoothDevice* device : devices) { |
| 679 if (!device->IsPaired()) | 693 if (!device->IsPaired()) |
| 680 continue; | 694 continue; |
| 681 | 695 |
| 682 mojo::Array<BluetoothPropertyPtr> properties = | 696 mojo::Array<mojom::BluetoothPropertyPtr> properties = |
| 683 GetDeviceProperties(BluetoothPropertyType::ALL, device); | 697 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); |
| 684 | 698 |
| 685 arc_bridge_service()->bluetooth_instance()->OnDeviceFound( | 699 arc_bridge_service()->bluetooth_instance()->OnDeviceFound( |
| 686 std::move(properties)); | 700 std::move(properties)); |
| 687 | 701 |
| 688 BluetoothAddressPtr addr = BluetoothAddress::From(device->GetAddress()); | 702 mojom::BluetoothAddressPtr addr = |
| 703 mojom::BluetoothAddress::From(device->GetAddress()); |
| 689 | 704 |
| 690 // OnBondStateChanged must be called with BluetoothBondState::BONDING to | 705 // OnBondStateChanged must be called with mojom::BluetoothBondState::BONDING |
| 706 // to |
| 691 // make sure the bond state machine on Android is ready to take the | 707 // make sure the bond state machine on Android is ready to take the |
| 692 // pair-done event. Otherwise the pair-done event will be dropped as an | 708 // pair-done event. Otherwise the pair-done event will be dropped as an |
| 693 // invalid change of paired status. | 709 // invalid change of paired status. |
| 694 OnPairing(addr->Clone()); | 710 OnPairing(addr->Clone()); |
| 695 OnPairedDone(std::move(addr)); | 711 OnPairedDone(std::move(addr)); |
| 696 } | 712 } |
| 697 } | 713 } |
| 698 | 714 |
| 699 } // namespace arc | 715 } // namespace arc |
| OLD | NEW |