mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Promote FpDevice to a class
PiperOrigin-RevId: 520430547
This commit is contained in:
committed by
Copybara-Service
parent
c249c3079f
commit
94630e75ea
@@ -23,20 +23,12 @@
|
||||
namespace nearby {
|
||||
namespace fastpair {
|
||||
|
||||
FastPairDevice::FastPairDevice(std::string model_id, std::string ble_address,
|
||||
Protocol protocol)
|
||||
: model_id(std::move(model_id)),
|
||||
ble_address(std::move(ble_address)),
|
||||
protocol(protocol) {}
|
||||
|
||||
FastPairDevice::~FastPairDevice() = default;
|
||||
|
||||
std::ostream& operator<<(std::ostream& stream, const FastPairDevice& device) {
|
||||
stream << "[Device: model_id = " << device.model_id
|
||||
<< ", ble_address = " << device.ble_address
|
||||
<< ", piblic_address = " << device.public_address().value_or("null")
|
||||
stream << "[Device: model_id = " << device.GetModelId()
|
||||
<< ", ble_address = " << device.GetBleAddress()
|
||||
<< ", public_address = " << device.public_address().value_or("null")
|
||||
<< ", display_name = " << device.display_name().value_or("null")
|
||||
<< ", protocol = " << device.protocol << "]";
|
||||
<< ", protocol = " << device.GetProtocol() << "]";
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
@@ -34,20 +34,23 @@ enum class DeviceFastPairVersion {
|
||||
|
||||
// Thin class which is used by the higher level components of the Fast Pair
|
||||
// system to represent a device.
|
||||
struct FastPairDevice {
|
||||
FastPairDevice(std::string model_id, std::string ble_address,
|
||||
Protocol protocol);
|
||||
class FastPairDevice {
|
||||
public:
|
||||
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();
|
||||
~FastPairDevice() = default;
|
||||
|
||||
const std::optional<std::string>& public_address() const {
|
||||
return public_address_;
|
||||
}
|
||||
|
||||
void set_public_address(const std::string& address) {
|
||||
public_address_ = address;
|
||||
void set_public_address(absl::string_view address) {
|
||||
public_address_ = std::string(address);
|
||||
}
|
||||
|
||||
const std::optional<std::string>& display_name() const {
|
||||
@@ -72,15 +75,21 @@ struct FastPairDevice {
|
||||
account_key_ = account_key;
|
||||
}
|
||||
|
||||
const std::string model_id;
|
||||
absl::string_view GetModelId() const { return model_id_; }
|
||||
|
||||
// Bluetooth LE address of the device.
|
||||
const std::string ble_address;
|
||||
absl::string_view GetBleAddress() const { return ble_address_; }
|
||||
|
||||
// The Quick Pair protocol implementation that this device belongs to.
|
||||
const Protocol protocol;
|
||||
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_;
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ void FastPairDataEncryptorImpl::Factory::CreateAsync(
|
||||
return;
|
||||
}
|
||||
|
||||
if (device.protocol == Protocol::kFastPairInitialPairing) {
|
||||
if (device.GetProtocol() == Protocol::kFastPairInitialPairing) {
|
||||
CreateAsyncWithKeyExchange(device, std::move(on_get_instance_callback));
|
||||
}
|
||||
}
|
||||
@@ -87,7 +87,8 @@ void FastPairDataEncryptorImpl::Factory::CreateAsyncWithKeyExchange(
|
||||
// to generate the new secret key pair.
|
||||
NEARBY_LOGS(INFO) << __func__ << ": Attempting to get device metadata.";
|
||||
FastPairRepository::Get()->GetDeviceMetadata(
|
||||
device.model_id, [&on_get_instance_callback](DeviceMetadata& metadata) {
|
||||
device.GetModelId(),
|
||||
[&on_get_instance_callback](DeviceMetadata& metadata) {
|
||||
FastPairDataEncryptorImpl::Factory::DeviceMetadataRetrieved(
|
||||
std::move(on_get_instance_callback), metadata);
|
||||
});
|
||||
|
||||
@@ -190,9 +190,9 @@ void FastPairDiscoverableScannerImpl::OnDeviceMetadataRetrieved(
|
||||
void FastPairDiscoverableScannerImpl::NotifyDeviceFound(
|
||||
FastPairDevice& device) {
|
||||
NEARBY_LOGS(VERBOSE) << "Notify Device found:"
|
||||
<< "BluetoothAddress = " << device.ble_address
|
||||
<< ", Model id = " << device.model_id;
|
||||
notified_devices_[device.ble_address] = &device;
|
||||
<< "BluetoothAddress = " << device.GetBleAddress()
|
||||
<< ", Model id = " << device.GetModelId();
|
||||
notified_devices_[device.GetBleAddress()] = &device;
|
||||
found_callback_(device);
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ void ScannerBrokerImpl::StopFastPairScanning() {
|
||||
|
||||
void ScannerBrokerImpl::NotifyDeviceFound(const FastPairDevice& device) {
|
||||
NEARBY_LOGS(INFO) << __func__ << ": Notifying device found, model id = "
|
||||
<< device.model_id;
|
||||
<< device.GetModelId();
|
||||
for (auto& observer : observers_) {
|
||||
observer->OnDeviceFound(device);
|
||||
}
|
||||
@@ -79,7 +79,7 @@ void ScannerBrokerImpl::NotifyDeviceFound(const FastPairDevice& device) {
|
||||
|
||||
void ScannerBrokerImpl::NotifyDeviceLost(const FastPairDevice& device) {
|
||||
NEARBY_LOGS(INFO) << __func__ << ": Notifying device lost, model id = "
|
||||
<< device.model_id;
|
||||
<< device.GetModelId();
|
||||
for (auto& observer : observers_) {
|
||||
observer->OnDeviceLost(device);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ void FastPairPresenterImpl::ShowDiscovery(
|
||||
const FastPairDevice& device,
|
||||
FastPairNotificationController& notification_controller) {
|
||||
FastPairRepository::Get()->GetDeviceMetadata(
|
||||
device.model_id,
|
||||
device.GetModelId(),
|
||||
[¬ification_controller, this](const DeviceMetadata& device_metadata) {
|
||||
NEARBY_LOGS(INFO) << __func__
|
||||
<< "Retrieved metadata to notification controller.";
|
||||
|
||||
Reference in New Issue
Block a user