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