fake_fast_pair_gatt_service_client.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright 2021 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. #ifndef ASH_QUICK_PAIR_FAST_PAIR_HANDSHAKE_FAKE_FAST_PAIR_GATT_SERVICE_CLIENT_H_
  5. #define ASH_QUICK_PAIR_FAST_PAIR_HANDSHAKE_FAKE_FAST_PAIR_GATT_SERVICE_CLIENT_H_
  6. #include "ash/quick_pair/common/pair_failure.h"
  7. #include "ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client.h"
  8. #include "base/callback.h"
  9. #include "third_party/abseil-cpp/absl/types/optional.h"
  10. namespace device {
  11. class BluetoothDevice;
  12. } // namespace device
  13. namespace ash {
  14. namespace quick_pair {
  15. class FastPairDataEncryptor;
  16. // This class fakes FastPairGattServiceClient and permits setting which
  17. // PairFailure, if any, is run with the callback.
  18. class FakeFastPairGattServiceClient : public FastPairGattServiceClient {
  19. public:
  20. FakeFastPairGattServiceClient(
  21. device::BluetoothDevice* device,
  22. scoped_refptr<device::BluetoothAdapter> adapter,
  23. base::OnceCallback<void(absl::optional<PairFailure>)>
  24. on_initialized_callback);
  25. ~FakeFastPairGattServiceClient() override;
  26. device::BluetoothRemoteGattService* gatt_service() override;
  27. bool IsConnected() override;
  28. void SetConnected(bool is_connected);
  29. void WriteRequestAsync(uint8_t message_type,
  30. uint8_t flags,
  31. const std::string& provider_address,
  32. const std::string& seekers_address,
  33. FastPairDataEncryptor* fast_pair_data_encryptor,
  34. base::OnceCallback<void(std::vector<uint8_t>,
  35. absl::optional<PairFailure>)>
  36. write_response_callback) override;
  37. void WritePasskeyAsync(uint8_t message_type,
  38. uint32_t passkey,
  39. FastPairDataEncryptor* fast_pair_data_encryptor,
  40. base::OnceCallback<void(std::vector<uint8_t>,
  41. absl::optional<PairFailure>)>
  42. write_response_callback) override;
  43. void WriteAccountKey(
  44. std::array<uint8_t, 16> account_key,
  45. FastPairDataEncryptor* fast_pair_data_encryptor,
  46. base::OnceCallback<
  47. void(absl::optional<device::BluetoothGattService::GattErrorCode>)>
  48. write_account_key_callback) override;
  49. void RunOnGattClientInitializedCallback(
  50. absl::optional<PairFailure> failure = absl::nullopt);
  51. void RunWriteResponseCallback(
  52. std::vector<uint8_t> data,
  53. absl::optional<PairFailure> failure = absl::nullopt);
  54. void RunWritePasskeyCallback(
  55. std::vector<uint8_t> data,
  56. absl::optional<PairFailure> failure = absl::nullopt);
  57. void RunWriteAccountKeyCallback(
  58. absl::optional<device::BluetoothGattService::GattErrorCode> error =
  59. absl::nullopt);
  60. private:
  61. bool is_connected_ = false;
  62. base::OnceCallback<void(absl::optional<PairFailure>)>
  63. on_initialized_callback_;
  64. base::OnceCallback<void(std::vector<uint8_t>, absl::optional<PairFailure>)>
  65. key_based_write_response_callback_;
  66. base::OnceCallback<void(std::vector<uint8_t>, absl::optional<PairFailure>)>
  67. passkey_write_response_callback_;
  68. base::OnceCallback<void(
  69. absl::optional<device::BluetoothGattService::GattErrorCode>)>
  70. write_account_key_callback_;
  71. };
  72. } // namespace quick_pair
  73. } // namespace ash
  74. #endif // ASH_QUICK_PAIR_FAST_PAIR_HANDSHAKE_FAKE_FAST_PAIR_GATT_SERVICE_CLIENT_H_