mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Retroactive pairing detector: check login status and if device has already been saved to the user's account
PiperOrigin-RevId: 551985769
This commit is contained in:
committed by
Copybara-Service
parent
749d528206
commit
e36b26184a
@@ -51,7 +51,7 @@ FastPairSeekerImpl::FastPairSeekerImpl(ServiceCallbacks callbacks,
|
||||
pairer_broker_->AddObserver(this);
|
||||
mediums_.GetBluetoothClassic().AddObserver(this);
|
||||
retro_detector_ = std::make_unique<RetroactivePairingDetectorImpl>(
|
||||
mediums_, devices, executor);
|
||||
mediums_, devices, account_manager_, executor);
|
||||
retro_detector_->AddObserver(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
#include "gmock/gmock.h"
|
||||
#include "protobuf-matchers/protocol-buffer-matchers.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/time/clock.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "fastpair/common/fast_pair_prefs.h"
|
||||
#include "fastpair/fast_pair_events.h"
|
||||
#include "fastpair/fast_pair_seeker.h"
|
||||
@@ -76,6 +74,8 @@ class FastPairSeekerImplTest : public testing::Test {
|
||||
NEARBY_LOG_SET_SEVERITY(VERBOSE);
|
||||
repository_ = FakeFastPairRepository::Create(
|
||||
kModelId, absl::HexStringToBytes(kBobPublicKey));
|
||||
repository_->SetResultOfIsDeviceSavedToAccount(
|
||||
absl::NotFoundError("not found"));
|
||||
account_manager_ = std::make_unique<FakeAccountManager>(
|
||||
preferences_manager_.get(), prefs::kNearbyFastPairUsersName,
|
||||
authentication_manager_.get(), task_runner_.get());
|
||||
|
||||
@@ -36,7 +36,9 @@ cc_library(
|
||||
"//fastpair/internal/mediums",
|
||||
"//fastpair/message_stream",
|
||||
"//fastpair/pairing",
|
||||
"//fastpair/repository",
|
||||
"//fastpair/repository:device_repository",
|
||||
"//internal/account",
|
||||
"//internal/base",
|
||||
"//internal/platform:comm",
|
||||
"//internal/platform:types",
|
||||
|
||||
@@ -17,18 +17,23 @@
|
||||
#include <ios>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "fastpair/internal/mediums/mediums.h"
|
||||
#include "fastpair/pairing/pairer_broker.h"
|
||||
#include "fastpair/repository/fast_pair_repository.h"
|
||||
#include "internal/account/account_manager.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace fastpair {
|
||||
|
||||
RetroactivePairingDetectorImpl::RetroactivePairingDetectorImpl(
|
||||
Mediums& mediums, FastPairDeviceRepository* repository,
|
||||
SingleThreadExecutor* executor)
|
||||
: mediums_(mediums), repository_(repository), executor_(executor) {
|
||||
AccountManager* account_manager, SingleThreadExecutor* executor)
|
||||
: mediums_(mediums),
|
||||
repository_(repository),
|
||||
account_manager_(account_manager),
|
||||
executor_(executor) {
|
||||
mediums_.GetBluetoothClassic().AddObserver(this);
|
||||
mediums_.GetBluetoothClassic().StartDiscovery();
|
||||
}
|
||||
@@ -75,15 +80,33 @@ void RetroactivePairingDetectorImpl::DevicePairedChanged(
|
||||
// first check if it has already been saved to the user's account. If it has
|
||||
// already been saved, we don't want to prompt the user to save a device
|
||||
// again.
|
||||
// TODO(b/285047010): check if device has already been saved to the user's
|
||||
// account
|
||||
if (!account_manager_->GetCurrentAccount().has_value()) {
|
||||
NEARBY_LOGS(INFO) << __func__ << ": Ignoring because no logged in user.";
|
||||
return;
|
||||
}
|
||||
|
||||
FastPairRepository::Get()->IsDeviceSavedToAccount(
|
||||
device.GetMacAddress(),
|
||||
[this, mac_address = device.GetMacAddress()](absl::Status status) {
|
||||
if (status.ok()) {
|
||||
NEARBY_LOGS(VERBOSE) << __func__
|
||||
<< ": Ignoring because device is already saved "
|
||||
"to the current account.";
|
||||
return;
|
||||
}
|
||||
NotifyRetroactiveDeviceFound(mac_address);
|
||||
});
|
||||
}
|
||||
|
||||
void RetroactivePairingDetectorImpl::NotifyRetroactiveDeviceFound(
|
||||
absl::string_view mac_address) {
|
||||
NEARBY_LOGS(VERBOSE) << __func__ << ": mac_address = " << mac_address;
|
||||
auto fast_pair_device =
|
||||
std::make_unique<FastPairDevice>(Protocol::kFastPairRetroactivePairing);
|
||||
fast_pair_device->SetPublicAddress(device.GetMacAddress());
|
||||
fast_pair_device->SetPublicAddress(mac_address);
|
||||
repository_->AddDevice(std::move(fast_pair_device));
|
||||
executor_->Execute("notify-retro-candidate",
|
||||
[this, address = device.GetMacAddress()]() {
|
||||
[this, address = std::string(mac_address)]() {
|
||||
std::optional<FastPairDevice*> fast_pair_device =
|
||||
repository_->FindDevice(address);
|
||||
if (!fast_pair_device) return;
|
||||
|
||||
@@ -14,13 +14,12 @@
|
||||
|
||||
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_RETROACTIVE_RETROACTIVE_PAIRING_DETECTOR_IMPL_H_
|
||||
#define THIRD_PARTY_NEARBY_FASTPAIR_RETROACTIVE_RETROACTIVE_PAIRING_DETECTOR_IMPL_H_
|
||||
#include <string>
|
||||
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "fastpair/internal/mediums/mediums.h"
|
||||
#include "fastpair/pairing/pairer_broker.h"
|
||||
#include "fastpair/repository/fast_pair_device_repository.h"
|
||||
#include "fastpair/retroactive/retroactive_pairing_detector.h"
|
||||
#include "internal/account/account_manager.h"
|
||||
#include "internal/base/observer_list.h"
|
||||
#include "internal/platform/bluetooth_classic.h"
|
||||
#include "internal/platform/single_thread_executor.h"
|
||||
@@ -34,6 +33,7 @@ class RetroactivePairingDetectorImpl
|
||||
public:
|
||||
RetroactivePairingDetectorImpl(Mediums& mediums,
|
||||
FastPairDeviceRepository* repository,
|
||||
AccountManager* account_manager,
|
||||
SingleThreadExecutor* executor);
|
||||
RetroactivePairingDetectorImpl(const RetroactivePairingDetectorImpl&) =
|
||||
delete;
|
||||
@@ -50,9 +50,11 @@ class RetroactivePairingDetectorImpl
|
||||
bool new_paired_status) override;
|
||||
|
||||
private:
|
||||
void NotifyRetroactiveDeviceFound(absl::string_view mac_address);
|
||||
Mediums& mediums_;
|
||||
ObserverList<RetroactivePairingDetector::Observer> observers_;
|
||||
FastPairDeviceRepository* repository_;
|
||||
AccountManager* account_manager_;
|
||||
SingleThreadExecutor* executor_;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user