fake_fast_pair_gatt_service_client.cc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/quick_pair/fast_pair_handshake/fake_fast_pair_gatt_service_client.h"
  5. #include "ash/quick_pair/common/logging.h"
  6. #include "ash/quick_pair/fast_pair_handshake/fast_pair_data_encryptor.h"
  7. #include "base/callback_helpers.h"
  8. #include "device/bluetooth/bluetooth_adapter.h"
  9. #include "device/bluetooth/bluetooth_device.h"
  10. namespace ash {
  11. namespace quick_pair {
  12. FakeFastPairGattServiceClient::FakeFastPairGattServiceClient(
  13. device::BluetoothDevice* device,
  14. scoped_refptr<device::BluetoothAdapter> adapter,
  15. base::OnceCallback<void(absl::optional<PairFailure>)>
  16. on_initialized_callback)
  17. : on_initialized_callback_(std::move(on_initialized_callback)) {}
  18. FakeFastPairGattServiceClient::~FakeFastPairGattServiceClient() = default;
  19. void FakeFastPairGattServiceClient::RunOnGattClientInitializedCallback(
  20. absl::optional<PairFailure> failure) {
  21. std::move(on_initialized_callback_).Run(failure);
  22. }
  23. device::BluetoothRemoteGattService*
  24. FakeFastPairGattServiceClient::gatt_service() {
  25. return nullptr;
  26. }
  27. bool FakeFastPairGattServiceClient::IsConnected() {
  28. return is_connected_;
  29. }
  30. void FakeFastPairGattServiceClient::SetConnected(bool is_connected) {
  31. is_connected_ = is_connected;
  32. }
  33. void FakeFastPairGattServiceClient::WriteRequestAsync(
  34. uint8_t message_type,
  35. uint8_t flags,
  36. const std::string& provider_address,
  37. const std::string& seekers_address,
  38. FastPairDataEncryptor* fast_pair_data_encryptor,
  39. base::OnceCallback<void(std::vector<uint8_t>, absl::optional<PairFailure>)>
  40. write_response_callback) {
  41. key_based_write_response_callback_ = std::move(write_response_callback);
  42. }
  43. void FakeFastPairGattServiceClient::RunWriteResponseCallback(
  44. std::vector<uint8_t> data,
  45. absl::optional<PairFailure> failure) {
  46. std::move(key_based_write_response_callback_).Run(data, failure);
  47. }
  48. void FakeFastPairGattServiceClient::RunWritePasskeyCallback(
  49. std::vector<uint8_t> data,
  50. absl::optional<PairFailure> failure) {
  51. std::move(passkey_write_response_callback_).Run(data, failure);
  52. }
  53. void FakeFastPairGattServiceClient::WritePasskeyAsync(
  54. uint8_t message_type,
  55. uint32_t passkey,
  56. FastPairDataEncryptor* fast_pair_data_encryptor,
  57. base::OnceCallback<void(std::vector<uint8_t>, absl::optional<PairFailure>)>
  58. write_response_callback) {
  59. passkey_write_response_callback_ = std::move(write_response_callback);
  60. }
  61. void FakeFastPairGattServiceClient::WriteAccountKey(
  62. std::array<uint8_t, 16> account_key,
  63. FastPairDataEncryptor* fast_pair_data_encryptor,
  64. base::OnceCallback<
  65. void(absl::optional<device::BluetoothGattService::GattErrorCode>)>
  66. write_account_key_callback) {
  67. write_account_key_callback_ = std::move(write_account_key_callback);
  68. }
  69. void FakeFastPairGattServiceClient::RunWriteAccountKeyCallback(
  70. absl::optional<device::BluetoothGattService::GattErrorCode> error) {
  71. std::move(write_account_key_callback_).Run(error);
  72. }
  73. } // namespace quick_pair
  74. } // namespace ash