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 <bluetooth/bluetooth.h> | 7 #include <bluetooth/bluetooth.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 using device::BluetoothLocalGattCharacteristic; | 46 using device::BluetoothLocalGattCharacteristic; |
47 using device::BluetoothLocalGattDescriptor; | 47 using device::BluetoothLocalGattDescriptor; |
48 using device::BluetoothLocalGattService; | 48 using device::BluetoothLocalGattService; |
49 using device::BluetoothRemoteGattCharacteristic; | 49 using device::BluetoothRemoteGattCharacteristic; |
50 using device::BluetoothRemoteGattDescriptor; | 50 using device::BluetoothRemoteGattDescriptor; |
51 using device::BluetoothRemoteGattService; | 51 using device::BluetoothRemoteGattService; |
52 using device::BluetoothTransport; | 52 using device::BluetoothTransport; |
53 using device::BluetoothUUID; | 53 using device::BluetoothUUID; |
54 | 54 |
55 namespace { | 55 namespace { |
56 constexpr int32_t kMinBtleVersion = 1; | 56 constexpr uint32_t kMinBtleVersion = 1; |
57 constexpr int32_t kMinBtleNotifyVersion = 2; | 57 constexpr uint32_t kMinBtleNotifyVersion = 2; |
58 constexpr int32_t kMinGattServerVersion = 3; | 58 constexpr uint32_t kMinGattServerVersion = 3; |
59 constexpr int32_t kMinAddrChangeVersion = 4; | 59 constexpr uint32_t kMinAddrChangeVersion = 4; |
60 constexpr int32_t kMinSdpSupportVersion = 5; | 60 constexpr uint32_t kMinSdpSupportVersion = 5; |
61 constexpr uint32_t kGattReadPermission = | 61 constexpr uint32_t kGattReadPermission = |
62 BluetoothGattCharacteristic::Permission::PERMISSION_READ | | 62 BluetoothGattCharacteristic::Permission::PERMISSION_READ | |
63 BluetoothGattCharacteristic::Permission::PERMISSION_READ_ENCRYPTED | | 63 BluetoothGattCharacteristic::Permission::PERMISSION_READ_ENCRYPTED | |
64 BluetoothGattCharacteristic::Permission:: | 64 BluetoothGattCharacteristic::Permission:: |
65 PERMISSION_READ_ENCRYPTED_AUTHENTICATED; | 65 PERMISSION_READ_ENCRYPTED_AUTHENTICATED; |
66 constexpr uint32_t kGattWritePermission = | 66 constexpr uint32_t kGattWritePermission = |
67 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE | | 67 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE | |
68 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE_ENCRYPTED | | 68 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE_ENCRYPTED | |
69 BluetoothGattCharacteristic::Permission:: | 69 BluetoothGattCharacteristic::Permission:: |
70 PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED; | 70 PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED; |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 bluetooth_adapter_->AddObserver(this); | 305 bluetooth_adapter_->AddObserver(this); |
306 } | 306 } |
307 | 307 |
308 void ArcBluetoothBridge::OnInstanceClosed() { | 308 void ArcBluetoothBridge::OnInstanceClosed() { |
309 if (bluetooth_adapter_) | 309 if (bluetooth_adapter_) |
310 bluetooth_adapter_->RemoveObserver(this); | 310 bluetooth_adapter_->RemoveObserver(this); |
311 } | 311 } |
312 | 312 |
313 void ArcBluetoothBridge::AdapterPoweredChanged(BluetoothAdapter* adapter, | 313 void ArcBluetoothBridge::AdapterPoweredChanged(BluetoothAdapter* adapter, |
314 bool powered) { | 314 bool powered) { |
315 if (!HasBluetoothInstance()) | |
316 return; | |
317 | |
318 // TODO(smbarber): Invoke EnableAdapter or DisableAdapter via ARC bridge | 315 // TODO(smbarber): Invoke EnableAdapter or DisableAdapter via ARC bridge |
319 // service. | 316 // service. |
320 } | 317 } |
321 | 318 |
322 void ArcBluetoothBridge::DeviceAdded(BluetoothAdapter* adapter, | 319 void ArcBluetoothBridge::DeviceAdded(BluetoothAdapter* adapter, |
323 BluetoothDevice* device) { | 320 BluetoothDevice* device) { |
324 if (!HasBluetoothInstance()) | 321 auto* bluetooth_instance = |
| 322 arc_bridge_service()->bluetooth()->GetInstanceForMethod("OnDeviceFound"); |
| 323 if (!bluetooth_instance) |
325 return; | 324 return; |
326 | 325 |
327 mojo::Array<mojom::BluetoothPropertyPtr> properties = | 326 mojo::Array<mojom::BluetoothPropertyPtr> properties = |
328 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); | 327 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); |
329 | 328 |
330 arc_bridge_service()->bluetooth()->instance()->OnDeviceFound( | 329 bluetooth_instance->OnDeviceFound(std::move(properties)); |
331 std::move(properties)); | |
332 | 330 |
333 if (!CheckBluetoothInstanceVersion(kMinBtleVersion)) | 331 auto* btle_instance = arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 332 "OnLEDeviceFound", kMinBtleVersion); |
| 333 if (!btle_instance) |
334 return; | 334 return; |
335 | 335 |
336 if (!(device->GetType() & device::BLUETOOTH_TRANSPORT_LE)) | 336 if (!(device->GetType() & device::BLUETOOTH_TRANSPORT_LE)) |
337 return; | 337 return; |
338 | 338 |
339 mojom::BluetoothAddressPtr addr = | 339 mojom::BluetoothAddressPtr addr = |
340 mojom::BluetoothAddress::From(device->GetAddress()); | 340 mojom::BluetoothAddress::From(device->GetAddress()); |
341 base::Optional<int8_t> rssi = device->GetInquiryRSSI(); | 341 base::Optional<int8_t> rssi = device->GetInquiryRSSI(); |
342 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = | 342 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = |
343 GetAdvertisingData(device); | 343 GetAdvertisingData(device); |
344 arc_bridge_service()->bluetooth()->instance()->OnLEDeviceFound( | 344 btle_instance->OnLEDeviceFound(std::move(addr), |
345 std::move(addr), rssi.value_or(mojom::kUnknownPower), | 345 rssi.value_or(mojom::kUnknownPower), |
346 std::move(adv_data)); | 346 std::move(adv_data)); |
347 | 347 |
348 if (!device->IsConnected()) | 348 if (!device->IsConnected()) |
349 return; | 349 return; |
350 | 350 |
351 addr = mojom::BluetoothAddress::From(device->GetAddress()); | 351 addr = mojom::BluetoothAddress::From(device->GetAddress()); |
352 OnGattConnectStateChanged(std::move(addr), true); | 352 OnGattConnectStateChanged(std::move(addr), true); |
353 } | 353 } |
354 | 354 |
355 void ArcBluetoothBridge::DeviceChanged(BluetoothAdapter* adapter, | 355 void ArcBluetoothBridge::DeviceChanged(BluetoothAdapter* adapter, |
356 BluetoothDevice* device) { | 356 BluetoothDevice* device) { |
(...skipping 26 matching lines...) Expand all Loading... |
383 if (!(device->GetType() & device::BLUETOOTH_TRANSPORT_LE)) | 383 if (!(device->GetType() & device::BLUETOOTH_TRANSPORT_LE)) |
384 return; | 384 return; |
385 | 385 |
386 auto it = gatt_connection_cache_.find(old_address); | 386 auto it = gatt_connection_cache_.find(old_address); |
387 if (it == gatt_connection_cache_.end()) | 387 if (it == gatt_connection_cache_.end()) |
388 return; | 388 return; |
389 | 389 |
390 gatt_connection_cache_.erase(it); | 390 gatt_connection_cache_.erase(it); |
391 gatt_connection_cache_.insert(device->GetAddress()); | 391 gatt_connection_cache_.insert(device->GetAddress()); |
392 | 392 |
393 if (!HasBluetoothInstance()) | 393 auto* btle_instance = arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
394 return; | 394 "OnLEDeviceAddressChange", kMinAddrChangeVersion); |
395 | 395 if (!btle_instance) |
396 if (!CheckBluetoothInstanceVersion(kMinAddrChangeVersion)) | |
397 return; | 396 return; |
398 | 397 |
399 mojom::BluetoothAddressPtr old_addr = | 398 mojom::BluetoothAddressPtr old_addr = |
400 mojom::BluetoothAddress::From(old_address); | 399 mojom::BluetoothAddress::From(old_address); |
401 mojom::BluetoothAddressPtr new_addr = | 400 mojom::BluetoothAddressPtr new_addr = |
402 mojom::BluetoothAddress::From(device->GetAddress()); | 401 mojom::BluetoothAddress::From(device->GetAddress()); |
403 arc_bridge_service()->bluetooth()->instance()->OnLEDeviceAddressChange( | 402 btle_instance->OnLEDeviceAddressChange(std::move(old_addr), |
404 std::move(old_addr), std::move(new_addr)); | 403 std::move(new_addr)); |
405 } | 404 } |
406 | 405 |
407 void ArcBluetoothBridge::DevicePairedChanged(BluetoothAdapter* adapter, | 406 void ArcBluetoothBridge::DevicePairedChanged(BluetoothAdapter* adapter, |
408 BluetoothDevice* device, | 407 BluetoothDevice* device, |
409 bool new_paired_status) { | 408 bool new_paired_status) { |
410 DCHECK(adapter); | 409 DCHECK(adapter); |
411 DCHECK(device); | 410 DCHECK(device); |
412 | 411 |
413 mojom::BluetoothAddressPtr addr = | 412 mojom::BluetoothAddressPtr addr = |
414 mojom::BluetoothAddress::From(device->GetAddress()); | 413 mojom::BluetoothAddress::From(device->GetAddress()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 | 450 |
452 void ArcBluetoothBridge::GattServiceRemoved( | 451 void ArcBluetoothBridge::GattServiceRemoved( |
453 BluetoothAdapter* adapter, | 452 BluetoothAdapter* adapter, |
454 BluetoothDevice* device, | 453 BluetoothDevice* device, |
455 BluetoothRemoteGattService* service) { | 454 BluetoothRemoteGattService* service) { |
456 // Placeholder for GATT client functionality | 455 // Placeholder for GATT client functionality |
457 } | 456 } |
458 | 457 |
459 void ArcBluetoothBridge::GattServicesDiscovered(BluetoothAdapter* adapter, | 458 void ArcBluetoothBridge::GattServicesDiscovered(BluetoothAdapter* adapter, |
460 BluetoothDevice* device) { | 459 BluetoothDevice* device) { |
461 if (!HasBluetoothInstance()) | 460 auto* btle_instance = arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
462 return; | 461 "OnSearchComplete", kMinBtleVersion); |
463 | 462 if (!btle_instance) |
464 if (!CheckBluetoothInstanceVersion(kMinBtleVersion)) | |
465 return; | 463 return; |
466 | 464 |
467 mojom::BluetoothAddressPtr addr = | 465 mojom::BluetoothAddressPtr addr = |
468 mojom::BluetoothAddress::From(device->GetAddress()); | 466 mojom::BluetoothAddress::From(device->GetAddress()); |
469 | 467 |
470 arc_bridge_service()->bluetooth()->instance()->OnSearchComplete( | 468 btle_instance->OnSearchComplete(std::move(addr), |
471 std::move(addr), mojom::BluetoothGattStatus::GATT_SUCCESS); | 469 mojom::BluetoothGattStatus::GATT_SUCCESS); |
472 } | 470 } |
473 | 471 |
474 void ArcBluetoothBridge::GattDiscoveryCompleteForService( | 472 void ArcBluetoothBridge::GattDiscoveryCompleteForService( |
475 BluetoothAdapter* adapter, | 473 BluetoothAdapter* adapter, |
476 BluetoothRemoteGattService* service) { | 474 BluetoothRemoteGattService* service) { |
477 // Placeholder for GATT client functionality | 475 // Placeholder for GATT client functionality |
478 } | 476 } |
479 | 477 |
480 void ArcBluetoothBridge::GattServiceChanged( | 478 void ArcBluetoothBridge::GattServiceChanged( |
481 BluetoothAdapter* adapter, | 479 BluetoothAdapter* adapter, |
(...skipping 22 matching lines...) Expand all Loading... |
504 void ArcBluetoothBridge::GattDescriptorRemoved( | 502 void ArcBluetoothBridge::GattDescriptorRemoved( |
505 BluetoothAdapter* adapter, | 503 BluetoothAdapter* adapter, |
506 BluetoothRemoteGattDescriptor* descriptor) { | 504 BluetoothRemoteGattDescriptor* descriptor) { |
507 // Placeholder for GATT client functionality | 505 // Placeholder for GATT client functionality |
508 } | 506 } |
509 | 507 |
510 void ArcBluetoothBridge::GattCharacteristicValueChanged( | 508 void ArcBluetoothBridge::GattCharacteristicValueChanged( |
511 BluetoothAdapter* adapter, | 509 BluetoothAdapter* adapter, |
512 BluetoothRemoteGattCharacteristic* characteristic, | 510 BluetoothRemoteGattCharacteristic* characteristic, |
513 const std::vector<uint8_t>& value) { | 511 const std::vector<uint8_t>& value) { |
514 if (!HasBluetoothInstance()) | 512 auto* btle_instance = arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
515 return; | 513 "OnGattNotify", kMinBtleNotifyVersion); |
516 | 514 if (!btle_instance) |
517 if (!CheckBluetoothInstanceVersion(kMinBtleNotifyVersion)) | |
518 return; | 515 return; |
519 | 516 |
520 BluetoothRemoteGattService* service = characteristic->GetService(); | 517 BluetoothRemoteGattService* service = characteristic->GetService(); |
521 BluetoothDevice* device = service->GetDevice(); | 518 BluetoothDevice* device = service->GetDevice(); |
522 mojom::BluetoothAddressPtr address = | 519 mojom::BluetoothAddressPtr address = |
523 mojom::BluetoothAddress::From(device->GetAddress()); | 520 mojom::BluetoothAddress::From(device->GetAddress()); |
524 mojom::BluetoothGattServiceIDPtr service_id = | 521 mojom::BluetoothGattServiceIDPtr service_id = |
525 mojom::BluetoothGattServiceID::New(); | 522 mojom::BluetoothGattServiceID::New(); |
526 service_id->is_primary = service->IsPrimary(); | 523 service_id->is_primary = service->IsPrimary(); |
527 service_id->id = mojom::BluetoothGattID::New(); | 524 service_id->id = mojom::BluetoothGattID::New(); |
528 service_id->id->inst_id = ConvertGattIdentifierToId(service->GetIdentifier()); | 525 service_id->id->inst_id = ConvertGattIdentifierToId(service->GetIdentifier()); |
529 service_id->id->uuid = service->GetUUID(); | 526 service_id->id->uuid = service->GetUUID(); |
530 | 527 |
531 mojom::BluetoothGattIDPtr char_id = mojom::BluetoothGattID::New(); | 528 mojom::BluetoothGattIDPtr char_id = mojom::BluetoothGattID::New(); |
532 char_id->inst_id = ConvertGattIdentifierToId(characteristic->GetIdentifier()); | 529 char_id->inst_id = ConvertGattIdentifierToId(characteristic->GetIdentifier()); |
533 char_id->uuid = characteristic->GetUUID(); | 530 char_id->uuid = characteristic->GetUUID(); |
534 | 531 |
535 arc_bridge_service()->bluetooth()->instance()->OnGattNotify( | 532 btle_instance->OnGattNotify(std::move(address), std::move(service_id), |
536 std::move(address), std::move(service_id), std::move(char_id), | 533 std::move(char_id), true /* is_notify */, |
537 true /* is_notify */, mojo::Array<uint8_t>::From(value)); | 534 mojo::Array<uint8_t>::From(value)); |
538 } | 535 } |
539 | 536 |
540 void ArcBluetoothBridge::GattDescriptorValueChanged( | 537 void ArcBluetoothBridge::GattDescriptorValueChanged( |
541 BluetoothAdapter* adapter, | 538 BluetoothAdapter* adapter, |
542 BluetoothRemoteGattDescriptor* descriptor, | 539 BluetoothRemoteGattDescriptor* descriptor, |
543 const std::vector<uint8_t>& value) { | 540 const std::vector<uint8_t>& value) { |
544 // Placeholder for GATT client functionality | 541 // Placeholder for GATT client functionality |
545 } | 542 } |
546 | 543 |
547 template <class LocalGattAttribute> | 544 template <class LocalGattAttribute> |
548 void ArcBluetoothBridge::OnGattAttributeReadRequest( | 545 void ArcBluetoothBridge::OnGattAttributeReadRequest( |
549 const BluetoothDevice* device, | 546 const BluetoothDevice* device, |
550 const LocalGattAttribute* attribute, | 547 const LocalGattAttribute* attribute, |
551 int offset, | 548 int offset, |
552 const ValueCallback& success_callback, | 549 const ValueCallback& success_callback, |
553 const ErrorCallback& error_callback) { | 550 const ErrorCallback& error_callback) { |
554 DCHECK(CalledOnValidThread()); | 551 DCHECK(CalledOnValidThread()); |
555 if (!HasBluetoothInstance() || | 552 auto* bluetooth_instance = |
556 !CheckBluetoothInstanceVersion(kMinGattServerVersion) || | 553 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
557 !IsGattOffsetValid(offset)) { | 554 "RequestGattRead", kMinGattServerVersion); |
| 555 if (!bluetooth_instance || !IsGattOffsetValid(offset)) { |
558 error_callback.Run(); | 556 error_callback.Run(); |
559 return; | 557 return; |
560 } | 558 } |
561 | 559 |
562 DCHECK(gatt_handle_.find(attribute->GetIdentifier()) != gatt_handle_.end()); | 560 DCHECK(gatt_handle_.find(attribute->GetIdentifier()) != gatt_handle_.end()); |
563 | 561 |
564 arc_bridge_service()->bluetooth()->instance()->RequestGattRead( | 562 bluetooth_instance->RequestGattRead( |
565 mojom::BluetoothAddress::From(device->GetAddress()), | 563 mojom::BluetoothAddress::From(device->GetAddress()), |
566 gatt_handle_[attribute->GetIdentifier()], offset, false /* is_long */, | 564 gatt_handle_[attribute->GetIdentifier()], offset, false /* is_long */, |
567 base::Bind(&OnGattServerRead, success_callback, error_callback)); | 565 base::Bind(&OnGattServerRead, success_callback, error_callback)); |
568 } | 566 } |
569 | 567 |
570 template <class LocalGattAttribute> | 568 template <class LocalGattAttribute> |
571 void ArcBluetoothBridge::OnGattAttributeWriteRequest( | 569 void ArcBluetoothBridge::OnGattAttributeWriteRequest( |
572 const BluetoothDevice* device, | 570 const BluetoothDevice* device, |
573 const LocalGattAttribute* attribute, | 571 const LocalGattAttribute* attribute, |
574 const std::vector<uint8_t>& value, | 572 const std::vector<uint8_t>& value, |
575 int offset, | 573 int offset, |
576 const base::Closure& success_callback, | 574 const base::Closure& success_callback, |
577 const ErrorCallback& error_callback) { | 575 const ErrorCallback& error_callback) { |
578 DCHECK(CalledOnValidThread()); | 576 DCHECK(CalledOnValidThread()); |
579 if (!HasBluetoothInstance() || | 577 auto* bluetooth_instance = |
580 !CheckBluetoothInstanceVersion(kMinGattServerVersion) || | 578 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
581 !IsGattOffsetValid(offset)) { | 579 "RequestGattWrite", kMinGattServerVersion); |
| 580 if (!bluetooth_instance || !IsGattOffsetValid(offset)) { |
582 error_callback.Run(); | 581 error_callback.Run(); |
583 return; | 582 return; |
584 } | 583 } |
585 | 584 |
586 DCHECK(gatt_handle_.find(attribute->GetIdentifier()) != gatt_handle_.end()); | 585 DCHECK(gatt_handle_.find(attribute->GetIdentifier()) != gatt_handle_.end()); |
587 | 586 |
588 arc_bridge_service()->bluetooth()->instance()->RequestGattWrite( | 587 bluetooth_instance->RequestGattWrite( |
589 mojom::BluetoothAddress::From(device->GetAddress()), | 588 mojom::BluetoothAddress::From(device->GetAddress()), |
590 gatt_handle_[attribute->GetIdentifier()], offset, | 589 gatt_handle_[attribute->GetIdentifier()], offset, |
591 mojo::Array<uint8_t>::From(value), | 590 mojo::Array<uint8_t>::From(value), |
592 base::Bind(&OnGattServerWrite, success_callback, error_callback)); | 591 base::Bind(&OnGattServerWrite, success_callback, error_callback)); |
593 } | 592 } |
594 | 593 |
595 void ArcBluetoothBridge::OnCharacteristicReadRequest( | 594 void ArcBluetoothBridge::OnCharacteristicReadRequest( |
596 const BluetoothDevice* device, | 595 const BluetoothDevice* device, |
597 const BluetoothLocalGattCharacteristic* characteristic, | 596 const BluetoothLocalGattCharacteristic* characteristic, |
598 int offset, | 597 int offset, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 DCHECK(bluetooth_adapter_); | 660 DCHECK(bluetooth_adapter_); |
662 bluetooth_adapter_->SetPowered( | 661 bluetooth_adapter_->SetPowered( |
663 false, base::Bind(&ArcBluetoothBridge::OnPoweredOff, | 662 false, base::Bind(&ArcBluetoothBridge::OnPoweredOff, |
664 weak_factory_.GetWeakPtr(), callback), | 663 weak_factory_.GetWeakPtr(), callback), |
665 base::Bind(&ArcBluetoothBridge::OnPoweredError, | 664 base::Bind(&ArcBluetoothBridge::OnPoweredError, |
666 weak_factory_.GetWeakPtr(), callback)); | 665 weak_factory_.GetWeakPtr(), callback)); |
667 } | 666 } |
668 | 667 |
669 void ArcBluetoothBridge::GetAdapterProperty(mojom::BluetoothPropertyType type) { | 668 void ArcBluetoothBridge::GetAdapterProperty(mojom::BluetoothPropertyType type) { |
670 DCHECK(bluetooth_adapter_); | 669 DCHECK(bluetooth_adapter_); |
671 if (!HasBluetoothInstance()) | 670 auto* bluetooth_instance = |
| 671 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 672 "OnAdapterProperties"); |
| 673 if (!bluetooth_instance) |
672 return; | 674 return; |
673 | 675 |
674 mojo::Array<mojom::BluetoothPropertyPtr> properties = | 676 mojo::Array<mojom::BluetoothPropertyPtr> properties = |
675 GetAdapterProperties(type); | 677 GetAdapterProperties(type); |
676 | 678 |
677 arc_bridge_service()->bluetooth()->instance()->OnAdapterProperties( | 679 bluetooth_instance->OnAdapterProperties(mojom::BluetoothStatus::SUCCESS, |
678 mojom::BluetoothStatus::SUCCESS, std::move(properties)); | 680 std::move(properties)); |
679 } | 681 } |
680 | 682 |
681 void ArcBluetoothBridge::OnSetDiscoverable(bool discoverable, | 683 void ArcBluetoothBridge::OnSetDiscoverable(bool discoverable, |
682 bool success, | 684 bool success, |
683 uint32_t timeout) { | 685 uint32_t timeout) { |
684 DCHECK(CalledOnValidThread()); | 686 DCHECK(CalledOnValidThread()); |
685 | 687 |
686 if (success && discoverable && timeout > 0) { | 688 if (success && discoverable && timeout > 0) { |
687 discoverable_off_timer_.Start( | 689 discoverable_off_timer_.Start( |
688 FROM_HERE, base::TimeDelta::FromSeconds(timeout), | 690 FROM_HERE, base::TimeDelta::FromSeconds(timeout), |
689 base::Bind(&ArcBluetoothBridge::SetDiscoverable, | 691 base::Bind(&ArcBluetoothBridge::SetDiscoverable, |
690 weak_factory_.GetWeakPtr(), false, 0)); | 692 weak_factory_.GetWeakPtr(), false, 0)); |
691 } | 693 } |
692 | 694 |
693 if (!HasBluetoothInstance()) | 695 auto* bluetooth_instance = |
| 696 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 697 "OnAdapterProperties"); |
| 698 if (!bluetooth_instance) |
694 return; | 699 return; |
695 | 700 |
696 if (success) { | 701 if (success) { |
697 arc_bridge_service()->bluetooth()->instance()->OnAdapterProperties( | 702 bluetooth_instance->OnAdapterProperties( |
698 mojom::BluetoothStatus::SUCCESS, GetDiscoveryTimeoutProperty(timeout)); | 703 mojom::BluetoothStatus::SUCCESS, GetDiscoveryTimeoutProperty(timeout)); |
699 } else { | 704 } else { |
700 arc_bridge_service()->bluetooth()->instance()->OnAdapterProperties( | 705 bluetooth_instance->OnAdapterProperties( |
701 mojom::BluetoothStatus::FAIL, | 706 mojom::BluetoothStatus::FAIL, |
702 mojo::Array<arc::mojom::BluetoothPropertyPtr>::New(0)); | 707 mojo::Array<arc::mojom::BluetoothPropertyPtr>::New(0)); |
703 } | 708 } |
704 } | 709 } |
705 | 710 |
706 // Set discoverable state to on / off. | 711 // Set discoverable state to on / off. |
707 // In case of turning on, start timer to turn it back off in |timeout| seconds. | 712 // In case of turning on, start timer to turn it back off in |timeout| seconds. |
708 void ArcBluetoothBridge::SetDiscoverable(bool discoverable, uint32_t timeout) { | 713 void ArcBluetoothBridge::SetDiscoverable(bool discoverable, uint32_t timeout) { |
709 DCHECK(bluetooth_adapter_); | 714 DCHECK(bluetooth_adapter_); |
710 DCHECK(CalledOnValidThread()); | 715 DCHECK(CalledOnValidThread()); |
711 DCHECK(!discoverable || timeout == 0); | 716 DCHECK(!discoverable || timeout == 0); |
712 | 717 |
713 bool currently_discoverable = bluetooth_adapter_->IsDiscoverable(); | 718 bool currently_discoverable = bluetooth_adapter_->IsDiscoverable(); |
714 | 719 |
715 if (!discoverable && !currently_discoverable) | 720 if (!discoverable && !currently_discoverable) |
716 return; | 721 return; |
717 | 722 |
| 723 auto* bluetooth_instance = |
| 724 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 725 "OnAdapterProperties"); |
| 726 |
718 if (discoverable && currently_discoverable) { | 727 if (discoverable && currently_discoverable) { |
719 if (base::TimeDelta::FromSeconds(timeout) > | 728 if (base::TimeDelta::FromSeconds(timeout) > |
720 discoverable_off_timer_.GetCurrentDelay()) { | 729 discoverable_off_timer_.GetCurrentDelay()) { |
721 // Restart discoverable_off_timer_ if new timeout is greater | 730 // Restart discoverable_off_timer_ if new timeout is greater |
722 OnSetDiscoverable(true, true, timeout); | 731 OnSetDiscoverable(true, true, timeout); |
723 } else if (HasBluetoothInstance()) { | 732 } else if (bluetooth_instance) { |
724 // Just send message to Android if new timeout is lower. | 733 // Just send message to Android if new timeout is lower. |
725 arc_bridge_service()->bluetooth()->instance()->OnAdapterProperties( | 734 bluetooth_instance->OnAdapterProperties( |
726 mojom::BluetoothStatus::SUCCESS, | 735 mojom::BluetoothStatus::SUCCESS, |
727 GetDiscoveryTimeoutProperty(timeout)); | 736 GetDiscoveryTimeoutProperty(timeout)); |
728 } | 737 } |
729 return; | 738 return; |
730 } | 739 } |
731 | 740 |
732 bluetooth_adapter_->SetDiscoverable( | 741 bluetooth_adapter_->SetDiscoverable( |
733 discoverable, | 742 discoverable, |
734 base::Bind(&ArcBluetoothBridge::OnSetDiscoverable, | 743 base::Bind(&ArcBluetoothBridge::OnSetDiscoverable, |
735 weak_factory_.GetWeakPtr(), discoverable, true, timeout), | 744 weak_factory_.GetWeakPtr(), discoverable, true, timeout), |
736 base::Bind(&ArcBluetoothBridge::OnSetDiscoverable, | 745 base::Bind(&ArcBluetoothBridge::OnSetDiscoverable, |
737 weak_factory_.GetWeakPtr(), discoverable, false, timeout)); | 746 weak_factory_.GetWeakPtr(), discoverable, false, timeout)); |
738 } | 747 } |
739 | 748 |
740 void ArcBluetoothBridge::SetAdapterProperty( | 749 void ArcBluetoothBridge::SetAdapterProperty( |
741 mojom::BluetoothPropertyPtr property) { | 750 mojom::BluetoothPropertyPtr property) { |
742 DCHECK(bluetooth_adapter_); | 751 DCHECK(bluetooth_adapter_); |
743 if (!HasBluetoothInstance()) | 752 auto* bluetooth_instance = |
| 753 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 754 "OnAdapterProperties"); |
| 755 if (!bluetooth_instance) |
744 return; | 756 return; |
745 | 757 |
746 if (property->is_discovery_timeout()) { | 758 if (property->is_discovery_timeout()) { |
747 uint32_t discovery_timeout = property->get_discovery_timeout(); | 759 uint32_t discovery_timeout = property->get_discovery_timeout(); |
748 if (discovery_timeout > 0) { | 760 if (discovery_timeout > 0) { |
749 SetDiscoverable(true, discovery_timeout); | 761 SetDiscoverable(true, discovery_timeout); |
750 } else { | 762 } else { |
751 arc_bridge_service()->bluetooth()->instance()->OnAdapterProperties( | 763 bluetooth_instance->OnAdapterProperties( |
752 mojom::BluetoothStatus::PARM_INVALID, | 764 mojom::BluetoothStatus::PARM_INVALID, |
753 mojo::Array<arc::mojom::BluetoothPropertyPtr>::New(0)); | 765 mojo::Array<arc::mojom::BluetoothPropertyPtr>::New(0)); |
754 } | 766 } |
755 } else { | 767 } else { |
756 // TODO(puthik) Implement other case. | 768 // TODO(puthik) Implement other case. |
757 arc_bridge_service()->bluetooth()->instance()->OnAdapterProperties( | 769 bluetooth_instance->OnAdapterProperties( |
758 mojom::BluetoothStatus::UNSUPPORTED, | 770 mojom::BluetoothStatus::UNSUPPORTED, |
759 mojo::Array<arc::mojom::BluetoothPropertyPtr>::New(0)); | 771 mojo::Array<arc::mojom::BluetoothPropertyPtr>::New(0)); |
760 } | 772 } |
761 } | 773 } |
762 | 774 |
763 void ArcBluetoothBridge::GetRemoteDeviceProperty( | 775 void ArcBluetoothBridge::GetRemoteDeviceProperty( |
764 mojom::BluetoothAddressPtr remote_addr, | 776 mojom::BluetoothAddressPtr remote_addr, |
765 mojom::BluetoothPropertyType type) { | 777 mojom::BluetoothPropertyType type) { |
766 DCHECK(bluetooth_adapter_); | 778 DCHECK(bluetooth_adapter_); |
767 if (!HasBluetoothInstance()) | 779 auto* bluetooth_instance = |
| 780 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 781 "OnRemoteDeviceProperties"); |
| 782 if (!bluetooth_instance) |
768 return; | 783 return; |
769 | 784 |
770 std::string addr_str = remote_addr->To<std::string>(); | 785 std::string addr_str = remote_addr->To<std::string>(); |
771 BluetoothDevice* device = bluetooth_adapter_->GetDevice(addr_str); | 786 BluetoothDevice* device = bluetooth_adapter_->GetDevice(addr_str); |
772 | 787 |
773 mojo::Array<mojom::BluetoothPropertyPtr> properties = | 788 mojo::Array<mojom::BluetoothPropertyPtr> properties = |
774 GetDeviceProperties(type, device); | 789 GetDeviceProperties(type, device); |
775 mojom::BluetoothStatus status = mojom::BluetoothStatus::SUCCESS; | 790 mojom::BluetoothStatus status = mojom::BluetoothStatus::SUCCESS; |
776 | 791 |
777 if (!device) { | 792 if (!device) { |
778 VLOG(1) << __func__ << ": device " << addr_str << " not available"; | 793 VLOG(1) << __func__ << ": device " << addr_str << " not available"; |
779 status = mojom::BluetoothStatus::FAIL; | 794 status = mojom::BluetoothStatus::FAIL; |
780 } | 795 } |
781 | 796 |
782 arc_bridge_service()->bluetooth()->instance()->OnRemoteDeviceProperties( | 797 bluetooth_instance->OnRemoteDeviceProperties(status, std::move(remote_addr), |
783 status, std::move(remote_addr), std::move(properties)); | 798 std::move(properties)); |
784 } | 799 } |
785 | 800 |
786 void ArcBluetoothBridge::SetRemoteDeviceProperty( | 801 void ArcBluetoothBridge::SetRemoteDeviceProperty( |
787 mojom::BluetoothAddressPtr remote_addr, | 802 mojom::BluetoothAddressPtr remote_addr, |
788 mojom::BluetoothPropertyPtr property) { | 803 mojom::BluetoothPropertyPtr property) { |
789 DCHECK(bluetooth_adapter_); | 804 DCHECK(bluetooth_adapter_); |
790 if (!HasBluetoothInstance()) | 805 auto* bluetooth_instance = |
| 806 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 807 "OnRemoteDeviceProperties"); |
| 808 if (!bluetooth_instance) |
791 return; | 809 return; |
792 | 810 |
793 // TODO(smbarber): Implement SetRemoteDeviceProperty | 811 // TODO(smbarber): Implement SetRemoteDeviceProperty |
794 arc_bridge_service()->bluetooth()->instance()->OnRemoteDeviceProperties( | 812 bluetooth_instance->OnRemoteDeviceProperties( |
795 mojom::BluetoothStatus::FAIL, std::move(remote_addr), | 813 mojom::BluetoothStatus::FAIL, std::move(remote_addr), |
796 mojo::Array<mojom::BluetoothPropertyPtr>::New(0)); | 814 mojo::Array<mojom::BluetoothPropertyPtr>::New(0)); |
797 } | 815 } |
798 | 816 |
799 void ArcBluetoothBridge::GetRemoteServiceRecord( | 817 void ArcBluetoothBridge::GetRemoteServiceRecord( |
800 mojom::BluetoothAddressPtr remote_addr, | 818 mojom::BluetoothAddressPtr remote_addr, |
801 const BluetoothUUID& uuid) { | 819 const BluetoothUUID& uuid) { |
802 // TODO(smbarber): Implement GetRemoteServiceRecord | 820 // TODO(smbarber): Implement GetRemoteServiceRecord |
803 } | 821 } |
804 | 822 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const { | 867 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const { |
850 LOG(WARNING) << "failed to change power state"; | 868 LOG(WARNING) << "failed to change power state"; |
851 | 869 |
852 callback.Run(bluetooth_adapter_->IsPowered() | 870 callback.Run(bluetooth_adapter_->IsPowered() |
853 ? mojom::BluetoothAdapterState::ON | 871 ? mojom::BluetoothAdapterState::ON |
854 : mojom::BluetoothAdapterState::OFF); | 872 : mojom::BluetoothAdapterState::OFF); |
855 } | 873 } |
856 | 874 |
857 void ArcBluetoothBridge::OnDiscoveryStarted( | 875 void ArcBluetoothBridge::OnDiscoveryStarted( |
858 std::unique_ptr<BluetoothDiscoverySession> session) { | 876 std::unique_ptr<BluetoothDiscoverySession> session) { |
859 if (!HasBluetoothInstance()) | 877 auto* bluetooth_instance = |
| 878 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 879 "OnDiscoveryStateChanged"); |
| 880 if (!bluetooth_instance) |
860 return; | 881 return; |
861 | 882 |
862 discovery_session_ = std::move(session); | 883 discovery_session_ = std::move(session); |
863 | 884 |
864 arc_bridge_service()->bluetooth()->instance()->OnDiscoveryStateChanged( | 885 bluetooth_instance->OnDiscoveryStateChanged( |
865 mojom::BluetoothDiscoveryState::STARTED); | 886 mojom::BluetoothDiscoveryState::STARTED); |
866 | 887 |
867 SendCachedDevicesFound(); | 888 SendCachedDevicesFound(); |
868 } | 889 } |
869 | 890 |
870 void ArcBluetoothBridge::OnDiscoveryStopped() { | 891 void ArcBluetoothBridge::OnDiscoveryStopped() { |
871 if (!HasBluetoothInstance()) | 892 auto* bluetooth_instance = |
| 893 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 894 "OnDiscoveryStateChanged"); |
| 895 if (!bluetooth_instance) |
872 return; | 896 return; |
873 | 897 |
874 discovery_session_.reset(); | 898 discovery_session_.reset(); |
875 | 899 |
876 arc_bridge_service()->bluetooth()->instance()->OnDiscoveryStateChanged( | 900 bluetooth_instance->OnDiscoveryStateChanged( |
877 mojom::BluetoothDiscoveryState::STOPPED); | 901 mojom::BluetoothDiscoveryState::STOPPED); |
878 } | 902 } |
879 | 903 |
880 void ArcBluetoothBridge::CreateBond(mojom::BluetoothAddressPtr addr, | 904 void ArcBluetoothBridge::CreateBond(mojom::BluetoothAddressPtr addr, |
881 int32_t transport) { | 905 int32_t transport) { |
882 std::string addr_str = addr->To<std::string>(); | 906 std::string addr_str = addr->To<std::string>(); |
883 BluetoothDevice* device = bluetooth_adapter_->GetDevice(addr_str); | 907 BluetoothDevice* device = bluetooth_adapter_->GetDevice(addr_str); |
884 if (!device || !device->IsPairable()) { | 908 if (!device || !device->IsPairable()) { |
885 VLOG(1) << __func__ << ": device " << addr_str | 909 VLOG(1) << __func__ << ": device " << addr_str |
886 << " is no longer valid or pairable"; | 910 << " is no longer valid or pairable"; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 weak_factory_.GetWeakPtr())); | 996 weak_factory_.GetWeakPtr())); |
973 } | 997 } |
974 | 998 |
975 void ArcBluetoothBridge::StopLEScan() { | 999 void ArcBluetoothBridge::StopLEScan() { |
976 CancelDiscovery(); | 1000 CancelDiscovery(); |
977 } | 1001 } |
978 | 1002 |
979 void ArcBluetoothBridge::OnGattConnectStateChanged( | 1003 void ArcBluetoothBridge::OnGattConnectStateChanged( |
980 mojom::BluetoothAddressPtr addr, | 1004 mojom::BluetoothAddressPtr addr, |
981 bool connected) const { | 1005 bool connected) const { |
982 if (!HasBluetoothInstance()) | 1006 auto* btle_instance = arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
983 return; | 1007 "OnLEConnectionStateChange", kMinBtleVersion); |
984 | 1008 if (!btle_instance) |
985 if (!CheckBluetoothInstanceVersion(kMinBtleVersion)) | |
986 return; | 1009 return; |
987 | 1010 |
988 DCHECK(addr); | 1011 DCHECK(addr); |
989 | 1012 |
990 arc_bridge_service()->bluetooth()->instance()->OnLEConnectionStateChange( | 1013 btle_instance->OnLEConnectionStateChange(std::move(addr), connected); |
991 std::move(addr), connected); | |
992 } | 1014 } |
993 | 1015 |
994 void ArcBluetoothBridge::OnGattConnected( | 1016 void ArcBluetoothBridge::OnGattConnected( |
995 mojom::BluetoothAddressPtr addr, | 1017 mojom::BluetoothAddressPtr addr, |
996 std::unique_ptr<BluetoothGattConnection> connection) { | 1018 std::unique_ptr<BluetoothGattConnection> connection) { |
997 DCHECK(CalledOnValidThread()); | 1019 DCHECK(CalledOnValidThread()); |
998 gatt_connections_[addr->To<std::string>()] = std::move(connection); | 1020 gatt_connections_[addr->To<std::string>()] = std::move(connection); |
999 OnGattConnectStateChanged(std::move(addr), true); | 1021 OnGattConnectStateChanged(std::move(addr), true); |
1000 } | 1022 } |
1001 | 1023 |
(...skipping 12 matching lines...) Expand all Loading... |
1014 << "but no gatt connection was found"; | 1036 << "but no gatt connection was found"; |
1015 } else { | 1037 } else { |
1016 gatt_connections_.erase(it); | 1038 gatt_connections_.erase(it); |
1017 } | 1039 } |
1018 | 1040 |
1019 OnGattConnectStateChanged(std::move(addr), false); | 1041 OnGattConnectStateChanged(std::move(addr), false); |
1020 } | 1042 } |
1021 | 1043 |
1022 void ArcBluetoothBridge::ConnectLEDevice( | 1044 void ArcBluetoothBridge::ConnectLEDevice( |
1023 mojom::BluetoothAddressPtr remote_addr) { | 1045 mojom::BluetoothAddressPtr remote_addr) { |
1024 if (!HasBluetoothInstance()) | 1046 auto* bluetooth_instance = |
| 1047 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 1048 "OnLEConnectionStateChange", kMinBtleVersion); |
| 1049 if (!bluetooth_instance) |
1025 return; | 1050 return; |
1026 | 1051 |
1027 BluetoothDevice* device = | 1052 BluetoothDevice* device = |
1028 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); | 1053 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); |
1029 DCHECK(device); | 1054 DCHECK(device); |
1030 | 1055 |
1031 if (device->IsConnected()) { | 1056 if (device->IsConnected()) { |
1032 arc_bridge_service()->bluetooth()->instance()->OnLEConnectionStateChange( | 1057 bluetooth_instance->OnLEConnectionStateChange(std::move(remote_addr), true); |
1033 std::move(remote_addr), true); | |
1034 return; | 1058 return; |
1035 } | 1059 } |
1036 | 1060 |
1037 // Also pass disconnect callback in error case since it would be disconnected | 1061 // Also pass disconnect callback in error case since it would be disconnected |
1038 // anyway. | 1062 // anyway. |
1039 mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone(); | 1063 mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone(); |
1040 device->CreateGattConnection( | 1064 device->CreateGattConnection( |
1041 base::Bind(&ArcBluetoothBridge::OnGattConnected, | 1065 base::Bind(&ArcBluetoothBridge::OnGattConnected, |
1042 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr)), | 1066 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr)), |
1043 base::Bind(&ArcBluetoothBridge::OnGattConnectError, | 1067 base::Bind(&ArcBluetoothBridge::OnGattConnectError, |
1044 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr_clone))); | 1068 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr_clone))); |
1045 } | 1069 } |
1046 | 1070 |
1047 void ArcBluetoothBridge::DisconnectLEDevice( | 1071 void ArcBluetoothBridge::DisconnectLEDevice( |
1048 mojom::BluetoothAddressPtr remote_addr) { | 1072 mojom::BluetoothAddressPtr remote_addr) { |
1049 if (!HasBluetoothInstance()) | 1073 auto* bluetooth_instance = |
| 1074 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 1075 "OnLEConnectionStateChange", kMinBtleVersion); |
| 1076 if (!bluetooth_instance) |
1050 return; | 1077 return; |
1051 | 1078 |
1052 BluetoothDevice* device = | 1079 BluetoothDevice* device = |
1053 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); | 1080 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); |
1054 DCHECK(device); | 1081 DCHECK(device); |
1055 | 1082 |
1056 if (!device->IsConnected()) { | 1083 if (!device->IsConnected()) { |
1057 arc_bridge_service()->bluetooth()->instance()->OnLEConnectionStateChange( | 1084 bluetooth_instance->OnLEConnectionStateChange(std::move(remote_addr), |
1058 std::move(remote_addr), false); | 1085 false); |
1059 return; | 1086 return; |
1060 } | 1087 } |
1061 | 1088 |
1062 mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone(); | 1089 mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone(); |
1063 device->Disconnect( | 1090 device->Disconnect( |
1064 base::Bind(&ArcBluetoothBridge::OnGattDisconnected, | 1091 base::Bind(&ArcBluetoothBridge::OnGattDisconnected, |
1065 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr)), | 1092 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr)), |
1066 base::Bind(&ArcBluetoothBridge::OnGattDisconnected, | 1093 base::Bind(&ArcBluetoothBridge::OnGattDisconnected, |
1067 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr_clone))); | 1094 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr_clone))); |
1068 } | 1095 } |
1069 | 1096 |
1070 void ArcBluetoothBridge::SearchService(mojom::BluetoothAddressPtr remote_addr) { | 1097 void ArcBluetoothBridge::SearchService(mojom::BluetoothAddressPtr remote_addr) { |
1071 if (!HasBluetoothInstance()) | 1098 auto* bluetooth_instance = |
| 1099 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 1100 "OnSearchComplete", kMinBtleVersion); |
| 1101 if (!bluetooth_instance) |
1072 return; | 1102 return; |
1073 | 1103 |
1074 BluetoothDevice* device = | 1104 BluetoothDevice* device = |
1075 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); | 1105 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); |
1076 DCHECK(device); | 1106 DCHECK(device); |
1077 | 1107 |
1078 // Call the callback if discovery is completed | 1108 // Call the callback if discovery is completed |
1079 if (device->IsGattServicesDiscoveryComplete()) { | 1109 if (device->IsGattServicesDiscoveryComplete()) { |
1080 arc_bridge_service()->bluetooth()->instance()->OnSearchComplete( | 1110 bluetooth_instance->OnSearchComplete( |
1081 std::move(remote_addr), mojom::BluetoothGattStatus::GATT_SUCCESS); | 1111 std::move(remote_addr), mojom::BluetoothGattStatus::GATT_SUCCESS); |
1082 return; | 1112 return; |
1083 } | 1113 } |
1084 | 1114 |
1085 // Discard result. Will call the callback when discovery is completed. | 1115 // Discard result. Will call the callback when discovery is completed. |
1086 device->GetGattServices(); | 1116 device->GetGattServices(); |
1087 } | 1117 } |
1088 | 1118 |
1089 void ArcBluetoothBridge::OnStartLEListenDone( | 1119 void ArcBluetoothBridge::OnStartLEListenDone( |
1090 const StartLEListenCallback& callback, | 1120 const StartLEListenCallback& callback, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 BluetoothAdvertisement::ErrorCode::ERROR_ADVERTISEMENT_DOES_NOT_EXIST); | 1166 BluetoothAdvertisement::ErrorCode::ERROR_ADVERTISEMENT_DOES_NOT_EXIST); |
1137 return; | 1167 return; |
1138 } | 1168 } |
1139 advertisment_->Unregister(base::Bind(&ArcBluetoothBridge::OnStopLEListenDone, | 1169 advertisment_->Unregister(base::Bind(&ArcBluetoothBridge::OnStopLEListenDone, |
1140 weak_factory_.GetWeakPtr(), callback), | 1170 weak_factory_.GetWeakPtr(), callback), |
1141 base::Bind(&ArcBluetoothBridge::OnStopLEListenError, | 1171 base::Bind(&ArcBluetoothBridge::OnStopLEListenError, |
1142 weak_factory_.GetWeakPtr(), callback)); | 1172 weak_factory_.GetWeakPtr(), callback)); |
1143 } | 1173 } |
1144 | 1174 |
1145 void ArcBluetoothBridge::GetGattDB(mojom::BluetoothAddressPtr remote_addr) { | 1175 void ArcBluetoothBridge::GetGattDB(mojom::BluetoothAddressPtr remote_addr) { |
1146 if (!HasBluetoothInstance()) | 1176 auto* bluetooth_instance = |
| 1177 arc_bridge_service()->bluetooth()->GetInstanceForMethod("OnGetGattDB", |
| 1178 kMinBtleVersion); |
| 1179 if (!bluetooth_instance) |
1147 return; | 1180 return; |
1148 | 1181 |
1149 BluetoothDevice* device = | 1182 BluetoothDevice* device = |
1150 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); | 1183 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); |
1151 mojo::Array<mojom::BluetoothGattDBElementPtr> db; | 1184 mojo::Array<mojom::BluetoothGattDBElementPtr> db; |
1152 for (auto* service : device->GetGattServices()) { | 1185 for (auto* service : device->GetGattServices()) { |
1153 mojom::BluetoothGattDBElementPtr service_element = CreateGattDBElement( | 1186 mojom::BluetoothGattDBElementPtr service_element = CreateGattDBElement( |
1154 service->IsPrimary() | 1187 service->IsPrimary() |
1155 ? mojom::BluetoothGattDBAttributeType::BTGATT_DB_PRIMARY_SERVICE | 1188 ? mojom::BluetoothGattDBAttributeType::BTGATT_DB_PRIMARY_SERVICE |
1156 : mojom::BluetoothGattDBAttributeType::BTGATT_DB_SECONDARY_SERVICE, | 1189 : mojom::BluetoothGattDBAttributeType::BTGATT_DB_SECONDARY_SERVICE, |
(...skipping 19 matching lines...) Expand all Loading... |
1176 db.push_back(std::move(characteristic_element)); | 1209 db.push_back(std::move(characteristic_element)); |
1177 | 1210 |
1178 for (auto* descriptor : characteristic->GetDescriptors()) { | 1211 for (auto* descriptor : characteristic->GetDescriptors()) { |
1179 db.push_back(CreateGattDBElement( | 1212 db.push_back(CreateGattDBElement( |
1180 mojom::BluetoothGattDBAttributeType::BTGATT_DB_DESCRIPTOR, | 1213 mojom::BluetoothGattDBAttributeType::BTGATT_DB_DESCRIPTOR, |
1181 descriptor)); | 1214 descriptor)); |
1182 } | 1215 } |
1183 } | 1216 } |
1184 } | 1217 } |
1185 | 1218 |
1186 arc_bridge_service()->bluetooth()->instance()->OnGetGattDB( | 1219 bluetooth_instance->OnGetGattDB(std::move(remote_addr), std::move(db)); |
1187 std::move(remote_addr), std::move(db)); | |
1188 } | 1220 } |
1189 | 1221 |
1190 BluetoothRemoteGattCharacteristic* ArcBluetoothBridge::FindGattCharacteristic( | 1222 BluetoothRemoteGattCharacteristic* ArcBluetoothBridge::FindGattCharacteristic( |
1191 mojom::BluetoothAddressPtr remote_addr, | 1223 mojom::BluetoothAddressPtr remote_addr, |
1192 mojom::BluetoothGattServiceIDPtr service_id, | 1224 mojom::BluetoothGattServiceIDPtr service_id, |
1193 mojom::BluetoothGattIDPtr char_id) const { | 1225 mojom::BluetoothGattIDPtr char_id) const { |
1194 DCHECK(remote_addr); | 1226 DCHECK(remote_addr); |
1195 DCHECK(service_id); | 1227 DCHECK(service_id); |
1196 DCHECK(char_id); | 1228 DCHECK(char_id); |
1197 | 1229 |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1576 bluetooth_adapter_->RemoveServiceRecord( | 1608 bluetooth_adapter_->RemoveServiceRecord( |
1577 service_handle, base::Bind(&OnRemoveServiceRecordDone, callback), | 1609 service_handle, base::Bind(&OnRemoveServiceRecordDone, callback), |
1578 base::Bind(&OnRemoveServiceRecordError, callback)); | 1610 base::Bind(&OnRemoveServiceRecordError, callback)); |
1579 } | 1611 } |
1580 | 1612 |
1581 void ArcBluetoothBridge::OnDiscoveryError() { | 1613 void ArcBluetoothBridge::OnDiscoveryError() { |
1582 LOG(WARNING) << "failed to change discovery state"; | 1614 LOG(WARNING) << "failed to change discovery state"; |
1583 } | 1615 } |
1584 | 1616 |
1585 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { | 1617 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { |
1586 if (!HasBluetoothInstance()) | 1618 auto* bluetooth_instance = |
| 1619 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 1620 "OnBondStateChanged"); |
| 1621 if (!bluetooth_instance) |
1587 return; | 1622 return; |
1588 | 1623 |
1589 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged( | 1624 bluetooth_instance->OnBondStateChanged(mojom::BluetoothStatus::SUCCESS, |
1590 mojom::BluetoothStatus::SUCCESS, std::move(addr), | 1625 std::move(addr), |
1591 mojom::BluetoothBondState::BONDING); | 1626 mojom::BluetoothBondState::BONDING); |
1592 } | 1627 } |
1593 | 1628 |
1594 void ArcBluetoothBridge::OnPairedDone(mojom::BluetoothAddressPtr addr) const { | 1629 void ArcBluetoothBridge::OnPairedDone(mojom::BluetoothAddressPtr addr) const { |
1595 if (!HasBluetoothInstance()) | 1630 auto* bluetooth_instance = |
| 1631 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 1632 "OnBondStateChanged"); |
| 1633 if (!bluetooth_instance) |
1596 return; | 1634 return; |
1597 | 1635 |
1598 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged( | 1636 bluetooth_instance->OnBondStateChanged(mojom::BluetoothStatus::SUCCESS, |
1599 mojom::BluetoothStatus::SUCCESS, std::move(addr), | 1637 std::move(addr), |
1600 mojom::BluetoothBondState::BONDED); | 1638 mojom::BluetoothBondState::BONDED); |
1601 } | 1639 } |
1602 | 1640 |
1603 void ArcBluetoothBridge::OnPairedError( | 1641 void ArcBluetoothBridge::OnPairedError( |
1604 mojom::BluetoothAddressPtr addr, | 1642 mojom::BluetoothAddressPtr addr, |
1605 BluetoothDevice::ConnectErrorCode error_code) const { | 1643 BluetoothDevice::ConnectErrorCode error_code) const { |
1606 if (!HasBluetoothInstance()) | 1644 auto* bluetooth_instance = |
| 1645 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 1646 "OnBondStateChanged"); |
| 1647 if (!bluetooth_instance) |
1607 return; | 1648 return; |
1608 | 1649 |
1609 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged( | 1650 bluetooth_instance->OnBondStateChanged(mojom::BluetoothStatus::FAIL, |
1610 mojom::BluetoothStatus::FAIL, std::move(addr), | 1651 std::move(addr), |
1611 mojom::BluetoothBondState::NONE); | 1652 mojom::BluetoothBondState::NONE); |
1612 } | 1653 } |
1613 | 1654 |
1614 void ArcBluetoothBridge::OnForgetDone(mojom::BluetoothAddressPtr addr) const { | 1655 void ArcBluetoothBridge::OnForgetDone(mojom::BluetoothAddressPtr addr) const { |
1615 if (!HasBluetoothInstance()) | 1656 auto* bluetooth_instance = |
| 1657 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 1658 "OnBondStateChanged"); |
| 1659 if (!bluetooth_instance) |
1616 return; | 1660 return; |
1617 | 1661 |
1618 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged( | 1662 bluetooth_instance->OnBondStateChanged(mojom::BluetoothStatus::SUCCESS, |
1619 mojom::BluetoothStatus::SUCCESS, std::move(addr), | 1663 std::move(addr), |
1620 mojom::BluetoothBondState::NONE); | 1664 mojom::BluetoothBondState::NONE); |
1621 } | 1665 } |
1622 | 1666 |
1623 void ArcBluetoothBridge::OnForgetError(mojom::BluetoothAddressPtr addr) const { | 1667 void ArcBluetoothBridge::OnForgetError(mojom::BluetoothAddressPtr addr) const { |
1624 if (!HasBluetoothInstance()) | 1668 auto* bluetooth_instance = |
| 1669 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 1670 "OnBondStateChanged"); |
| 1671 if (!bluetooth_instance) |
1625 return; | 1672 return; |
1626 | 1673 |
1627 BluetoothDevice* device = | 1674 BluetoothDevice* device = |
1628 bluetooth_adapter_->GetDevice(addr->To<std::string>()); | 1675 bluetooth_adapter_->GetDevice(addr->To<std::string>()); |
1629 mojom::BluetoothBondState bond_state = mojom::BluetoothBondState::NONE; | 1676 mojom::BluetoothBondState bond_state = mojom::BluetoothBondState::NONE; |
1630 if (device && device->IsPaired()) { | 1677 if (device && device->IsPaired()) { |
1631 bond_state = mojom::BluetoothBondState::BONDED; | 1678 bond_state = mojom::BluetoothBondState::BONDED; |
1632 } | 1679 } |
1633 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged( | 1680 bluetooth_instance->OnBondStateChanged(mojom::BluetoothStatus::FAIL, |
1634 mojom::BluetoothStatus::FAIL, std::move(addr), bond_state); | 1681 std::move(addr), bond_state); |
1635 } | 1682 } |
1636 | 1683 |
1637 mojo::Array<mojom::BluetoothPropertyPtr> | 1684 mojo::Array<mojom::BluetoothPropertyPtr> |
1638 ArcBluetoothBridge::GetDeviceProperties(mojom::BluetoothPropertyType type, | 1685 ArcBluetoothBridge::GetDeviceProperties(mojom::BluetoothPropertyType type, |
1639 BluetoothDevice* device) const { | 1686 BluetoothDevice* device) const { |
1640 mojo::Array<mojom::BluetoothPropertyPtr> properties; | 1687 mojo::Array<mojom::BluetoothPropertyPtr> properties; |
1641 | 1688 |
1642 if (!device) { | 1689 if (!device) { |
1643 return properties; | 1690 return properties; |
1644 } | 1691 } |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1840 | 1887 |
1841 service_data_element->set_service_data(std::move(service_data)); | 1888 service_data_element->set_service_data(std::move(service_data)); |
1842 advertising_data.push_back(std::move(service_data_element)); | 1889 advertising_data.push_back(std::move(service_data_element)); |
1843 } | 1890 } |
1844 | 1891 |
1845 return advertising_data; | 1892 return advertising_data; |
1846 } | 1893 } |
1847 | 1894 |
1848 void ArcBluetoothBridge::SendCachedDevicesFound() const { | 1895 void ArcBluetoothBridge::SendCachedDevicesFound() const { |
1849 // Send devices that have already been discovered, but aren't connected. | 1896 // Send devices that have already been discovered, but aren't connected. |
1850 if (!HasBluetoothInstance()) | 1897 auto* bluetooth_instance = |
| 1898 arc_bridge_service()->bluetooth()->GetInstanceForMethod("OnDeviceFound"); |
| 1899 if (!bluetooth_instance) |
1851 return; | 1900 return; |
| 1901 auto* btle_instance = arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 1902 "OnLEDeviceFound", kMinBtleVersion); |
1852 | 1903 |
1853 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); | 1904 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); |
1854 for (auto* device : devices) { | 1905 for (auto* device : devices) { |
1855 if (device->IsPaired()) | 1906 if (device->IsPaired()) |
1856 continue; | 1907 continue; |
1857 | 1908 |
1858 mojo::Array<mojom::BluetoothPropertyPtr> properties = | 1909 mojo::Array<mojom::BluetoothPropertyPtr> properties = |
1859 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); | 1910 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); |
1860 | 1911 |
1861 arc_bridge_service()->bluetooth()->instance()->OnDeviceFound( | 1912 bluetooth_instance->OnDeviceFound(std::move(properties)); |
1862 std::move(properties)); | |
1863 | 1913 |
1864 if (arc_bridge_service()->bluetooth()->version() >= kMinBtleVersion) { | 1914 if (btle_instance) { |
1865 mojom::BluetoothAddressPtr addr = | 1915 mojom::BluetoothAddressPtr addr = |
1866 mojom::BluetoothAddress::From(device->GetAddress()); | 1916 mojom::BluetoothAddress::From(device->GetAddress()); |
1867 base::Optional<int8_t> rssi = device->GetInquiryRSSI(); | 1917 base::Optional<int8_t> rssi = device->GetInquiryRSSI(); |
1868 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = | 1918 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = |
1869 GetAdvertisingData(device); | 1919 GetAdvertisingData(device); |
1870 arc_bridge_service()->bluetooth()->instance()->OnLEDeviceFound( | 1920 btle_instance->OnLEDeviceFound(std::move(addr), |
1871 std::move(addr), rssi.value_or(mojom::kUnknownPower), | 1921 rssi.value_or(mojom::kUnknownPower), |
1872 std::move(adv_data)); | 1922 std::move(adv_data)); |
1873 } | 1923 } |
1874 } | 1924 } |
1875 } | 1925 } |
1876 | 1926 |
1877 bool ArcBluetoothBridge::HasBluetoothInstance() const { | |
1878 if (!arc_bridge_service()->bluetooth()->instance()) { | |
1879 LOG(WARNING) << "no Bluetooth instance available"; | |
1880 return false; | |
1881 } | |
1882 | |
1883 return true; | |
1884 } | |
1885 | |
1886 void ArcBluetoothBridge::SendCachedPairedDevices() const { | 1927 void ArcBluetoothBridge::SendCachedPairedDevices() const { |
1887 DCHECK(bluetooth_adapter_); | 1928 DCHECK(bluetooth_adapter_); |
1888 if (!HasBluetoothInstance()) | 1929 auto* bluetooth_instance = |
| 1930 arc_bridge_service()->bluetooth()->GetInstanceForMethod("OnDeviceFound"); |
| 1931 if (!bluetooth_instance) |
1889 return; | 1932 return; |
| 1933 auto* btle_instance = arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 1934 "OnLEDeviceFound", kMinBtleVersion); |
1890 | 1935 |
1891 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); | 1936 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); |
1892 for (auto* device : devices) { | 1937 for (auto* device : devices) { |
1893 if (!device->IsPaired()) | 1938 if (!device->IsPaired()) |
1894 continue; | 1939 continue; |
1895 | 1940 |
1896 mojo::Array<mojom::BluetoothPropertyPtr> properties = | 1941 mojo::Array<mojom::BluetoothPropertyPtr> properties = |
1897 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); | 1942 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); |
1898 | 1943 |
1899 arc_bridge_service()->bluetooth()->instance()->OnDeviceFound( | 1944 bluetooth_instance->OnDeviceFound(std::move(properties)); |
1900 std::move(properties)); | |
1901 | 1945 |
1902 mojom::BluetoothAddressPtr addr = | 1946 mojom::BluetoothAddressPtr addr = |
1903 mojom::BluetoothAddress::From(device->GetAddress()); | 1947 mojom::BluetoothAddress::From(device->GetAddress()); |
1904 | 1948 |
1905 if (arc_bridge_service()->bluetooth()->version() >= kMinBtleVersion) { | 1949 if (btle_instance) { |
1906 base::Optional<int8_t> rssi = device->GetInquiryRSSI(); | 1950 base::Optional<int8_t> rssi = device->GetInquiryRSSI(); |
1907 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = | 1951 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = |
1908 GetAdvertisingData(device); | 1952 GetAdvertisingData(device); |
1909 arc_bridge_service()->bluetooth()->instance()->OnLEDeviceFound( | 1953 btle_instance->OnLEDeviceFound(addr->Clone(), |
1910 addr->Clone(), rssi.value_or(mojom::kUnknownPower), | 1954 rssi.value_or(mojom::kUnknownPower), |
1911 std::move(adv_data)); | 1955 std::move(adv_data)); |
1912 } | 1956 } |
1913 | 1957 |
1914 // OnBondStateChanged must be called with mojom::BluetoothBondState::BONDING | 1958 // OnBondStateChanged must be called with mojom::BluetoothBondState::BONDING |
1915 // to make sure the bond state machine on Android is ready to take the | 1959 // to make sure the bond state machine on Android is ready to take the |
1916 // pair-done event. Otherwise the pair-done event will be dropped as an | 1960 // pair-done event. Otherwise the pair-done event will be dropped as an |
1917 // invalid change of paired status. | 1961 // invalid change of paired status. |
1918 OnPairing(addr->Clone()); | 1962 OnPairing(addr->Clone()); |
1919 OnPairedDone(std::move(addr)); | 1963 OnPairedDone(std::move(addr)); |
1920 } | 1964 } |
1921 } | 1965 } |
1922 | 1966 |
1923 void ArcBluetoothBridge::OnGetServiceRecordsDone( | 1967 void ArcBluetoothBridge::OnGetServiceRecordsDone( |
1924 mojom::BluetoothAddressPtr remote_addr, | 1968 mojom::BluetoothAddressPtr remote_addr, |
1925 const BluetoothUUID& target_uuid, | 1969 const BluetoothUUID& target_uuid, |
1926 const std::vector<bluez::BluetoothServiceRecordBlueZ>& records_bluez) { | 1970 const std::vector<bluez::BluetoothServiceRecordBlueZ>& records_bluez) { |
1927 if (!CheckBluetoothInstanceVersion(kMinSdpSupportVersion)) | 1971 auto* sdp_bluetooth_instance = |
| 1972 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
| 1973 "OnGetSdpRecords", kMinSdpSupportVersion); |
| 1974 if (!sdp_bluetooth_instance) |
1928 return; | 1975 return; |
1929 | 1976 |
1930 if (!HasBluetoothInstance()) | 1977 sdp_bluetooth_instance->OnGetSdpRecords( |
1931 return; | |
1932 | |
1933 arc_bridge_service()->bluetooth()->instance()->OnGetSdpRecords( | |
1934 mojom::BluetoothStatus::SUCCESS, std::move(remote_addr), target_uuid, | 1978 mojom::BluetoothStatus::SUCCESS, std::move(remote_addr), target_uuid, |
1935 mojo::Array<mojom::BluetoothSdpRecordPtr>::From(records_bluez)); | 1979 mojo::Array<mojom::BluetoothSdpRecordPtr>::From(records_bluez)); |
1936 } | 1980 } |
1937 | 1981 |
1938 void ArcBluetoothBridge::OnGetServiceRecordsError( | 1982 void ArcBluetoothBridge::OnGetServiceRecordsError( |
1939 mojom::BluetoothAddressPtr remote_addr, | 1983 mojom::BluetoothAddressPtr remote_addr, |
1940 const BluetoothUUID& target_uuid, | 1984 const BluetoothUUID& target_uuid, |
1941 bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code) { | 1985 bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code) { |
1942 if (!HasBluetoothInstance()) | 1986 auto* sdp_bluetooth_instance = |
1943 return; | 1987 arc_bridge_service()->bluetooth()->GetInstanceForMethod( |
1944 | 1988 "OnGetSdpRecords", kMinSdpSupportVersion); |
1945 if (!CheckBluetoothInstanceVersion(kMinSdpSupportVersion)) | 1989 if (!sdp_bluetooth_instance) |
1946 return; | 1990 return; |
1947 | 1991 |
1948 mojom::BluetoothStatus status; | 1992 mojom::BluetoothStatus status; |
1949 | 1993 |
1950 switch (error_code) { | 1994 switch (error_code) { |
1951 case bluez::BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY: | 1995 case bluez::BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY: |
1952 status = mojom::BluetoothStatus::NOT_READY; | 1996 status = mojom::BluetoothStatus::NOT_READY; |
1953 break; | 1997 break; |
1954 case bluez::BluetoothServiceRecordBlueZ::ErrorCode:: | 1998 case bluez::BluetoothServiceRecordBlueZ::ErrorCode:: |
1955 ERROR_DEVICE_DISCONNECTED: | 1999 ERROR_DEVICE_DISCONNECTED: |
1956 status = mojom::BluetoothStatus::RMT_DEV_DOWN; | 2000 status = mojom::BluetoothStatus::RMT_DEV_DOWN; |
1957 break; | 2001 break; |
1958 default: | 2002 default: |
1959 status = mojom::BluetoothStatus::FAIL; | 2003 status = mojom::BluetoothStatus::FAIL; |
1960 break; | 2004 break; |
1961 } | 2005 } |
1962 | 2006 |
1963 arc_bridge_service()->bluetooth()->instance()->OnGetSdpRecords( | 2007 sdp_bluetooth_instance->OnGetSdpRecords( |
1964 status, std::move(remote_addr), target_uuid, | 2008 status, std::move(remote_addr), target_uuid, |
1965 mojo::Array<mojom::BluetoothSdpRecordPtr>::New(0)); | 2009 mojo::Array<mojom::BluetoothSdpRecordPtr>::New(0)); |
1966 } | 2010 } |
1967 | 2011 |
1968 bool ArcBluetoothBridge::CheckBluetoothInstanceVersion( | |
1969 uint32_t version_need) const { | |
1970 uint32_t version = arc_bridge_service()->bluetooth()->version(); | |
1971 if (version >= version_need) | |
1972 return true; | |
1973 LOG(WARNING) << "Bluetooth instance is too old (version " << version | |
1974 << ") need version " << version_need; | |
1975 return false; | |
1976 } | |
1977 | |
1978 bool ArcBluetoothBridge::CalledOnValidThread() { | 2012 bool ArcBluetoothBridge::CalledOnValidThread() { |
1979 return thread_checker_.CalledOnValidThread(); | 2013 return thread_checker_.CalledOnValidThread(); |
1980 } | 2014 } |
1981 | 2015 |
1982 } // namespace arc | 2016 } // namespace arc |
OLD | NEW |