diff --git a/fastpair/common/fast_pair_device.cc b/fastpair/common/fast_pair_device.cc index 75497d58..96c206cb 100644 --- a/fastpair/common/fast_pair_device.cc +++ b/fastpair/common/fast_pair_device.cc @@ -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; } diff --git a/fastpair/common/fast_pair_device.h b/fastpair/common/fast_pair_device.h index 72c36dbf..7a0b8e9f 100644 --- a/fastpair/common/fast_pair_device.h +++ b/fastpair/common/fast_pair_device.h @@ -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& 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& 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 public_address_; diff --git a/fastpair/handshake/fast_pair_data_encryptor_impl.cc b/fastpair/handshake/fast_pair_data_encryptor_impl.cc index 8975bc35..6f9eba7a 100644 --- a/fastpair/handshake/fast_pair_data_encryptor_impl.cc +++ b/fastpair/handshake/fast_pair_data_encryptor_impl.cc @@ -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); }); diff --git a/fastpair/scanning/fastpair/fast_pair_discoverable_scanner_impl.cc b/fastpair/scanning/fastpair/fast_pair_discoverable_scanner_impl.cc index dbedf2e3..8ab560cf 100644 --- a/fastpair/scanning/fastpair/fast_pair_discoverable_scanner_impl.cc +++ b/fastpair/scanning/fastpair/fast_pair_discoverable_scanner_impl.cc @@ -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); } diff --git a/fastpair/scanning/scanner_broker_impl.cc b/fastpair/scanning/scanner_broker_impl.cc index 8964531d..3fd6ebf9 100644 --- a/fastpair/scanning/scanner_broker_impl.cc +++ b/fastpair/scanning/scanner_broker_impl.cc @@ -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); } diff --git a/fastpair/ui/fast_pair/fast_pair_presenter_impl.cc b/fastpair/ui/fast_pair/fast_pair_presenter_impl.cc index 511919c0..d9e12572 100644 --- a/fastpair/ui/fast_pair/fast_pair_presenter_impl.cc +++ b/fastpair/ui/fast_pair/fast_pair_presenter_impl.cc @@ -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.";