1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_QUICK_PAIR_COMMON_DEVICE_H_
#define ASH_QUICK_PAIR_COMMON_DEVICE_H_
#include <cstdint>
#include <optional>
#include <vector>
#include "ash/quick_pair/common/protocol.h"
#include "base/component_export.h"
#include "base/containers/flat_map.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
namespace ash {
namespace quick_pair {
enum class DeviceFastPairVersion {
kV1,
kHigherThanV1,
};
// Thin class which is used by the higher level components of the Quick Pair
// system to represent a device.
//
// Lower level components will use |protocol|, |metadata_id|, |ble_address| and
// |account_key| to fetch objects which contain more information. E.g. A
// Fast Pair component can use |metadata_id| to query the Service to receive a
// full metadata object.
class COMPONENT_EXPORT(QUICK_PAIR_COMMON) Device
: public base::RefCounted<Device> {
public:
Device(const std::string& metadata_id,
const std::string& ble_address,
Protocol protocol);
Device(const Device&) = delete;
Device& operator=(const Device&) = delete;
Device& operator=(Device&&) = delete;
const std::optional<std::string>& classic_address() const {
return classic_address_;
}
void set_classic_address(const std::optional<std::string>& address) {
classic_address_ = address;
}
const std::optional<std::string>& display_name() const {
return display_name_;
}
void set_display_name(const std::optional<std::string>& display_name) {
display_name_ = display_name;
}
const std::optional<DeviceFastPairVersion> version() const {
return version_;
}
void set_version(std::optional<DeviceFastPairVersion> version) {
version_ = version;
}
const std::optional<std::vector<uint8_t>> account_key() const {
return account_key_;
}
void set_account_key(const std::vector<uint8_t>& account_key) {
account_key_ = account_key;
}
const std::optional<uint8_t> key_based_pairing_flags() const {
return key_based_pairing_flags_;
}
void set_key_based_pairing_flags(uint8_t key_based_pairing_flags) {
key_based_pairing_flags_ = key_based_pairing_flags;
}
const std::string& metadata_id() const { return metadata_id_; }
const std::string& ble_address() const { return ble_address_; }
Protocol protocol() const { return protocol_; }
private:
friend class base::RefCounted<Device>;
~Device();
// An identifier which components can use to fetch additional metadata for
// this device. This ID will correspond to different things depending on
// |protocol_|. For example, if |protocol_| is Fast Pair, this ID will be the
// model ID of the Fast Pair device.
const std::string metadata_id_;
// Bluetooth LE address of the device.
const std::string ble_address_;
// The Quick Pair protocol implementation that this device belongs to.
const Protocol protocol_;
// Bluetooth classic address of the device.
std::optional<std::string> classic_address_;
// Display name for the device
// Similar to Bluetooth classic address field, this will be null when a
// device is found from a discoverable advertisement due to the fact that
// initial pair notifications show the OEM default name from the device
// metadata instead of the display name.
std::optional<std::string> display_name_;
// Fast Pair version number, possible versions numbers are defined at the top
// of this file.
std::optional<DeviceFastPairVersion> version_;
// Account key which will be saved to the user's account during Fast Pairing
// for eligible devices (V2 or higher) and used for detecting subsequent
// pairing scenarios.
std::optional<std::vector<uint8_t>> account_key_;
// Flags received during a Key-based Pairing Extended Response.
std::optional<uint8_t> key_based_pairing_flags_;
};
COMPONENT_EXPORT(QUICK_PAIR_COMMON)
std::ostream& operator<<(std::ostream& stream, const Device& device);
COMPONENT_EXPORT(QUICK_PAIR_COMMON)
std::ostream& operator<<(std::ostream& stream, scoped_refptr<Device> device);
} // namespace quick_pair
} // namespace ash
#endif // ASH_QUICK_PAIR_COMMON_DEVICE_H_
|