fake_fast_pair_repository.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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_REPOSITORY_FAKE_FAST_PAIR_REPOSITORY_H_
  5. #define ASH_QUICK_PAIR_REPOSITORY_FAKE_FAST_PAIR_REPOSITORY_H_
  6. #include "ash/quick_pair/common/device.h"
  7. #include "ash/quick_pair/proto/fastpair.pb.h"
  8. #include "ash/quick_pair/repository/fast_pair/device_metadata.h"
  9. #include "ash/quick_pair/repository/fast_pair_repository.h"
  10. #include "base/callback.h"
  11. #include "base/containers/flat_map.h"
  12. #include "third_party/abseil-cpp/absl/types/optional.h"
  13. namespace chromeos {
  14. namespace bluetooth_config {
  15. class DeviceImageInfo;
  16. } // namespace bluetooth_config
  17. } // namespace chromeos
  18. namespace device {
  19. class BluetoothDevice;
  20. } // namespace device
  21. namespace ash {
  22. namespace quick_pair {
  23. // The entry point for the Repository component in the Quick Pair system,
  24. // responsible for connecting to back-end services.
  25. class FakeFastPairRepository : public FastPairRepository {
  26. public:
  27. FakeFastPairRepository();
  28. FakeFastPairRepository(const FakeFastPairRepository&) = delete;
  29. FakeFastPairRepository& operator=(const FakeFastPairRepository&) = delete;
  30. ~FakeFastPairRepository() override;
  31. void SetFakeMetadata(const std::string& hex_model_id,
  32. nearby::fastpair::Device metadata,
  33. gfx::Image image = gfx::Image());
  34. void ClearFakeMetadata(const std::string& hex_model_id);
  35. void SetCheckAccountKeysResult(absl::optional<PairingMetadata> result);
  36. void set_is_account_key_paired_locally(bool is_account_key_paired_locally) {
  37. is_account_key_paired_locally_ = is_account_key_paired_locally;
  38. }
  39. bool HasKeyForDevice(const std::string& mac_address);
  40. void set_is_network_connected(bool is_connected) {
  41. is_network_connected_ = is_connected;
  42. }
  43. void SetOptInStatus(nearby::fastpair::OptInStatus status);
  44. nearby::fastpair::OptInStatus GetOptInStatus();
  45. void SetSavedDevices(nearby::fastpair::OptInStatus status,
  46. std::vector<nearby::fastpair::FastPairDevice> devices);
  47. // FastPairRepository::
  48. void GetDeviceMetadata(const std::string& hex_model_id,
  49. DeviceMetadataCallback callback) override;
  50. void CheckAccountKeys(const AccountKeyFilter& account_key_filter,
  51. CheckAccountKeysCallback callback) override;
  52. void AssociateAccountKey(scoped_refptr<Device> device,
  53. const std::vector<uint8_t>& account_key) override;
  54. bool AssociateAccountKeyLocally(scoped_refptr<Device> device) override;
  55. void DeleteAssociatedDevice(const std::string& mac_address,
  56. DeleteAssociatedDeviceCallback callback) override;
  57. void FetchDeviceImages(scoped_refptr<Device> device) override;
  58. bool PersistDeviceImages(scoped_refptr<Device> device) override;
  59. bool EvictDeviceImages(const device::BluetoothDevice* device) override;
  60. absl::optional<chromeos::bluetooth_config::DeviceImageInfo>
  61. GetImagesForDevice(const std::string& device_id) override;
  62. void CheckOptInStatus(CheckOptInStatusCallback callback) override;
  63. void UpdateOptInStatus(nearby::fastpair::OptInStatus opt_in_status,
  64. UpdateOptInStatusCallback callback) override;
  65. void DeleteAssociatedDeviceByAccountKey(
  66. const std::vector<uint8_t>& account_key,
  67. DeleteAssociatedDeviceByAccountKeyCallback callback) override;
  68. void GetSavedDevices(GetSavedDevicesCallback callback) override;
  69. bool IsAccountKeyPairedLocally(
  70. const std::vector<uint8_t>& account_key) override;
  71. private:
  72. static void SetInstance(FastPairRepository* instance);
  73. nearby::fastpair::OptInStatus status_ =
  74. nearby::fastpair::OptInStatus::STATUS_UNKNOWN;
  75. std::vector<nearby::fastpair::FastPairDevice> devices_;
  76. bool is_network_connected_ = true;
  77. bool is_account_key_paired_locally_ = true;
  78. base::flat_map<std::string, std::unique_ptr<DeviceMetadata>> data_;
  79. base::flat_map<std::string, std::vector<uint8_t>> saved_account_keys_;
  80. absl::optional<PairingMetadata> check_account_keys_result_;
  81. base::WeakPtrFactory<FakeFastPairRepository> weak_ptr_factory_{this};
  82. };
  83. } // namespace quick_pair
  84. } // namespace ash
  85. #endif // ASH_QUICK_PAIR_REPOSITORY_FAKE_FAST_PAIR_REPOSITORY_H_