mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Write account association to footprints
PiperOrigin-RevId: 549693215
This commit is contained in:
committed by
Copybara-Service
parent
2e1ed2b465
commit
0cd8aaab25
@@ -105,6 +105,9 @@ std::ostream& operator<<(std::ostream& stream, PairFailure failure) {
|
||||
case PairFailure::kPairingTimeout:
|
||||
stream << "[Potential pairing failed with timeout.]";
|
||||
break;
|
||||
case PairFailure::kWriteAccountKeyToFootprints:
|
||||
stream << "[Failed to write Account Key to Footprints.]";
|
||||
break;
|
||||
}
|
||||
|
||||
return stream;
|
||||
|
||||
@@ -77,7 +77,8 @@ enum class PairFailure {
|
||||
kPairingAndConnect = 24,
|
||||
// Potential pairing timeout.
|
||||
kPairingTimeout = 25,
|
||||
kMaxValue = kPairingTimeout,
|
||||
kWriteAccountKeyToFootprints = 26,
|
||||
kMaxValue = kWriteAccountKeyToFootprints,
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& stream, PairFailure failure);
|
||||
|
||||
@@ -64,6 +64,7 @@ TEST(PairFailureTest, PairFailureValue) {
|
||||
EXPECT_EQ(static_cast<int>(PairFailure::kDeviceLostMidPairing), 23);
|
||||
EXPECT_EQ(static_cast<int>(PairFailure::kPairingAndConnect), 24);
|
||||
EXPECT_EQ(static_cast<int>(PairFailure::kPairingTimeout), 25);
|
||||
EXPECT_EQ(static_cast<int>(PairFailure::kWriteAccountKeyToFootprints), 26);
|
||||
}
|
||||
} // namespace
|
||||
} // namespace fastpair
|
||||
|
||||
@@ -33,6 +33,7 @@ cc_library(
|
||||
"//fastpair/crypto",
|
||||
"//fastpair/handshake",
|
||||
"//fastpair/internal/mediums",
|
||||
"//fastpair/repository",
|
||||
"//internal/platform:comm",
|
||||
"//internal/platform:types",
|
||||
"@com_google_absl//absl/functional:any_invocable",
|
||||
@@ -64,6 +65,7 @@ cc_test(
|
||||
"@com_github_protobuf_matchers//protobuf-matchers",
|
||||
"@com_google_absl//absl/functional:any_invocable",
|
||||
"@com_google_absl//absl/functional:bind_front",
|
||||
"@com_google_absl//absl/status",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/time",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "fastpair/crypto/fast_pair_message_type.h"
|
||||
#include "fastpair/handshake/fast_pair_handshake_lookup.h"
|
||||
#include "fastpair/internal/mediums/mediums.h"
|
||||
#include "fastpair/repository/fast_pair_repository.h"
|
||||
#include "internal/platform/bluetooth_classic.h"
|
||||
#include "internal/platform/single_thread_executor.h"
|
||||
|
||||
@@ -302,8 +303,23 @@ void FastPairPairerImpl::OnWriteAccountKey(
|
||||
return;
|
||||
}
|
||||
device_.SetAccountKey(account_key.value());
|
||||
// // TODO(b/281785681): Write account association to footprints
|
||||
NotifyPairingCompleted();
|
||||
|
||||
// Devices in the Retroactive Pair scenario are not written to Footprints
|
||||
// on account key write, but when the user hits 'Save' on the retroactive pair
|
||||
// notification.
|
||||
if (device_.GetProtocol() == Protocol::kFastPairRetroactivePairing) {
|
||||
NotifyPairingCompleted();
|
||||
return;
|
||||
}
|
||||
|
||||
FastPairRepository::Get()->WriteAccountAssociationToFootprints(
|
||||
device_, [&](absl::Status status) {
|
||||
if (status.ok()) {
|
||||
NotifyPairingCompleted();
|
||||
} else {
|
||||
NotifyAccountKeyFailure(PairFailure::kWriteAccountKeyToFootprints);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void FastPairPairerImpl::NotifyPaired() {
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "absl/functional/bind_front.h"
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "fastpair//handshake/fast_pair_handshake_lookup.h"
|
||||
@@ -44,6 +45,7 @@
|
||||
#include "fastpair/handshake/fast_pair_handshake_impl.h"
|
||||
#include "fastpair/pairing/fastpair/fast_pair_pairer.h"
|
||||
#include "fastpair/proto/fastpair_rpcs.proto.h"
|
||||
#include "fastpair/repository/fake_fast_pair_repository.h"
|
||||
#include "internal/base/bluetooth_address.h"
|
||||
#include "internal/platform/ble_v2.h"
|
||||
#include "internal/platform/bluetooth_adapter.h"
|
||||
@@ -373,6 +375,8 @@ class FastPairPairerImplTest : public testing::Test {
|
||||
|
||||
TEST_F(FastPairPairerImplTest,
|
||||
SuccessInitialPairingWithDeviceVersionHigherThanV1) {
|
||||
auto repository = std::make_unique<FakeFastPairRepository>();
|
||||
repository->SetResultOfWriteAccountAssociationToFootprints(absl::OkStatus());
|
||||
ConfigurePairingContext();
|
||||
SetPairingResult(std::nullopt);
|
||||
CreateMockDevice(DeviceFastPairVersion::kHigherThanV1,
|
||||
@@ -386,29 +390,25 @@ TEST_F(FastPairPairerImplTest,
|
||||
|
||||
CountDownLatch paired_latch(1);
|
||||
CountDownLatch complete_latch(1);
|
||||
CountDownLatch failure_latch(1);
|
||||
CountDownLatch account_failure_latch(1);
|
||||
|
||||
EXPECT_FALSE(device_->GetAccountKey().Ok());
|
||||
fast_pair_pairer_ = FastPairPairerImpl::Factory::Create(
|
||||
*device_, *mediums_, &executor_,
|
||||
[&](FastPairDevice& cb_device) { paired_latch.CountDown(); },
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
failure_latch.CountDown();
|
||||
FAIL() << "Unexpected pairing failure " << failure;
|
||||
},
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
account_failure_latch.CountDown();
|
||||
FAIL() << "Unexpected pairing failure " << failure;
|
||||
},
|
||||
[&](FastPairDevice& device) {
|
||||
EXPECT_TRUE(device.GetAccountKey().Ok());
|
||||
complete_latch.CountDown();
|
||||
});
|
||||
fast_pair_pairer_->StartPairing();
|
||||
paired_latch.Await();
|
||||
EXPECT_FALSE(failure_latch.Await(kWaitTimeout).result());
|
||||
EXPECT_FALSE(account_failure_latch.Await(kWaitTimeout).result());
|
||||
complete_latch.Await();
|
||||
|
||||
paired_latch.Await();
|
||||
complete_latch.Await();
|
||||
EXPECT_TRUE(fast_pair_pairer_->IsPaired());
|
||||
EXPECT_TRUE(device_->GetAccountKey().Ok());
|
||||
}
|
||||
@@ -422,26 +422,23 @@ TEST_F(FastPairPairerImplTest, SuccessInitialPairingWithDeviceV1) {
|
||||
|
||||
CountDownLatch paired_latch(1);
|
||||
CountDownLatch complete_latch(1);
|
||||
CountDownLatch failure_latch(1);
|
||||
CountDownLatch account_failure_latch(1);
|
||||
|
||||
fast_pair_pairer_ = FastPairPairerImpl::Factory::Create(
|
||||
*device_, *mediums_, &executor_,
|
||||
[&](FastPairDevice& cb_device) { paired_latch.CountDown(); },
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
failure_latch.CountDown();
|
||||
FAIL() << "Unexpected pairing failure " << failure;
|
||||
},
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
account_failure_latch.CountDown();
|
||||
FAIL() << "Unexpected pairing failure " << failure;
|
||||
},
|
||||
[&](FastPairDevice& device) {
|
||||
EXPECT_FALSE(device.GetAccountKey().Ok());
|
||||
complete_latch.CountDown();
|
||||
});
|
||||
fast_pair_pairer_->StartPairing();
|
||||
|
||||
paired_latch.Await();
|
||||
EXPECT_FALSE(failure_latch.Await(kWaitTimeout).result());
|
||||
EXPECT_FALSE(account_failure_latch.Await(kWaitTimeout).result());
|
||||
complete_latch.Await();
|
||||
EXPECT_TRUE(fast_pair_pairer_->IsPaired());
|
||||
}
|
||||
@@ -460,26 +457,23 @@ TEST_F(FastPairPairerImplTest, SuccessSubsequentPairingWithDevice) {
|
||||
|
||||
CountDownLatch paired_latch(1);
|
||||
CountDownLatch complete_latch(1);
|
||||
CountDownLatch failure_latch(1);
|
||||
CountDownLatch account_failure_latch(1);
|
||||
|
||||
fast_pair_pairer_ = FastPairPairerImpl::Factory::Create(
|
||||
*device_, *mediums_, &executor_,
|
||||
[&](FastPairDevice& cb_device) { paired_latch.CountDown(); },
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
failure_latch.CountDown();
|
||||
FAIL() << "Unexpected pairing failure " << failure;
|
||||
},
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
account_failure_latch.CountDown();
|
||||
FAIL() << "Unexpected pairing failure " << failure;
|
||||
},
|
||||
[&](FastPairDevice& device) {
|
||||
EXPECT_TRUE(device.GetAccountKey().Ok());
|
||||
complete_latch.CountDown();
|
||||
});
|
||||
fast_pair_pairer_->StartPairing();
|
||||
|
||||
paired_latch.Await();
|
||||
EXPECT_FALSE(failure_latch.Await(kWaitTimeout).result());
|
||||
EXPECT_FALSE(account_failure_latch.Await(kWaitTimeout).result());
|
||||
complete_latch.Await();
|
||||
EXPECT_TRUE(fast_pair_pairer_->IsPaired());
|
||||
}
|
||||
@@ -494,30 +488,25 @@ TEST_F(FastPairPairerImplTest, SuccessRetroactivePairingWithDevice) {
|
||||
SetDecryptedResponse();
|
||||
CreateFastPairHandshakeInstanceForDevice();
|
||||
|
||||
CountDownLatch paired_latch(1);
|
||||
CountDownLatch complete_latch(1);
|
||||
CountDownLatch failure_latch(1);
|
||||
CountDownLatch account_failure_latch(1);
|
||||
|
||||
EXPECT_FALSE(device_->GetAccountKey().Ok());
|
||||
|
||||
fast_pair_pairer_ = FastPairPairerImpl::Factory::Create(
|
||||
*device_, *mediums_, &executor_,
|
||||
[&](FastPairDevice& cb_device) { paired_latch.CountDown(); },
|
||||
[&](FastPairDevice& cb_device) { FAIL() << "Unexpected callback"; },
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
failure_latch.CountDown();
|
||||
FAIL() << "Unexpected pairing failure " << failure;
|
||||
},
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
account_failure_latch.CountDown();
|
||||
FAIL() << "Unexpected pairing failure " << failure;
|
||||
},
|
||||
[&](FastPairDevice& device) {
|
||||
EXPECT_TRUE(device.GetAccountKey().Ok());
|
||||
complete_latch.CountDown();
|
||||
});
|
||||
fast_pair_pairer_->StartPairing();
|
||||
EXPECT_FALSE(paired_latch.Await(kWaitTimeout).result());
|
||||
EXPECT_FALSE(failure_latch.Await(kWaitTimeout).result());
|
||||
EXPECT_FALSE(account_failure_latch.Await(kWaitTimeout).result());
|
||||
|
||||
complete_latch.Await();
|
||||
EXPECT_TRUE(device_->GetAccountKey().Ok());
|
||||
}
|
||||
@@ -530,32 +519,27 @@ TEST_F(FastPairPairerImplTest, FailedToUnPair) {
|
||||
SetDecryptedResponse();
|
||||
CreateFastPairHandshakeInstanceForDevice();
|
||||
|
||||
CountDownLatch paired_latch(1);
|
||||
CountDownLatch complete_latch(1);
|
||||
CountDownLatch failure_latch(1);
|
||||
CountDownLatch account_failure_latch(1);
|
||||
|
||||
EXPECT_FALSE(device_->GetAccountKey().Ok());
|
||||
|
||||
fast_pair_pairer_ = FastPairPairerImpl::Factory::Create(
|
||||
*device_, *mediums_, &executor_,
|
||||
[&](FastPairDevice& cb_device) { paired_latch.CountDown(); },
|
||||
[&](FastPairDevice& cb_device) { FAIL() << "Unexpected callback"; },
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
EXPECT_EQ(failure, PairFailure::kPairingAndConnect);
|
||||
failure_latch.CountDown();
|
||||
},
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
account_failure_latch.CountDown();
|
||||
FAIL() << "Unexpected pairing failure " << failure;
|
||||
},
|
||||
[&](FastPairDevice& device) {
|
||||
EXPECT_TRUE(device.GetAccountKey().Ok());
|
||||
complete_latch.CountDown();
|
||||
FAIL() << "Unexpected callback";
|
||||
});
|
||||
fast_pair_pairer_->StartPairing();
|
||||
EXPECT_FALSE(paired_latch.Await(kWaitTimeout).result());
|
||||
|
||||
failure_latch.Await();
|
||||
EXPECT_FALSE(complete_latch.Await(kWaitTimeout).result());
|
||||
EXPECT_FALSE(account_failure_latch.Await(kWaitTimeout).result());
|
||||
|
||||
EXPECT_FALSE(fast_pair_pairer_->IsPaired());
|
||||
EXPECT_FALSE(device_->GetAccountKey().Ok());
|
||||
}
|
||||
@@ -572,32 +556,25 @@ TEST_F(FastPairPairerImplTest, FailedToPairingWithAuthTimeout) {
|
||||
SetDecryptedPasskey();
|
||||
CreateFastPairHandshakeInstanceForDevice();
|
||||
|
||||
CountDownLatch paired_latch(1);
|
||||
CountDownLatch complete_latch(1);
|
||||
CountDownLatch failure_latch(1);
|
||||
CountDownLatch account_failure_latch(1);
|
||||
|
||||
EXPECT_FALSE(device_->GetAccountKey().Ok());
|
||||
|
||||
fast_pair_pairer_ = FastPairPairerImpl::Factory::Create(
|
||||
*device_, *mediums_, &executor_,
|
||||
[&](FastPairDevice& cb_device) { paired_latch.CountDown(); },
|
||||
[&](FastPairDevice& cb_device) { FAIL() << "Unexpected callback"; },
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
EXPECT_EQ(failure, PairFailure::kPairingAndConnect);
|
||||
failure_latch.CountDown();
|
||||
},
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
account_failure_latch.CountDown();
|
||||
FAIL() << "Unexpected pairing failure " << failure;
|
||||
},
|
||||
[&](FastPairDevice& device) {
|
||||
EXPECT_TRUE(device.GetAccountKey().Ok());
|
||||
complete_latch.CountDown();
|
||||
});
|
||||
[&](FastPairDevice& device) { FAIL() << "Unexpected callback"; });
|
||||
fast_pair_pairer_->StartPairing();
|
||||
EXPECT_FALSE(paired_latch.Await(kWaitTimeout).result());
|
||||
|
||||
failure_latch.Await();
|
||||
EXPECT_FALSE(complete_latch.Await(kWaitTimeout).result());
|
||||
EXPECT_FALSE(account_failure_latch.Await(kWaitTimeout).result());
|
||||
|
||||
EXPECT_FALSE(fast_pair_pairer_->IsPaired());
|
||||
EXPECT_FALSE(device_->GetAccountKey().Ok());
|
||||
}
|
||||
@@ -612,32 +589,25 @@ TEST_F(FastPairPairerImplTest, NoPasskeyResponse) {
|
||||
SetDecryptedResponse();
|
||||
CreateFastPairHandshakeInstanceForDevice();
|
||||
|
||||
CountDownLatch paired_latch(1);
|
||||
CountDownLatch complete_latch(1);
|
||||
CountDownLatch failure_latch(1);
|
||||
CountDownLatch account_failure_latch(1);
|
||||
|
||||
EXPECT_FALSE(device_->GetAccountKey().Ok());
|
||||
|
||||
fast_pair_pairer_ = FastPairPairerImpl::Factory::Create(
|
||||
*device_, *mediums_, &executor_,
|
||||
[&](FastPairDevice& cb_device) { paired_latch.CountDown(); },
|
||||
[&](FastPairDevice& cb_device) { FAIL() << "Unexpected callback"; },
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
EXPECT_EQ(failure, PairFailure::kPasskeyResponseTimeout);
|
||||
failure_latch.CountDown();
|
||||
},
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
account_failure_latch.CountDown();
|
||||
FAIL() << "Unexpected pairing failure " << failure;
|
||||
},
|
||||
[&](FastPairDevice& device) {
|
||||
EXPECT_TRUE(device.GetAccountKey().Ok());
|
||||
complete_latch.CountDown();
|
||||
});
|
||||
[&](FastPairDevice& device) { FAIL() << "Unexpected callback"; });
|
||||
fast_pair_pairer_->StartPairing();
|
||||
EXPECT_FALSE(paired_latch.Await(kWaitTimeout).result());
|
||||
|
||||
failure_latch.Await();
|
||||
EXPECT_FALSE(complete_latch.Await(kWaitTimeout).result());
|
||||
EXPECT_FALSE(account_failure_latch.Await(kWaitTimeout).result());
|
||||
|
||||
EXPECT_FALSE(fast_pair_pairer_->IsPaired());
|
||||
EXPECT_FALSE(device_->GetAccountKey().Ok());
|
||||
}
|
||||
@@ -654,32 +624,25 @@ TEST_F(FastPairPairerImplTest, PasskeyMismatch) {
|
||||
SetDecryptedPasskey("654321");
|
||||
CreateFastPairHandshakeInstanceForDevice();
|
||||
|
||||
CountDownLatch paired_latch(1);
|
||||
CountDownLatch complete_latch(1);
|
||||
CountDownLatch failure_latch(1);
|
||||
CountDownLatch account_failure_latch(1);
|
||||
|
||||
EXPECT_FALSE(device_->GetAccountKey().Ok());
|
||||
|
||||
fast_pair_pairer_ = FastPairPairerImpl::Factory::Create(
|
||||
*device_, *mediums_, &executor_,
|
||||
[&](FastPairDevice& cb_device) { paired_latch.CountDown(); },
|
||||
[&](FastPairDevice& cb_device) { FAIL() << "Unexpected callback"; },
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
EXPECT_EQ(failure, PairFailure::kPasskeyMismatch);
|
||||
failure_latch.CountDown();
|
||||
},
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
account_failure_latch.CountDown();
|
||||
FAIL() << "Unexpected pairing failure " << failure;
|
||||
},
|
||||
[&](FastPairDevice& device) {
|
||||
EXPECT_TRUE(device.GetAccountKey().Ok());
|
||||
complete_latch.CountDown();
|
||||
});
|
||||
[&](FastPairDevice& device) { FAIL() << "Unexpected callback"; });
|
||||
fast_pair_pairer_->StartPairing();
|
||||
EXPECT_FALSE(paired_latch.Await(kWaitTimeout).result());
|
||||
|
||||
failure_latch.Await();
|
||||
EXPECT_FALSE(complete_latch.Await(kWaitTimeout).result());
|
||||
EXPECT_FALSE(account_failure_latch.Await(kWaitTimeout).result());
|
||||
|
||||
EXPECT_FALSE(fast_pair_pairer_->IsPaired());
|
||||
EXPECT_FALSE(device_->GetAccountKey().Ok());
|
||||
}
|
||||
@@ -696,32 +659,26 @@ TEST_F(FastPairPairerImplTest, ReceiveWithWrongPasskeyResponse) {
|
||||
CreateFastPairHandshakeInstanceForDevice();
|
||||
|
||||
SetPairingResult(std::nullopt);
|
||||
CountDownLatch paired_latch(1);
|
||||
CountDownLatch complete_latch(1);
|
||||
|
||||
CountDownLatch failure_latch(1);
|
||||
CountDownLatch account_failure_latch(1);
|
||||
|
||||
EXPECT_FALSE(device_->GetAccountKey().Ok());
|
||||
|
||||
fast_pair_pairer_ = FastPairPairerImpl::Factory::Create(
|
||||
*device_, *mediums_, &executor_,
|
||||
[&](FastPairDevice& cb_device) { paired_latch.CountDown(); },
|
||||
[&](FastPairDevice& cb_device) { FAIL() << "Unexpected callback"; },
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
EXPECT_EQ(failure, PairFailure::kPasskeyDecryptFailure);
|
||||
failure_latch.CountDown();
|
||||
},
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
account_failure_latch.CountDown();
|
||||
FAIL() << "Unexpected pairing failure " << failure;
|
||||
},
|
||||
[&](FastPairDevice& device) {
|
||||
EXPECT_TRUE(device.GetAccountKey().Ok());
|
||||
complete_latch.CountDown();
|
||||
});
|
||||
[&](FastPairDevice& device) { FAIL() << "Unexpected callback"; });
|
||||
fast_pair_pairer_->StartPairing();
|
||||
EXPECT_FALSE(paired_latch.Await(kWaitTimeout).result());
|
||||
|
||||
failure_latch.Await();
|
||||
EXPECT_FALSE(complete_latch.Await(kWaitTimeout).result());
|
||||
EXPECT_FALSE(account_failure_latch.Await(kWaitTimeout).result());
|
||||
|
||||
EXPECT_FALSE(fast_pair_pairer_->IsPaired());
|
||||
EXPECT_FALSE(device_->GetAccountKey().Ok());
|
||||
}
|
||||
@@ -739,38 +696,32 @@ TEST_F(FastPairPairerImplTest, ReceiveWithWrongPasskeyMessageType) {
|
||||
CreateFastPairHandshakeInstanceForDevice();
|
||||
|
||||
SetPairingResult(std::nullopt);
|
||||
CountDownLatch paired_latch(1);
|
||||
CountDownLatch complete_latch(1);
|
||||
|
||||
CountDownLatch failure_latch(1);
|
||||
CountDownLatch account_failure_latch(1);
|
||||
|
||||
EXPECT_FALSE(device_->GetAccountKey().Ok());
|
||||
|
||||
fast_pair_pairer_ = FastPairPairerImpl::Factory::Create(
|
||||
*device_, *mediums_, &executor_,
|
||||
[&](FastPairDevice& cb_device) { paired_latch.CountDown(); },
|
||||
[&](FastPairDevice& cb_device) { FAIL() << "Unexpected callback"; },
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
EXPECT_EQ(failure, PairFailure::kIncorrectPasskeyResponseType);
|
||||
failure_latch.CountDown();
|
||||
},
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
account_failure_latch.CountDown();
|
||||
FAIL() << "Unexpected pairing failure " << failure;
|
||||
},
|
||||
[&](FastPairDevice& device) {
|
||||
EXPECT_TRUE(device.GetAccountKey().Ok());
|
||||
complete_latch.CountDown();
|
||||
});
|
||||
[&](FastPairDevice& device) { FAIL() << "Unexpected callback"; });
|
||||
fast_pair_pairer_->StartPairing();
|
||||
EXPECT_FALSE(paired_latch.Await(kWaitTimeout).result());
|
||||
|
||||
failure_latch.Await();
|
||||
EXPECT_FALSE(complete_latch.Await(kWaitTimeout).result());
|
||||
EXPECT_FALSE(account_failure_latch.Await(kWaitTimeout).result());
|
||||
|
||||
EXPECT_FALSE(fast_pair_pairer_->IsPaired());
|
||||
EXPECT_FALSE(device_->GetAccountKey().Ok());
|
||||
}
|
||||
|
||||
TEST_F(FastPairPairerImplTest,
|
||||
SuccessPairingWithDeviceButFailedToWriteAccountkey) {
|
||||
SuccessPairingWithDeviceButFailedToWriteAccountkeyToRemoteDevice) {
|
||||
ConfigurePairingContext();
|
||||
SetPairingResult(std::nullopt);
|
||||
CreateMockDevice(DeviceFastPairVersion::kHigherThanV1,
|
||||
@@ -797,6 +748,7 @@ TEST_F(FastPairPairerImplTest,
|
||||
failure_latch.CountDown();
|
||||
},
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
EXPECT_EQ(failure, PairFailure::kAccountKeyCharacteristicWrite);
|
||||
account_failure_latch.CountDown();
|
||||
},
|
||||
[&](FastPairDevice& device) {
|
||||
@@ -812,6 +764,45 @@ TEST_F(FastPairPairerImplTest,
|
||||
EXPECT_FALSE(device_->GetAccountKey().Ok());
|
||||
}
|
||||
|
||||
TEST_F(FastPairPairerImplTest,
|
||||
SuccessPairingWithDeviceButFailedToWriteAccountkeyToFootprints) {
|
||||
auto repository = std::make_unique<FakeFastPairRepository>();
|
||||
repository->SetResultOfWriteAccountAssociationToFootprints(
|
||||
absl::InternalError("Failed to write account key to foot prints"));
|
||||
ConfigurePairingContext();
|
||||
SetPairingResult(std::nullopt);
|
||||
CreateMockDevice(DeviceFastPairVersion::kHigherThanV1,
|
||||
Protocol::kFastPairInitialPairing);
|
||||
SetupProviderGattServer();
|
||||
SetNotifyResponse(*key_based_characteristic_, kKeyBasedResponse);
|
||||
SetNotifyResponse(*passkey_characteristic_, kPasskeyResponse);
|
||||
SetDecryptedResponse();
|
||||
SetDecryptedPasskey();
|
||||
CreateFastPairHandshakeInstanceForDevice();
|
||||
|
||||
CountDownLatch paired_latch(1);
|
||||
CountDownLatch account_failure_latch(1);
|
||||
|
||||
EXPECT_FALSE(device_->GetAccountKey().Ok());
|
||||
fast_pair_pairer_ = FastPairPairerImpl::Factory::Create(
|
||||
*device_, *mediums_, &executor_,
|
||||
[&](FastPairDevice& cb_device) { paired_latch.CountDown(); },
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
FAIL() << "Unexpected pairing failure " << failure;
|
||||
},
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
EXPECT_EQ(failure, PairFailure::kWriteAccountKeyToFootprints);
|
||||
account_failure_latch.CountDown();
|
||||
},
|
||||
[&](FastPairDevice& device) { FAIL() << "Unexpected callback"; });
|
||||
fast_pair_pairer_->StartPairing();
|
||||
|
||||
paired_latch.Await();
|
||||
account_failure_latch.Await();
|
||||
EXPECT_TRUE(fast_pair_pairer_->IsPaired());
|
||||
EXPECT_TRUE(device_->GetAccountKey().Ok());
|
||||
}
|
||||
|
||||
TEST_F(FastPairPairerImplTest, TestCancelPairing) {
|
||||
ConfigurePairingContext();
|
||||
SetPairingResult(std::nullopt);
|
||||
@@ -823,29 +814,25 @@ TEST_F(FastPairPairerImplTest, TestCancelPairing) {
|
||||
CreateFastPairHandshakeInstanceForDevice();
|
||||
SetTryToCancelOngoingPairing(true);
|
||||
|
||||
CountDownLatch paired_latch(1);
|
||||
CountDownLatch complete_latch(1);
|
||||
CountDownLatch failure_latch(1);
|
||||
CountDownLatch account_failure_latch(1);
|
||||
|
||||
EXPECT_FALSE(device_->GetAccountKey().Ok());
|
||||
|
||||
fast_pair_pairer_ = FastPairPairerImpl::Factory::Create(
|
||||
*device_, *mediums_, &executor_,
|
||||
[&](FastPairDevice& cb_device) { paired_latch.CountDown(); },
|
||||
[&](FastPairDevice& cb_device) { FAIL() << "Unexpected callback"; },
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
EXPECT_EQ(failure, PairFailure::kPairingAndConnect);
|
||||
failure_latch.CountDown();
|
||||
},
|
||||
[&](FastPairDevice& device, PairFailure failure) {
|
||||
account_failure_latch.CountDown();
|
||||
FAIL() << "Unexpected pairing failure " << failure;
|
||||
},
|
||||
[&](FastPairDevice& device) { complete_latch.CountDown(); });
|
||||
[&](FastPairDevice& device) { FAIL() << "Unexpected callback"; });
|
||||
fast_pair_pairer_->StartPairing();
|
||||
EXPECT_FALSE(paired_latch.Await(kWaitTimeout).result());
|
||||
|
||||
failure_latch.Await();
|
||||
EXPECT_FALSE(account_failure_latch.Await(kWaitTimeout).result());
|
||||
EXPECT_FALSE(complete_latch.Await(kWaitTimeout).result());
|
||||
|
||||
EXPECT_FALSE(device_->GetAccountKey().Ok());
|
||||
}
|
||||
} // namespace fastpair
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "fastpair/handshake/fast_pair_handshake_lookup.h"
|
||||
#include "fastpair/internal/mediums/mediums.h"
|
||||
#include "fastpair/proto/fastpair_rpcs.proto.h"
|
||||
#include "fastpair/repository/fake_fast_pair_repository.h"
|
||||
#include "internal/base/bluetooth_address.h"
|
||||
#include "internal/platform/ble_v2.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
@@ -427,6 +428,8 @@ TEST_F(PairerBrokerImplTest, SuccessInitialPairingWithDeviceV1) {
|
||||
}
|
||||
|
||||
TEST_F(PairerBrokerImplTest, SuccessInitialPairingWithDevice) {
|
||||
auto repository = std::make_unique<FakeFastPairRepository>();
|
||||
repository->SetResultOfWriteAccountAssociationToFootprints(absl::OkStatus());
|
||||
ConfigurePairingContext();
|
||||
SetPairingResult(std::nullopt);
|
||||
CreateMockDevice(DeviceFastPairVersion::kHigherThanV1,
|
||||
@@ -546,7 +549,7 @@ TEST_F(PairerBrokerImplTest, FaileToCreateHandshakeRetryThreeTimes) {
|
||||
PairFailure::kKeyBasedPairingResponseTimeout);
|
||||
}
|
||||
|
||||
TEST_F(PairerBrokerImplTest, FaileToWriteAccountkey) {
|
||||
TEST_F(PairerBrokerImplTest, FaileToWriteAccountkeyToRemoteDevice) {
|
||||
ConfigurePairingContext();
|
||||
SetPairingResult(std::nullopt);
|
||||
CreateMockDevice(DeviceFastPairVersion::kHigherThanV1,
|
||||
@@ -581,6 +584,43 @@ TEST_F(PairerBrokerImplTest, FaileToWriteAccountkey) {
|
||||
PairFailure::kAccountKeyCharacteristicWrite);
|
||||
}
|
||||
|
||||
TEST_F(PairerBrokerImplTest, FaileToWriteAccountkeyToFootprints) {
|
||||
auto repository = std::make_unique<FakeFastPairRepository>();
|
||||
repository->SetResultOfWriteAccountAssociationToFootprints(
|
||||
absl::InternalError("Failed to write account key to foot prints"));
|
||||
ConfigurePairingContext();
|
||||
SetPairingResult(std::nullopt);
|
||||
CreateMockDevice(DeviceFastPairVersion::kHigherThanV1,
|
||||
Protocol::kFastPairInitialPairing);
|
||||
SetupProviderGattServer();
|
||||
SetNotifyResponse(*key_based_characteristic_, kKeyBasedResponse);
|
||||
SetNotifyResponse(*passkey_characteristic_, kPasskeyResponse);
|
||||
SetDecryptedResponse();
|
||||
SetDecryptedPasskey();
|
||||
CreateFastPairHandshakeInstanceForDevice();
|
||||
|
||||
CountDownLatch device_paired_latch(1);
|
||||
CountDownLatch account_key_writed_latch(1);
|
||||
CountDownLatch pairing_completed_latch(1);
|
||||
CountDownLatch pairing_failure_latch(1);
|
||||
|
||||
EXPECT_FALSE(device_->GetAccountKey().Ok());
|
||||
|
||||
pairer_broker_ = std::make_unique<PairerBrokerImpl>(*mediums_, &executor_);
|
||||
PairerBrokerObserver pairer_broker_observer(
|
||||
pairer_broker_.get(), &device_paired_latch, &account_key_writed_latch,
|
||||
&pairing_completed_latch, &pairing_failure_latch);
|
||||
pairer_broker_->PairDevice(*device_);
|
||||
|
||||
device_paired_latch.Await();
|
||||
EXPECT_FALSE(pairing_completed_latch.Await(kWaitTimeout).result());
|
||||
account_key_writed_latch.Await();
|
||||
EXPECT_FALSE(pairing_failure_latch.Await(kWaitTimeout).result());
|
||||
EXPECT_TRUE(device_->GetAccountKey().Ok());
|
||||
EXPECT_EQ(pairer_broker_observer.account_key_failure_,
|
||||
PairFailure::kWriteAccountKeyToFootprints);
|
||||
}
|
||||
|
||||
TEST_F(PairerBrokerImplTest, FailToPairRetryThreeTimes) {
|
||||
ConfigurePairingContext();
|
||||
SetPairingResult(std::nullopt);
|
||||
|
||||
@@ -83,6 +83,7 @@ cc_library(
|
||||
"//fastpair/proto:fastpair_cc_proto",
|
||||
"//internal/platform:types",
|
||||
"@com_google_absl//absl/container:flat_hash_map",
|
||||
"@com_google_absl//absl/status",
|
||||
"@com_google_absl//absl/strings",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "fastpair/common/account_key.h"
|
||||
#include "fastpair/common/constant.h"
|
||||
#include "fastpair/common/fast_pair_device.h"
|
||||
#include "fastpair/proto/fastpair_rpcs.proto.h"
|
||||
|
||||
namespace nearby {
|
||||
@@ -45,6 +46,16 @@ void FakeFastPairRepository::SetResultOfCheckIfAssociatedWithCurrentAccount(
|
||||
model_id_ = std::move(model_id);
|
||||
}
|
||||
|
||||
void FakeFastPairRepository::SetResultOfWriteAccountAssociationToFootprints(
|
||||
absl::Status status) {
|
||||
write_account_association_to_footprints_ = status;
|
||||
}
|
||||
|
||||
void FakeFastPairRepository::SetResultOfDeleteAssociatedDeviceByAccountKey(
|
||||
absl::Status status) {
|
||||
deleted_associated_device_ = status;
|
||||
}
|
||||
|
||||
void FakeFastPairRepository::GetDeviceMetadata(
|
||||
absl::string_view hex_model_id, DeviceMetadataCallback callback) {
|
||||
executor_.Execute([this, callback = std::move(callback),
|
||||
@@ -57,6 +68,20 @@ void FakeFastPairRepository::GetDeviceMetadata(
|
||||
});
|
||||
}
|
||||
|
||||
void FakeFastPairRepository::WriteAccountAssociationToFootprints(
|
||||
FastPairDevice& device, OperationToFootprintsCallback callback) {
|
||||
executor_.Execute([callback = std::move(callback), this]() mutable {
|
||||
callback(write_account_association_to_footprints_);
|
||||
});
|
||||
}
|
||||
|
||||
void FakeFastPairRepository::DeleteAssociatedDeviceByAccountKey(
|
||||
const AccountKey& account_key, OperationToFootprintsCallback callback) {
|
||||
executor_.Execute([callback = std::move(callback), this]() mutable {
|
||||
callback(deleted_associated_device_);
|
||||
});
|
||||
}
|
||||
|
||||
void FakeFastPairRepository::CheckIfAssociatedWithCurrentAccount(
|
||||
AccountKeyFilter& account_key_filter, CheckAccountKeysCallback callback) {
|
||||
executor_.Execute([this, callback = std::move(callback)]() mutable {
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "fastpair/common/account_key.h"
|
||||
#include "fastpair/common/device_metadata.h"
|
||||
@@ -40,7 +41,8 @@ class FakeFastPairRepository : public FastPairRepository {
|
||||
|
||||
void SetFakeMetadata(absl::string_view hex_model_id, proto::Device metadata);
|
||||
void ClearFakeMetadata(absl::string_view hex_model_id);
|
||||
|
||||
void SetResultOfWriteAccountAssociationToFootprints(absl::Status status);
|
||||
void SetResultOfDeleteAssociatedDeviceByAccountKey(absl::Status status);
|
||||
void SetResultOfCheckIfAssociatedWithCurrentAccount(
|
||||
std::optional<AccountKey> account_key,
|
||||
std::optional<absl::string_view> model_id);
|
||||
@@ -55,12 +57,11 @@ class FakeFastPairRepository : public FastPairRepository {
|
||||
void GetUserSavedDevices() override{};
|
||||
|
||||
void WriteAccountAssociationToFootprints(
|
||||
FastPairDevice& device,
|
||||
OperationToFootprintsCallback callback) override{};
|
||||
FastPairDevice& device, OperationToFootprintsCallback callback) override;
|
||||
|
||||
void DeleteAssociatedDeviceByAccountKey(
|
||||
const AccountKey& account_key,
|
||||
OperationToFootprintsCallback callback) override{};
|
||||
OperationToFootprintsCallback callback) override;
|
||||
|
||||
void CheckIfAssociatedWithCurrentAccount(
|
||||
AccountKeyFilter& account_key_filter,
|
||||
@@ -72,6 +73,10 @@ class FakeFastPairRepository : public FastPairRepository {
|
||||
// Results of CheckIfAssociatedWithCurrentAccount
|
||||
std::optional<AccountKey> account_key_;
|
||||
std::optional<absl::string_view> model_id_;
|
||||
// Results of WriteAccountAssociationToFootprints
|
||||
absl::Status write_account_association_to_footprints_;
|
||||
// Results of DeleteAssociatedDeviceByAccountKey
|
||||
absl::Status deleted_associated_device_;
|
||||
SingleThreadExecutor executor_;
|
||||
};
|
||||
} // namespace fastpair
|
||||
|
||||
Reference in New Issue
Block a user