Files
nearby/fastpair/common/fast_pair_device.h
T
Janusz Sobczak 013bf1f420 Add retroactive pairing
PiperOrigin-RevId: 531637311
2023-05-12 16:56:55 -07:00

123 lines
3.8 KiB
C++

// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_COMMON_FAST_PAIR_DEVICE_H_
#define THIRD_PARTY_NEARBY_FASTPAIR_COMMON_FAST_PAIR_DEVICE_H_
#include <cstdint>
#include <optional>
#include <ostream>
#include <string>
#include <utility>
#include <vector>
#include "absl/container/flat_hash_map.h"
#include "fastpair/common/account_key.h"
#include "fastpair/common/protocol.h"
namespace nearby {
namespace fastpair {
enum class DeviceFastPairVersion {
kV1,
kHigherThanV1,
};
// Thin class which is used by the higher level components of the Fast Pair
// system to represent a device.
class FastPairDevice {
public:
explicit FastPairDevice(Protocol protocol) : protocol_(protocol) {}
FastPairDevice(absl::string_view model_id, absl::string_view ble_address,
Protocol protocol)
: model_id_(model_id), ble_address_(ble_address), protocol_(protocol) {}
FastPairDevice(const FastPairDevice&) = delete;
FastPairDevice& operator=(const FastPairDevice&) = delete;
FastPairDevice& operator=(FastPairDevice&&) = delete;
~FastPairDevice() = default;
const std::optional<std::string>& public_address() const {
return public_address_;
}
void set_public_address(absl::string_view address) {
public_address_ = std::string(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;
}
std::optional<DeviceFastPairVersion> version() { return version_; }
void set_version(std::optional<DeviceFastPairVersion> version) {
version_ = version;
}
const AccountKey& GetAccountKey() const { return account_key_; }
void SetAccountKey(AccountKey account_key) { account_key_ = account_key; }
void SetModelId(absl::string_view model_id) { model_id_ = model_id; }
absl::string_view GetModelId() const { return model_id_; }
void SetBleAddress(absl::string_view address) {
ble_address_ = std::string(address);
}
absl::string_view GetBleAddress() const { return ble_address_; }
Protocol GetProtocol() const { return protocol_; }
private:
std::string model_id_;
// Bluetooth LE address of the device.
std::string ble_address_;
// The Quick Pair protocol implementation that this device belongs to.
Protocol protocol_;
// Bluetooth public classic address of the device.
std::optional<std::string> public_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.
AccountKey account_key_;
};
std::ostream& operator<<(std::ostream& stream, const FastPairDevice& device);
} // namespace fastpair
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_FASTPAIR_COMMON_FAST_PAIR_DEVICE_H_