Add retro pairing in scalable seeker

Listen for manual pairing events and notify plugins.
Add retroactive pairing flow in the scalable seeker.
Actually upload the account key to the provider.
Missing bits:
- Notify the user and get their permission,
- Upload the new Account Key to user's account.

PiperOrigin-RevId: 544616348
This commit is contained in:
Janusz Sobczak
2023-06-30 04:06:43 -07:00
committed by Copybara-Service
parent a8b6fdee59
commit e00bdfb3e3
16 changed files with 260 additions and 96 deletions
+24 -27
View File
@@ -21,6 +21,7 @@
#include <vector>
#include "absl/status/status.h"
#include "absl/strings/escaping.h"
#include "fastpair/common/protocol.h"
#include "fastpair/handshake/fast_pair_data_encryptor_impl.h"
#include "fastpair/message_stream/message_stream.h"
@@ -32,18 +33,13 @@
namespace nearby {
namespace fastpair {
FastPairController::FastPairController(Mediums* mediums,
const BluetoothDevice& device,
FastPairController::FastPairController(Mediums* mediums, FastPairDevice* device,
SingleThreadExecutor* executor)
: mediums_(mediums),
device_(Protocol::kFastPairRetroactivePairing),
executor_(executor) {
device_.SetPublicAddress(device.GetMacAddress());
}
: mediums_(mediums), device_(device), executor_(executor) {}
absl::Status FastPairController::OpenMessageStream() {
message_stream_ = std::make_unique<MessageStream>(
device_, &mediums_->GetBluetoothClassic().GetMedium(), *this);
*device_, &mediums_->GetBluetoothClassic().GetMedium(), *this);
return message_stream_->OpenRfcomm();
}
@@ -51,10 +47,10 @@ void FastPairController::AddMessageStreamConnectionObserver(
MessageStreamConnectionObserver* observer) {
connection_observers_.AddObserver(observer);
if (message_stream_status_.ok() && observer->on_connected != nullptr) {
observer->on_connected(device_);
observer->on_connected(*device_);
} else if (!message_stream_status_.ok() &&
observer->on_disconnected != nullptr) {
observer->on_disconnected(device_, message_stream_status_);
observer->on_disconnected(*device_, message_stream_status_);
}
}
@@ -66,8 +62,8 @@ void FastPairController::RemoveMessageStreamConnectionObserver(
void FastPairController::AddAddressRotationObserver(
BleAddressRotationObserver* observer) {
address_rotation_observers_.AddObserver(observer);
if (!device_.GetBleAddress().empty()) {
observer->on_ble_address_rotated(device_, device_.GetBleAddress());
if (!device_->GetBleAddress().empty()) {
observer->on_ble_address_rotated(*device_, device_->GetBleAddress());
}
}
@@ -78,8 +74,8 @@ void FastPairController::RemoveAddressRotationObserver(
void FastPairController::AddModelIdObserver(ModelIdObserver* observer) {
model_id_observers_.AddObserver(observer);
if (!device_.GetModelId().empty()) {
observer->on_model_id(device_);
if (!device_->GetModelId().empty()) {
observer->on_model_id(*device_);
}
}
@@ -92,12 +88,12 @@ FastPairController::GetDataEncryptor() {
if (!encryptor_) {
encryptor_ =
std::make_unique<Future<std::shared_ptr<FastPairDataEncryptor>>>();
if (device_.GetMetadata()) {
if (device_->GetMetadata()) {
CreateDataEncryptor();
} else {
FastPairRepository::Get()->GetDeviceMetadata(
device_.GetModelId(), [this](DeviceMetadata& metadata) {
device_.SetMetadata(metadata);
device_->GetModelId(), [this](DeviceMetadata& metadata) {
device_->SetMetadata(metadata);
CreateDataEncryptor();
});
}
@@ -107,8 +103,8 @@ FastPairController::GetDataEncryptor() {
void FastPairController::CreateDataEncryptor() {
FastPairDataEncryptorImpl::Factory::CreateAsync(
device_, [borrowable = lender_.GetBorrowable()](
std::unique_ptr<FastPairDataEncryptor> encryptor) mutable {
*device_, [borrowable = lender_.GetBorrowable()](
std::unique_ptr<FastPairDataEncryptor> encryptor) mutable {
auto borrowed = borrowable.Borrow();
if (borrowed) {
(*borrowed)->SetDataEncryptor(std::move(encryptor));
@@ -122,7 +118,7 @@ FastPairController::GetGattClientRef() {
if (gatt_client_ == nullptr) {
gatt_client_ref_count_ = 0;
gatt_client_ = FastPairGattServiceClientImpl::Factory::Create(
device_, *mediums_, executor_);
*device_, *mediums_, executor_);
gatt_client_->InitializeGattConnection(
[](std::optional<PairFailure> result) {
if (result.has_value()) {
@@ -146,7 +142,7 @@ void FastPairController::OnConnectionResult(absl::Status result) {
}
for (auto* observer : connection_observers_.GetObservers()) {
if (observer->on_connected != nullptr) {
observer->on_connected(device_);
observer->on_connected(*device_);
}
}
}
@@ -155,24 +151,25 @@ void FastPairController::OnDisconnected(absl::Status status) {
message_stream_status_ = status;
for (auto* observer : connection_observers_.GetObservers()) {
if (observer->on_disconnected != nullptr) {
observer->on_disconnected(device_, status);
observer->on_disconnected(*device_, status);
}
}
}
void FastPairController::OnEnableSilenceMode(bool enable) {}
void FastPairController::OnLogBufferFull() {}
void FastPairController::OnModelId(absl::string_view model_id) {
device_.SetModelId(model_id);
device_->SetModelId(absl::BytesToHexString(model_id));
NEARBY_LOGS(INFO) << "Setting model id: " << device_->GetModelId();
for (auto* observer : model_id_observers_.GetObservers()) {
observer->on_model_id(device_);
observer->on_model_id(*device_);
}
}
void FastPairController::OnBleAddressUpdated(absl::string_view address) {
std::string old_address = std::string(device_.GetBleAddress());
device_.SetBleAddress(address);
std::string old_address = std::string(device_->GetBleAddress());
device_->SetBleAddress(address);
for (auto* observer : address_rotation_observers_.GetObservers()) {
observer->on_ble_address_rotated(device_, old_address);
observer->on_ble_address_rotated(*device_, old_address);
}
}